﻿// 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 gotoLink (link) {
   
    var str = link;
    //var checkbrowser = CheckBrowserVersion();

    //if (checkbrowser == true) {

        if ((str.substring(1, 4) == "dtc") || (str == "/FARealEstate")) {
            //link = "http:" + "//" + document.location.hostname + link;
            var host = document.location.hostname;

            if (host.substring(0, 4) == "www.")
                host = host.substring(4);
            link = "https:" + "//" + host + link;
        }
        //alert(link);
        document.location.href = link;
    //}
}

function gotoRELink(link) {

    var str = link;
   // var checkbrowser = CheckBrowserVersion();

    //if (checkbrowser == true) {

        if ((str.substring(1, 4) == "dtc") || (str == "/FARealEstate")) {
            //link = "http:" + "//" + document.location.hostname + link;
            var host = document.location.hostname;

            if (host.substring(0, 4) == "www.")
                host = host.substring(4);
            link = "https:" + "//" + host + link;
        }
        //alert(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;
    //alert(document.location.hostname);
    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';
    //alert(document.location.href);
    //document.location.href = "http:" + "//" + document.location.hostname + '/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;

       //alert(document.location.hostname);
       if (host.substring(0, 4) == "www.")
           host = host.substring(4);
       document.location.href = "https:" + "//" + host + '/FARealEstate';
       //alert(document.location.href);
       //document.location.href = "http:" + "//" + document.location.hostname + '/FARealEstate';
}

//added by skoka for secure REUserReg link
function gotosecureREUserRegLink() {
   var host = document.location.hostname;
//    
//    var checkbrowser = CheckBrowserVersion();

//    if (checkbrowser == true) {

        //alert(document.location.hostname);
        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';
        // alert(document.location.href);
        //document.location.href = "http:" + "//" + document.location.hostname + '/FARealEstate/spring/Client-flow?wm=fa-re-web-webui&amp;wn=UserRegistration&amp;vm=fa-re-web-webui&amp;vn=ResetPassword';
//    }
}


function popupLink (link) {
	window.open(link);
}

function CheckBrowserVersionAndRedirect(sUserVal, sPasswordVal) {
    if (CheckText(sUserVal, false, "User Id") && CheckText(sPasswordVal, false, "Password")) {

        //to uncomment for production
        document.forms[0].action = 'https:' + '//' + document.location.hostname + '/FARealEstate/spring/loginProcess;';
        //for test only
        //document.forms[0].action = 'http:' + '//' + document.location.hostname + '/FARealEstate/spring/loginProcess;';
    }
}



function CheckAndRedirectAfterKeyPress(sUserVal, sPasswordVal) {

    if (window.event.keyCode == 13) 
    {
        if (CheckText(sUserVal, false, "User Id") && CheckText(sPasswordVal, false, "Password")) {

            document.forms[0].action = 'https:' + '//' + document.location.hostname + '/FARealEstate/spring/loginProcess;';
             //for test only - below code
            //document.forms[0].action = 'http:' + '//' + document.location.hostname + '/FARealEstate/spring/loginProcess;';
            document.forms[0].submit();
        }
    }
}

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: This site is optimized for Internet Explorer 7.0 or higher. To use the features available in ‘Order A Warranty’, 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: This site is optimized for Firefox®  3.0 or higher. To use the features available in ‘Order A Warranty’, please upgrade your browser to Firefox®  3.0 or higher.');
                return false;
            }
            else return true;
        }
        //for chrome 
        else return true;

    }
    //other browsers
    else return true;


}

//for contractor portal 1/14/2010
//added by skoka for secure ContractorUserReg link
function gotosecureContractorUserRegLink() {
    var host = document.location.hostname;
    
    
    if (host.substring(0, 4) == "www.")
        host = host.substring(4);
       //to uncomment this for production
    document.location.href = "https:" + "//" + host + '/ContractorPortal/spring/Client-flow?wm=fa-cp-web-webui&wn=UserRegistration&vm=fa-cp-web-webui&vn=ResetPassword';
    
    //for testing purpose only
    //document.location.href = "http:" + "//" + document.location.hostname + '/FAContractorPortal/spring/Client-flow?wm=fa-cp-web-webui&wn=UserRegistration&vm=fa-cp-web-webui&vn=ResetPassword';
    //    }
}


//for contractor portal 1/14/2010
function CheckBrowserVersionAndRedirectToContractor(sUserVal,sPasswordVal) {

  if (CheckText(sUserVal,false,"User Id") && CheckText(sPasswordVal,false,"Password"))
  {
    //to uncomment for production
    document.forms[0].action = 'https:' + '//' + document.location.hostname + '/ContractorPortal/spring/loginProcess;';

    //for test only- below code
    //document.forms[0].action = 'http:' + '//' + document.location.hostname + '/FAContractorPortal/spring/loginProcess;';
  }

}

//for contractor portal 1/14/2010
function CheckAndRedirectToContractorAfterKeyPress(sUserVal, sPasswordVal) {
    if (window.event.keyCode == 13) {
        if (CheckText(sUserVal, false, "User Id") && CheckText(sPasswordVal, false, "Password")) {
            //to be uncommented for production
            document.forms[0].action = 'https:' + '//' + document.location.hostname + '/ContractorPortal/spring/loginProcess;';

            //for testing only
            //document.forms[0].action = 'http:' + '//' + document.location.hostname + '/FAContractorPortal/spring/loginProcess;';

            document.forms[0].submit();
        }
    }
}

//added by skoka for secure contractor link 1/14/2010
function gotosecurecontractorLink(sUserVal, sPasswordVal) {

    var host = document.location.hostname;
    //if (CheckText(sUserVal, false, "User Id") && CheckText(sPasswordVal, false, "Password")) {
        if (host.substring(0, 4) == "www.")
            host = host.substring(4);
        //to uncomment the below line for production
        document.location.href = "https:" + "//" + host + '/ContractorPortal';
        //alert(document.location.href);
        //document.location.href = "http:" + "//" + document.location.hostname + '/FAContractorPortal';
    //}
}




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();
}