var clickit=0;

function markSelect(selID,selList){
	
	var selObj=document.getElementById(selID);
	for(var i=0;i<selObj.length;i++){
		if(findIt(selObj[i].value,selList)){
			selObj[i].selected=true;
		}
	}

}


function findIt(needle,haystack){
	var hayArr=haystack.split(",");
	for(var n=0;n<hayArr.length;n++){
		if(needle==hayArr[n]){
			return true;
		}
	}
	return false;
}

function checkNumber(chObj){
	if(typeof(chObj)=="string"){
		var myObj=document.getElementsByName(chObj);	
	}else{
		var myObj=document.getElementsByName(chObj.name);
	}
	var tot=0;
	for(var i=0;i<myObj.length;i++){
			if(myObj[i].checked==true){
				tot++;	
			}
	}
	if(tot>5){
				chObj.checked=false;
				alert("You are only allowed to select up to 5 lisitng.");
				return false;
	}

		return true;
	
}

function getReturnData(data,statCode,statMesg){
	//document.write(data);
	
		document.getElementById("mapContent").innerHTML=data;
}

function saveChanges(sID){
clickit=1;
hideSetting(sID);
document.myform.submit()

//doSwitch(sID);

}
function openTab(sID){
		var tObj=document.getElementById(sID+"_content");
		var mObj=document.getElementById(sID+"_img");	
		tObj.style.display="";
		mObj.src="images/minimize.gif";	
}

function doSwitch(sID){
	var tObj=document.getElementById(sID+"_content");
	var mObj=document.getElementById(sID+"_img");
	var ttObj=document.getElementById(sID+"_tabber");
	//alert(mObj);
	var curDisp=tObj.style.display;
	if(curDisp==""){
		tObj.style.display="none";
		mObj.src="images/maximize.gif";	
			ttObj.className="tabHead";
	}else{
		tObj.style.display="";
		mObj.src="images/minimize.gif";	
	
		ttObj.className="tabHeadOpen";
	}

}

function showWeekOpenHouses(){
	var tobjary=document.getElementsByName("tnwd");
	var tstr="";
	for(var i=0;i<tobjary.length;i++){
		if(tobjary[i].checked==true){
			tstr+=tobjary[i].value+",";
		}
	}

	if(tstr!=""){
		tstr=tstr.substr(0,tstr.length-1);
	}
	//alert("Map will only include Open Houses on the selected dates. All search criteria will be excluded.");	
	showInfo();
	document.myweekfrm.mwd.value=tstr;
	document.myweekfrm.submit();
}

function showOpenHouse(){
	var tob=document.getElementById("hd10").style.display;
	if(tob==""){
		document.getElementById("hd10").style.display="none";
		document.getElementById("wop").src="images/maximize.gif";
	}else{
		document.getElementById("wop").src="images/minimize.gif";
		document.getElementById("hd10").style.display="";
	}
}

function showInfo(){
	document.getElementById("infoDiv").style.display='';
	setTimeout("hideInfo()",4000);
}

function hideInfo(){
	document.getElementById("infoDiv").style.display='none';
}

function showSetting(sid){

	if(clickit!=1){
		document.getElementById("settingID_"+sid).style.display="";
	}
				clickit=0;
	
}
function hideSetting(sid){

	document.getElementById("settingID_"+sid).style.display="none";

}
function createTabber(tabName,sID,disp,heightx){

	var imgIC="images/maximize.gif";
	if(disp==""){
		imgIC="images/minimize.gif";
	}
	var ncont="<div id=\""+sID+"_tabber\" class='tabHead' onclick=\"doSwitch('"+sID+"');\" ><span class='imgTab'><img src='"+imgIC+"' id='"+sID+"_img' align='absmiddle'></span> &nbsp;<span class='tabText'>"+tabName+"</span></div><div id='"+sID+"_content' class='tabCont' style=\"width:99%;height:"+heightx+";display:"+disp+"\" onclick=\"showSetting('"+sID+"');\" >"+document.getElementById(sID).innerHTML+"<div id='settingID_"+sID+"' style='display:none;text-align:right;padding-right:10px;padding-top:10px;'><input type='button' value='APPLY SETTINGS' class='submit' onclick='saveChanges(\""+sID+"\");' /></div></div>";
	//clear out
	
	document.getElementById(sID).innerHTML=ncont;
	document.getElementById(sID).className="shownData";
}

function switchPrice(cObj){
	var tVal=cObj.value;
	if(tVal==1){
			document.getElementById("dvBuy").style.display="";
			document.getElementById("dvLease").style.display="none";
	}else{
					document.getElementById("dvBuy").style.display="none";
			document.getElementById("dvLease").style.display="";
	}	

}



function compfrmreturn(form, buttonName){
// require that at least one checkbox be checked
		var checkSelected = false;
		var checkCounter = 0;
		for (i = 0;  i < document.compareForm.listMLNUM.length;  i++){
			if (document.compareForm.listMLNUM[i].checked){
				checkSelected = true;
				checkCounter = checkCounter + 1;
				}
		}
		if (!checkSelected)	{
			alert("Please select at least one of the listings.");
			return;
			
		}
		if (checkCounter > 5){
			alert("You are only allowed to select up to 5 lisitng.\n Please uncheck one or some of your selection in order to select more.");
			return;
			
		}
		if(checkSelected && checkCounter <= 5 ){
			
			if(buttonName =='Compare'){
				 win=window.open('','myWin','width=850,height=900,scrollbars=yes,resizable=yes,left:0px, top:0px'); 
				 document.compareForm.target='myWin';
				 document.compareForm.action='http://search.har.com/engine/dispSetMycartTransit.cfm'
		
			 }else if (buttonName == 'showMap'){
				document.compareForm.target = '';
				//form.action='default.cfm';
				document.compareForm.action='default.cfm';
			 }
			 document.compareForm.submit();
		}
	
}


function flipdiv(divid){
//alert(divid);
		whichviewmap = document.getElementById('mmapview');
		whichviewlisting = document.getElementById('mlistingview');
		whichviewopen=document.getElementById("mopenhouses");
	if (divid == 'searchlist'){

		whichviewmap.style.display = 'none';
		whichviewopen.style.display='none';
		whichviewlisting.style.display = '';
		window.location = '#searchlist';
		
	}
	if (divid == 'myMap'){
		whichviewmap.style.display = '';
		whichviewopen.style.display='none';
		whichviewlisting.style.display = 'none';
		///
		document.getElementById("openhouse_dv").style.display='none';
		document.getElementById(divid).style.display='';
		window.location = '#maplist';
		//alert('map view now');
	}
	if(divid=='openhouse_dv'){
		whichviewmap.style.display = 'none';
		whichviewlisting.style.display = 'none';
			whichviewopen.style.display='';
		document.getElementById(divid).style.display='';
		document.getElementById("myMap").style.display='none';
		window.location = '#maplist';
	}
}
function waitPreloadPage() { //DOM
	if (document.getElementById){
		document.getElementById('prepage').style.visibility='hidden';
	}else{
		if (document.layers){ //NS4
		document.prepage.visibility = 'hidden';
		}
		else { //IE4
		document.all.prepage.style.visibility = 'hidden';
		}
	}
}

function frmvalidator(aform){
if (aform.Address.value == '' && aform.zip.value == ''){
	alert('Please enter an address or a zip code to search');
	return false;
	}
}

function copy_obj(o){
	  	var c = new Object();
		
		for (var e in o) {
			c[e] = o[e];
		}
		return c;
	  }
	  
function buildArray(lgt) {
    for (var i=0; i<= lgt; i++) this[i]=0;
    this.length = lgt;
    return this;
}

function buildGSpot(mlongtitude,mlatitude, mhtml, mlabel,mcity, mzip) { 
    this.longitude=mlongtitude;
    this.latitude=mlatitude;
	this.html = mhtml;
  	this.address = mlabel;
	this.city = mcity;
	this.zip = mzip
    return this;
}



function buildGSpotSingle(maddr, mlat,mlng) { 
 	this.label = maddr;
	this.lat = mlat;
	this.lng = mlng;
    return this;
};

function showPh(oid, mlnum, mid, phone) {
		document.getElementById("phbroker").innerHTML = "<span class='headers'>Phone:</span> " + phone;
		
	}
	