﻿// 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.fontWeight = "bold";
    ele.style.backgroundColor = "#dddddd";
	ele.style.cursor = "hand";
}

function menuStyleOrig (ele) {
    //ele.style.fontWeight = "normal";
    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 Firefox®  3.0 or higher.');
                return false;
            }
            else return true;
        }
        else return true;

    }
    else return true;
}

function gotoLink (link) {
   var str = link;
   var docloc = document.location.hostname;

   if (str.substring(0, 3) == "../") {
       str = str.substring(3);
   }

    //change for HTTPS
   if ((str.substring(0, 4) == "home") || (str.substring(0, 4) == "real") || (str.substring(0, 4) == "serv") || (str == "/ALRealEstate")
        || (str == "/ALConsumerPortal/spring/Login")) {


       if ((str == "/ALRealEstate") || (str == "/ALConsumerPortal/spring/Login")) {
           var checkbrowser = CheckBrowserVersion();
           if (checkbrowser == true) {
               str = str.substring(1);
           }
           else return;
       }
       if (docloc.substring(0, 14) == "alliancehwtest") {
           //code required for testing purposes
           link = "https://" + docloc + "/" + str;
       }
       else {
           if (docloc.substring(0, 3) == 'www')
               link = "https://" + docloc + "/" + str;
           else
               link = "https://www." + docloc + "/" + str;
       }
       document.location.href = link;
   }
   else {
       document.location.href = link;
   } 
   
    
}

function gotoRELink(link) {
    var str = link;
    var docloc = document.location.hostname;
    
      if (str.substring(0, 3) == "../") {
       str = str.substring(3);
   }
   
   var checkbrowser = CheckBrowserVersion();
   if (checkbrowser == true) {
   
       //change for HTTPS
       if ((str == "/ALRealEstate")) {



           if (docloc.substring(0, 14) == "alliancehwtest") {
               //code required for testing purposes
               link = "https://" + docloc + link;
           }
           else {
               if (docloc.substring(0, 3) == 'www')
                   link = "https://" + docloc + link;
               else
                   link = "https://www." + docloc + link;
           }
       }
       document.location.href = link;
   }
}

//added by skoka for secure RE link
function gotosecureRELink() {
    var docloc = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();
    if (checkbrowser == true) {

        if (docloc.substring(0, 14) == "alliancehwtest") {
            //code required for testing purposes
            document.location.href = "https://" + docloc + '/ALRealEstate';
        }
        else {
            //for production
            if (docloc.substring(0, 3) == 'www')
                document.location.href = "https://" + docloc + '/ALRealEstate';
            else
                document.location.href = "https://www." + docloc + '/ALRealEstate';
        }
    }
}


//added by skoka for secure consumer portal link 06 14 2010
function gotosecureConsumerLink() {
    var docloc = document.location.hostname;
   var checkbrowser = CheckBrowserVersion();
   if (checkbrowser == true) 
   {

    if (docloc.substring(0, 14) == "alliancehwtest") {
        //code required for testing purposes
        document.location.href = "https://" + docloc + '/ALConsumerPortal';
    }
    else {
        //for production
        if (docloc.substring(0, 3) == 'www')
            document.location.href = "https://" + docloc + '/ALConsumerPortal';
        else
            document.location.href = "https://www." + docloc + '/ALConsumerPortal';
    }
   }
}


//added by skoka for secure consumer portal register link 07272010
function GoToConsumerRegisterLink() {
    var docloc = document.location.hostname;
    var checkbrowser = CheckBrowserVersion();
    if (checkbrowser == true) {

        if (docloc.substring(0, 14) == "alliancehwtest") {
            //code required for testing purposes
            document.location.href = "https://" + docloc + '/ChooseUser.aspx?RequestType=register';
        }
        else {
            //for production
            if (docloc.substring(0, 3) == 'www')
                document.location.href = "https://" + docloc + '/ChooseUser.aspx?RequestType=register';
            else
                document.location.href = "https://www." + docloc + '/ChooseUser.aspx?RequestType=register';
        }
    }
}

function gotosecureREpage() {
    document.location.href = "https://" + document.location.hostname + 'realtor.aspx';
}

function popupLink (link) {
	window.open(link);
}

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();
 }

