/*
place the following line in the header of the page that you want to include this file in
<script src="/jscript/shared.js" type="text/javascript"></script>
*/
var _mapSearchUrl			= "/MapSearch/MapSearch/MapSearch.aspx";
var _mappingUrl				= _mapSearchUrl;
var _searchResultUrl		= _mapSearchUrl;
var _freeSearchResultUrl	= _mapSearchUrl;

function checkZipCode(id)
{
    var obj = document.getElementById(id);
    var exp = /^\d+$/; // all digits
    var regExp = new RegExp(exp);
    
    if (!regExp.exec(obj.value) && obj.value!="")
    {
        alert("Zip Code must contain only Digits!"); 
        obj.value = "";  
    }  
}

function refreshTopBan() {
  //used to refresh the b@nner in the top of the page (funky spelling and abreviations used to defeat keyword searches)
  ban = document.getElementById("wrap-topBanFrame")
  if (ban != null) 
    ban.src = ban.src
}

function refreshRightBan() {
  //used to refresh the b@nner on the right side of the page (funky spelling and abreviations used to defeat keyword searches)
  ban = document.getElementById("wrap-rightBanFrame")
  if (ban != null) 
    ban.src = ban.src
}

function openFeedbackWindow(userId) {
	openCustomWindow('http://realtytrac.custhelp.com/cgi-bin/realtytrac.cfg/php/enduser/doc_serve.php?5=2&userid=' + userId,'Feedback', 550, 780, 125, 100, false, true)
}

function openFSBOOpenHouse(situsId) {
  url = "/FSBO/OpenHouse.aspx?situsID=" + situsId
  openCustomWindow(url,'FSBOContactOwner', 710, 500, 0, 0, false, true, 0)
}

function openFSBOContactOwner(situsId) {
  url = "/FSBO/ContactOwner.aspx?situsID=" + situsId
  openCustomWindow(url,'FSBOContactOwner', 830, 710, 0, 0, false, true, 0)
}

function openFSBOFlyer(situsId) {
  url = "/FSBO/FSBOFlyerReport.aspx?situsID=" + situsId
  openCustomWindow(url,'FSBOContactOwner', 830, 830, 0, 0, false, true, 0)
}

function openFSBOShowing(situsId) {
  url = "/FSBO/RequestShowing.aspx?situsID=" + situsId
  openCustomWindow(url,'FSBOContactOwner', 830, 830, 0, 0, false, true, 0)
}

function openMapWindow(propAddress) {
  url = "http://maps.google.com/maps?q=" + propAddress
  openCustomWindow(url,'AddressMap', 0, 0, 0, 0, false, true, .75)
}


function varIsEmpty(testVar) {
  if (testVar == null) return true;
  if (isNaN(testVar) && testVar == '') return true;
  return false
}

function getCSSAttribute(cssClassName,toChange) {
  //retrieves the value of a CSS class attribute
  if (!document.styleSheets) {
    window.alert("Your browser won't support the changing of a style sheet by javascript!");
    return false;
  }
  for(i = 0; document.styleSheets.length > i; i++) {
    //Mozilla
    if(document.styleSheets[i].rules != null) {
      for(j = 0; document.styleSheets[i].rules.length > j; j++) {
        if(document.styleSheets[i].rules[j].selectorText != null) {
          if(document.styleSheets[i].rules[j].selectorText.toLowerCase() == cssClassName) {
            return document.styleSheets[i].rules[j].style[toChange];
          }
        }
      }
    } else if(!varIsEmpty(document.styleSheets[i].cssRules)) {
      //IE
      for(j = 0; document.styleSheets[i].cssRules.length > j; j++) {
        if(document.styleSheets[i].cssRules[j].selectorText != null) {
          if(document.styleSheets[i].cssRules[j].selectorText.toLowerCase() == cssClassName) {
            return document.styleSheets[i].cssRules[j].style[toChange];
          }
        }
      }
    } 
  }
}

function changeCSSAttribute(cssClassName,toChange,changeTo) {
  //changes the value of a CSS class attribute
  if (!document.styleSheets) {
    return false;
  }
  for(i = 0; document.styleSheets.length > i; i++) {
    //Mozilla
    if(document.styleSheets[i].rules != null) {
      for(j = 0; document.styleSheets[i].rules.length > j; j++) {
        if(document.styleSheets[i].rules[j].selectorText != null) {
          if(document.styleSheets[i].rules[j].selectorText.toLowerCase() == cssClassName) {
            document.styleSheets[i].rules[j].style[toChange] = changeTo;
          }
        }
      }
    } else if(document.styleSheets[i].cssRules != null) {
      //IE
      for(j = 0; document.styleSheets[i].cssRules.length > j; j++) {
        if(document.styleSheets[i].cssRules[j].selectorText != null) {
          if(document.styleSheets[i].cssRules[j].selectorText.toLowerCase() == cssClassName) {
            document.styleSheets[i].cssRules[j].style[toChange] = changeTo;
          }
        }
      }
    } else {
      window.alert("Your browser won't support the changing of a style sheet by javascript!");
      return false;
    }
  }
}

function openNewFeaturesWindow() {
  //shows the new features for the 2005 wrap & price change
  openCustomWindow('/pub/popup_2005_features.html','2005Features', 820, 720, 0, 0, false, true)
}

function openBBBWindow() {
  /*
  used for opening the Better Business Bureau info on realtytrac
  */
  openCustomWindow('http://www.labbb.org/bbbweb/forms/business/companyreportpage_expository.aspx?companyid=13159967','BBB', 777, 345, 0, 0, false, true)
}

function openSurveyWindow() {
  /*
  used for opening the customer survey popup
  */
  openCustomWindow('/pub/pop-up-survey-winners.asp','upgradePopup', 830, 500, 0, 0, false, true)
}

function openAVMupgradeWindow(propId) {
  /*
    centralized function to open property lien records window
  */
  openCustomWindow('/database/upgradeAVMpopup.html?propId=' + propId,'avmUpgrade',750,750,0,0,false,true)
}

function openLienBankUpgradeWindow(propId,buyLien,buyBank) {
  /*
    centralized function to open property lien records window
  */
  openCustomWindow('/database/upgradeLiensPopup.html?propId=' + propId + '&buyLien=' + buyLien + '&buyBank='+ buyBank,'avmUpgrade',750,750,0,0,false,true)
}

function openFieldNamesWindow(loc) {
  /*
    centralized function to open property lien records window
  */
  openCustomWindow('/education/fieldNames.html#'+loc,'propFieldNames',470,80,125,100,false,true)
}

function openPropLienWindow(propId) {
  /*
    centralized function to open property lien records window
  */
  openCustomWindow('/database/propLien.asp?propId=' + propId,'propTypeCodes',470,440,125,100,false,true)
}

function openPropBankruptcyWindow(propId) {
  /*
    centralized function to open property bankruptcy records window
  */
  openCustomWindow('/database/propBankruptcy.asp?propId=' + propId,'propTypeCodes',470,495,125,100,false,true)
}

function openPropTypeCodesWindow() {
  /*
    centralized function to open property codes definitions window
  */
  openCustomWindow('/pub/propTypeCodes.html','propTypeCodes',750,550,125,100,false,true)
}

function openSampleReportWindow(url) {
  /*
    centralized function to open samel xml reports window
  */
  openCustomWindow(url,'sampleReport',790,550,125,100,false,true)
}

function openTermsOfUseWindow() {
  /*
    centralized function to open terms of use help window
  */
  openCustomWindow('/pub/terms.html','termsOfUse',820,550,125,100,false,true)
}


function openHelpWindow(location) {
  /*
    centralized function to open a help window
    paramter : location : specifies the location for the help section
      possible values:
        chat
        answer
        ask
  */
  openCustomWindow('/pub/help_frameset.asp?' + location + '=true','SupportCenter',802,550,125,100,true,true)
}

function openFAQwindow(url) {
  /*
    centralized function to open faq window
  */
  openCustomWindow(url,'faq',500,550,125,100,false,true)
}

function openWideFAQwindow(url) {
  /*
    centralized function to open faq window
  */
  openCustomWindow(url,'faq',820,550,125,100,false,true)
}


function autoTab(input, len) {
/************************************************
DESCRIPTION: Automatically jumps the focus to the next field  
  in the tab sequence when a specified number of character is entered.  

PARAMETERS: 
  input - Text INPUT field to be tested.  
  len   - length of input before autotabbing.

  To use, include the following code as an inline event handler
  in an INPUT text field:
	 onKeyUp="return autoTab(this, n);"  
  where n is a number specifying len. 
    
RETURNS: 
  True if tab is made.

*************************************************/
	if(input.value.length >= len) 
	{
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function getIndex(input) 
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input) index = i;
		else i++;
		return index;
	}
	return true;
}

function promptLink(message,valueName,defaultValue,link) {
  /*
  used to show a prompt box before proceeding.
  the value entered is passed to the link as the valueName
  used on:
    /database/util/userResults.asp
  */

  value = (prompt(message,defaultValue)) 
  changeWindowLocation(link + '&' + valueName + '=' + value,"");
}

function confirmLink(message,link,link2) {
  /*
  used to show a confirmation box before proceeding.
  if users hits cancel and link2 is empty, nothing happens
  used on:
    /database/util/userResults.asp
  */

  if (confirm(message)) 
    changeWindowLocation(link,"");
  else if (link2 != '' && link2 != null)
    changeWindowLocation(link2,"");
}


bName=navigator.appName;

function prepareUrl(url) {
  //makes URL point to a non-secure page if no https is specified
  newUrl = String(url);
  newUrl.toLowerCase();
  if ( (newUrl.indexOf('http') == -1) && (newUrl.indexOf('javascript') == -1) && (newUrl.indexOf('/util/') == -1) && (newUrl.indexOf('/') == 0) ) {
//make suret: url isn't fully qualified           not a javascript link               not in the admin panel              not a relative URL
    domain = String(document.domain);
    domain.toLowerCase();
    //put www in front of realtytrac.com domain name so that 
    if (domain == 'realtytrac.com') domain = 'www.realtytrac.com'
    newUrl = 'http://' + domain + '/' + url
  } else {
    //return url unmolested
    return url;
  }
  //return new url with domain
  return newUrl;
}

function changeWindowLocation(url,hitboxTrackingName) {
  if (hitboxTrackingName != '') _hbLink(hitboxTrackingName,'right','0,0,30,30');
  window.location.href = prepareUrl(url);
}

function openCustomWindow(url,name,width,height,leftPos,topPos,toolbars,scrollbars,windowRatio) {
  //function used for opening a window, uses passed parameters
  //name is the name of the window
  //toolbars and scrollbars are boolean fields that determine whether those should be shown on window
  //if a windowRatio is passes (and it is between 0 and 1) then the window will be sized as a percentage of the screen size (resolution)
  
  toolbarTxt = "toolbar=no,status=no"
  if (toolbars) {
    toolbarTxt = "toolbar=yes,status=yes"
  }
  scrollbarTxt = "scrollbars=no,resizable=yes"
  if (scrollbars) {
    scrollbarTxt = "scrollbars=yes,resizable=yes"
  }
  if (!isNaN(windowRatio) && windowRatio < 1 && windowRatio > 0) {
    width = screen.width * windowRatio;
    height = screen.height * windowRatio;
    leftPos = (screen.width - width) / 2;
    topPos = 20;
  }
  leftPosTxt = ''
  topPosTxt = ''
  if (!isNaN(leftPos) && !isNaN(topPos)) {
    if (bName != 'Netscape') {
      leftPos = leftPos + 10
      topPos = topPos + 10
    }
    topPosTxt = 'top=' + topPos
    leftPosTxt = 'left=' + leftPos
  }
  windowSpecs = topPosTxt + ',' + leftPosTxt + ',width=' + width + ',height=' + height + ',' + scrollbarTxt + ',' + toolbarTxt
  child = window.open(prepareUrl(url),name, windowSpecs)
  child.window.focus()
}

function openPostcard(propID,reload) {
  openCustomWindow('/database/noframes/postcard_selection.asp?propId=' + propID + '&reload=' + reload,'PrintPostcard',585,700,'','',false,true)
}
function openExamine(propId,webSitePk,queryStr) {
  if (webSitePk == null) webSitePk = 1
  if (queryStr == null) queryStr = ''
  openCustomWindow('/database/noframes/examineSave.asp?pageTo=examineComps.asp&propId=' + propId + '&webSitePk=' + webSitePk + queryStr,'xamine',800,725,'-10','-10',false,false)
}

tab = 1
function setTabIndex(id) {
  eval('document.frm.' + id + '.tabIndex = ' + tab++)
}

function DropDownSelect(p_cntrlname, p_value) {
//selects a option in a Select control by control name and option value.
// ES 10/24/05
	var len;
	len = document.getElementById(p_cntrlname).options.length;
	for (var i = 0;i<len-1;i++) {
		if (document.getElementById(p_cntrlname).options[i].value == p_value) {
			document.getElementById(p_cntrlname).options.selectedIndex=i;
		}
	}
}

// used by member and non-member quick search.
function fnVerifyState(pbValidUser, poForm, pbFlag){

    	var loCityState = document.getElementById("MarketPlaceSearchForm_citystate")
		var loZipCode	= document.getElementById("MarketPlaceSearchForm_zip")
		var lsSearch	= ""
		var lsRedirectURL = _mapSearchUrl;
		
		pbValidUser=gMember;
		
		// Clear out cookie value
		fnClearSearchRequestCookieValue();

		if (fnTrim(loZipCode.value) != ""){
			lsSearch = fnTrim(loZipCode.value)
		} else {
			lsSearch = fnTrim(loCityState.value)
		}

        if (pbFlag){
		    var lsSearchFieldValue	= fnTrim(lsSearch.replace(",", ""));
        }
        else
        {
    		var lsSearchFieldValue	= fnTrim(poForm.txtQuickSearch.value.replace(",", ""));
    	}
    	
		var lsAllStates			= "Alabama|AL~Alaska|AK~Arizona|AZ~Arkansas|AR~California|CA~Colorado|CO~Connecticut|CT~Delaware|DE~District of Columbia|DC~Florida|FL~Georgia|GA~Hawaii|HI~Idaho|ID~Illinois|IL~Indiana|IN~Iowa|IA~Kansas|KS~Kentucky|KY~Louisiana|LA~Maine|ME~Maryland|MD~Massachusetts|MA~Michigan|MI~Minnesota|MN~Mississippi|MS~Missouri|MO~Montana|MT~Nebraska|NE~Nevada|NV~New Hampshire|NH~New Jersey|NJ~New Mexico|NM~New York|NY~North Carolina|NC~North Dakota|ND~Ohio|OH~Oklahoma|OK~Oregon|OR~Pennsylvania|PA~Rhode Island|RI~South Carolina|SC~South Dakota|SD~Tennessee|TN~Texas|TX~Utah|UT~Vermont|VT~Virginia|VA~Washington|WA~West Virginia|WV~Wisconsin|WI~Wyoming|WY"
			lsAllStates			= lsAllStates.toLowerCase();
			lsSearchFieldValue	= lsSearchFieldValue.toLowerCase();
		var laStates			= lsAllStates.split("~");
		var laSearch			= lsSearchFieldValue.split(' ');
		var lsReturn			= ""
		var lreSearchField		= /west virginia/gi;
		var lbWestVirginiaFlag	= lreSearchField.test(lsSearchFieldValue)
		
		if (lsSearchFieldValue==""){if(!pbFlag){alert("You must enter both city and state!");}else{alert("You must enter search parameters.");} return false;}
		
	
		
		if (isNaN(lsSearchFieldValue))
		{//NON ZIPCODE SEARCH
			//	[ Check for one word ] [ below statement looking for the exeption of west virginia]
			if ((laSearch.length==1)||((laSearch.length==2)&&(lsSearchFieldValue=="west virginia"))){if(!pbFlag){alert("You must enter both city and state!");}else{alert("You must enter search parameters.");} return false;}

			for (i = 0; i < laStates.length; i++)
			{	
				var laPart			= laStates[i].split("|");
				var liStartOfState	= laPart[0].split(" ").length	
				var liLoopCount		= laSearch.length - liStartOfState	

				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				//	EXEPTION - "west virginia"
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				if (lbWestVirginiaFlag)
				{
					for (j=0; j<=laSearch.length-3; j++) {
						lsReturn = lsReturn + " " + laSearch[j];}
						
					if (pbValidUser){
					    if(pbFlag)
					    {
					        window.opener.location = lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=wv", "headerQuickSearchBar";
					        window.close();
					    }
					    else
						    changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=wv", "headerQuickSearchBar");
					} else {
					    if(pbFlag)
					    {
					        window.opener.location = lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=wv", "headerQuickSearchBar";
					        window.close();
					    }
						changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=wv", "headerQuickSearchBar");}

					return false;				
				}

				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				//	FULL STATE-MULTIPLE
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				if((lsSearchFieldValue.search(laPart[0])>=0)&&(laSearch[laSearch.length-1].length!=2))
				{
					if (liStartOfState == laSearch.length)
					{//USER ONLY ENTERED A STATE
						alert("Please enter a city along with the state");
						return false;
					} else {

						for (j=0; j<=liLoopCount - liStartOfState; j++) {
							lsReturn = lsReturn + " " + laSearch[j];}
							
						if (pbValidUser){
						    if(pbFlag)
					        {
											
											if(window.opener)
											{
												window.opener.location = _searchResultUrl + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1];//, "headerQuickSearchBar";
											}
					            changeWindowLocation(lsRedirectURL + "?" + GetQueryString("city",lsReturn + "~" + laPart[1]), "");
					            
					        }
					        else
							    changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar");
						} else {
						    if(pbFlag)
					        {
										if(window.opener)
										{
					            window.opener.location = lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar";
					          }
					          changeWindowLocation(lsRedirectURL + "?" + GetQueryString("city",lsReturn + "~" + laPart[1]), "");
					            
					        }
					        else
							    changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar");}
							
						return false;
					} 
				} 
				
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				//	STATE ABBREVIATION
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				if((laSearch[laSearch.length-1].search(laPart[1])>=0)&&(laSearch[laSearch.length-1].length==2))
				{
					for (k=0; k<=laSearch.length-2; k++){
						lsReturn = lsReturn + " " + laSearch[k];}
						
					if (pbValidUser){
					    if(pbFlag)
				        {
										if(window.opener)
										{
											window.opener.location = _searchResultUrl + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar";
										}
										changeWindowLocation(_mappingUrl + "?" + GetQueryString("city",lsReturn + "~" + laPart[1]), "");
				            
				        }
				        else
						    changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar");
					} else {
					    if(pbFlag)
				        {
										if(window.opener)
										{
											window.opener.location = lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar";
										}
										changeWindowLocation(lsRedirectURL + "?" + GetQueryString("city",lsReturn + "~" + laPart[1]), "");
				            
				        }
				        else
						    changeWindowLocation(lsRedirectURL + "?searchType=city&txtCity=" + lsReturn + "&txtcity=" + laPart[1], "headerQuickSearchBar");}
						
					return false;
				} 
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			//	NO STATE MATCH
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			if(i == laStates.length){
				alert("Please enter a valid state!")
				return false;
			}	
		} else {
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			//	ZIP CODE SEARCH
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			if (pbValidUser){
			    if(pbFlag)
		        {
								if(window.opener)
								{
									window.opener.location = lsRedirectURL + "?searchType=zip&txtZip=" + lsSearchFieldValue + "&selStatus=D";//, "headerQuickSearchBar";
								}
								changeWindowLocation(lsRedirectURL + "?" + GetQueryString("zip",lsSearchFieldValue), "");
		            
		            
		        }
		        else
				    changeWindowLocation(lsRedirectURL + "?searchType=zip&txtZip=" + lsSearchFieldValue + "&selStatus=D", "headerQuickSearchBar");
			} else {
			    if(pbFlag)
		        {
								if(window.opener)
								{
									window.opener.location = lsRedirectURL + "?searchType=zip&txtZip=" + lsSearchFieldValue + "&selStatus=D", "headerQuickSearchBar";
								}
								
		            changeWindowLocation(lsRedirectURL + "?" + GetQueryString("zip",lsSearchFieldValue), "");
		        }
		        else
				    changeWindowLocation(lsRedirectURL + "?searchType=zip&txtZip=" + lsSearchFieldValue + "&selStatus=D", "headerQuickSearchBar");}    
				
			return false;
		}
		return false;
	}	//end function 

	//Used by member quick search bar
	function fnViewSavedSearch(poForm)
	{	
		var lsRedirectURL	= _mappingUrl;
		var liSelectedValue = poForm.cboSavedSearch.value;
		
		if (liSelectedValue != 0)
		{
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
		
			changeWindowLocation(lsRedirectURL + "?prefId=" + liSelectedValue, "headerQuickSearchBar_savedSearch");
		}
	}
	
	//Used by member quick search bar
	function fnViewSavedSearchChanged()
	{	
		var lsRedirectURL	= _mappingUrl;
		var cboSavedSearch = document.getElementById("cboSavedSearch");
		if (cboSavedSearch != null)
		{
		    var liSelectedValue = cboSavedSearch.value;
    		
		    if (liSelectedValue != 0)
		    {
			    // Clear out cookie value
			    fnClearSearchRequestCookieValue();
    		
			    changeWindowLocation(lsRedirectURL + "?prefId=" + liSelectedValue, "headerQuickSearchBar_savedSearch");
		    }
		}
	}	
	
	// used by member and non-member quick search.
	function fnTrim(psCleanup) 
	{
		while (psCleanup.substring(0, 1) == ' ') 
		{
			psCleanup = psCleanup.substring(1, psCleanup.length);
		}
		
		while (psCleanup.substring(psCleanup.length-1, psCleanup.length) == ' ') 
		{
			psCleanup = psCleanup.substring(0, psCleanup.length-1);
		}
		
		psCleanup.replace(/^\s*|\s*$/g,"");
		
		return psCleanup;
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	PopUnder functions
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function fnGetPopUnder() {
	if (fnGetCookie("RT_PopUnder") == null)	{
		//Set cookie and expire it in 1 day (3rd Parameter)		
		fnSetCookie("RT_PopUnder", "1", 1, "", "", "")

    /********************************************************************************************************
    The following line has been split up to fix a norton internet security problem. 
    The program was blocking this entire file because "a d s" and/or "a d d y n a m i x" (without spaces) where found using a string search. 
    By splitting them up like this the program doesn't recognize this file and therfore the site works with the norton ad blocking software (lame, i know) */
		win2=window.open('http://a' + 'ds.a' + 'ddynamix.com/creative/2-2130092-1l?', 'RealtyTrac', 'SCROLLBARS=NO, RESIZABLE=NO, WIDTH=750, HEIGHT=325, TOOLBAR=NO, MENUBAR=NO, TOP=250, LEFT=250');
    //********************************************************************************************************
    if (win2 != null) win2.blur(); //have to check that pop-up was not blocked
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Client Side Cookie Functions
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	

function fnSetCookie(psName, psValue, piExpires, psPath, psDomain, psSecure) 
{
	var ldToday	= new Date();
	ldToday.setTime(ldToday.getTime());
	
	//piExpires = Days
	if (piExpires){piExpires = piExpires * 1000 * 60 * 60 * 24;}
	var ldExpiresDate = new Date(ldToday.getTime() + (piExpires) );

	document.cookie = psName + "=" + escape(psValue) +
					((piExpires ) ? ";expires="	+ ldExpiresDate.toGMTString() : "" ) + 
					((psPath) ? ";path=" + psPath : "" ) + 
					((psDomain) ? ";domain="	+ psDomain : "" ) +
					((psSecure) ? ";secure" : "" );
}

function fnGetCookie(psName) 
{
	var liStart = document.cookie.indexOf(psName + "=" );
	var liLen = liStart + psName.length + 1;
	if ((!liStart) && (psName != document.cookie.substring(0, psName.length))){return null;}
	if (liStart== -1){return null;}
	var liEnd = document.cookie.indexOf(";", liLen);
	if (liEnd == -1 ){
		liEnd = document.cookie.length;}
	return unescape(document.cookie.substring(liLen, liEnd));
}

function fnDeleteCookie(psName, psPath, psDomain) 
{
	if (fnGetCookie(psName)) 
	{
		document.cookie = psName + "=" +
		((psPath) ? ";path=" + psPath: "") +
		((psDomain) ? ";domain=" + psDomain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}
function GetQueryString(criteriaType,criteriaValue)
{
	var strQueryString='';
		if(queryString('cobrandPK')!='false')
		{
			strQueryString +="cobrandPK=" + queryString('cobrandPK');
		}
		else
		{
			strQueryString +="cobrandPK=";
		}
		if(queryString('ms')!='false')
		{
			strQueryString +="&ms=" + queryString('ms');
		}
		else
		{
			strQueryString +="&ms=";
		}
		if(queryString('ms')!='false')
		{
			strQueryString +="&ms=" + queryString('ms');
		}
		else
		{
			strQueryString +="&ms=";
		}
		if(queryString('code')!='false')
		{
			strQueryString +="&code=" + queryString('code');
		}
		else
		{
			strQueryString +="&code=";
		}
		strQueryString+="&criteriaType=" + criteriaType + "&criteriaValue=" + criteriaValue;
		
		return strQueryString;
}
/*************************************
Querystring parsing 
**************************************/
function PageQuery(q) 
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;

	this.keyValuePairs = new Array();
	if(q) 
	{
		for(var i=0; i < this.q.split("&").length; i++) 
		{
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}

	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) 
	{
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() 
	{
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) 
		{
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key)
{
		var laQueryString = window.location.search;
		
		if(laQueryString && laQueryString.length > 0)
		{
			laQueryString = laQueryString.substring(1); 
		}
		
		var laValues = laQueryString.split("&"); 
		 
		for (var i = 0; i < laValues.length; i++) 
		{ 
			var laPair = laValues[i].split("="); 
			 
			if (laPair[0].toLowerCase() == key.toLowerCase()) 
			{ 
				return unescape(laPair[1]); 
			} 
		} 
		
		return 'false';
}

function displayItem(key)
{
	if(queryString(key)=='false')
	{
		document.write("you didn't enter a ?name=value querystring item.");
	}
	else
	{
	document.write(queryString(key));
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	Client Side Cookie Functions
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//function fnSetCookie(psName, psValue, piExpires, psPath, psDomain, psSecure) 
//{
//	var ldToday	= new Date();
//	ldToday.setTime(ldToday.getTime());
//	
//	//piExpires = Days
//	if (piExpires){piExpires = piExpires * 1000 * 60 * 60 * 24;}
//	var ldExpiresDate = new Date(ldToday.getTime() + (piExpires) );

//	document.cookie = psName + "=" + escape(psValue) +
//					((piExpires ) ? ";expires="	+ ldExpiresDate.toGMTString() : "" ) + 
//					((psPath) ? ";path=" + psPath : "" ) + 
//					((psDomain) ? ";domain="	+ psDomain : "" ) +
//					((psSecure) ? ";secure" : "" );

//}

function fnGetCookie(psName) 
{
	var liStart = document.cookie.indexOf(psName + "=" );
	var liLen = liStart + psName.length + 1;
		
	if ((!liStart) && (psName != document.cookie.substring(0, psName.length))){return null;}
	if (liStart== -1){return null;}
	var liEnd = document.cookie.indexOf(";", liLen);
	if (liEnd == -1 ){
		liEnd = document.cookie.length;}
	return unescape(document.cookie.substring(liLen, liEnd));
}


function fnDeleteCookie(psName, psPath, psDomain) 
{
	if (fnGetCookie(psName)) 
	{
		document.cookie = psName + "=" +
		((psPath) ? ";path=" + psPath: "") +
		((psDomain) ? ";domain=" + psDomain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function fnLoginBox(poFillElement)
{
	loElement = document.getElementById(poFillElement);
	if (loElement.style.display == "block")
	{
		loElement.style.display = "none";
	}
	else
	{
		loElement.style.display = "block";
		window.setTimeout("fnFillLogin('frm_UserName')",200)
	}
}

function fnFillLogin(poFocusElement)
{
	var loUserName = document.getElementById('frm_UserName');
	var loPassword = document.getElementById('frm_Password');
	var loRemember = document.getElementById('frm_RememberLogin');
	
	if (fnGetCookie("RememberUN") != null)
	{
		loUserName.value = fnGetCookie('RememberUN');
		loPassword.focus();
	}
	else 
	{
		loUserName.value = "";
		loUserName.focus();
	}
	
	loRemember.checked = (fnGetCookie("RememberLogin") == 0) ? false : true;
	loPassword.value = "";
}

function fnSearchSubmit(poForm)
{
	var loZip		= poForm.searchFormZip
	var loZipcode	= poForm.zipcode
	var loCity		= poForm.searchFormCity
	var loState		= poForm.searchFormState
	
	if (fnTrim(loZip.value) != '' && !isNaN(loZip.value))
	{
		loZipcode.value		= loZip.value
		loCity.value		= '' 
		loState.value		= ''
	} 
	else if (fnTrim(loCity.value) != '' && fnTrim(loState.value) == '')
	{
		alert(fnErrorNoState());
		return false;
	} 
	else if (fnTrim(loCity.value) == '' && fnTrim(loState.value) != '')
	{
		alert(fnErrorNoCity());
		return false;
	} 
	else if (fnTrim(loCity.value) != '' && fnTrim(loState.value) != '')
	{
		loZipcode.value = loCity.value + ', ' + loState.value;
		loZip.value = '';
	} 
	else
	{
		alert(fnErrorMissingVariables());
		return false;
	}
	_hbLink('homeSearch','right','0,0,30,30');
	return true;
}

function fnEnterSubmit(psSubmit, psEvent) 
{
	// check if the key hit is "return," submit via the submit function if it is
	// Usage: pass the name of the button (poSubmit) and an event (psEvent, usually event) when calling this script
	var liCharacter;
		
		liCharacter = (psEvent && psEvent.which) ? psEvent.which : ((psEvent) ? psEvent.keyCode : null);	//determine whether to use the Netscape or IE key character
		
		if (liCharacter == 13 || psEvent == "enter")	// if the user hits return or clicks the button
		{
			fnActivate(psSubmit);
		}
}

function fnActivate(psSubmit)
{
// pass the id of the button (psSubmit) when calling this script
	if (psSubmit == 'GO')
	{
		g_fnHeaderLoginGet('frm_UserName, frm_Password', '/pub/login.asp?checkLogin=true&sessionTestSet=true&originalPage=' + escape(document.location.pathname + document.location.search));
	}
	else if (psSubmit == 'SearchNMList')
	{
		g_fnValidateSearchSubmit('SearchList');
	}
	else if (psSubmit == 'SearchMList')
	{
		g_fnValidateSearchSubmit('SearchList');
	}
}

function g_fnHeaderLoginGet(paElementIDs, psDestination) 
{
// submit the login and check for existing cookies
	var loUserName			= document.getElementById('frm_UserName');
	var loPassword			= document.getElementById('frm_Password');
	var loRemember			= document.getElementById('frm_RememberLogin');
	var lsErrorMessage		= "";
	
		if (!loUserName.value || !loPassword.value)
		{
			loUserName.focus();
			alert(fnErrorNoLoginInfo());
			return false;
		}
		
		if (loRemember && loRemember.checked == true) //IE 6 is blocking cookies: no good way around this 06.2007 BGM
		{
			fnSetCookie("RememberUN", loUserName.value, 365, "/", "", "");	//UserName value
			fnSetCookie("RememberLogin", 1, 365, "/", "", "");
		}
		else
		{
			fnDeleteCookie("RememberUN", "/", "");
			fnSetCookie("RememberLogin", 0, 365, "/", "", "");
		}
	
		fnForm(paElementIDs, psDestination, "&");
		
		_hbLink('header_login_go','right','0,0,30,30');
		return true;
}

function fnForm(paElementIDs, psDestination, psVariableInitialAdditionOverRide, psVariables, pbPopup) 
{
// paElementNames are the id's of all elements to be submitted, psDestination is the destination the elements are being submitted to.
	var laElementIDs				= paElementIDs.split(", ") // put the Elements into an array called laElementIDs
	var loElementID;	// used in the loop for the specific element
	var lsVariableInitialAddition	= (psVariableInitialAdditionOverRide) ? psVariableInitialAdditionOverRide : "?";
	var lsVariables					= (psVariables != null) ? psVariables : ""; // the variables to be listed in the destination URL
	var lbPopup                     = (pbPopup) ? pbPopup : false;
	
		if (paElementIDs)
		{
			for(var x=0; x<laElementIDs.length; x++) //cycle through the elements
			{
				var loElementID = document.getElementById(laElementIDs[x]);
		
				if (x != 0){ lsVariables +=  "&"; }// check if it's the first addition of a variable: if it's not add an &
				lsVariables += loElementID.name + "=" + loElementID.value; // add on the variable		
			}
		}
		
		if (lsVariables.toLowerCase().match("password") != null)
		{
			document.getElementById('ifLogin').src = psDestination + lsVariableInitialAddition + lsVariables;
		}
		else if(lbPopup)
		{
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
		
		    //If lbPopup is passed in as True, we'll display the results in Popup
		    window.open(psDestination + lsVariableInitialAddition + lsVariables);
		}
		else
		{
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
		
			document.location.href = psDestination + lsVariableInitialAddition + lsVariables; // add on the variable to the end of the destination
		}	
}

function g_fnClearFormField(psFieldIdToClear,psColor)
{ 
	var lsFieldIdToClear = document.getElementById(psFieldIdToClear);
		
		lsFieldIdToClear.value  = ''; 
		lsFieldIdToClear.style.color =  (undefined != psColor && psColor != '') ? psColor : '#000';
}

function g_fnValidateSearchSubmit(psButtonClicked,psFormName,psFormFieldName_City,psFormFieldName_State,psFormFieldName_Zip,psFormFieldName_SearchCriteria,psFormFieldDefaultValue_City,psFormFieldDefaultValue_Zip,psViewMapButtonName,piIsForm,psURLDestination,psTemplate, psMapURL, pbPopup, psVariableInitialAdditionOverRide) {
	// initialize and set values
	var lsFormFieldCityName					= (psFormFieldName_City) ? fnTrim(psFormFieldName_City) : 'frm_City';
	var lsFormFieldStateName				= (psFormFieldName_State) ? fnTrim(psFormFieldName_State) : 'frm_State';		
	var lsFormFieldZipName					= (psFormFieldName_Zip) ? fnTrim(psFormFieldName_Zip) : 'frm_Zip';
	var lsFormFieldSearchCriteriaName		= (psFormFieldName_SearchCriteria) ? fnTrim(psFormFieldName_SearchCriteria) : 'zipcode';
	var lsFormFieldCityValueDefaultValue 	= (psFormFieldDefaultValue_City) ? fnTrim(psFormFieldDefaultValue_City) : 'Enter City';
	var lsFormFieldZipValueDefaultValue 	= (psFormFieldDefaultValue_Zip) ? fnTrim(psFormFieldDefaultValue_Zip) : 'Enter Zip';
	var lsViewMapButtonName					= (psViewMapButtonName) ? fnTrim(psViewMapButtonName) :'SearchMap';
	var lsFormName							= (psFormName) ? fnTrim(psFormName) : 'quickSearchForm';
	var liIsForm							= (piIsForm) ? piIsForm : null;
	var lsURLDestination					= (psURLDestination) ? psURLDestination : _mappingUrl;
	var lsMapURL							= (psMapURL) ? psMapURL : '/MapSearch/MapSearch/MapSearch.aspx';
	var lsButtonToTrack						= (psButtonClicked) ? psButtonClicked : null;
	var lsCriteriaValue;
	var lsCriteriaType;
	var lsDefaultButton						= 'SearchList';
	var lsTemplate							= (psTemplate) ? psTemplate : "MCode";
	var loTemplate							= document.getElementById(lsTemplate);
	var lsErrorMessage						= "";
	var loFormFieldSearchCriteriaName		= document.getElementById(lsFormFieldSearchCriteriaName);
	var loFormFieldCityName 				= document.getElementById(lsFormFieldCityName);
	var loFormFieldStateName				= document.getElementById(lsFormFieldStateName);
	var loFormFieldZipName					= document.getElementById(lsFormFieldZipName);
	var lsVariables;
    var lbPopup                             = (pbPopup) ? pbPopup : false; //Local var to specify whether or not the search is opened in popup or current windows
	var lsVariableInitialAddition	        = (psVariableInitialAdditionOverRide) ? psVariableInitialAdditionOverRide : '';

        //Begin Validation
		if ( (loFormFieldCityName.value == '' || loFormFieldCityName.value == lsFormFieldCityValueDefaultValue) && loFormFieldStateName.value == '' &&  (loFormFieldZipName.value == '' || loFormFieldZipName.value == lsFormFieldZipValueDefaultValue ) )
		{
			//No values entered
			lsErrorMessage += "- " + fnErrorNoCity() + "\n";
			lsErrorMessage += "- " + fnErrorNoState() + "\n";
		}
		else if (loFormFieldZipName.value != "" && loFormFieldZipName.value != lsFormFieldZipValueDefaultValue && (loFormFieldZipName.value.length != 5 || isNaN(loFormFieldZipName.value) ) )
		{
			//incorrect zip entered
			lsErrorMessage += "- " + fnErrorBadZipCode() + "\n";
		} 
		else if (loFormFieldCityName.value != '' && loFormFieldCityName.value != lsFormFieldCityValueDefaultValue && loFormFieldStateName.value == '')
		{
			//City entered but no state or zip
			lsErrorMessage += "- " + fnErrorNoState() + "\n";
		} 
		else if (loFormFieldStateName.value != '' && ( loFormFieldCityName.value == lsFormFieldCityValueDefaultValue || loFormFieldCityName.value == ''  ) && ( loFormFieldZipName.value == '' || loFormFieldZipName.value == lsFormFieldZipValueDefaultValue) ) 
		{	
			//State selected but no Zip or City
			lsErrorMessage += "- " + fnErrorNoCity() + "\n";
		}
		
		if (lsErrorMessage)
		{
			alert(lsErrorMessage);
		}
		else
		{
			if (loFormFieldZipName.value != '' &&  loFormFieldZipName.value != lsFormFieldZipValueDefaultValue)
			{
				if (lsURLDestination == '/MapSearch/MapSearch/MapSearch.aspx')
				{
					lsVariables = 'txtZip=' + loFormFieldZipName.value;
					loFormFieldSearchCriteriaName.value = loFormFieldZipName.value;
				} 
				else 
				{
					loFormFieldSearchCriteriaName.value = loFormFieldZipName.value
				}
			
				loFormFieldCityName.value	= '';
				loFormFieldStateName.value	= '';
				lsCriteriaType				= 'zip';
				lsCriteriaValue				= loFormFieldZipName.value;
			} 
			else 
			{
				if (lsURLDestination == '/MapSearch/MapSearch/MapSearch.aspx')
				{
					lsVariables = 'txtCity=' + loFormFieldCityName.value + '&txtCity=' + loFormFieldStateName.value;
				}
				else
				{
					loFormFieldSearchCriteriaName.value = loFormFieldCityName.value + ', ' + loFormFieldStateName.value;
				}				
				loFormFieldZipName.value	= '';
				lsCriteriaType				= 'city';
				lsCriteriaValue				= loFormFieldCityName.value + '~' + loFormFieldStateName.value;
			}
			
			
			if (psButtonClicked == lsViewMapButtonName) 
			{
				lsVariables = "criteriaType=" + lsCriteriaType + '&criteriaValue=' + lsCriteriaValue + '&' + loTemplate.name + '=' + loTemplate.value;
				fnForm('', lsMapURL, lsVariableInitialAddition, lsVariables, lbPopup);
			}
			else
			{
				lsCriteriaValue = lsCriteriaValue.replace('~',', ');
				
				if (lsURLDestination == '/MapSearch/MapSearch/MapSearch.aspx')
				{
					fnForm('', lsURLDestination, lsVariableInitialAddition, lsVariables, lbPopup);
				}
				else
				{
					lsVariables = 'zipcode=' + lsCriteriaValue + "&zipOnly=true";
					fnForm('', lsURLDestination, lsVariableInitialAddition, lsVariables, lbPopup);
				}
				
			}
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
			
			_hbLink(lsButtonToTrack,'right','0,0,30,30');
			return true;
		}
}

function fnTabSwitch(psSwitchElements, poCurrentElement, psPath)
{
	var laSwitchElements		= psSwitchElements.split(',');
	var laCurrentElement		= poCurrentElement.src.split('.')
	var liX						= 0;
	var lsPath					= (psPath) ? psPath : '';
		
		for(liX; liX<laSwitchElements.length; liX++)
		{
			var lsSwitchElement 		= document.getElementById(laSwitchElements[liX]);
			var lsSwitchElementSrc		= lsSwitchElement.src.replace('.gif','');
			var laSwitchElement			= lsSwitchElementSrc.split('/');
			var lsSwitchElementSrcPre	= laSwitchElement[laSwitchElement.length-1].replace('_1','');
			
				lsSwitchElement.src = (lsSwitchElement==poCurrentElement) ? lsPath + lsSwitchElementSrcPre + "_1.gif" : lsPath + lsSwitchElementSrcPre + ".gif";
		}

}

function MakeCalendarVisible(calendarID)
{
	var calendar = document.getElementById(calendarID);
	
	if(calendar)
	{
		var visible = 'none';
		
		if(calendar.style.display == 'none')
		{
			visible = 'block';
		}
		else
		{
			visible = 'none';
		}
		calendar.style.display = visible;
	}
}
	
function fnQADisplay(psElement, psQuestionElement)
{
	fnQASwitch("a1,a2,a3,a4,a5,a6,a7", psElement, 0);
	fnQASwitch("q1,q2,q3,q4,q5,q6,q7", psQuestionElement, 1);
}

function fnQASwitch(psSwitchElements, psCurrentElement, piElementLogic)
{
	var laSwitchElements		= psSwitchElements.split(",");
	var liX						= 0;
		
		for(liX; liX<laSwitchElements.length; liX++)
		{
			var lsSwitchElement		= laSwitchElements[liX];
			var loSwitchElement 	= document.getElementById(lsSwitchElement);
			
				if (piElementLogic == 0)
				{
					loSwitchElement.style.display = (lsSwitchElement==psCurrentElement) ? "block" : "none";
				}
				else if (piElementLogic == 1)
				{
					loSwitchElement.style.textDecoration = (lsSwitchElement==psCurrentElement) ? "none" : "underline";
				}
		}

}

function fnSwitchDisplay(psFillElement)
{
	var loFillElement = document.getElementById(psFillElement);
		
		if (loFillElement.style.display == "block") //if the element does not have any display set via jscript, it will skip to the "else" statement
		{
			loFillElement.style.display = "none";
		}
		else
		{
			loFillElement.style.display = "block";
		}
}


/********************************
Error Messages
********************************/

function fnErrorNoState(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please select a state."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoCounty(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please select a county."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoAddress(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please select an address."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoCity(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please enter a city."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoZip(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please enter a zip."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorMissingVariables(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Some search parameters are missing."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorBadZipCode(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please enter a 5-digit numerical zip code."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoCityOrState(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please enter a city and select a state."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
	
}

function fnErrorNoLoginInfo(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage	= "Please fill in both username and password."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
}

function fnErrorValidState(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please enter a valid state!"; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
}

function fnErrorNoSavedSearch(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "There are no saved searches in this list"; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
}

function fnErrorNoSavedSearchName(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "You must give the search a name to save it."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
}

function fnErrorNoSavedSearchSelect(psOverRideMessage)
{
	// returns an error message
	var lsDefaultMessage 	= "Please select a saved search."; // default error message
	var lsReturn			= fnErrorReturn(lsDefaultMessage, psOverRideMessage);
	
		return lsReturn;
}

function fnErrorIllegalCharacter(psOverRideMessage, psIllegalCharacter)
{
	// returns an error message
	var lsIllegalCharacter	= (psIllegalCharacter != undefined) ? psIllegalCharacter : 'a character you typed';
	var lsDefaultMessage 	= "Use of " + lsIllegalCharacter + " is not supported."; // default error message
	var lsReturn 			= (psOverRideMessage != '') ? psOverRideMessage : lsDefaultMessage;
	
		return lsReturn;
}

function fnErrorReturn(psDefaultMessage, psOverRideMessage)
{
	var lsReturn			= (psOverRideMessage != undefined) ? psOverRideMessage : psDefaultMessage;
	
		return lsReturn;
}

function fnErrorCatchAll(psErrors)
{
	alert('These fields must be entered:\n\n' + psErrors);
}

//Validation of Zip Code
function ValidateZipCode(psZipValue) {

  rExp = / /gi
  
  psZipValue = psZipValue.replace(rExp,'')
  
  if (isNaN(psZipValue) || psZipValue.length != 5) 
  {
    alert('You must enter a 5 digit numeric zip code')
    
    return false;
  }
  
  return true;
}

//Foreclosure Laws Searching Functions

//searchType - specified parameter shows whether searching type is quick or something else
function ExtendedSearchPropertyByList(searchType, state, county, city, zip)
{
    if(searchType == 'quicksearch')
    {
        if (state != '' && city != '')
        {
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
        
            if (zip != '')
            {
                location.href = _freeSearchResultUrl + '?zipcode=' + zip + '&zipOnly=true&submit=Begin+Search&selStatus='; 
            }
            else
            {
                location.href = _freeSearchResultUrl + '?txtCity=' + city + '&txtCity=' + city;
            }
        }
        else if (zip != '')
        {
            if(ValidateZipCode(zip))
            {
				// Clear out cookie value
				fnClearSearchRequestCookieValue();
            
                location.href = _freeSearchResultUrl + '?zipcode=' + zip + '&zipOnly=true&submit=Begin+Search&selStatus='; 
            }
        }
        else
        {
             alert('Please enter a city and state, or zip code');
        }
    } 
    else 
    {
        if (county != '0') 
        {
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
        
            location.href = _freeSearchResultUrl + '?selCounties=' + objCounty.value;    
        } 
        else 
        {
            alert('Please select a county');
        }
    }
}

function ExtendedSearchPropertyByMap(searchType, state, county, city, zip, serverRoot)
{   
    if(searchType == 'quicksearch')
    {
        if (state != '' && city != '')
        {
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
        
            if (zip != '')
            {
                location.href = '' + serverRoot + _mappingUrl + '?criteriaType=zip&criteriaValue=' + zip;
            }   
            else
            {       
                location.href = '' + serverRoot + _mappingUrl + '?criteriaType=city&criteriaValue=' + city + '~' + state;
            }
        }
        else if(zip != '')
        {
            if(ValidateZipCode(zip))
            {
				// Clear out cookie value
				fnClearSearchRequestCookieValue();
            
                location.href = '' + serverRoot + _mappingUrl + '?criteriaType=zip&criteriaValue=' + zip;
            }
        }
        else
        {
            alert('Please enter a city and state, or zip code');
        }
    }
    else
    {
        if ( county != '0')
        {
			// Clear out cookie value
			fnClearSearchRequestCookieValue();
			
            location.href = '' + serverRoot + _mappingUrl + '?criteriaType=county&criteriaValue=' + county;
        }
        else
        {
            alert('Please select a county');
        }
    } 
}

function fnClearSearchRequestCookieValue()
{
	// Clear out cookie value
	fnSetCookie("SearchRequest", "", null, "/", null, null);
}

//Custom Declarative Catalog [Web Parts]

function ShowDeclarativeCatalogSelectedItem(sender)
{
    var imageURL = sender.options[sender.selectedIndex].getAttribute("ImagePath");
    var imgPreview = document.getElementById("imgpreview");
    
    imgPreview.src = imageURL;
    
//    var AutoClose = false;
//    
//    var optNN='scrollbars=no,width=500,height=500,left=100,top=100';
//    var optIE='scrollbars=no,width=150,height=100,left=100,top=100';

//    if (navigator.appName=="Netscape")
//    {
//        imgWin=window.open('about:blank','',optNN);
//    }
//        
//    if (navigator.appName.indexOf("Microsoft")!=-1)
//    {
//        imgWin=window.open('about:blank','',optIE);
//    }
//    with (imgWin.document)
//    {
//        writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
//        writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
//        writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
//        writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
//        writeln('width=300-(document.body.clientWidth-document.images[0].width);');
//        writeln('height=300-(document.body.clientHeight-document.images[0].height);');
//        writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
//        writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
//        writeln('function doTitle(){document.title="Web Part Preview";}');writeln('</sc'+'ript>');
//        
//    if (!AutoClose)
//    { 
//        writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
//    }
//    else
//    { 
//        writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
//    }
//        
//    writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
//    close();		
//    }
}

function g_fnWindowOpen(psURL, psLocation, psName, psParameters)
{
	var loChildWindow;
	var lsURL   = psURL + psLocation;

		loChildWindow = window.open(lsURL, psName, psParameters)
		loChildWindow.window.focus()
}

function g_fnSharperAgentFlashRedirect()
{
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	
	if (sPage == "Advertisement.aspx")
	{
		window.location.href = "http://" + document.domain + "/" + sPage;
	}
}

function g_fnShowHideFieldDef(mDiv,obj,Ovr)
{
    // Remove any whitespace characters.
    var nDiv = mDiv.replace(/\s/g,'_');
    nDiv = "fieldDef_" + nDiv;

    // position and show.
    var iDiv = document.getElementById(nDiv);
    
    if(!iDiv)
    {
        return false;
    }
    
    var curleft = 0
    var curtop = 0;
    var curwidth = 0;
    var newWidth = 456;
    // retrieves shadow <div>
    var sDiv = iDiv.lastChild;
    
	if (obj.offsetParent && obj.offsetWidth) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		curwidth = obj.offsetWidth;
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		curtop += 26;
		//curleft += curwidth + 8;
	}
	else
	{
	    return false;
	}
	
    iDiv.style.top = curtop + "px";
    iDiv.style.left = curleft + "px";
    iDiv.style.display = ( iDiv.style.display.indexOf("block") < 0 && Ovr == 1 )?"block":"none";
}

function noSelects(state)
{
    var f = document.getElementsByTagName('SELECT');
    for (i=0;i<f.length;i++)
    {
        if (state > 0)
        {
            f[i].style.display = 'none';
        }
        else
        {
            f[i].style.display = 'inline';        
        }
    }
}
