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(){

	endPanTimer = null; 
	myzoomlevel  = map.GetZoomLevel();
	thismapcenter = map.GetCenter();
	icon = "searchlist";
	//getPropInfo();
	submitSearch(document.sidesearch);
} 


function updateSearch(){

	map.DeleteAllShapes();
	//getFrmparameters(url, icon);
	submitSearch(document.sidesearch);
	}

	// Call the Web service method to get the lat/longs 

function stopMappan(){
	
	map.DetachEvent("onendpan",EventEndCPan);
	map.DetachEvent("onendzoom", EventEndCPan);

	}


var isBusy;
var mapPoints;
var totalcnt;

function CallToGetList (url, icon){
//	alert(url)
	var  xmlhttp=getHTTPObject();	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState == 4) {
        // only if "OK"
        if (xmlhttp.status == 200) {
		 isBusy=false;
			SucceededCallback(xmlhttp.responseText, icon, url);
	
		} else {
            alert("There was a problem retrieving the lisitngs:\n" +    xmlhttp.statusText);
			isBusy=false;
        }
 		}
	};



  	xmlhttp.open("GET",url,true);
  	xmlhttp.send(null);
	isBusy=true;
}

//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, url){

    var points = result;
	
	//mapPoints = new Array(1);
	if(points.length > 0 ) {
		
        var latLongTokens = points.split('|');
        var veLatLongs = new Array(latLongTokens.length -1);
		
        //alert(latLongTokens.length);
        var centerLatLong;
		totalcnt = latLongTokens[0].split(',')[1];

	
		if(totalcnt < 202){
		var outputHTML="<div class='clear mb15' ></div><h3 class='title'>"+totalcnt +" Mapped Listings</h3><table width='100%'>	<tr><th align='left' valign='bottom'>Address</th><th align='left' valign='bottom'>Price</th><th align='left' valign='bottom'>Description</th></tr>";
		var counter = 1;
		//var stoppanning ;	
        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 image  = latLongTokens[index].split('~')[14];
			var soldRange  = latLongTokens[index].split('~')[15];
			var openhouse  = latLongTokens[index].split('~')[16];
			var myencodedurl  = latLongTokens[index].split('~')[17];
			var mydecodedurl = 'http://realestate.marthaturner.com/Sites/MTP/homevalueidx/index.cfm?gotourl='+ escape(myencodedurl);
			var state = "TX";
			
			var propIcon = "images/forsalepin.png";
			//number formating
			if(PropStatus != 'Closed'){
				pPrice = '$'+new NumberFormat(pPrice).toFormatted();
			}else
				pPrice = '$'+soldRange;
				
			var myclass='';
			if (counter%2==0){
				myclass = 'even';
				}
			
			
			sqft = new NumberFormat(sqft).toFormatted();
			detailurl = 'http://realestate.marthaturner.com/Sites/MTP/dispSearch.cfm?mlnum='+mlnum;
			
			if(PropStatus == 'Closed'){
				//pPrice =soldRange;
				detailurl = 'http://realestate.marthaturner.com/Sites/MTP/homevalueidx/index.cfm?gotourl='+myencodedurl;
				propIcon = "images/soldpin.png";
			}
			
			if(pid ==7){
				propIcon = "images/leasepin.png";
				}
				
			if(openhouse =='Y'){
				propIcon = "images/openhousepin.png";
				}
				
			if (index == 1 && (icon =='singlepoint'|| icon =='searchwithloc' )){
			   	centerLatLong = new VELatLong (latitude, longitude);
				map.SetCenterAndZoom(centerLatLong, myzoomlevel);
				thismapcenter = map.GetCenter();
			
			}
					
			veLatLongs[index] = new VELatLong(latitude, longitude);
			outputHTML  += "<tr class='"+ myclass+"'><td align='left' valign='middle'><a href='";
			outputHTML += detailurl+ "'  target='new'><strong>" +address + "</strong></a></td><td width='100' align='left' valign='middle'>";
			outputHTML +=  pPrice + "</td><td align='left' valign='middle'>";
			outputHTML += bed+ " Bedroom(s)"+" / "+ bath+ " Bathroom(s)"+ sqft+" sq ft home</td></tr>";	

			counter += 1;
			if( (pid != 6 && pid !=2) || PropStatus == 'Closed'){
					
				if(PropStatus == 'Closed'){
					propString = "<div style='width:200px'><a href='"+mydecodedurl+"' target='new'><img src='"+image+"' width='190' height='155px' border='0'></a><div  id='propDetailDiv' style='font-size:10px; background-color:ffffff;width:200px'>"+"<span class='mdBlueBold'>"+address+"<br></span> "+city+', '+zip+"<br>"+pPrice+" (" +propclass+")- " + PropStatus 
					} else{
				propString = "<div style='width:200px'><a href='"+detailurl+"' target='new'><img src='"+image+"' width='190' height='155px' border='0'></a><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 + " Bed";
				if(bath != '')
					propString = propString +" / "+bath + " Bath";
			
				
				if(sqft != '')
					propString = propString +"<br>SQFT: "+sqft;
				if(sqftsrc != '')
					propString = propString +sqftsrc;
			//address = address.replace(' ', '-');
				if(PropStatus == 'Closed'){
				propString = propString +"<br><a href='"+mydecodedurl+"' target='new'>View Details</a>"
				}else{
					propString = propString +"<br><a href='"+detailurl+"' target='new'>View Details</a>"
					}

		}
		if((pid ==6 || pid== 2) &&  PropStatus != 'Closed'){
			propString = "<div style='width:200px'><a href='"+detailurl+"' target='new'><img src='"+image+"' width='190' height='155px' border='0'></a>"
			
			propString += "<iframe src='multiLists.cfm?mlnum="+mlnum + "' width='200' height='200px' scrolling='auto' frameborder='0' marginwidth='0' marginheight='0'></iframe>"
		
		}

propString = propString +"<br>Drive Direction <a href='#' onclick=\"javascript:showDriveDiv('drivedivfrom');\">From Here</a>  <a href='#' onclick=\"javascript:showDriveDiv('drivedivto');\">To Here</a></div></div>";
propString = propString +"<div>";



var driveDivHTMLfrom = "";
driveDivHTMLfrom = driveDivHTMLfrom +"<div id='drivedivfrom' style='display:none;width:200px;backgroudcolor:ffffff;font-size:10px;font-family:Verdana'><input style='font-size:10px;font-family:Arial' id='txtFrom' type='text' name='txtFrom' value=' "+address+','+city+','+zip+"' size='40'>"
driveDivHTMLfrom = driveDivHTMLfrom +"<br>  To:<INPUT style='font-size:10px;font-family:Arial' id='fromtxtTo' type='text' name='fromtxtTo' value='' size='40'>"

driveDivHTMLfrom = driveDivHTMLfrom +"<br><INPUT  style='font-size:10px;font-family:Arial' id='find' type='button' value='Find' onclick=\"FindLoc('from');\" ></div>"

var driveDivHTMLto = "";
driveDivHTMLto = driveDivHTMLto +"<div id='drivedivto' style='display:none;width:200px;backgroudcolor:ffffff;font-size:10px;font-family:Verdana'><input style='font-size:10px;font-family:Arial' id='totxtFrom' type='text' name='totxtFrom' value='' size='40'>"
driveDivHTMLto = driveDivHTMLto +"<br>  To:<INPUT style='font-size:10px;font-family:Arial' id='txtTo' type='text' name='txtTo' value=' "+address+','+city+','+zip+"' size='40'>"

driveDivHTMLto = driveDivHTMLto +"<br><INPUT  style='font-size:10px;font-family:Arial' id='find' type='button' value='Find' onclick=\"FindLoc('to');\" ></div>"

propString = propString +driveDivHTMLto + driveDivHTMLfrom;

//var myPin = new VEPushpin(mlnum, veLatLongs[index], propIcon, 'Property Information', propString, 'iconStyle',    'titleSytle',  'detailsStyle');

var shape = new VEShape(VEShapeType.Pushpin, veLatLongs[index]);

         //Set the icon
         shape.SetCustomIcon(propIcon);
         
         //Set the info box
       //  map.ClearInfoBoxStyles();
	   if(pid != 6 && pid !=2){
         shape.SetTitle("<font face='Arial, Helvetica, sans-serif' size='1px' color='666666'>Property Information</font>");
	   }
	   
	   if(pid == 6 || pid ==2){
		     shape.SetTitle("<span class='mdBlueBold'>"+address+"</span>");

		   }
         shape.SetDescription(propString);
  
         //Add the shape the the map
		try{

			 map.AddShape(shape);
		
		}
		catch(e){}
		
		    var currentMarkerID = shape.GetID();
		
			
        }//end for
	//	alert(outputHTML);	
		outputHTML += "</table>";

		
		
      }//if  results less 202
			//alert(icon+'edn');
	
    }// end if
	else{
		var outputHTML="<div class='clear mb15' ></div><h3 class='title'> No Listings Found</h3></div>";
		}
	document.getElementById('rearchResult').innerHTML = outputHTML;
	//alert(icon);
		if( icon != 'poly'){
			map.AttachEvent("onendpan",EventEndCPan);
			map.AttachEvent("onendzoom", EventEndCPan);
			
		}
		
	//	alert(url + ',' + icon);
		
}


if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
