function EventEndCPan(){
   //If the timer is set, clear it and reset it

   if (endPanTimer != null)
   {
      window.clearTimeout(endPanTimer);
   }
   endPanTimer = window.setTimeout(HandleEndPan, END_PAN_TIMER_DELAY);
} 
function HandleEndPan(){
	 //  alert('I am here');

   endPanTimer = null; 

   // insert your end pan code here…
  ShowResults();
} 
function GetMapConner(url){
		var myMap = map.GetMapView();
		var dc = new VELatLongDecoder;
		
		var tl_s = ''+dc.Decode(myMap.TopLeftLatLong);
		var br_s = ''+dc.Decode(myMap.BottomRightLatLong);
		
		
		//var latitude = latLongTokens[index].split(',')[0];
		topLeftLat = tl_s.split(',')[0] ;
		topLeftLong = tl_s.split(',')[1] ;
		bottomRightLat = br_s.split(',')[0];
		bottomRightLong = br_s.split(',')[1];
	
		url = url.concat('&NElat=');
		url = url.concat(topLeftLat);
		
		url = url.concat('&NElng=');
		url = url.concat(topLeftLong);
		
		url = url.concat('&SWlat=');
		url = url.concat(bottomRightLat);
		
		url = url.concat('&SWlng=');
		url = url.concat(bottomRightLong);
		//alert(url);
		return(url);
		
}

function ShowResults(e)   {

	document.getElementById('resultDiv').innerHTML="";
     	
	var url = "/maps/m/getTempoPointsAround.cfm?all=1"
	icon = "aroundlist";
    
	getFrmparameters(url, icon);
	//alert('will get surrounding listings here');
	  }
	// Call the Web service method to get the lat/longs 
function getPropInfo()  {
    // Call the Web service method to get the lat/longs
	
	var url = "/maps/m/getTempoPoints.cfm?all=1"; // The server-side script
	//alert(mypoints);
	
	icon = "searchlist";
    
	getFrmparameters(url, icon);
}
function getFrmparameters(url, icon){

	var property_class_id = searchform.property_class_id.value;
	var LISTING_PRICE_MIN = searchform.LISTING_PRICE_MIN.value;
	var LISTING_PRICE_MAX = searchform.LISTING_PRICE_MAX.value;
	
	var LEASING_PRICE_MIN = searchform.LEASING_PRICE_MIN.value;
	var LISTING_PRICE_MAX = searchform.LEASING_PRICE_MAX.value;
	
	var SQURE_FEET_MIN = searchform.SQURE_FEET_MIN.value;
	var SQURE_FEET_MAX = searchform.SQURE_FEET_MAX.value;
	
	var LOTSIZE_MIN = searchform.LOTSIZE_MIN.value;
	var LOTSIZE_MAX = searchform.LOTSIZE_MAX.value;
	
	var BEDROOM_NUM = searchform.BEDROOM_NUM.value;
	var FULL_BATH_NUM = searchform.FULL_BATH_NUM.value;
	var liststatus = '';
	var liststatus_sel = document.getElementById('liststatus');
	
	
	for (var i=0; i<=liststatus_sel.options.length-1; i++) {
		if (liststatus_sel.options[i].selected) {
			if(i>0){
			liststatus = liststatus + liststatus_sel.options[i].value + ',';
			}
		}
	}
	if (icon != 'poly'){
	var SUBDIVISION = searchform.SUBDIVISION.value;
	var KEYMAP = searchform.KEYMAP.value;
	var ZIPCODE = searchform.ZIPCODE.value;
	
	var MLS_AREA_sel = document.getElementById('MLS_AREA');
	var location_sel = document.getElementById('LOCATION');
	
	var MLS_AREA = '';
	var location = '';
	
	
	for (var i=0; i<=MLS_AREA_sel.options.length-1; i++) {
			if (MLS_AREA_sel.options[i].selected) {
				if(i>0){
				MLS_AREA = MLS_AREA + MLS_AREA_sel.options[i].value + ',';
				}
			}
	}
	

	for (var i=0; i<=location_sel.options.length-1; i++) {
			if (location_sel.options[i].selected) {
				if(i>0){
				location = location + location_sel.options[i].value + ',';
				}
			}
	}
	}
	
	if (liststatus != ''){
		liststatus = liststatus+ "'end'";
		//alert(liststatus);
		url = url.concat('&liststatus=');
		url = url.concat(liststatus);
	}
	
	if (property_class_id != ''){
		url = url.concat('&property_class_id=');
		url = url.concat(property_class_id);
	}
	
	if (property_class_id != '' && property_class_id!= 7){
		if (LISTING_PRICE_MIN != ''){
			url = url.concat('&LISTING_PRICE_MIN=');
			url = url.concat(LISTING_PRICE_MIN);
		}
		if (LISTING_PRICE_MAX != ''){
			url = url.concat('&LISTING_PRICE_MAX=');
			url = url.concat(LISTING_PRICE_MAX);
		}
	}
	
	if (property_class_id != '' && property_class_id == 7){
		if (LEASING_PRICE_MIN != ''){
			url = url.concat('&LEASING_PRICE_MIN=');
			url = url.concat(LEASING_PRICE_MIN);
		}
		
		if (LEASING_PRICE_MAX != ''){
		url = url.concat('&LEASING_PRICE_MAX=');
		url = url.concat(LEASING_PRICE_MAX);
		}
	}
	
	
	

	if (SQURE_FEET_MIN != ''){
		url = url.concat('&SQURE_FEET_MIN=');
		url = url.concat(SQURE_FEET_MIN);
	}
	if (SQURE_FEET_MAX != ''){
		url = url.concat('&SQURE_FEET_MAX=');
		url = url.concat(SQURE_FEET_MAX);
	}
	if (LOTSIZE_MIN != ''){
		url = url.concat('&LOTSIZE_MIN=');
		url = url.concat(LOTSIZE_MIN);
	}
	if (LOTSIZE_MAX != ''){
		url = url.concat('&LOTSIZE_MAX=');
		url = url.concat(LOTSIZE_MAX);
	}
	

	
	if (BEDROOM_NUM != ''){
		url = url.concat('&BEDROOM_NUM=');
		url = url.concat(BEDROOM_NUM);
	}
	
	if (FULL_BATH_NUM != ''){
		url = url.concat('&FULL_BATH_NUM=');
		url = url.concat(FULL_BATH_NUM);
	}
	
if (icon != 'poly'){
	if (SUBDIVISION != ''){
		url = url.concat('&SUBDIVISION=');
		url = url.concat(SUBDIVISION);
	}
	if (KEYMAP != ''){
		url = url.concat('&KEYMAP=');
		url = url.concat(KEYMAP);
	}
	
	if (location != ''){
		location = location + '999'
		url = url.concat('&location=');
		url = url.concat(location);
	}

	if (MLS_AREA != ''){
		MLS_AREA = MLS_AREA + '999';
		url = url.concat('&MLS_AREA=');
		url = url.concat(MLS_AREA);
	}
	if (ZIPCODE != ''){
		url = url.concat('&ZIPCODE=');
		url = url.concat(ZIPCODE);
	}
}
	//if (ZIPCODE =='' && MLS_AREA ==''&&location =='' && SUBDIVISION == ''){
	if (icon != 'poly'){
	url=GetMapConner(url);
	}
		
	//}
	//alert(url);
	CallToGetList(url, icon);
}

function CallToGetList(url, icon){
	var http=getHTTPObject();
//window.open(url,'mywindow','width=650,height=500,toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');

	http.open("GET", url, false);
	http.send(null);

	var mypoints=http.responseText;
	if(http.status == 200){
		SucceededCallback(mypoints, icon);
	}
}
//added function:
//do not touch below
 function getHTTPObject() {
  var xmlhttp;
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  
  return xmlhttp;
}



// This is the callback function that 
// processes the value returned by the Web service.
function SucceededCallback(result, icon)
{
	//alert(icon);
    var points = result;
	
	
	if (icon =='singlepoint'){
		propIcon = HAR.pins.blueHouse;
	}
	else{
		HAR.deleteMarkers();
	    document.getElementById('resultDiv').innerHTML="";
	}
	
	   if(points.length > 0 ) {
		
        var latLongTokens = points.split('|');
        var veLatLongs = new Array(latLongTokens.length -1);
        
        var centerLatLong;
		var totalcnt = latLongTokens[0].split(',')[1];
		var curstatus = latLongTokens[1].split(',')[11];
		if(icon != 'singlepoint')
		if(curstatus == 'Active on Market' || curstatus =='Pending Continue to Show' || curstatus == 'Option Pending'){
			propIcon = HAR.pins.greenHouse;
		}else if (curstatus == 'closd'){
			propIcon = HAR.pins.redHouse;
		}else{		
			propIcon = HAR.pins.purpleHouse;
		}
		//alert(curstatus);
		document.getElementById('resultDiv').innerHTML+="<br>Total listing count: "+totalcnt;
		if(totalcnt >=200){
		document.getElementById('resultDiv').innerHTML+=
		"  Please note: the map only display top 200 listings including the search results and surounding listings.  To see more listings within the map view please zoom in the map or refine your search.";
		}
		
		if(totalcnt < 202){
        for(index = 1; index <= veLatLongs.length-1; index++)
        {
		
			var latitude = latLongTokens[index].split(',')[0];
			var longitude = latLongTokens[index].split(',')[1];
			var address  = latLongTokens[index].split(',')[2];
			var mlnum  = latLongTokens[index].split(',')[3];
			var pid  = latLongTokens[index].split(',')[4];
			var pPrice  = latLongTokens[index].split(',')[5];
			var propclass = latLongTokens[index].split(',')[6];
			var bed = latLongTokens[index].split(',')[7];
			var bath  = latLongTokens[index].split(',')[8];
			
			var sqft = latLongTokens[index].split(',')[9];
			var sqftsrc = latLongTokens[index].split(',')[10];
			
			var PropStatus  = latLongTokens[index].split(',')[11];
			var city  = latLongTokens[index].split(',')[12];
			var zip  = latLongTokens[index].split(',')[13];
			var uid  = latLongTokens[index].split(',')[14];
			var qtable  = latLongTokens[index].split(',')[15];

			//		alert(latitude+ ','+ longitude+','+pid);
			//number formating
			pPrice = '$'+new NumberFormat(pPrice).toFormatted();
			sqft = new NumberFormat(sqft).toFormatted();
			
			if (index == 1 && icon  == 'singlepoint'){
			   	centerLatLong = new google.maps.LatLng(latitude, longitude);
				HAR.map.setCenter(centerLatLong);
				HAR.map.setZoom(14);
				
			}

			if(pid != 6 && pid !=2)
			{				
				propString = "<div style='width:200px'><iframe src='/maps/m/slideroll.cfm?tempoagentview="+tempoagentview+"&mlnum="+mlnum+"&propclass="+propclass+"&PropStatus="+PropStatus+"&uid="+uid+"' width='200' height='180px' scrolling='no' frameborder='0' marginwidth='0' marginheight='0'></iframe><div  id='propDetailDiv' style='font-size:10px; background-color:ffffff;width:200px'>"+"<span class='mdBlueBold'>"+address+"<br></span> "+city+', '+zip+"<br>"+pPrice+" (" +propclass+")- " + PropStatus 

				if(bed != '')
					propString = propString +"<br>"+bed;
				if(bath != '')
					propString = propString +" / "+bath;
			
				
				if(sqft != '')
					propString = propString +"<br>SQFT: "+sqft;
				if(sqftsrc != '')
					propString = propString +sqftsrc;
			
				if(detailurl == 'http://www.harmls.com/SearchDetail/Scripts/PrtAgtFul/PrtAgtFul.asp?')	{
					propString = propString +"<br><a href='"+detailurl+"UidList="+uid+"&prp="+propclass+"' target='new'><img src='http://www.har.com/SeniorLiving/graphics/btnDetails.gif' border='0'></a>"
				}	
				else{
					propString = propString +"<br><a href='"+detailurl+"mlnum="+mlnum+"&class="+pid+"&sType=0' target='new'><img src='http://www.har.com/SeniorLiving/graphics/btnDetails.gif' border='0'></a>"
				}
			}
			if(pid ==6 || pid== 2){
				propString = "<div style='width:200px'><iframe src='/maps/m/multiTempoLists.cfm?UidList="+uid+"&qtable="+qtable+"' width='200' height='200px' scrolling='auto' frameborder='0' marginwidth='0' marginheight='0'></iframe>"
			}
	
			// Plot our pin
			HAR.plotPin({
				lat: latitude,
				lng: longitude,
				html: propString,
				pinIcon: propIcon
			});	
			
				
        }//end for

      }//if  results less 202
			//alert(icon+'edn');
		
    }// end if
	
		if(icon != 'singlepoint' && icon != 'poly'){
			//alert('map pan');
			map.AttachEvent("onendpan",EventEndCPan);
			map.AttachEvent("onendzoom", EventEndCPan);
		}
}


if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

