// ---------------------------------------------------------------------------------------
// browser sniffer, defines variables for the rest of the functions below to use.

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
sNS6 = (!document.all && document.getElementById) ? true : false;
var FINISHED = false;

var g_el =0;
var IF_PADDING = 90;
var emulateURL="";


// resizes page to its proper dimension

function resizeFix() {
	if(widthCheck != window.innerWidth || heightCheck != window.innerHeight) {
		window.location.reload();
   }
}


// ---------------------------------------------------------------------------------------
// handles netscape resizing problem by forcing to reload when window is resized

if(ns4) {
	widthCheck = window.innerWidth;
    	heightCheck = window.innerHeight;
    	window.onresize = resizeFix();
}


// ---------------------------------------------------------------------------------------
//To be used for popup windows all parameters passed

function popup_all(topic,namer,tool,loc,dir,stat,menu,scroll,resize,x,y) {
eval('window.open(topic, namer, "history=no,toolbar='+tool+',location='+loc+',directories='+dir+',status='+stat+',menubar='+menu+ ',scrollbars='+scroll+',resizable='+resize+',width=' +  x  + ',height=' +  y + '");');
}
// ---------------------------------------------------------------------------------------
//Close window function

function closeMe() {
	window.close();
}


function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.Email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}



function SH () {
	id ="ff";
	var d = document;
	el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	if (window.innerHeight){ 
		el.style.height =  0;
		el.style.height = Math.max (400, window.frames["ff"].document.height + 40);
	} 
	if ( document.body.clientHeight) {
		el.style.height =  0;
		el.style.height =  Math.max (400, window.frames["ff"].document.body.scrollHeight + 40);
	} 
	
	if (!navigator.userAgent.toLowerCase().match(/safari/)) {
		window.location="#toppage";
	}
}

function fixLvl3() {
	var qs = document.location.href;
	var newid = -1;
	if (qs.search(/ACTLIKEID/i) != -1) {
		var arga=qs.split("?")[1].split("&");
		for (i = 0; i < arga.length; i++) {
			if (arga[i].split("=")[0].toUpperCase() == "ACTLIKEID") {
				newid=arga[i].split("=")[1]
			}
			else if (arga[i].split("=")[0].toUpperCase() == "ID" && newid == -1) {
				newid=arga[i].split("=")[1]
			}
		}
	}
	//alert (newid);
	id ="Level3Nav";
	var d = document;
	var temp = null;
	el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	if (el != null) {
		var x = el.getElementsByTagName("a");
		for (i=0;i<x.length;i++) {
			//if (x.item(i).toString().replace(/&actlikeid=\d+/, "").toUpperCase() == d.location.href.replace(/&actlikeid=\d+/, "").replace(/id=\d+/, "id="+newid).toUpperCase()) {
			//if (x.item(i).toString().toUpperCase() == d.location.href.toUpperCase()) {
			var test = false;
			try
			{	if (x.item(i).toString().toUpperCase() == d.location.href.toUpperCase())
			               test = true;
			}
			catch(e) {}
			//check to see if the path matches
			if (test) {
	
				if (x.item(i).parentNode.parentNode.className.search(/level3/) != -1) {

					y = x.item(i).parentNode.parentNode.getElementsByTagName("div");
					for (j=0;j<y.length;j++) {
						if (y.item(j).className.search(/subnav/) == 0) {
							x.item(i).parentNode.className = x.item(i).parentNode.className.replace (/itemlast/, "itemmid")
						}
					}
					x.item(i).parentNode.className += "selected";
					x.item(i).parentNode.parentNode.className += " level3selected";
					
				}
				if (x.item(i).parentNode.className.search(/level4/) != -1) {
					x.item(i).parentNode.className += " selected";
					y = x.item(i).parentNode.parentNode.parentNode.getElementsByTagName("div");
					for (j=0;j<y.length;j++) {
						if (y.item(j).className.search(/item/) == 0) {
							temp = y.item(j);
							y.item(j).className += "selected";
							y.item(j).parentNode.className += " level3selected";
						}
					}
					for (j=0;j<y.length;j++) {
						if (y.item(j).className.search(/subnav/) == 0) {
							temp.className = temp.className.replace (/itemlast/, "itemmid")
						}
					}
				}
			}
		}
	}
}


function fixLvl2() {
	id ="Level2Nav";
	var d = document;
	var temp = null;
	el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var dlh = d.location.href;
	
	if (emulateURL != "") {
		dlh = emulateURL;
	}
	
	if (el != null) {
		var x = el.getElementsByTagName("a");
		for (i=0;i<x.length;i++) {
			if (x.item(i).toString().toUpperCase().replace(/.*CMSTEMPLATES/i, "").replace(/[^\/]*\.aspx.*/i, "") == 
				dlh.toUpperCase().replace(/.*CMSTEMPLATES/i, "").replace(/[^\/]*\.aspx.*/i, "") && x.item(i).toString().toUpperCase().search(/CMSTEMPLATES/i) > 0 ) {
				if (x.item(i).className.search(/flyoutnavNoHighlight/) < 0 ) {  
					x.item(i).className += " selected";
				}
			}
			if (x.item(i).toString().toUpperCase() == dlh.toUpperCase()) {
				if (x.item(i).className.search(/flyoutnavNoHighlight/) < 0 ) {  
					x.item(i).className += " selected";
				}
			}
		}
		el.style.display="none";
		el.style.display="block";
	}
}
function fixLvl1() {
	id ="Level1Nav";
	var d = document;
	var temp = null;
	el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var dlh = d.location.href;
	
	if (emulateURL != "") {
		dlh = emulateURL;
	}

	if (el != null) {
		var x = el.getElementsByTagName("a");
		for (i=0;i<x.length;i++) {
//				alert (dlh.toUpperCase().replace(/\/[^\/]*$/, "") +"\n" + x.item(i).toString().toUpperCase().replace(/\/[^\/]*$/, ""))
				

				if (dlh.toUpperCase().replace(/\/[^\/]*$/, "")== x.item(i).toString().toUpperCase().replace(/\/[^\/]*$/, "") && !x.item(i).className.match (/flyoutnav/) ) {
						x.item(i).className = "menuitem menuitemselected"
						x.item(i).parentNode.onmouseover = null;
						x.item(i).parentNode.onmouseout = null;
				}
			if (x.item(i).className.match (/menuitem/) && (dlh.search(/ABOUTUS/i) != -1 ||dlh.search(/ASKRLP/i) != -1 ||dlh.search(/PropertySearch/i) != -1 )) {
				if (x.item(i).toString().toUpperCase().search (dlh.toUpperCase().replace(/[^\/]*\/[^\/]*$/, ""))== 0 && dlh.toUpperCase().replace(/[^\/]*\/[^\/]*$/, "").search (/CMSTEMPLATES/i) > 0 ) {
						x.item(i).className = "menuitem menuitemselected"
						x.item(i).parentNode.onmouseover = null;
						x.item(i).parentNode.onmouseout = null;
				}


			}
			if (x.item(i).className.match (/menuitem/) && x.item(i).toString().toUpperCase() == dlh.toUpperCase()) {
				x.item(i).className = "menuitem menuitemselected"
				x.item(i).parentNode.onmouseover = null;
				x.item(i).parentNode.onmouseout = null;
			}
		}
	}
}


function initR() {
	fixLvl2();
	fixLvl1();
}
function init() {
	fixLvl3();
	fixLvl2();
	fixLvl1();
	FINISHED = true;
}

function initb(a) {
//	alert ("jere");
	a.onmouseover=null;
}


// ff pages 
function rif() {
	if (window.innerHeight){ 
		el = window.frames["contenu"].document.height;
	} 
	else if (document.body.clientHeight) {
	 el =  window.frames["contenu"].document.body.scrollHeight;
	}

	if (navigator.userAgent.toLowerCase().match(/safari/)) {
	 el =  window.frames["contenu"].document.body.scrollHeight - IF_PADDING;
	}
		//alert (el);
	
	g_el = el;
	//parent.a(400);
	setTimeout("delayed_a()",1);
}

function delayed_a () {
	//alert ("here");
	parent.a(Math.max (400, g_el + IF_PADDING));
}


function a(z) {
	id ="ff";
	var d = document;
	el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	el.style.height = z;

}

//end ff

// ##############################
// Buttons for Agent search pages 
// ##############################

function makeButton (a) {
	a.className += " hovered";
}
function unmakeButton (a) {
	a.className = a.className.replace(/ hovered/g, "");
}
function makeClick (a) {
	var x = a.getElementsByTagName("A");

	if (x == null) {return;}

	window.open (x[0].href);
	return false
}

function makeClickHere (a) {
	var x = a.getElementsByTagName("A");

	if (x == null) {return;}

	window.top.location.href = x[0].href;
	return false
}

window.onload=init;
window.onresize=initR;


var d = document;

function mainover (a) {
	if (FINISHED == false) { return;}
	var id = "Level1Nav";
	var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	x = el.getElementsByTagName("a");
	for (i=0;i<x.length;i++) {
		if (x.item(i).className.match (/menuitemselected/) ) {
			x.item(i).className += " menuitemselectedOther";
		}
	}
	a.className += " butselected"
}

function mainout (a) {
	if (FINISHED == false) { return;}
	var id = "Level1Nav";
	var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	x = el.getElementsByTagName("a");
	for (i=0;i<x.length;i++) {
		if (x.item(i).className.match (/menuitemselectedOther/) ) {
			x.item(i).className = x.item(i).className.replace (/ menuitemselectedOther/, "") ;
		}
	}
	a.className = a.className.replace (/ butselected/, "") ;
}
function hide (a) {
	//window.status+="a";
}


function toggleCollapseRow () {
	var id = "collapseBottom";
	var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	if (el.className == "collapsed") {
		el.className = "uncollapsed";
	}
	else {
		el.className = "collapsed";

	}
}
