/* Show/Hide Layers */
function showhidelayer(l){
	var currentdisplay = document.getElementById(l).style.display;
	
	if(currentdisplay == "none"){
		document.getElementById(l).style.display = "";
		if(l == "div_refinesearch"){
			document.getElementById("div_refinesearch_marker").innerHTML = "-";
		}
		if(l == "div_rightrail"){
			document.getElementById("div_rightrail_marker").innerHTML = "+";
			document.getElementById("map").className = "displayMap";
		}
	}else{
		document.getElementById(l).style.display = "none";
		if(l == "div_refinesearch"){
			document.getElementById("div_refinesearch_marker").innerHTML = "+";
		}
		if(l == "div_rightrail"){
			document.getElementById("div_rightrail_marker").innerHTML = "-";
			document.getElementById("map").className = "displayMap_large";
		}
	}
}

function icon_maploading(){
	var currentdisplay = document.getElementById("icon_maploading").style.display;
	
	if(currentdisplay == "none"){
		document.getElementById("icon_maploading").style.display = "";
	}else{
		document.getElementById("icon_maploading").style.display = "none";
	}
}


/* Search Listings */
function LookAtNextPage(ThisPage) {
	var myPage = ThisPage;
	document.forms.TheNextPage.method = "Post"
	document.TheNextPage.ThisPage.value = myPage;
	document.TheNextPage.submit();
}
function LookDetails(lc,lid,ct) {
	document.details.Lid.value = lid;
	document.details.LIndex.value = ct;
	document.details.action =  lc + "details.asp?Lid="+ lid;
	document.details.submit();
}
function ReSortListings(Sort,Order) {
	document.forms.TheNextPage.method = "Post"
	document.TheNextPage.Sort.value = Sort;
	document.TheNextPage.Order.value = Order;
	document.TheNextPage.ThisPage.value = "";
	document.TheNextPage.submit();
}
function BackToResult() {
	document.details.action = "results.asp";
	document.details.submit();
}
function searchtype(s){
	if(s){
		document.refinesearch.searchtype.value= s;
	}
}


/* Search Listings - Detail Paging */
function goPreviousDetail(){
	if (document.forms.details.ALLIndex ) {
		var arryLsId = document.forms.details.ALstrLsId.value.split(","); 
		document.forms.details.ALLIndex.value =  parseInt ( document.forms.details.ALLIndex.value )-1 ; 
		if ( arryLsId[document.forms.details.ALLIndex.value-1].substr(0,1 ).toUpperCase() == 'U' )  
			document.forms.details.action = "udetails.asp"; 
		else 
			document.forms.details.action = "ndetails.asp"; 			
		document.forms.details.submit(); 
	}else{
		var arryLsId = document.forms.details.strLsId.value.split(","); 
		document.forms.details.LIndex.value =  parseInt ( document.forms.details.LIndex.value )-1 ; 
		if ( arryLsId[document.forms.details.LIndex.value-1].substr(0,1 ).toUpperCase() == 'U' )  
			document.forms.details.action = "udetails.asp"; 
		else 
			document.forms.details.action = "ndetails.asp"; 
		document.forms.details.submit(); 
	}
	
}
function goNextDetail(){
	if (document.forms.details.ALLIndex ) {
		var arryLsId = document.forms.details.ALstrLsId.value.split(",");
		document.forms.details.ALLIndex.value = 1+ parseInt ( document.forms.details.ALLIndex.value ); 	 
		if ( arryLsId[document.forms.details.ALLIndex.value-1].substr(0,1 ).toUpperCase() == 'U' )  
			document.forms.details.action = "udetails.asp"; 
		else 
			document.forms.details.action = "ndetails.asp"; 			
		document.forms.details.submit(); 
	}else{	
		var arryLsId = document.forms.details.strLsId.value.split(",");
		document.forms.details.LIndex.value = 1+ parseInt ( document.forms.details.LIndex.value ); 	 
		if ( arryLsId[document.forms.details.LIndex.value-1].substr(0,1 ).toUpperCase() == 'U' )  
			document.forms.details.action = "udetails.asp"; 
		else 
			document.forms.details.action = "ndetails.asp"; 
		document.forms.details.submit(); 
	}
		
}


/* Popups */
function popup(URL, w, h) {
	//default values
	if(w == ""){ w = 400; }
	if(h == ""){ h = 500; }
	features = ",scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";

	//tweaked window sizes
	if (URL.indexOf("/googlemap.asp") != -1){ //map1
		w = 630;
		h = 630;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/maps.google.com") != -1){ //map1
		w = 700;
		h = 650;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}	else if (URL.indexOf("/popup_emailafriend.asp") != -1){ //email friend
		w = 560;
		h = 550;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/printlisting.asp") != -1){ //print listing
		w = 650;
		h = 600;
		features = ",scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/popup_thumbnails.asp") != -1){ //thumbnails
		w = 750;
		h = 600;
		features = ",scrollbars=yes,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/popup_emailagent.asp") != -1){ //email agent
		w = 560;
		h = 600;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/popup_textmessage.asp") != -1){ //text message
		w = 485;
		h = 420;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}else if (URL.indexOf("/popup_mortgagecalculator.asp") != -1){ //text message
		w = 610;
		h = 440;
		features = ",scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no,location=no,directories=no";
	}

	mywindow = window.open(URL,"","width=" +w +",height=" +h +features);
}
function getRSS() {
	document.forms.TheNextPage.action = "../rss/rss_sro.asp";
	document.forms.TheNextPage.method = "get"
	document.forms.TheNextPage.target = "_blank"; 
	document.forms.TheNextPage.submit();
	//document.forms.TheNextPage.action = "results.asp";
	//document.forms.TheNextPage.target = ""; 
	
}
function viewList() {
	document.forms.TheNextPage.method = "Post"
	document.forms.TheNextPage.action = "results.asp";
	document.forms.TheNextPage.submit();
}
function viewMap() {
	document.forms.TheNextPage.method = "Post"
	document.forms.TheNextPage.ThisPage.value = parseInt( (document.forms.TheNextPage.ThisPage.value-1) /10 )+ 1; 
	
	document.forms.TheNextPage.action = "results_map.asp";
	document.forms.TheNextPage.submit();
}

function viewSingleMap() {
	document.forms.TheNextPage.method = "Post"
	document.forms.TheNextPage.ThisPage.value = parseInt( (document.forms.TheNextPage.ThisPage.value-1) /10 )+ 1; 
	
	document.forms.TheNextPage.action = "single_map.asp";
	document.forms.TheNextPage.submit();
}


//////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////
/* Change Font */
	/* Interstital */
function changefont_interstitial(myform, myid){
	if(myform){
		document.getElementById(myid).className = 'txt_blue01';
	}
	else{
		document.getElementById(myid).className = 'td';
	}
}


/* Clean Data */
function cleandata(f){
	if(f.length == 0){ f = 0; return f;}

	f = f.replace("$","");
	f = f.replace(/%/g,"");
	f = f.replace(/,/g,"");

	return f;
}


/* Auto Jump Form Fields (as in phone numbers) */
var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength) {
	var myForm=document.forms[document.forms.length - 1];
	var myField=myForm.elements[fieldName];
	myField.nextField=myForm.elements[nextFieldName];
	if (myField.maxLength == null)
		myField.maxLength=fakeMaxLength;
		myField.onkeydown=autojump_keyDown;
		myField.onkeyup=autojump_keyUp;
}
function autojump_keyDown(){
	this.beforeLength=this.value.length;
	downStrokeField=this;
}
function autojump_keyUp(){
	if (
	   (this == downStrokeField) && 
	   (this.value.length > this.beforeLength) && 
	   (this.value.length >= this.maxLength)
	   )
	   this.nextField.focus();
	downStrokeField=null;
}
/*search */
function findLonLat( pAddress ) {	  
	var geocoder = new GClientGeocoder(); 
	geocoder.getLocations( pAddress, getAddressLatLon); 
}
function msgLocationNotFound(){
		alert("Sorry, we were unable to find that address. For best results, make sure to include city and zip code.\nFor example: 6205 Peachtree Dunwoody Road, Atlanta, GA, 30328" ) ; 		
}
/* Is Numeric */
function IsNumeric(sText){
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
    
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}

/* Format Currency */
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + '$' + num);// + '.' + cents);
}

/* Fill Homestyle */
function fillhomestyle(f){
	var array_finalarray_text = new Array("- Home Style -");
	var array_finalarray_values = new Array("");

	//home style values for single family homes
	var array_sf_text = new Array("A-Frame", "Bungalow", "Cape cod", "Chalet", "Cluster", "Colonial", "Contemporary", "Cottage", "County", "European", "French provincial", "Mobile", "Modular", "Other", "Patio", "Ranch", "Rustic", "Step less entry", "Traditional", "Tutor", "Victorian");
	var array_sf_values = new Array("80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100");

	//home style values for multi family homes
	var array_mf_text = new Array("Duplex", "Multiplex", "Other", "Top floor", "Triplex");
	var array_mf_values = new Array("", "101", "102", "103", "104", "105");
	
	//home style values for apartments, condos, townhouse
	var array_aptcontown_text = new Array("End unit", "Garden", "Ground floor", "High rise", "Loft", "Other", "Top floor");
	var array_aptcontown_values = new Array("", "106", "107", "108", "109", "110", "111", "112");
	
	//home style values for manufactured/mobile homes
	var array_manuhomes_text = new Array("Mobile", "Modular", "Other");
	var array_manuhomes_values = new Array("113", "114", "115");
	
	//clear homestyle dropdown; default to No Preference
	document.refinesearch.homestyle.options[0].text = "- Home Style -";
	document.refinesearch.homestyle.options[0].value = "";
	document.refinesearch.homestyle.options.length = 1;
	
	//determine arrays to use
	if((f == 22) || (f == 30)){// default, singlefamily/home for rent
		array_finalarray_text = array_finalarray_text.concat(array_sf_text);
		array_finalarray_values = array_finalarray_values.concat(array_sf_values);
	}else if(f == 18){//multifamily
		array_finalarray_text = array_finalarray_text.concat(array_mf_text);
		array_finalarray_values = array_finalarray_values.concat(array_mf_values);
	}else if((f == 11) || (f == 25)){//apartments, condos, townhouse
		array_finalarray_text = array_finalarray_text.concat(array_aptcontown_text);
		array_finalarray_values = array_finalarray_values.concat(array_aptcontown_values);
	}else if((f == 17) || (f == 32)){//manufactured/mobile homes
		array_finalarray_text = array_finalarray_text.concat(array_manuhomes_text);
		array_finalarray_values = array_finalarray_values.concat(array_manuhomes_values);
	}else{//clear homestyle dropdown; default to No Preference
		document.refinesearch.homestyle.options[0].text = "- Home Style -";
		document.refinesearch.homestyle.options[0].value = "";
		document.refinesearch.homestyle.options.length = 1;
	}
	
	//loop through homestyle array and populate homestyle dropdown
	for (var k = 0; k < array_finalarray_text.length - 1; k++){
		document.refinesearch.homestyle.options[k] = new Option(array_finalarray_text[k],array_finalarray_values[k]);
	}
	
	if (f == 16){
		document.refinesearch.builttype.disabled = true;
		document.refinesearch.homestyle.disabled = true;
		document.refinesearch.storiestype.disabled = true;
		document.refinesearch.constructiontype.disabled = true;
		document.refinesearch.basementtype.disabled = true;
		document.refinesearch.garage.disabled = true;
	}else{
		document.refinesearch.builttype.disabled = false;
		document.refinesearch.homestyle.disabled = false;
		document.refinesearch.storiestype.disabled = false;
		document.refinesearch.constructiontype.disabled = false;
		document.refinesearch.basementtype.disabled = false;
		document.refinesearch.garage.disabled = false;
	}
}
function viewMapDef( defLid ) {
	document.forms.TheNextPage.defaultLid.value = defLid; 	
	document.forms.TheNextPage.ThisPage.value = parseInt( (document.forms.TheNextPage.ThisPage.value-1) /10 )+ 1; 
	viewMap(); 
}
function NHviewMapDef( defLid ) {
	document.forms.TheNextPage.defaultLid.value = defLid; 		
	 document.forms.TheNextPage.ThisPage.value = parseInt( (document.forms.TheNextPage.ThisPage.value-1) /10 )+ 1; 	 
	document.forms.TheNextPage.action = "index.asp";
	document.forms.TheNextPage.submit();

}
function getFormPars(){
		var myform= document.forms.TheNextPage;
		 
		returnVal = ""; 
		if (myform ){
			for( var i = 0; i < myform.elements.length; i ++ ){
				returnVal += myform.elements[i].name + "=" + myform.elements[i].value +"&"; 
			}
			returnVal = returnVal.substr(0, returnVal.length-1); 
		}
		return returnVal; 
}
var AjaxObj = {
	getObj : function( handler ){
			var obj = null;
			 try {
				obj =  new ActiveXObject('Msxml2.XMLHTTP');
				obj.onreadystatechange = handler;
				return obj;
			  } catch (e) {}
			  try {
			 	obj= new ActiveXObject('Microsoft.XMLHTTP')
				obj.onreadystatechange = handler;
				return obj;
			  } catch (e) {}
			  try {				
			   	obj= new XMLHttpRequest();
			   	obj.onload=handler;
				obj.onerror=handler; 					
					return obj;
			  } catch (e) {}			  
			return obj;
	}
 }

function openSend( xmlreq, url, updatestr){				  
  	xmlreq.open( "POST",url, true);			
	xmlreq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
	xmlreq.setRequestHeader('Content-length', updatestr.length);			
	xmlreq.send(updatestr);
}

function trackClickThrought( flag, ftarget, fcat, fsubcat ){
	var params = "jcall=yes&flag="+flag +"&ftarget=" + ftarget +"&fcat=" + fcat +"&fsubcat="+ fsubcat;
	var url  = "../+comshare/clickthrough.asp"; 
	var flagreq = AjaxObj.getObj(null);	
	openSend(flagreq, url, params); 
}

    function movedescription()
    	{
    	document.getElementById("hidephoto").style.display ="none"
	    	if (document.getElementById("EnlargeImageLink"))
	    	{
	    	document.getElementById("EnlargeImageLink").style.display ="none"
	    	}
    	document.getElementById("border_general011").id='NONE'
    	}
    	
    function clearipixlink(){
	document.getElementById("ipixlink").style.display = "none";
}	
