﻿// JScript File

function showMenu(menuName) {
	var theMenuToShow = document.getElementById(menuName);
		theMenuToShow.style.display = "block";
		theMenuToShow.style.visibility = "visible";
}

function showSubMenu(menuName, parentName) {
	var theMenuToShow = document.getElementById(menuName);
	theMenuToShow.style.display = "block";
	theMenuToShow.style.visibility = "visible";
	var theParent = document.getElementById(parentName);
	theMenuToShow.style.top = theParent.offsetTop + 34 + "px";
	var theIframe = document.getElementById('menuIframe2');
	theIframe.style.top = theParent.offsetTop + 34 + "px";
}

function setIframe(idx,xleft,items) {
	var theIframe = document.getElementById('menuIframe' + idx);
	var frameHeight = 24 * items;
	theIframe.style.display = "block";
	theIframe.style.visibility = "visible";
	theIframe.style.left = xleft;
	theIframe.height = frameHeight;
}

function closeMenu(menuName) {
	var theMenuToShow = document.getElementById(menuName);
		theMenuToShow.style.display = "none";
		theMenuToShow.style.visibility = "hidden";
}

function closeIframe(idx) {
	var theIframe = document.getElementById('menuIframe' + idx);
		theIframe.style.display = "none";
}

function menuStyleChange (ele) {
    
    ele.style.backgroundColor = "#dddddd";
	ele.style.cursor = "hand";
}

function menuStyleOrig (ele) {
    
    ele.style.backgroundColor = "#ffffff";
}

function CheckBrowserVersion() {

    var browser = navigator.appName;


    if (browser == 'Microsoft Internet Explorer') {

        if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
            version = new Number(RegExp.$1) // capture x.x portion and store as a number

            if (version < 7) {
                alert('WARNING: Your browser version is too old and is not compatible with this site. This site is optimized for Internet Explorer 7.0 or higher. To use the features available on this site, please upgrade your browser to Internet Explorer 7.0 or higher.');
                return false;
            }
            else return true;
        }
    }
    else if (browser == 'Netscape') {


        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
            version = new Number(RegExp.$1) // capture x.x portion and store as a number

            if (version < 3) {
                alert('WARNING: Your browser version is too old and is not compatible with this site. This site is optimized for FireFox 3.0 or higher. To use the features available on this site, please upgrade your browser to Internet Explorer 7.0 or higher.');
                return false;
            }
            else return true;
        }
        //for chrome 
        else return true;

    }
    //other browsers
    else return true;


}


function gotoLink(link) {
    var str = link;


    if ((str.substring(0, 4) == "/dtc") || (str == "/FARealEstate") || (str == "/FAConsumerPortal/spring/Login")) {

        var checkbrowser = CheckBrowserVersion();
        
        if (checkbrowser == true) {
            var host = document.location.hostname;

            if (host.substring(0, 16) == "homewarrantytest") {
                //code required for testing purposes
                link = "https://" + host + link;
            }
            else {
                if (host.substring(0, 4) == "www.")
                    host = host.substring(4);
                link = "https:" + "//" + host + link;
            }
            document.location.href = link;
        }
    }
    else {
        document.location.href = link;
    } 
    
}

function gotoRELink(link) {
    var str = link;
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) 
    {
        if ((str == "/FARealEstate")) {
            var host = document.location.hostname;

            if (host.substring(0, 16) == "homewarrantytest") {
                //code required for testing purposes
                link = "https://" + host + link;
            }
            else {
                if (host.substring(0, 4) == "www.")
                    host = host.substring(4);
                link = "https:" + "//" + host + link;
            }
            document.location.href = link;
        }
    }
}

//added by skoka to prefix https
function prefixProtocol() {
    window.open("http://www.fanhd.com");
}


//added by skoka for secure DTC link
function gotosecureDTCLink() {
    var host = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) {
        if (host.substring(0, 16) == "homewarrantytest") {
            document.location.href = "https:" + "//" + document.location.hostname + '/dtc/spring/Client-flow?wm=fa-dtc-web-webui&wn=DTCTask&vm=fa-dtc-web-webui&vn=DTCTask';
        }
        else {
            if (host.substring(0, 4) == "www.")
                host = host.substring(4);
            document.location.href = "https:" + "//" + host + '/dtc/spring/Client-flow?wm=fa-dtc-web-webui&wn=DTCTask&vm=fa-dtc-web-webui&vn=DTCTask';
        }
    }
}

//added by skoka for secure RE link
function gotosecureRELink() {
    var host = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) {
        if (host.substring(0, 16) == "homewarrantytest") {
            document.location.href = "https:" + "//" + document.location.hostname + '/FARealEstate';
        }
        else {
            if (host.substring(0, 4) == "www.")
                host = host.substring(4);

            document.location.href = "https:" + "//" + host + '/FARealEstate';
        }
    }
}

//added by skoka for secure consumer link 06152010
function gotosecureConsumerLink() {
    var host = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) {

        if (host.substring(0, 16) == "homewarrantytest") {
            document.location.href = "https:" + "//" + document.location.hostname + '/FAConsumerPortal/spring/Login';
        }
        else {
            if (host.substring(0, 4) == "www.")
                host = host.substring(4);

            document.location.href = "https:" + "//" + host + '/FAConsumerPortal/spring/Login';
        }
    }
}



//added by skoka for the register consumer link page
function GoToConsumerRegisterLink() {
    var host = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) {

        if (host.substring(0, 16) == "homewarrantytest") {
            document.location.href = "https:" + "//" + document.location.hostname + '/ChooseUser.aspx?RequestType=register';
        }
        else {
            if (host.substring(0, 4) == "www.")
                host = host.substring(4);

            document.location.href = "https:" + "//" + host + '/ChooseUser.aspx?RequestType=register';
        }
    }
}

//added by skoka for secure consumer link 06152010
function gotoRegisterConsumerLink() {
    var host = document.location.hostname;

    if (host.substring(0, 16) == "homewarrantytest") {
        document.location.href = "https:" + "//" + document.location.hostname + '/FAConsumerPortal/spring/Client-flow?wm=fa-hp-web-webui&wn=ConsumerRegistration&vm=fa-hp-web-webui&vn=ConsumerRegistration';
    }
    else {
        if (host.substring(0, 4) == "www.")
            host = host.substring(4);

        document.location.href = "https:" + "//" + host + '/FAConsumerPortal/spring/Client-flow?wm=fa-hp-web-webui&wn=ConsumerRegistration&vm=fa-hp-web-webui&vn=ConsumerRegistration';
    }
}

function popupLink (link) {
	window.open(link);
}

//added by skoka for secure REUserReg link
function gotosecureREUserRegLink() {
    var host = document.location.hostname;
    if (host.substring(0, 16) == "homewarrantytest") {
        document.location.href = "https:" + "//" + document.location.hostname + '/FARealEstate/spring/Client-flow?wm=fa-re-web-webui&amp;wn=UserRegistration&amp;vm=fa-re-web-webui&amp;vn=ResetPassword';
    }
    else {
        if (host.substring(0, 4) == "www.")
            host = host.substring(4);
        document.location.href = "https:" + "//" + host + '/FARealEstate/spring/Client-flow?wm=fa-re-web-webui&amp;wn=UserRegistration&amp;vm=fa-re-web-webui&amp;vn=ResetPassword';
    }
}

//for contractor portal 1/14/2010
//added by skoka for secure ContractorUserReg link
function gotosecureContractorUserRegLink() {
    var host = document.location.hostname;

    if (host.substring(0, 16) == "homewarrantytest") {
        //for testing purpose only
        document.location.href = "https:" + "//" + document.location.hostname + '/ContractorPortal/spring/Client-flow?wm=fa-cp-web-webui&wn=UserRegistration&vm=fa-cp-web-webui&vn=ResetPassword';
    }
    else {
    //for production
        if (host.substring(0, 4) == "www.")
            host = host.substring(4);
        document.location.href = "https:" + "//" + host + '/FAContractorPortal/spring/Client-flow?wm=fa-cp-web-webui&wn=UserRegistration&vm=fa-cp-web-webui&vn=ResetPassword';
    }

}

function CheckBrowserVersionAndRedirect(sUserVal, sPasswordVal) {
    var checkbrowser = CheckBrowserVersion();

    if (checkbrowser == true) {
        if (CheckText(sUserVal, false, "User Id") && CheckText(sPasswordVal, false, "Password")) {
            return true;
        }
    }
}


function CheckText(theField, isEmptyOK, fieldName) {
    var checkStr;

    checkStr = theField.value;
    if (isEmptyOK && isEmpty(checkStr))
        return true;

    if (isWhitespace(checkStr)) {
        WarnInvalid(theField, fieldName);
        return false;
    }

    return true;
}

function WarnInvalid(theField, fieldName) {
    Warn(theField, "Please enter a valid " + fieldName);
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isWhitespace(s) {
    var whitespace = " \t\n\r";
    var i;

    if (isEmpty(s))
        return true;

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1)
            return false;
    }

    return true;
}

function Warn(theField, s) {
    alert(s);
    theField.focus();
}


