<!--

//Constant values.
var sPersistQstr; 		sPersistQstr="";
var sBuilderDevLoc; 	sBuilderDevLoc 		= "sto02web008d"; 			
var sBuilderQALoc; 		sBuilderQALoc 		= "sto02web008q"; 			
var sBuilderProdLoc; 	sBuilderProdLoc 	= "homepage.realtor.com";	
var sControlBarDevLoc; 	sControlBarDevLoc 	= "sto02web005d";			
var sControlBarQALoc; 	sControlBarQALoc 	= "sto02ilead2q";			
var sControlBarProdLoc; sControlBarProdLoc 	= "ilead.realtor.com";		

//Feed in all vlaues to be persisted in QString.
persistQstr("id");

function navigate(sectArg,optArg,pageArg,QstrArg) {
//Refresh page with passed in parameters.

	sSect	 = new String(sectArg);
	sOpt 	 = new String(optArg);
	sPage	 = new String(pageArg);
	sQstr	 = new String(QstrArg);

	myString = new String(document.location.href);
	mySplit	 = myString.split("?");
	myURL	 = buildAbsPath("default.asp") + "?sect=" + sSect;
	
	if (sOpt!="undefined" && sOpt!=0)   {myURL = myURL + "&opt=" + sOpt}
	if (sPage!="undefined" && sPage!=0) {myURL = myURL + "&page=" + sPage}
	if (sPersistQstr.length>0) {myURL = myURL + "&" + sPersistQstr}
	if (sQstr!="undefined" && sQstr!=0) {myURL = myURL + "&" + sQstr}
	myURL = myURL + "&rt="+getTimeStamp(); //Request time overrides browser cache.
	
	window.location.href = myURL;
}

function link(sLocArg) {
//Navigation outside of framework
	sLoc = buildAbsPath(sLocArg);
	document.location.href = sLoc;
}

function getQueryStrValue(sVarArg) {
//Pass in a queryString keyName and recieve back it's value.

	qs = new String(location.search);
	qs=qs.substr(1,qs.length).split("&");
	qsKeys = new Array();
	qsVals = new Array();
	myValue = "";

	//Parse values into 2 arrays for search
	for (i=0;i<qs.length;i++){
	   qsElem=qs[i].split("=");
	   key=qsElem[0]; value=qsElem[1];
	   qsKeys=qsKeys.concat(key);
	   qsVals=qsVals.concat(value);
 	}

	//Search for key that matches request
	for (i=0;i<qsKeys.length;i++){
	   if (qsKeys[i].valueOf() == sVarArg) {
		myValue=qsVals[i].valueOf(); break;	   		
	   } 
	} 
	return(myValue);
}
	
function popUp(sLocArg,iHeight,iWidth) {
//Open a child window.
	sLoc = buildAbsPath(sLocArg);
	eval("window.open('"+sLoc+"','me','height="+iHeight+",width="+iWidth+"scrollbars=no,resizable=no');");
}	

function scrollingPopUp(sLocArg,iHeightArg,iWidthArg,bToolBarArg) {
//Open a child window.
	iWidth		= new String(iWidthArg);		
	iHeight		= new String(iHeightArg);	
	bToolBar	= new String(bToolBarArg);
	sLoc 		= buildAbsPath(sLocArg);
		
	if (iWidth.length="undefined") {iWidth=590}
	if (iHeight.length="undefined") {iHeight=500}
	
	if (bToolBar.length="undefined") {
		bToolBar="yes"
	}else{
		if(bMenuBarArg=="false" || bMenuBarArg=="0") {bToolBar="no"}
		else{bToolBar="yes"}
	}
	eval("window.parent.open('"+sLoc+"','child_','height="+iHeight+",width="+iWidth+",scrollbars=yes,toolbar=" + bToolBar + ",resizable=yes');");
}
			
function statusMsg(myMsg) {
//Place message into status bar.
	window.status = myMsg;
	return(true);
}

function chat(agentID,agentScreenName,emailURL,promoURL,ftmlsid,ftmlsalias,fthsid,ftspg,ftsid,ftaid,ftlid,ftctype){
//Launch the "chat with me" window.

	var url = "http://homestoreimlink.facetime.net/messengerLaunch.html" + "?agentID=" + agentID + "&agentScreenName=" + escape(agentScreenName) + "&emailURL=\"" + escape(emailURL) + "\"" + "&promoURL=\"" + promoURL + "\"" + "&mlsid=" + escape(ftmlsid) + "&mlsalias=" + escape(ftmlsalias) + "&aid=" + escape(ftaid) + "&lid="  + escape(ftlid) + "&ctype=" + escape(ftctype) + "&spg="  + escape(ftspg) + "&HSID=" + escape(fthsid) + "&sid=" + escape(ftsid);
	var urlRD = "http://www.realtor.com/Redir/Redir.asp?target=" + escape(url) ;	
	window.open(urlRD,'_blank','width=3,height=3');
}
		
function help(whichSect) {
//Launch help wizard.

	myURL = buildAbsPath("help/default.asp");
	window.open(myURL,"Help","height=400,width=600,scrollBars=yes,resizable=no");
}

function comingSoon() {
	alert("Not Yet Implemented");
}

function persistQstr(keyArg) {
//Adds values to persisted qString.

   sKey = new String(keyArg);
   sVal = new String(getQueryStrValue(keyArg));

   if (sKey.length>0 && sVal>0) { 
     if (sPersistQstr.length>0) {sPersistQstr+="&"}
       	sPersistQstr+=sKey + "=" + sVal 
   }
}

function logOut() {
//Push the user to a logOut area.

	myURL = buildAbsPath("logOut.asp?"+getTimeStamp());
	myMsg = "Are you sure that you wish to Log Out of iLead?";
	x = confirm(myMsg);
	if (x) {window.location.href = myURL}
}

function buildAbsPath(sRelPathArg) {
//Uses currentServer() and goToServer() to determine the 
// base by which to form an absolute path.  Path presumes
// relative path is relavent to controlBar dir.

	myPath = new String(sRelPathArg); myIndex = myPath.indexOf("http://");
	if ((myIndex>=0) && (myIndex<=2)) {
		myURL = myPath;
	}else{
		if (DisplayORControlBar()=="Display" || DisplayORControlBar()=="display") {
			myURL = "http://" + goToServer() + virtualDir() +  "display/" + myPath;
		}else{
			myURL = "http://" + goToServer() + virtualDir() + "controlBar/" + myPath;
		}
	}
	//Strip spaces out.
	return(normalize(myURL));
}

function virtualDir() {
//Function adds Virtual Directory reference as needed.

	sCurrServer = currentServer();
	
	if (sCurrServer==sControlBarQALoc) 		 {myVal = "/iLead/"}
	else if (sCurrServer==sControlBarDevLoc) {myVal = "/iLead/"}
	else {myVal = "/";}
	
	return(myVal);
}

function goToServer(){
//Temporary function intended to take care of the bouncing between servers
//that is necissary while iLead2.0 uses the iLead1.0 builder. This function
//should be retired for a more generic method once the builder resides on 
//the same system. 

	currServer = currentServer();

	if (currServer == sBuilderQALoc){
		myURL = sControlBarQALoc;
	}else if (currServer == sBuilderDevLoc){
		myURL = sControlBarDevLoc;
	}else if (currServer == sBuilderProdLoc){
		myURL = sControlBarProdLoc;
	}else{
		myURL = currServer;
	}
	return(myURL);
}

function goToBuilder(){
//Temporary ... same story as goToServer()

	currServer = currentServer();

	if (currServer == sControlBarQALoc){
		myURL = sBuilderQALoc;
	}else if (currServer == sControlBarDevLoc){
		myURL = sBuilderDevLoc;
	}else if (currServer == sControlBarProdLoc){
		myURL = sBuilderProdLoc;
	}else{
		myURL = currServer;
	}
	return(myURL);
}

function DisplayORControlBar(){
	myString = new String(document.location.href);
	mySplit	 = myString.split("/");
	myTestVal = mySplit[3].toLowerCase()
	
	if (myTestVal=="ilead") {myDir = mySplit[4]}
	else{myDir = mySplit[3]}
	
	return(myDir);
}

function currentServer(){
//Returns name of machine

	myString = new String(document.location.href).toLowerCase();
	mySplit	 = myString.split("/");
	myURL	 = mySplit[2];
	
	return(myURL);
}

//-->		
