


function TopNavRollover (ImgId) {
		
	var ThisCell = null;
	if (document.getElementById) {
		ThisCell = document.getElementById ('TopNav' + ImgId);
				
	}
	else if(document.all){
		ThisCell = document.all['TopNav' + ImgId];
	}
	if (ThisCell == null) {
		return false;
	}
			
	if (ThisCell.className=="SiteTopNav"){
		ThisCell.className="SiteTopNavActive";
	}
	else{
		ThisCell.className="SiteTopNav";
	}
	return true;
}

function LoadImage(src) {
	if (document.images) {
		var NewImg = new Image();
		NewImg.src = src;
		return src;
	}
}


function PatchHomePageTable () {
 // Start: Home Page Init //
 if (document.all) {
	if (document.all.SearchRow2 && document.all.BottomLeftCell && document.all.BottomRightCell && document.all.AgentSearchTable && document.all.MortgageSearchTable ){
		if (document.all.BottomRightCell.offsetHeight>document.all.BottomLeftCell.offsetHeight){
			document.all.AgentSearchTable.height=document.all.SearchRow2.offsetHeight-2;
		}else{
			document.all.MortgageSearchTable.height=document.all.SearchRow2.offsetHeight-2;
		}
	}
 }
 else if (document.getElementById) {
	if (document.getElementById ("SearchRow2") && document.getElementById ("BottomLeftCell") && document.getElementById ("BottomRightCell")&& document.getElementById("MortgageSearchTable")  && document.getElementById("AgentSearchTable") ){
		if (document.getElementById("BottomRightCell").offsetHeight>document.getElementById("BottomLeftCell").offsetHeight){
			document.getElementById("AgentSearchTable").style.height=document.getElementById("SearchRow2").offsetHeight-2;
		}else{
			document.getElementById("MortgageSearchTable").style.height=document.getElementById("SearchRow2").offsetHeight-2;
		}
	}
 }
 // End: Home Page Init //
}


function ChangeLanguage( strServerName,strScriptName,strQString,lid) 
	{
		window.location.href = eval("'http://" + strServerName + strScriptName + "?_lid=" + lid + "&" + strQString.replace("_lid=","_!lid=") + "'")
		return;
	}
	
function fnClearInnerHTML(elemId) {
		
	var ThisElem = null;
	if (document.getElementById) {
		ThisElem = document.getElementById (elemId);
				
	}
	else if (document.all){
		ThisElem = document.all[elemId];
	}
	if (ThisElem == null) {
		return false;
	}
			
	ThisElem.innerHTML="";
	return true;
}

function fnWriteInnerHTML(elemId,strHTML) {
		
	var ThisElem = null;
	if (document.getElementById) {
		ThisElem = document.getElementById (elemId);
				
	}
	else if (document.all){
		ThisElem = document.all[elemId];
	}
	if (ThisElem == null || strHTML==null) {
		return false;
	}
			
	ThisElem.innerHTML=strHTML.toString();
	return true;
}

function fnHideElem(elemId,blnDisplay) {
		
	var ThisElem = null;
	if (document.getElementById) {
		ThisElem = document.getElementById (elemId);
				
	}
	else if(document.all){
		ThisElem = document.all[elemId];
	}
	if (ThisElem == null) {
		return false;
	}
			
	ThisElem.style.visibility="hidden";
	if (!blnDisplay)ThisElem.style.display="none";
	return true;
}

function fnShowElem(elemId) {
		
	var ThisElem = null;
	if (document.getElementById) {
		ThisElem = document.getElementById (elemId);
				
	}
	else if(document.all){
		ThisElem = document.all[elemId];
	}
	if (ThisElem == null) {
		return false;
	}
			
	ThisElem.style.visibility="visible";
	ThisElem.style.display="block";
	return true;
}

function fnCheckInteger(input,msg) {
	
	var sStr = input.value;
	if (!sStr.length) return true;
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if (ch < "0" || ch > "9") {
			input.focus();
			if (msg!="")alert(msg);
			return false;
		}
	}
	return true;
}
function fnCheckCurrency(input,msg) {
	//var msg = "<%if lid = 1 then %>ˇHa especificado un valor monetario inválido!<%else%>You have specified an invalid currency value!<%end if%>";
	var sStr = input.value;
	if (!sStr.length) return true;
	if (sStr.length > 14) {
		input.focus();
		alert(msg);
		return false;
	}
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if ((ch < "0" || ch > "9") && ch != '.' && ch != ",") {
			input.focus();
			alert(msg);
			return false;
		}
	}
	return true;
}
function fnValidYear(input,msg) {
	var tm = new Date();
	var sStr = input.value
	if (!sStr.length)
		return true;
	if (!fnCheckInteger(input,'You have specified a non-numeric value!'))
		return false;
	if (input.value < 1750 || input.value > (1900 + tm.getYear() + 1)) {
		input.focus();
		alert(msg);
		return false;
	}
	return true;
}
function fnCheckDecimal(input,msg) {
	//var msg = "<%if lid = 1 then %>ˇHa especificado un valor que no es numérico!<%else%>You have specified a non-numeric value!<%end if%>";
	var sStr = input.value;
	if (!sStr.length)
		return true;
	// Catch errors that isNan() misses, such as:  "8 8" (causes errors later)
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if ((ch < "0" || ch > "9") && ch != '.' && ch != ",") {
			input.focus();
			alert(msg);
			return false;
		}
	}
	// isNaN() catches invalid inputs like ",8.5"
	if (isNaN(parseFloat(sStr))) {
			input.focus();
			alert(msg);
			return false;
	}
	input.value = parseFloat(sStr);  // prevent any other misunderstandings that can occur.
	return true;
}
function fnCheckBlank(input,msg) {
	//var msg = "<%if lid = 1 then %>ˇNo ha especificado un valor válido!<%else%>Input cannot be blank!<%end if%>";
	var sStr = input.value;
	for ( var i = 0 ; i < sStr.length ; i++ ) {
		var ch = sStr.substring( i, i + 1);
		if (ch != ' ') {
			return true;  // good, the input is not blank/empty
		}
	}
	input.focus();
	alert(msg);
	return false;
}
function fnCheckForInvalidCharacters(input){
//the search string can only contain numbers, upper or lowercase letters, spaces, or a comma
//the function returns true if any invalid character are present
	input = input.toUpperCase()
	for (var i=0 ; i < input.length; i++){
		asciiNum = input.charCodeAt(i)
		if  (asciiNum < 32 || (asciiNum>32 && asciiNum < 44) || (asciiNum > 45 && asciiNum < 48) || (asciiNum > 57 && asciiNum < 65) || (asciiNum > 90 && asciiNum < 95) || asciiNum > 95) {
			return true
		}
	}
	return false				
}

function runMySearch(form,strQS,err_msg){
	if (form){
		if(strQS!=""){
			location.href=form.action + "?" + strQS
		}else{
			alert(err_msg)
		}
	}
}
//new utility function
document.getElementsByClassName = function ( class_name ) {
    var all_obj, ret_obj = new Array(), j = 0, strict = 0;
    if ( document.getElementsByClassName.arguments.length > 1 )
        strict = ( document.getElementsByClassName.arguments[1] ? 1 : 0 );
    if ( document.all )
        all_obj = document.all;
    else if ( document.getElementsByTagName && !document.all )
        all_obj = document.getElementsByTagName ( "*" );
    for ( i = 0; i < all_obj.length; i++ ) {
        if ( ( ' ' + all_obj[i].getAttribute("class") + ' ').toLowerCase().match(
            new RegExp ( ( strict ? '^ ' + class_name.trim() + ' $' : 
                '^.* ' + class_name.trim() + ' .*$' ).toLowerCase(),'g' ) ) ) {
            ret_obj[j++] = all_obj[i];
        }
    }
    return ret_obj;
}

var arrRecentHiddenSelects
function fnHideAllSelectObjects()
{
	var arrLocal
	if (arguments.length<1){
		//Hide Selects in all forms of document
		for(var i = 0; i < document.forms.length; i++)
		{
			for(j = 0; j < document.forms[i].elements.length; j++)
			{		
				if (document.forms[i].elements[j].type == "select-one" || document.forms[i].elements[j].type == "select-multiple")
					
					if (document.forms[i].elements[j].style.visibility != "hidden"){
						if (arrRecentHiddenSelects==null){
							//arrRecentHiddenSelects=new Array(document.forms[i].elements[j])
						}else{
							arrLocal=new Array(document.forms[i].elements[j])
							//arrRecentHiddenSelects=arrRecentHiddenSelects.concat(arrLocal)
							arrLocal=null
						}
						document.forms[i].elements[j].style.visibility = "hidden";
					}
				
				
			}
		}
	}else{
		//Hide selects in Form Objects passed to function
		for(var i = 0; i < arguments.length; i++)
		{
			if (arguments[i].elements.length){
				//we have a form
				for(j = 0; j < arguments[i].elements.length; j++)
				{		
					if (arguments[i].elements[j].type == "select-one" || arguments[i].elements[j].type == "select-multiple"){
						if (arguments[i].elements[j].style.visibility != "hidden"){
							if (arrRecentHiddenSelects==null){
								arrRecentHiddenSelects=new Array(arguments[i].elements[j])
							}else{
								arrLocal=new Array(arguments[i].elements[j])
								arrRecentHiddenSelects=arrRecentHiddenSelects.concat(arrLocal)
								arrLocal=null
							}
							arguments[i].elements[j].style.visibility = "hidden";
						}
					}
				}
			}
		}
	}
}

function fnShowAllSelectObjects()
{
	if (arguments.length<1){
		//Show Selects in all forms of document
		for(var i = 0; i < document.forms.length; i++)
		{
			for(j = 0; j < document.forms[i].elements.length; j++)
			{		
				if (document.forms[i].elements[j].type == "select-one" || document.forms[i].elements[j].type == "select-multiple")
								document.forms[i].elements[j].style.visibility = "visible";
				
				
			}
		}
	}else{
		//Show selects in Form Objects passed to function
		for(var i = 0; i < arguments.length; i++)
		{
			if (arguments[i].elements.length){
				//we have a form
				for(j = 0; j < arguments[i].elements.length; j++)
				{		
					if (arguments[i].elements[j].type == "select-one" || arguments[i].elements[j].type == "select-multiple")
							arguments[i].elements[j].style.visibility = "visible";
				}
			}
		}
	}
}
				
function fnTrim(str){
	return fnRTrim(fnLTrim(str));
}

function fnRTrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;      
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)i--;
		s = s.substring(0, i+1);
   }
	return s;
}

function fnLTrim(str){
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)j++;
		s = s.substring(j, i);
   }
   return s;
}

 
