//***************THE FOLLOWING FUNCTIONS ARE USED THROUGHOUT************
function openWin(url,windowName,options){
	var WindowHandle=window.open(url,windowName,options);
	WindowHandle.focus();
}

var ns6=document.getElementById&&!document.all
var ie=document.all

function showSpan(spanID,thetext){
	if (ie) eval("document.all."+spanID).innerHTML=thetext
	else if (ns6) document.getElementById(spanID).innerHTML=thetext
}
function hideSpan(spanID){
	if (ie) eval("document.all."+spanID).innerHTML=' '
	else if (ns6) document.getElementById(spanID).innerHTML=' '
}

function getElementBy(elemTag){
	var elem = document.getElementById (elemTag);
	if (elem)
		return elem;
	var elems = document.getElementsByName (elemTag);
	if (elems.length > 0)
		return elems[0];
	return null;
}

function toggleOpenCloseElem(elemName){
	var elem = getElementBy (elemName);
	if (!elem)
		return;
	if (elem.style.display == "")
		elem.style.display = "none";
	else
		elem.style.display = "";
}
//***************THE ABOVE FUNCTION IS USED THROUGHOUT************



//***************THE FOLLOWING FUNCTION IS USED FOR FORM VALIDATION************
function confirmPrompt(msg,url){
	if(confirm(msg)) 
		document.location = url;
}

function validateLength(objTB,maxChar){
	if (objTB.value.length > maxChar){return false;}
	return true;
}

function validateEmail(objTB){
	var invalidChars = "*|,\":<> []{}`\';()&$#%";
	if (objTB.value.indexOf('@') < 0 || objTB.value.indexOf('.') < 0 || objTB.value.length < 5){return false;}
	for (var i = 0; i < objTB.value.length; i++){
	   if (invalidChars.indexOf(objTB.value.charAt(i)) != -1){return false;}
	}
	return true;
} 

function validateEmailNonReq(objTB){
	var invalidChars = "*|,\":<> []{}`\';()&$#%";
	if (objTB.value.length > 0){
		if (objTB.value.indexOf('@') < 0 || objTB.value.indexOf('.') < 0 || objTB.value.length < 5){return false;}
		for (var i = 0; i < objTB.value.length; i++){
		   if (invalidChars.indexOf(objTB.value.charAt(i)) != -1){return false;}
		}
		return true;
	}
	return true;
} 

function validateTextBox(objTB){
	if (objTB.value==''){return false;}
	return true;
}

function validateSelectList(objTB){
	if (objTB.selectedIndex==''){return false;}
	return true;
}

function validateNumberTextBoxNonReq(objTB){
	if (isNaN(objTB.value)){return false;}
	return true;
}

function validateNumberTextBox(objTB){
	if (objTB.value=='' || isNaN(objTB.value)){return false;}
	return true;
}

function restrictNumberKeys(e){
		/*
		Description: This function restricts an input box to only accept numerics, dashes,
					 parentheses and spaces.
		Usage:
			<input onKeyPress="return restrictNumberKeys(event);">
		Known Browser Support: MSIE 6.0, FireFox 1.0.4, Safari 2.0
		*/
		var keyCode;
		
		
		if(window.event) //MSIE
			keyCode = e.keyCode;
		else //FireFox
			keyCode = e.which;

        if(keyCode >= 48 && keyCode <= 57 //Numeric Digits 0-9
			|| (keyCode == 8) //Backspace
			|| (keyCode == 0) //keys like Enter and Delete will return zero
			|| (keyCode == 99 && e.ctrlKey) // Ctrl-C
			|| (keyCode == 118 && e.ctrlKey) // Ctrl-V
			|| (keyCode == 44) // comma
			)
			return true;
		else
			return false;
	}
//***************THE ABOVE FUNCTION IS USED FOR FORM VALIDATION************



//***************THE FOLLOWING FUNCTIONS ARE USED BY THE PROPERTY COMPARE FEATURE************
var thecookie = document.cookie;

function getCookie(name) { // use: getCookie("name");
	var index = thecookie.indexOf(name + "=");
	if (index == -1) return null;
	index = thecookie.indexOf("=", index) + 1; // first character
	var endstr = thecookie.indexOf(";", index);
	if (endstr == -1) endstr = thecookie.length; // last character
	return unescape(thecookie.substring(index, endstr));
}

function setCookie(name, value) { // use: setCookie("name", value);
    document.cookie=name + "=" + escape(value) + ";";
}

function commitCompareList(){		
	setCookie("VAR_CompareList",GLOBAL_CompareList);
	setCookie("CompareCount",GLOBAL_CompareCount);
}		

function sendToCompare(){
	if (GLOBAL_CompareCount < 2){
		alert('Please check more than 1 property!');
	}else{
		if (GLOBAL_CompareCount > 4){
			alert('Please check no more than 4 properties!');
		}else{
			window.location = "/property/propertycompare.asp?VAR_CompareList=" + GLOBAL_CompareList + "&CompareCount=" + GLOBAL_CompareCount;
		}
	}
}
		
function compareClear(){
	GLOBAL_CompareList = "";
	GLOBAL_CompareCount = 0;		
	setCookie("VAR_CompareList","");
	setCookie("CompareCount","");
}

function addCompare(obj){
	//the maximum number of listings a user can check to compare
	var Max_Number_Properties = 4;
	
	if (obj.checked == true) 
	{
		if (GLOBAL_CompareCount == Max_Number_Properties) {			
			obj.checked = false;
			alert('You have already chosen ' + Max_Number_Properties + ' properties!');
		}
		else {
			GLOBAL_CompareList = GLOBAL_CompareList + obj.value;
			GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) + 1;
		}
	}	
	else 
	{
		GLOBAL_CompareCount = parseInt(GLOBAL_CompareCount) - 1
		GLOBAL_CompareList = GLOBAL_CompareList.replace(obj.value,"");
	}
}
//***************THE ABOVE FUNCTIONS ARE USED BY THE COMPARE TOOL************




//***********THE BELOW SCRIPT IS FOR THE IMAGE MOUSEOVERS**************

icona = new Image()   
icona.src = "/images/icon1a.gif"  

iconb = new Image()
iconb.src = "/images/icon1.gif"

iconc = new Image()   
iconc.src = "/images/icon2a.gif"  

icond = new Image()
icond.src = "/images/icon2.gif"

icone = new Image()   
icone.src = "/images/icon3a.gif"  

iconf = new Image()
iconf.src = "/images/icon3.gif"

icong = new Image()   
icong.src = "/images/icon4a.gif"  

iconh = new Image()
iconh.src = "/images/icon4.gif"

iconi = new Image()   
iconi.src = "/images/icon5a.gif"  

iconj = new Image()
iconj.src = "/images/icon5.gif"

iconk = new Image()   
iconk.src = "/images/icon6a.gif"  

iconl = new Image()
iconl.src = "/images/icon6.gif"

iconm = new Image()   
iconm.src = "/images/icon7a.gif"  

iconn = new Image()
iconn.src = "/images/icon7.gif"

icono = new Image()   
icono.src = "/images/icon16a.gif"  

iconp = new Image()
iconp.src = "/images/icon16.gif"


iconq = new Image()   
iconq.src = "/images/box_openhouse_on.gif"  

iconr = new Image()
iconr.src = "/images/box_openhouse.gif"

icons = new Image()   
icons.src = "/images/box_career_on.gif"  

icont = new Image()
icont.src = "/images/box_career.gif"

iconu = new Image()   
iconu.src = "/images/box_nla_on.gif"  

iconv = new Image()
iconv.src = "/images/box_nla.gif"

iconw = new Image()   
iconw.src = "/images/box_luxury_on.gif"  

iconx = new Image()
iconx.src = "/images/box_luxury.gif"

icony = new Image()   
icony.src = "/images/box_concierge_on.gif"  

iconz = new Image()
iconz.src = "/images/box_concierge.gif"

iconaa = new Image()   
iconaa.src = "/images/box_list_on.gif"  

iconbb = new Image()
iconbb.src = "/images/box_list.gif"

iconcc = new Image()   
iconcc.src = "/images/box_latestnews_on.gif"  

icondd = new Image()
icondd.src = "/images/box_latestnews.gif"


iconee = new Image()   
iconee.src = "/images/icon17a.gif"  

iconff = new Image()
iconff.src = "/images/icon17.gif"

iconww = new Image()   
iconww.src = "/images/box_magazine_on.gif"  

iconxx = new Image()
iconxx.src = "/images/box_magazine.gif"

iconaaa = new Image()   
iconaaa.src = "/images/box_propman_on.gif"  

iconbbb = new Image()
iconbbb.src = "/images/box_propman.gif"


function imageChange(imgName,imgSrc){
document.images[imgName].src = eval(imgSrc +".src")
}

//***********THE ABOVE SCRIPT IS FOR THE IMAGE MOUSEOVERS**************
	

/*
Note that this tries several methods of creating the XmlHttpRequest object,
depending on the browser in use. Also note that as of this writing, the
Opera browser does not support the XmlHttpRequest.
*/
function XMLHTTPRequest_createRequester()
{
	var myRequest;
    try{
        myRequest = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            myRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(oc){
            myRequest = null;
        }
    }

    if(!myRequest && typeof XMLHttpRequest != "undefined"){
        myRequest = new XMLHttpRequest();
    }

    return myRequest;
}