// JavaScript Document
var receiveReq = getXmlHttpRequestObject(); // Global http request object
var receiveReq1 = getXmlHttpRequestObject(); // Global http request object
var receiveReq2 = getXmlHttpRequestObject();
var map = null;
var limitForNoOfRecords=100;
var TYPE=null;
var POSTURL="";
var LISTINGID=null;
var PTYPE=null;
var NO_OF_RECORDS=0;
var SEARCHED=true;
//var pinPoint = null;
//var pinPixel = null;

// ====== Geocoding ======	  
var geoPin;
function showAddress() 
{
        showdivNoOfRecords();
        var searchData = document.getElementById("searchLoc").value;
        var geo = new GClientGeocoder();        
        var reasons=[];
      reasons[G_GEO_SUCCESS]            = "Success";
      reasons[G_GEO_MISSING_ADDRESS]    = "Address Missing: The address was either missing or had no value.";
      reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
      reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
      reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
      reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
      reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
   
    
        geo.getLocations(searchData, function (result)
          { 
            // If that was successful
            if (result.Status.code == G_GEO_SUCCESS) 
			{
			  var p = result.Placemark[0].Point.coordinates;
			  var gPoint = new GLatLng(p[1],p[0]);		  
			  
			  var point = new VELatLong(gPoint.lat(),gPoint.lng());
			
			 map.SetCenterAndZoom(point,13);
	
	var minPrice = document.getElementById('minPrice').value;
	var maxPrice = document.getElementById('maxPrice').value;
	var minBedRoom = document.getElementById('minBedRoom').value;
	var maxBedRoom = document.getElementById('maxBedRoom').value;
	var minBathRoom = document.getElementById('minBathRoom').value;
	var maxBathRoom = document.getElementById('maxBathRoom').value;
	var minSqft = document.getElementById('minSqft').value;
	var maxSqft = document.getElementById('maxSqft').value;
	var minA = document.getElementById('minacres').value;
	var maxA = document.getElementById('maxacres').value;
	var pType =document.getElementById('propertyType').value;
	 var c = document.getElementById("myMap");	
	 	 
	var url = "tomlinsonservice.asmx/SearchByPropertyType";
	 var UL = map.PixelToLatLong(new VEPixel(0,0));
	 var BR = map.PixelToLatLong(new VEPixel(c.offsetWidth,c.offsetHeight))       
	var postStr = "minlat="+BR.Latitude+"&minlong="+UL.Longitude+"&maxlat="+UL.Latitude+"&maxlong="+BR.Longitude+"&minp="+minPrice+"&maxp="+maxPrice+"&minbath="+minBathRoom+"&maxbath="+maxBathRoom+"&minbed="+minBedRoom+"&maxbed="+maxBedRoom+"&minsq="+minSqft+"&maxsq="+maxSqft+"&mina="+minA+"&maxa="+maxA+"&type="+pType;
	//alert(postStr);
	// setCookie('postStringUrl',postStr,365,"/"); set cookie for user searches
		
	TYPE=2;
	makeRequest1(url, postStr,displaymarker); 
			  
//			    var url = "tomlinsonservice.asmx/SearchBygeocode";  
//	            var postStr = "lat="+p[1]+"&lang="+p[0]; 
//	            makeRequest(url, postStr,displayEndpan);			 
			  
            }
            // ====== Decode the error status ======
            else 
			{
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) 
			  {
                reason = reasons[result.Status.code];
              } 
              alert('Could not find "'+searchData+ '" ' + reason);
              document.getElementById("searchLoc").focus();			
            }
          } );
}
    
function GetMap()
{
	if (map!=null)
	{
	 map.Dispose();
	}
     map = new VEMap('myMap');     
     map.SetDashboardSize(VEDashboardSize.Tiny);	// MAP ZOOM-IN & ZOOM-OUT BUTTON 
     map.LoadMap();
     var pnt = new VELatLong(47.653544,-117.411263);
     map.SetCenterAndZoom(pnt,13);
     map.HideDashboard(); 
     map.AttachEvent("onendpan",OnEndPan); 
     map.AttachEvent("onmousewheel",MouseHandler);
    // map.AttachEvent("ondoubleclick",MouseHandler);
     map.AttachEvent("onendzoom", function_name);
     map.AttachEvent("onclick", test_onclick);
} 	

// *********************search by corner 

    function test_onclick()
    {
   // unCheckNearBy();
    }

    function unCheckNearBy()
    {
          /*  document.getElementById('restaurant').checked = false; 
            document.getElementById('dayCenter').checked = false;
            document.getElementById('school').checked = false;
            document.getElementById('officeChBox').checked = false;*/
    }

function function_name()
{
 OnEndPan();
 r.setValue(map.GetZoomLevel()); 
}
function MouseHandler()
{
 r.setValue(map.GetZoomLevel());
 //alert("Mouse SEARCHED="+SEARCHED);
}

 //var TESTBOOL=false;
 function OnEndPan()
 { 
 // alert("OnEndPan")
   if(SEARCHED)	
    return false;
	callLeftSearch();	
} 
  


function callSearch()
{
	showdivNoOfRecords();
	txt2search = document.getElementById('txtSearch').value; 	
	if(txt2search == "")
	{
		// document.getElementById('findErrorMsg').style.display = "block";
    // setTimeout('document.getElementById("findErrorMsg").style.display = "none"',4000);
     alert("Please enter MLS Number. ");
		document.getElementById('txtSearch').focus();
		return false;
	}
	else
	{
	   var url = "tomlinsonservice.asmx/dataforinfowindow";		
		var postStr = "searchtxt="+txt2search;
		POSTURL=postStr;
		TYPE=1;		
		// alert(postStr);
		 makeRequest(url, postStr,displayEndpan);
	}
}

function createMarker(point, B_mid,B_price,B_add, B_city, B_bed, B_bath, B_acre, B_sqft,url,type)
{
	
	if(url == 'saveListing.gif')
	{
	var txt ='<div class="divHead"><div class="newTitle" >Property Type</div><div class="infoContent" style="padding-bottom:5px;"><b>'+type+'</b></div><div class="newTitle"><span class="newTitleCity">'+B_city+'</span> '+B_add+'</div><div class="infoContent"><div>$'+B_price+'</div>  <b>Price</b></div><div class="infoContent"><div>'+B_bed+'/'+B_bath+'</div>  <b>Bed/Bath</b></div><div class="infoContent"><div>'+B_acre+'</div>  <b>Acres</b></div><div class="infoContent"><div>'+B_sqft+'</div>  <b>Square Ft.</b></div></div><div class="divHead" style="margin-top:10px;"></div><div class="divHead" style="margin-top:10px;"><div class="newTitle">Get Directions</div><div class="links" id="headerDivInfo'+B_mid+'"><a id="123" href="javascript:void(0)"  onclick="toHere('+B_mid+');" >To here </a> -  <a href="javascript:void(0)" onclick="fromHere('+B_mid+');" >From here </a></div><form action="http://maps.google.com/maps" method="get" target="_blank"><div id="toDiv'+B_mid+'" style="display:none; .margin-top:-15px;">Start address:<br /><input id="txtTo'+B_mid+'" name="saddr" type="text" /><input name="daddr" type="hidden" value="'+point+'" /><input type="Submit" value="Go" /></div></form><form action="http://maps.google.com/maps" method="get" target="_blank"><div id="fromDiv'+B_mid+'" style="display:none; .margin-top:-15px">End address:<br /><input  id="txtFrom'+B_mid+'" name="daddr" type="text"  /><input name="saddr" type="hidden" value="'+point+'" /><input  type="Submit" value="Go"  /></div></form ></div><div class="links" style="padding-top:5px"><ul><li><a href="javascript:void(0)" onclick="opentellafriend('+B_mid+');">Tell a Friend</a></li><li><a href="javascript:void(0);" onclick="openTab('+B_mid+','+B_price+',\''+type+'\');">More Info</a></li></ul></div>';
	}else
	{
	var txt ='<div class="divHead"><div class="newTitle" >Property Type</div><div class="infoContent" style="padding-bottom:5px;"><b>'+type+'</b></div><div class="newTitle"><span class="newTitleCity">'+B_city+'</span>'+B_add+'</div><div class="infoContent"><div>$'+B_price+'</div>  <b>Price</b></div><div class="infoContent"><div>'+B_bed+'/'+B_bath+'</div>  <b>Bed/Bath</b></div><div class="infoContent"><div>'+B_acre+'</div>  <b>Acres</b></div><div class="infoContent"><div>'+B_sqft+'</div>  <b>Square Ft.</b></div></div><div class="divHead" style="margin-top:10px;"></div><div class="divHead" style="margin-top:10px;"><div class="newTitle">Get Directions</div><div class="links" id="headerDivInfo'+B_mid+'"><a id="123" href="javascript:void(0)"  onclick="toHere('+B_mid+');" >To here </a> -  <a href="javascript:void(0)" onclick="fromHere('+B_mid+');" >From here </a></div><form action="http://maps.google.com/maps" method="get" target="_blank"><div id="toDiv'+B_mid+'" style="display:none; .margin-top:-15px;">Start address:<br /><input id="txtTo'+B_mid+'" name="saddr" type="text" /><input name="daddr" type="hidden" value="'+point+'" /><input type="Submit" value="Go" /></div></form><form action="http://maps.google.com/maps" method="get" target="_blank"><div id="fromDiv'+B_mid+'" style="display:none; .margin-top:-15px">End address:<br /><input  id="txtFrom'+B_mid+'" name="daddr" type="text"  /><input name="saddr" type="hidden" value="'+point+'" /><input  type="Submit" value="Go"  /></div></form ></div><div class="links" style="padding-top:5px"><ul><li><a href="javascript:void(0)" onclick="checkCookie('+B_mid+',\''+type+'\');"   >Save</a></li><li><a href="javascript:void(0)" onclick="opentellafriend('+B_mid+');">Tell a Friend</a></li><li><a href="javascript:void(0);" onclick="openTab('+B_mid+','+B_price+',\''+type+'\');">More Info</a></li></ul></div>';
	//alert(txt)
	}  
	var uniqueNumber=B_mid+ Math.random();
    var pin = new VEPushpin(uniqueNumber, point, "images/"+url,null,txt);        
	return pin;
} 


// paging  ==========================================================================================
function txtselect(id)
 {
    document.getElementById(id).select(); 
 }

function divOver(id)
{
 document.getElementById(''+id+'').className = "resultDivMouseOver"; 
}

function divOut(id)
{
 document.getElementById(''+id+'').className = "resultDiv";
}


var num_of_page = 0;
var cur_page = 1;
var prev_page = 1;
var next_page = 1;
var pageNum = 1;
var rowsperpage = 5;
function showData(pageNum)
{
	//alert(xmlDoc.getElementsByTagName('id').length);
//alert("paging show data"+pageNum);
  
     var id = xml.getElementsByTagName("ListingID");
     var A_price = xml.getElementsByTagName("Price");
	 var A_add = xml.getElementsByTagName("Address");
	 var A_city = xml.getElementsByTagName("CityName");
     var A_type = xml.getElementsByTagName("TBSubPropTypeName");	
     var tbldata = "";
	// tbldata = '<table bgcolor="#000000" width="100" border="0" cellpadding="0" cellspacing="0">';
	 

	 for(i = ((pageNum-1)*rowsperpage); i< (pageNum*rowsperpage) && i<id.length; i++)
	 {
        var B_price = parseInt(A_price[i].firstChild.nodeValue);
	    var B_add = String(A_add[i].firstChild.nodeValue);
        var B_city = String(A_city[i].firstChild.nodeValue);
        
	    var B_type = String(A_type[i].firstChild.nodeValue);
       // var A_type = xml.getElementsByTagName("TBSubPropTypeName");
        var str =B_city;
        var reg = new RegExp("'");
        if (reg.test(str))
        {
        B_city = B_city.replace("'","\'");
         // alert(B_city);
        } 
	 	//alert(B_city.test("'"));
	 	var pid = parseInt(id[i].firstChild.nodeValue); //alert(pid);
        tbldata += '<div id="div'+i+'" onmouseover="javascript:divOver(this.id);" onmouseout="javascript:divOut(this.id);" class="resultDiv" onclick="openTab('+pid+','+B_price+',\''+B_type+'\');"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr><td width="12%" style=" padding-top:4px" rowspan="2" valign="top"><span style="background-color:#FFFF99; color:#000000; padding:1px;">'+(i+1)+'</span></td><td width="88%" style="font-weight:bold; height:15px;">'+B_type+' $'+B_price+'</td></tr><tr><td>'+ B_add +','+ B_city +'</td></tr></table></div>';
       // tbldata += '<tr><td style="color:#FFFFFF">'+pid+'</td></tr>';
		//tbldata += '<tr><td style="color:#FFFFFF">'+pid+'</td></tr>';
	 }
	 //tbldata += '</table>';

	 document.getElementById('divsearchresult').innerHTML = tbldata;

	// Creating previous & first button 
	 if (pageNum > 1) // if pageno is greater than 1 else button will not 
	{ 
    	ppage = pageNum - 1; 
        pprev = '<input type="button" value=" < " name="ppre" onclick="showData('+ppage+');" />'; 
		pprev = '<span class="prev"><a href="javascript:void(0);" onclick="showData('+ppage+');" >Previous</a></span> ';
        pfirst = '<input type="button" value=" << " name="pfst" onclick="showData(1);" />'; 
	}  
	else 
	{ 
    	pprev  = '&nbsp;'; // we're on page one, don't print previous link 
	    pfirst = '&nbsp;'; // nor the first page link 
	} 

	if (pageNum < num_of_page) 
	{ 
	    ppage = pageNum + 1; 
	    //pnext = '<input type="button" value=" > " name="pnxt" onclick="showData('+ppage+');" />'; 
		pnext = ' <span class="nxt"><a href="javascript:void(0);" onclick="showData('+ppage+');" >Next</a></span> ';
	    plast = '<input type="button" value=" >> " name="plst" onclick="showData('+num_of_page+');" />'; 
	}  
	else 
	{ 
	    pnext = '&nbsp;'; // we're on the last page, don't print next link 
	    plast = '&nbsp;'; // nor the last page link 
	} 
	
	nav = "";
	for(ppage = pageNum-2 ; ppage <= (pageNum+2) && ppage <= num_of_page ; ppage++) 
	{ 
    	if(ppage > 0)
		{
			if (ppage == pageNum) 
    		{ 
        		nav += '<span class="current-link">'+ppage+'</span>';   // no need to create a link to current page 
    		} 
    		else 
    		{ 
        		//nav += ' <span class="num-links"><a href="javascript:void(0);" onClick="showData('+ppage+');" >'+ppage+'</a></span> '; 
    		}
		}         
	} 
	//alert(num_of_page)
	document.getElementById('pagination').innerHTML = '<div style="float:right">page '+nav +'/'+num_of_page+'</div> <div>'+pprev+' '+pnext+'</div>' ;//pprev +" "+ pnext +"  Page " + nav +"/"+ num_of_page ;
	 
}

function emptyPropertyDiv()
{
document.getElementById('divsearchresult').innerHTML="";
document.getElementById('pagination').innerHTML="";
}


//end paging ======


///////////////////  Left Welcome Search  /////////////////////
var pstString="";
function callLeftSearch()
{       
	//var cityid = document.getElementById('cityName').value;
	var minPrice = document.getElementById('minPrice').value;
	var maxPrice = document.getElementById('maxPrice').value;
	var minBedRoom = document.getElementById('minBedRoom').value;
	var maxBedRoom = document.getElementById('maxBedRoom').value;
	var minBathRoom = document.getElementById('minBathRoom').value;
	var maxBathRoom = document.getElementById('maxBathRoom').value;
	var minSqft = document.getElementById('minSqft').value;
	var maxSqft = document.getElementById('maxSqft').value;
	var minA = document.getElementById('minacres').value;
	var maxA = document.getElementById('maxacres').value;
    var pType =document.getElementById('propertyType').value;
     var c = document.getElementById("myMap");
	//var url = "tomlinsonservice.asmx/SearchByAll";
	var url = "tomlinsonservice.asmx/SearchByPropertyType";
	 var UL = map.PixelToLatLong(new VEPixel(0,0));
	 var BR = map.PixelToLatLong(new VEPixel(c.offsetWidth,c.offsetHeight))       
	var postStr = "minlat="+BR.Latitude+"&minlong="+UL.Longitude+"&maxlat="+UL.Latitude+"&maxlong="+BR.Longitude+"&minp="+minPrice+"&maxp="+maxPrice+"&minbath="+minBathRoom+"&maxbath="+maxBathRoom+"&minbed="+minBedRoom+"&maxbed="+maxBedRoom+"&minsq="+minSqft+"&maxsq="+maxSqft+"&mina="+minA+"&maxa="+maxA+"&type="+pType;
	// setCookie('postStringUrl',postStr,365,"/"); set cookie for user searches
	pstString=postStr;
	POSTURL=postStr;	
	TYPE=2;
	
	makeRequest1(url, postStr,displaymarker);
	
}

function displaymarker()
{
var no_of_records=0;
closeErrorMoreRecordsDiv();
//alert(receiveReq.readyState);
  if(receiveReq.readyState == 4) 
  {
        document.getElementById('divwaiting').style.display='none';
	    document.getElementById('greyPopup').style.display='none';
	    var xmlDoc = receiveReq.responseXML;
	  // alert(receiveReq.responseText);
	   
	   
	    var countrw = xmlDoc.getElementsByTagName('Cnt');
    	
	        if(countrw.length > 0 )
	        { 
	        map.DeleteAllPushpins();	
	        no_of_records = parseInt(countrw[0].firstChild.nodeValue);
            NO_OF_RECORDS=no_of_records;	    
	        //document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"> <span>'+no_of_records+'</span> Records Found&nbsp;</div><div class="rightImageRecord" ><a href="javascript:void(0);"><img src="images/tabImage.gif" alt="Image" border="0" onclick="call_savesearch();" /></a></div>' ;  //Properties found	</strong> </p>';
	     //  alert(no_of_records);
	        }
	    if(no_of_records <= limitForNoOfRecords)
	    {	
	          var data = xmlDoc.getElementsByTagName('Price');  
	           NO_OF_RECORDS=data.length;
	           no_ofrecords(NO_OF_RECORDS);
	            if(data.length > 0)
	                {
	                 setCookie('postStringUrl',pstString,365,"/");
	                 closeErrorMoreRecordsDiv();
	                 generatemarker(xmlDoc);	
	                 }
	                    else
	                {
		                map.DeleteAllPushpins();
		                document.getElementById('divsearchresult').innerHTML="";
		                document.getElementById('pagination').innerHTML="";
		                xml = null;
		                SEARCHED = false; // to implement search for aaddress
		               myalert();
		                //alert("No records found !");		                
		                closeErrorMoreRecordsDiv();
		               document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"> <span>'+no_of_records+'</span> Records Found&nbsp;</div>' ;  //Properties found	</strong> </p>'; 
	                }          
         }
         else
         {
         no_ofrecords_withoutsave(no_of_records);
         SEARCHED=false;
         document.getElementById('errorMoreRecordsDiv').style.display="block";
         emptyPropertyDiv();
        // alert("please Refine your search at present record is:: "+no_of_records);
         }
   } 
      else if(receiveReq.readyState == 1 || receiveReq.readyState == 2 || receiveReq.readyState == 0 || receiveReq.readyState == 3 )
        {
         document.getElementById('divwaiting').style.display='block';
         document.getElementById('greyPopup').style.display='block';
        }
}

var xml = null;
var locs = new Array(); 
function generatemarker(xmlDoc)
{
var savedListingTbl = "";
xml = xmlDoc;

  	map.DeleteAllPushpins();	
	
	var A_id = xmlDoc.getElementsByTagName("ListingID");
	var A_price = xmlDoc.getElementsByTagName("Price");
	var A_add = xmlDoc.getElementsByTagName("Address");
	var A_sqft = xmlDoc.getElementsByTagName("AssessedSqFt");
	var A_bed = xmlDoc.getElementsByTagName("Bedrooms");
	var A_bath = xmlDoc.getElementsByTagName("Bathrooms");
	var A_city = xmlDoc.getElementsByTagName("CityName");	
	var A_acre = xmlDoc.getElementsByTagName("Acreage");
	var A_lat = xmlDoc.getElementsByTagName("Latitude");
	var A_lng = xmlDoc.getElementsByTagName("Longitude");	
	var A_type = xmlDoc.getElementsByTagName("TBSubPropTypeName");	
	//var B_type = String(A_type[i].firstChild.nodeValue);
	locs.length = 0;
	//alert(A_id.length);
	for(i=0; i < A_id.length; i++)
	{
	 
		var B_mid = parseInt(A_id[i].firstChild.nodeValue);
		var B_price = parseInt(A_price[i].firstChild.nodeValue);
		var B_add = String(A_add[i].firstChild.nodeValue);
		
		var B_sqft = parseFloat(A_sqft[i].firstChild.nodeValue);
		
		var B_bed = parseInt(A_bed[i].firstChild.nodeValue);
		var B_bath = parseInt(A_bath[i].firstChild.nodeValue);
		var B_city = String(A_city[i].firstChild.nodeValue); 
		var B_acre = parseFloat(A_acre[i].firstChild.nodeValue);
		var B_lat = String(A_lat[i].firstChild.nodeValue);
		var B_lng = String(A_lng[i].firstChild.nodeValue);	
		var B_type = String(A_type[i].firstChild.nodeValue);			
	    
	//  alert(i);
//        var str =B_city;
//        var reg = new RegExp("'");
//        if (reg.test(str))
//        {
//          B_city = B_city.replace("'"," ");
//          alert(B_city);
//        } 
	       
		var point = new VELatLong(B_lat,B_lng);
        locs[i] = point;
       // alert(point);
		var marker = createMarker(point, B_mid,B_price,B_add, B_city, B_bed, B_bath, B_acre, B_sqft,'home.gif',B_type);
	   //alert(marker);
	    map.AddPushpin(marker);
	}
	if(TESTCOOKIE == true)
	{
	SEARCHED=true;
	map.SetMapView(locs);	
	}
	if(TEST == 1)
	{
	 SEARCHED=true;
	 map.SetMapView(locs);	 
	}
	setTimeout("SEARCHED=false;",2500);	
	TESTCOOKIE=false; 
	TEST=0;
	num_of_page = Math.ceil(A_id.length/rowsperpage);		
	
	showData(pageNum);
	
}

var TEST=0;
function callSavedWelcomeSearch()
{  
    SEARCHED=false;
    showdivNoOfRecords();
    TEST=1;
    map.DeleteAllPushpins(); //for previous marker
   //alert(xml);
    if(xml != null)
    {       
       generatemarker(xml);
       var A_id = xml.getElementsByTagName("ListingID");
       no_ofrecords(A_id.length);       
    }
    else
    {
       no_ofrecords_withoutsave(NO_OF_RECORDS);    
       if( NO_OF_RECORDS > limitForNoOfRecords )
       {      
       document.getElementById('errorMoreRecordsDiv').style.display="block";
       }
    }
    
}


function hidedivNoOfRecords()
{
 document.getElementById('ContainerdivNoOfRecords').style.display = "none";
}
function showdivNoOfRecords()
{
 document.getElementById('ContainerdivNoOfRecords').style.display = "block";
}
function no_ofrecords(no)
{
 document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"> <span>'+no+'</span> Records Found&nbsp;</div><div class="rightImageRecord" ><a href="javascript:void(0);"><img src="images/tabImage.gif" alt="Image" border="0" onclick="call_savesearch();" /></a></div>' ;  //Properties found	</strong> </p>'; <div class="recordDiv"><span>'+A_id.length+'</span> Records Found</div>';	
}
function no_ofrecords_withoutsave(no)
{
 document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"> <span>'+no+'</span> Records Found&nbsp;</div>';	
}
function closeErrorMoreRecordsDiv()
{
 document.getElementById('errorMoreRecordsDiv').style.display="none";
}

//////////////////////////////////////////////////////////////////////////
	
function callSearchEnter(e)
{
	var characterCode;
	if(e && e.which)
	{
		e = e;
		characterCode = e.which;
	}
	else
	{
		e = event;
		characterCode = e.keyCode;
	}

	 if(characterCode == 13)
	  callSearch();
}

function callAddressSearch(e)
{
	var characterCode;
	if(e && e.which)
	{
		e = e;
		characterCode = e.which;
	}
	else
	{
		e = event;
		characterCode = e.keyCode;
	}

	 if(characterCode == 13)
	  showAddress();
}
function ZoomIn()
{
	//Increase zoom level by a factor of 1
	map.ZoomIn();
	r.setValue(map.GetZoomLevel());
	
}
     
function ZoomOut()
{
	//Decrease zoom level by a factor of 1
	map.ZoomOut();	
	r.setValue(map.GetZoomLevel());
}

function road()
{
map.SetMapStyle(VEMapStyle.Road);
document.getElementById("road").style.color="#ff9900";
document.getElementById("aerial").style.color="#fff000";
document.getElementById("Mode3d").style.color="#ff9900";
}
function aerial()
{
map.SetMapStyle(VEMapStyle.Hybrid);
document.getElementById("road").style.color="#fff000";
document.getElementById("aerial").style.color="#ff9900";
document.getElementById("Mode3d").style.color="#ff9900";
}
function Mode3d()
{
map.SetMapStyle(VEMapStyle.Mode3d);
document.getElementById("road").style.color="#fff000";
document.getElementById("aerial").style.color="#ff9900";
document.getElementById("Mode3d").style.color="#ff9900";
}

function closediv()
{
disableddl('');
document.getElementById("greyPopup").style.display="none";
document.getElementById("tabdiv").style.display="none";

}

function openTab(listingid,pr,ptype)
{
PTYPE=ptype;
LISTINGID=listingid;
closetellafriend();
document.getElementById("greyPopup").style.display="block";
document.getElementById("tabdiv").style.display="block";

//document.getElementById("callPage").innerHTML="";
url="overview.asp?listingid="+LISTINGID+"&ptype="+ptype;
getTabsData(url);

//receiveReq2
//document.getElementById("callPage").src="overview.aspx?listingid="+LISTINGID+"&ptype="+ptype;
document.getElementById("lioverview").className = "current";
document.getElementById("tabprice").innerHTML="Price: $"+pr;
setcss('lioverview');
disableddl('true');
}
//code  for ajax tabs 
function getTabsData(url)
{
if (receiveReq2.readyState == 4 ||  receiveReq2.readyState == 0 ) 
	 {	 
	//alert("receiveReq.readyState == 4 ")
	   receiveReq2.open("GET", url, true);
	   //Set the function that will be called when the XmlHttpRequest objects state changes
	   receiveReq2.onreadystatechange = responseFun; 	
//	   receiveReq2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//	   receiveReq2.setRequestHeader("Content-length", param.length);
//	   receiveReq2.setRequestHeader("Connection", "close");	
	   //Make the request
	   receiveReq2.send(null);	   
	 }
	  else 
    if(receiveReq2.readyState == 0 || receiveReq2.readyState == 1 || receiveReq2.readyState == 3)
     {
     document.getElementById("callPage").innerHTML='<img src="images/loading.gif" />Searching please wait';
     }

}

function responseFun()
{
    if(receiveReq2.readyState == 4)
    {
   // alert(receiveReq2.responseText);
    document.getElementById("callPage").innerHTML=receiveReq2.responseText;
    }
    else 
    if(receiveReq2.readyState == 0 || receiveReq2.readyState == 1 || receiveReq2.readyState == 3)
     {
     document.getElementById("callPage").innerHTML='<img src="images/loading.gif" />Searching please wait';
     }
}


function disableddl(val1)
    {
        document.getElementById("propertyType").disabled=''+val1+'';
        document.getElementById("minPrice").disabled=''+val1+'';
        document.getElementById("maxPrice").disabled=''+val1+'';

        document.getElementById("minBedRoom").disabled=''+val1+'';
        document.getElementById("maxBedRoom").disabled=''+val1+'';

        document.getElementById("minBathRoom").disabled=''+val1+'';
        document.getElementById("maxBathRoom").disabled=''+val1+'';

        document.getElementById("minSqft").disabled=''+val1+'';
        document.getElementById("maxSqft").disabled=''+val1+'';
        document.getElementById("minacres").disabled=''+val1+'';
        document.getElementById("maxacres").disabled=''+val1+'';

    }


function callpropertydiv()
{

    if(document.getElementById("chboxproperty").checked ==false)
    {
    document.getElementById("propertydiv").style.display="none";
    }
    else
    document.getElementById("propertydiv").style.display="block";

}

function getpagedata1(tabid)
        {
        document.getElementById("callPage").src=null; 
       // alert(tabid);
           if(tabid==0)
           { 
           var url="overview.asp?listingid="+LISTINGID+"&ptype="+PTYPE; 
            getTabsData(url);           
          // document.getElementById("callPage").src="overview.aspx?listingid="+LISTINGID+"&ptype="+PTYPE;
           setcss('lioverview');//document.getElementById("").className = "current";
           }
           if(tabid==1)
           { 
            var url="photos.asp?listingid="+LISTINGID;
            getTabsData(url);               
           //document.getElementById("callPage").src="photos.aspx?listingid="+LISTINGID;
           setcss('photos');//document.getElementById("photos").className = "current";
           }
           if(tabid==2)
           { 
           var url="placestovisit.asp?listingid="+LISTINGID;
            getTabsData(url);                
           //document.getElementById("callPage").src="placestovisit.asp?listingid="+LISTINGID;
           setcss('places');
           }
           if(tabid==3)
           { 
          // alert("fdf");
          var url="contact.asp?listingid="+LISTINGID;
            getTabsData(url);
          // document.getElementById("callPage").src="contact.asp?listingid="+LISTINGID;
           setcss('locallink');
           }
        }
function setcss(curr)
{
//alert(curr);
document.getElementById("lioverview").className = "";
document.getElementById("photos").className = "";
document.getElementById("places").className = "";
document.getElementById("locallink").className = "";
document.getElementById(''+curr+'').className = "current";

}

///////////////////////////////  AJAX POST REQUEST FUNCTION COMMON FOR ALL REQUEST   //////////////////////////////////////

//Initiate the AJAX request
function makeRequest(url, param, fun)
{ 

	//If our readystate is either not started or finished, initiate a new request
	
	   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
	   receiveReq.open("POST", url, true);	  
	   receiveReq.onreadystatechange = fun; 
	
	   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   receiveReq.setRequestHeader("Content-length", param.length);
	   receiveReq.setRequestHeader("Connection", "close");
	
	   //Make the request
	   receiveReq.send(param);
	   //receiveReq.send(null);
	
	 
}

// For lefthand search By Rajesh


function makeRequest1(url, param, fun)
{ 
	//If our readystate is either not started or finished, initiate a new request
	
	 if (receiveReq.readyState == 4 || receiveReq.readyState == 0  ) 
	 {
	   
	    //document.getElementById('divwaiting').style.display='none';
	   // document.getElementById('greyPopup').style.display='none';
	   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
	   receiveReq.open("POST", url, true);
	   //Set the function that will be called when the XmlHttpRequest objects state changes
	   receiveReq.onreadystatechange = fun; 
	
	   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   receiveReq.setRequestHeader("Content-length", param.length);
	   receiveReq.setRequestHeader("Connection", "close");
	
	   //Make the request
	  
	  // alert(param);
	   receiveReq.send(param);
	   //receiveReq.send(null);
	 } 

}


//Gets the browser specific XmlHttpRequest Object 

function getXmlHttpRequestObject() 
{
	 if (window.XMLHttpRequest) 
	 {
		return new XMLHttpRequest(); //Mozilla, Safari ...
	 }
	 else if (window.ActiveXObject) 
	 {	 
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	 } 
	 else 
	 {
		//Display our error message
		alert("Your browser doesn't support the XmlHttpRequest object.");
	 }
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=")
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1 
		c_end=document.cookie.indexOf(";",c_start)
		if (c_end==-1) c_end=document.cookie.length
		return unescape(document.cookie.substring(c_start,c_end))
		} 
	  }
	return ""
}

///////////////////search button saved cookie and on body load function 
var TESTCOOKIE=false;
function getDataOnMap() 
{   
    TESTCOOKIE=true;
    var pst = null;
    pst =getCookie('postStringUrl');  
    //alert(pst);
    var txtlisttingid=document.getElementById('hiddenlid').value; // Permalink for single marker
      
       if(txtlisttingid != "")
       {
           
            var url1 = "tomlinsonservice.asmx/dataforinfowindow";		
		    var postStr = "searchtxt="+txtlisttingid;			
		    makeRequest(url1, postStr,displayEndpan);   
       }
       else
       {
         if( pst != "" || pst == null)
            {  
            SEARCHED = true;             
            var arr=new Array();   
            arr= pst.split("&"); 
            var minp=arr[4];
            var maxp=arr[5];           
            document.getElementById('maxPrice').value = arr[4].split("=")[1];
            document.getElementById('maxPrice').value = arr[5].split("=")[1];
            document.getElementById('minBedRoom').value = arr[8].split("=")[1];    
            document.getElementById('maxBedRoom').value = arr[9].split("=")[1];            
            document.getElementById('minBathRoom').value = arr[6].split("=")[1];
            document.getElementById('maxBathRoom').value = arr[7].split("=")[1];
            document.getElementById('minSqft').value = arr[10].split("=")[1];
            document.getElementById('maxSqft').value = arr[11].split("=")[1];            
            document.getElementById('minacres').value = arr[12].split("=")[1];
            document.getElementById('maxacres').value = arr[13].split("=")[1]; 
            document.getElementById('propertyType').value = arr[14].split("=")[1];       	
	        var url = "tomlinsonservice.asmx/SearchByPropertyType";  
	        makeRequest1(url, pst,displaymarker);
	        }
	        else
	        { //alert("default");
	             
	            var url = "tomlinsonservice.asmx/SearchBygeocode";  
	            var postStr = "lat=47.653544&lang=-117.411263";  
	            makeRequest(url, postStr,displaymarker);		
	        }
	   }     
	        
}


function setCookie(c_name,value,expiredays,path)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" +escape( value ) +
	( (expiredays==null) ? "" : ";expires="+exdate.toGMTString() ) + 
	( ( path ) ? ";path=" + path : "" ) 
}

function Delete_Cookie( name, path, domain ) 
{
	if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
	
	
function checkCookie(LID,ptype)
{  
	//alert("test123");
	username=getCookie('tomlinson')
	if (username!=null && username!="")
    {	   
	   var url = "TomlinsonService.asmx/savelistings";
	   var postStr = "uniqueid="+username+"&listingid="+LID+"&ptype="+ptype;
	  
	   makeRequest(url,postStr,cookieResponse);
	}	
	else // If First time saving or no cookie present on the client machine
	{
		var tomID = Math.random();
		setCookie('tomlinson',tomID,365,"/");
		
		//alert(tomID);
		
		var url = "TomlinsonService.asmx/savelistings";
		var postStr = "uniqueid="+tomID+"&listingid="+LID+"&ptype="+ptype;
		makeRequest(url, postStr,cookieResponse);
	}
}

function cookieResponse()
{
  if(receiveReq.readyState == 4) 
  {
   
  var myxmldoc=receiveReq.responseXML;
  var ad = myxmldoc.getElementsByTagName("int");
  var v1=parseInt(ad[0].firstChild.nodeValue)
   if(TT)
	{
	waitingdivnone();
	}
	TT=true;
 // alert(v1);
  if(v1==1)
    {
    alert("This listing is saved previously.");
	}
	else
	alert("One Listing saved");	
	
  }  
} 
function waitingdivnone()
{
    document.getElementById('divwaiting').style.display='none';
	document.getElementById('greyPopup').style.display='none';
}
////////////////////////   ###### Saved Listing Code from here  ////////////////////////////

function showSavedListing()
{  
    showdivNoOfRecords();
    SEARCHED=true; 
    closeErrorMoreRecordsDiv();	  
    map.DeleteAllPushpins();
	var username=getCookie('tomlinson')
	if (username!=null && username!="")
    {	   
	  var url = "TomlinsonService.asmx/showsavelistings";
		var postStr = "uniqueid="+username;		
		makeRequest1(url, postStr,displaySavedMarker);
	}
	else
	{      
	 no_ofrecords_withoutsave(0);	
     map.DeleteAllPushpins();
    }
}
var xmlsave=null;
function displaySavedMarker()
{
  if(receiveReq.readyState == 4) 
  {
    document.getElementById('divwaiting').style.display='none';
	document.getElementById('greyPopup').style.display='none';
	var xmlDoc = receiveReq.responseXML;	
	xmlsave=xmlDoc;
	var data = xmlDoc.getElementsByTagName('Price');

	if(data.length > 0)
	 {	 
	 displaySavedMarkerData(xmlDoc);	 
     no_ofrecords_withoutsave(data.length);
     }
	 else
	 {
	// alert("There is no records corresponding to saved listing");
	 closeErrorMoreRecordsDiv();
	 map.DeleteAllPushpins();
	 }
  } 
  else if(receiveReq.readyState == 1 || receiveReq.readyState == 2 || receiveReq.readyState == 0 || receiveReq.readyState == 3 )
 {
	 document.getElementById('divwaiting').style.display='block';
	document.getElementById('greyPopup').style.display='block';
 }
}


function displaySavedMarkerData(xmlDoc)
{

    map.DeleteAllPushpins();
     
	var A_id = xmlDoc.getElementsByTagName("ListingID");
	var A_price = xmlDoc.getElementsByTagName("Price");
	var A_add = xmlDoc.getElementsByTagName("Address");
	var A_sqft = xmlDoc.getElementsByTagName("AssessedSqFt");
	var A_bed = xmlDoc.getElementsByTagName("Bedrooms");
	var A_bath = xmlDoc.getElementsByTagName("Bathrooms");
	var A_city = xmlDoc.getElementsByTagName("CityName");
	var A_acre = xmlDoc.getElementsByTagName("Acreage");
	var A_lat = xmlDoc.getElementsByTagName("Latitude");
	var A_lng = xmlDoc.getElementsByTagName("Longitude");	
	var A_type = xmlDoc.getElementsByTagName("TBSubPropTypeName");	
	
	var savedListingTbl = "";
	locs.length = 0;
	
	for(i=0; (i< A_id.length && i< 100); i++)
	{
		var B_mid = parseInt(A_id[i].firstChild.nodeValue);
		var B_price = parseInt(A_price[i].firstChild.nodeValue);
		var B_add = String(A_add[i].firstChild.nodeValue);
		//alert(B_sqft);
		var B_sqft = parseFloat(A_sqft[i].firstChild.nodeValue);
		
		var B_bed = parseInt(A_bed[i].firstChild.nodeValue);
		var B_bath = parseInt(A_bath[i].firstChild.nodeValue);
		var B_city = String(A_city[i].firstChild.nodeValue); 
		var B_acre = parseFloat(A_acre[i].firstChild.nodeValue);
		var B_lat = String(A_lat[i].firstChild.nodeValue);
		var B_lng = String(A_lng[i].firstChild.nodeValue);
	    var B_type = String(A_type[i].firstChild.nodeValue);
		//savedListingTbl += '<div class="resultDiv" onclick="openTab('+B_mid+','+B_price+');"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="12%" style=" padding-top:4px" rowspan="2" valign="top"><span style="background-color:#FFFF99; color:#000000; padding:1px;">'+(i+1)+'</span></td><td width="88%" style="font-weight:bold; height:15px;">$'+B_price+'</td></tr><tr><td>'+ B_add +','+ B_city +'</td></tr></table></div>';

        var point = new VELatLong(B_lat,B_lng);
        
        locs[i] = point; 
        
        var marker = createMarker(point, B_mid,B_price,B_add, B_city, B_bed, B_bath, B_acre, B_sqft,'saveListing.gif',B_type);
	    map.AddPushpin(marker);	        
	    
	}
		
	map.SetMapView(locs);
	
	
	num_of_page = 0;
    cur_page = 1;
    prev_page = 1;
    next_page = 1;
    pageNum = 1;
    rowsperpage = 5;
	num_of_page = Math.ceil(A_id.length/rowsperpage);	
	showData1(pageNum);
	
		
	//document.getElementById('savedListing').innerHTML= savedListingTbl;
}


//********************************* Paging For Saved Listing *********************

function showData1(pageNum)
{
	//alert(xmlDoc.getElementsByTagName('id').length);
//	//alert(pageNum);
  
     var id = xmlsave.getElementsByTagName("ListingID");
     var A_price = xmlsave.getElementsByTagName("Price");
	 var A_add = xmlsave.getElementsByTagName("Address");
	 var A_city = xmlsave.getElementsByTagName("CityName");
     //
     var A_type = xmlsave.getElementsByTagName("TBSubPropTypeName");
     var tbldata = "";
	// tbldata = '<table bgcolor="#000000" width="100" border="0" cellpadding="0" cellspacing="0">';
	 

	 for(i = ((pageNum-1)*rowsperpage); i< (pageNum*rowsperpage) && i<id.length; i++)
	 {
        var B_price = parseInt(A_price[i].firstChild.nodeValue);
	    var B_add = String(A_add[i].firstChild.nodeValue);
        var B_city = String(A_city[i].firstChild.nodeValue); 
	 	var pid = parseInt(id[i].firstChild.nodeValue); //alert(pid);
	 	var B_type = String(A_type[i].firstChild.nodeValue);
        tbldata += '<div id="divsav'+i+'" onmouseover="javascript:divOver(this.id);" onmouseout="javascript:divOut(this.id);" class="resultDiv" onclick="openTab('+pid+','+B_price+',\''+B_type+'\');"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="12%" style=" padding-top:4px" rowspan="2" valign="top"><span style="background-color:#FFFF99; color:#000000; padding:1px;">'+(i+1)+'</span></td><td width="88%" style="font-weight:bold; height:15px;">'+B_type+' $'+B_price+'</td></tr><tr><td>'+ B_add +','+ B_city +'</td></tr></table></div>';
       // tbldata += '<tr><td style="color:#FFFFFF">'+pid+'</td></tr>';
		//tbldata += '<tr><td style="color:#FFFFFF">'+pid+'</td></tr>';
	 }
	 //tbldata += '</table>';

	 document.getElementById('savedListing').innerHTML = tbldata;

	// Creating previous & first button 
	 if (pageNum > 1) // if pageno is greater than 1 else button will not 
	{ 
    	ppage = pageNum - 1; 
        pprev = '<input type="button" value=" < " name="ppre" onclick="showData1('+ppage+');" />'; 
		pprev = '<span class="prev"><a href="javascript:void(0);" onclick="showData1('+ppage+');" >Previous</a></span> ';
        pfirst = '<input type="button" value=" << " name="pfst" onclick="showData1(1);" />'; 
	}  
	else 
	{ 
    	pprev  = '&nbsp;'; // we're on page one, don't print previous link 
	    pfirst = '&nbsp;'; // nor the first page link 
	} 

	if (pageNum < num_of_page) 
	{ 
	    ppage = pageNum + 1; 
	    //pnext = '<input type="button" value=" > " name="pnxt" onclick="showData1('+ppage+');" />'; 
		pnext = ' <span class="nxt"><a href="javascript:void(0);" onclick="showData1('+ppage+');" >Next</a></span> ';
	    plast = '<input type="button" value=" >> " name="plst" onclick="showData1('+num_of_page+');" />'; 
	}  
	else 
	{ 
	    pnext = '&nbsp;'; // we're on the last page, don't print next link 
	    plast = '&nbsp;'; // nor the last page link 
	} 
	
	nav = "";
	for(ppage = pageNum-2 ; ppage <= (pageNum+2) && ppage <= num_of_page ; ppage++) 
	{ 
    	if(ppage > 0)
		{
			if (ppage == pageNum) 
    		{ 
        		nav += '<span class="current-link">'+ppage+'</span>';   // no need to create a link to current page 
    		} 
    		else 
    		{ 
        		//nav += ' <span class="num-links"><a href="javascript:void(0);" onClick="showData1('+ppage+');" >'+ppage+'</a></span> '; 
    		}
		}         
	} 
	
	document.getElementById('savedListingPaging').innerHTML ='<div style="float:right">page '+nav +'/'+num_of_page+'</div> <div>'+pprev+' '+pnext+'</div>' ;//pprev +" "+ pnext +"  Page " + nav +"/"+ num_of_page ;
	 
}

//end paging ======



/////////#####   data for searches #################################################################################
function makeRequestforsearches()
{ 
      
      showdivNoOfRecords();
      closeErrorMoreRecordsDiv();
      SEARCHED=true;
      map.DeleteAllPushpins();
//      var url="tomlinsonservice.asmx/showdataforsearches";
//	  var param="uniqueid="+;
//	  document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"><span>0</span> Records Found&nbsp;</div>';	 
	//////
	var url="";
	 var param="";
	var username=getCookie('tomlinson')
	if (username!=null && username!="")
    {	
    
      url="tomlinsonservice.asmx/showdataforsearches";
	  param="uniqueid="+username;
	  document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"><span>0</span> Records Found&nbsp;</div>';	    
	 // var url = "TomlinsonService.asmx/showsavelistings";
	//	var postStr = "uniqueid="+username;		
	//	makeRequest1(url, postStr,displaySavedMarker);
	}
	else
	{      
	 no_ofrecords_withoutsave(0);	
     map.DeleteAllPushpins();
     myalert();
     return false;
    }
	
	
	//////
	//If our readystate is either not started or finished, initiate a new request
	 if (receiveReq1.readyState == 4 ||  receiveReq1.readyState == 0 ) 
	 {	 
	//alert("receiveReq.readyState == 4 ")
	   receiveReq1.open("POST", url, true);
	   //Set the function that will be called when the XmlHttpRequest objects state changes
	   receiveReq1.onreadystatechange = funfordata; 
	
	   receiveReq1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	   receiveReq1.setRequestHeader("Content-length", param.length);
	   receiveReq1.setRequestHeader("Connection", "close");
	
	   //Make the request
	   receiveReq1.send(param);
	   //receiveReq.send(null);
	 }
		
	   
	 
}
var xmlDocSearched;
function funfordata()
{
//alert("gfdfgh ++funfordata");
  if(receiveReq1.readyState == 4) 
  {
  var searchTbl="";
	xmlDocSearched = receiveReq1.responseXML;
	var data = xmlDocSearched.getElementsByTagName('title');
	//alert(data.length);
	//alert(xmlDoc.responseText);
	if(data.length >0)
	{	
	 var A_title = xmlDocSearched.getElementsByTagName("title");
	    num_of_page = 0;
        cur_page = 1;
        prev_page = 1;
        next_page = 1;
        pageNum = 1;
        rowsperpage = 5;
	    num_of_page = Math.ceil(A_title.length/rowsperpage);	
	    showData2(pageNum);	

	}
	else
	{		
		map.DeleteAllPushpins();
		document.getElementById('divsavedsearches').innerHTML=" There is no searched Listing ! ";
//		document.getElementById('pagination').innerHTML="";
		//alert("No record found!");
		myalert();
		closeErrorMoreRecordsDiv();
	}
  }
  else 
  if(receiveReq1.readyState == 0 || receiveReq1.readyState == 1 ||receiveReq1.readyState == 2 || receiveReq1.readyState == 3)
		{
		document.getElementById('divsavedsearchesPaging').innerHTML='          ';
		document.getElementById('divsavedsearches').innerHTML='<div class="divwaitingforsearches"> <img src="images/loading.gif" />Loading please wait...<div>'; 
		
		} 
}


/// Paging For Searched Data //

function showData2(pageNum)
{
  
        var A_title = xmlDocSearched.getElementsByTagName("title");
        var A_url = xmlDocSearched.getElementsByTagName("posturl");
        var A_type = xmlDocSearched.getElementsByTagName("qtype");
        var tbldata = "";
	     for(i = ((pageNum-1)*rowsperpage); i< (pageNum*rowsperpage) && i< A_title.length; i++)
	     {
                    var B_title = String(A_title[i].firstChild.nodeValue);
        		    var B_url = String(A_url[i].firstChild.nodeValue);
        		    var B_type = parseInt(A_type[i].firstChild.nodeValue); 	 	   
            tbldata += '<div id="divsearch'+i+'" onmouseover="javascript:divOver(this.id);" onmouseout="javascript:divOut(this.id);" class="resultDiv" onclick="showsearchs(\''+B_url+'\','+B_type+');"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="12%" style=" padding-top:4px" rowspan="2" valign="top"><span style="background-color:#FFFF99; color:#000000; padding:1px;">'+(i+1)+'</span></td><td width="88%" style="font-weight:bold; height:15px;">'+B_title+'</td></tr><tr><td></td></tr></table></div>';
          
	     }	
	 document.getElementById('divsavedsearches').innerHTML = tbldata;
	// Creating previous & first button 
	 if (pageNum > 1) // if pageno is greater than 1 else button will not 
	{ 
    	ppage = pageNum - 1; 
        pprev = '<input type="button" value=" < " name="ppre" onclick="showData2('+ppage+');" />'; 
		pprev = '<span class="prev"><a href="javascript:void(0);" onclick="showData2('+ppage+');" >Previous</a></span> ';
        pfirst = '<input type="button" value=" << " name="pfst" onclick="showData2(1);" />'; 
	}  
	else 
	{ 
    	pprev  = '&nbsp;'; // we're on page one, don't print previous link 
	    pfirst = '&nbsp;'; // nor the first page link 
	} 

	if (pageNum < num_of_page) 
	{ 
	    ppage = pageNum + 1; 
	    //pnext = '<input type="button" value=" > " name="pnxt" onclick="showData2('+ppage+');" />'; 
		pnext = ' <span class="nxt"><a href="javascript:void(0);" onclick="showData2('+ppage+');" >Next</a></span> ';
	    plast = '<input type="button" value=" >> " name="plst" onclick="showData2('+num_of_page+');" />'; 
	}  
	else 
	{ 
	    pnext = '&nbsp;'; // we're on the last page, don't print next link 
	    plast = '&nbsp;'; // nor the last page link 
	} 
	
	nav = "";
	for(ppage = pageNum-2 ; ppage <= (pageNum+2) && ppage <= num_of_page ; ppage++) 
	{ 
    	if(ppage > 0)
		{
			if (ppage == pageNum) 
    		{ 
        		nav += '<span class="current-link">'+ppage+'</span>';   // no need to create a link to current page 
    		} 
    		else 
    		{ 
        		//nav += ' <span class="num-links"><a href="javascript:void(0);" onClick="showData2('+ppage+');" >'+ppage+'</a></span> '; 
    		}
		}         
	} 
	
	document.getElementById('divsavedsearchesPaging').innerHTML ='<div style="float:right">page '+nav +'/'+num_of_page+'</div> <div>'+pprev+' '+pnext+'</div>' ;//pprev +" "+ pnext +"  Page " + nav +"/"+ num_of_page ;
	 
}

//end paging ======



///
function  showsearchs(url, type)
{
//alert(type);
       
        if(type == 1)
        {
        var url1 = "tomlinsonservice.asmx/dataforinfowindow";		
		var postStr = url;			
		makeRequest(url1, postStr,displaySearchMarker);
		 document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"><span>1</span> Records Found&nbsp;</div>';	 
		}
		else
		if(type == 2)
        {
        var url1 = "tomlinsonservice.asmx/SearchByPropertyType";		
		var postStr = url;		
		makeRequest1(url1, postStr,displaySearchMarker);
		}
		else
		if(type == 3)
        {
        var url1 = "tomlinsonservice.asmx/SearchByCorner";		
		var postStr = url;		
		makeRequest1(url1, postStr,displaySearchMarker);
		}
		
}

function displaySearchMarker()
{
  if(receiveReq.readyState == 4) 
  {
    document.getElementById('divwaiting').style.display='none';
	document.getElementById('greyPopup').style.display='none';
	var xmlDoc = receiveReq.responseXML;
	var data =xmlDoc.getElementsByTagName('Price');
	if(data.length >0)
	{	
	 SEARCHED=true;
	 displaySearchMarkerData(xmlDoc);
     no_ofrecords_withoutsave(data.length);    
	 }
	 else
	 {
	 map.DeleteAllPushpins();
	 no_ofrecords_withoutsave(0);	
	 myalert(); 
	// alert("Records not found");	 	
	 }
	  closeErrorMoreRecordsDiv();
  } 
  else
     if(receiveReq.readyState == 1 || receiveReq.readyState == 2 || receiveReq.readyState == 0 || receiveReq.readyState == 3 )
     {
	    document.getElementById('divwaiting').style.display='block';
	    document.getElementById('greyPopup').style.display='block';
     }
}

function displaySearchMarkerData(xmlDoc)
{

    map.DeleteAllPushpins();
     
	var A_id = xmlDoc.getElementsByTagName("ListingID");
	var A_price = xmlDoc.getElementsByTagName("Price");
	var A_add = xmlDoc.getElementsByTagName("Address");
	var A_sqft = xmlDoc.getElementsByTagName("AssessedSqFt");
	var A_bed = xmlDoc.getElementsByTagName("Bedrooms");
	var A_bath = xmlDoc.getElementsByTagName("Bathrooms");
	var A_city = xmlDoc.getElementsByTagName("CityName");
	var A_acre = xmlDoc.getElementsByTagName("Acreage");
	var A_lat = xmlDoc.getElementsByTagName("Latitude");
	var A_lng = xmlDoc.getElementsByTagName("Longitude");	
	var A_type = xmlDoc.getElementsByTagName("TBSubPropTypeName");	
	
	var savedListingTbl = "";
	locs.length = 0;
	
	for(i=0; (i< A_id.length && i< 100); i++)
	{
		var B_mid = parseInt(A_id[i].firstChild.nodeValue);
		var B_price = parseInt(A_price[i].firstChild.nodeValue);
		var B_add = String(A_add[i].firstChild.nodeValue);
		//alert(B_sqft);
		var B_sqft = parseFloat(A_sqft[i].firstChild.nodeValue);
		
		var B_bed = parseInt(A_bed[i].firstChild.nodeValue);
		var B_bath = parseInt(A_bath[i].firstChild.nodeValue);
		var B_city = String(A_city[i].firstChild.nodeValue); 
		var B_acre = parseFloat(A_acre[i].firstChild.nodeValue);
		var B_lat = String(A_lat[i].firstChild.nodeValue);
		var B_lng = String(A_lng[i].firstChild.nodeValue);	
	    var B_type = String(A_type[i].firstChild.nodeValue);		
        var point = new VELatLong(B_lat,B_lng);
        
        locs[i] = point;
        var marker = createMarker(point, B_mid,B_price,B_add, B_city, B_bed, B_bath, B_acre, B_sqft,'savedSearch.gif',B_type);
	    map.AddPushpin(marker);	        
	    
	}
		
	map.SetMapView(locs);	
		
}

///////////////////   *********        Offices    **********      /////////////////////////////

function accShowOnMap()
    { 
    
     map.DeleteAllPushpins();
     closeErrorMoreRecordsDiv();
     hidedivNoOfRecords();
     SEARCHED=true;
    // unCheckNearBy();
    }
function getRequest(url, fun)
{ 
	 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) 
	 {	
	   
	   receiveReq.open("GET", url, true);
	   receiveReq.onreadystatechange = fun; 
	   receiveReq.send(null);	
	 }   
}


function showOffices()
{
	var url = "offices.xml?sid="+Math.random();
	getRequest(url, officesPin);
}

function officesPin()
{
  if(receiveReq.readyState == 4) 
  {	 
    var xmlDoc = receiveReq.responseXML;	
	var data = xmlDoc.getElementsByTagName('item');
	//alert(data.length);
	if(data.length >0)
	{
		document.getElementById('divwaiting').style.display='none';//by me
	    document.getElementById('greyPopup').style.display='none';
		showOfficeMarker(xmlDoc);
	}	
  }  
}

function showOfficeMarker(xmlDoc)
{

	var A_title = xmlDoc.getElementsByTagName("title");
	var A_lat = xmlDoc.getElementsByTagName("lat");
	var A_lng = xmlDoc.getElementsByTagName("lng");	
	
	//alert(A_lng.length)
	for(i=0; (i< A_title.length && i< 100); i++)
	{
		var B_title = String(A_title[i].firstChild.nodeValue);
		var B_lat = String(A_lat[i].firstChild.nodeValue);
		var B_lng = String(A_lng[i].firstChild.nodeValue);		
        
		SEARCHED=true;
		var point = new VELatLong(B_lat,B_lng);
		var marker = createOfficeMarker(point, B_title);
	    map.AddPushpin(marker);
	}		
	
}
var pinID=0;
function createOfficeMarker(point, B_title)
{
   var pin = new VEPushpin(pinID, point, "images/office.gif",B_title,null);        
   pinID++;
	return pin;
} 


//////// Day care and schools   /////////////


function FindLoc(whatTxt)
{ 
closeErrorMoreRecordsDiv();  
//   var whereTxt = document.getElementById('cityName').value;   
//   if(whereTxt=="")
//   {
//     
//     document.getElementById('findErrorMsg').style.display = "block";
//     setTimeout('document.getElementById("findErrorMsg").style.display = "none"',4000);
//     
//     if(whatTxt == "restaurant")     
//        document.getElementById('restaurant').checked = false;
//     
//     if(whatTxt == "Day care center")     
//        document.getElementById('dayCenter').checked = false;
//     
//     if(whatTxt == "schools")     
//        document.getElementById('school').checked = false;
//         
//     return;
//   }
   try
   {
      results = map.Find(whatTxt,null);      
      //results = map.Find(whatTxt,whereTxt);      
   }
   catch(e)
   {
      alert(e.message);
   }
}

function callDayCareCenter()
{
  
  if(document.getElementById('dayCenter').checked)
  {
  SEARCHED=true;
   FindLoc("Day care center");
  }
}

function callSchool()
{
  if(document.getElementById('school').checked)
  {
  SEARCHED=true;
   FindLoc("schools");
  }
}

function restaurant()
{
  if(document.getElementById('restaurant').checked)
  {
  SEARCHED=true;
   FindLoc("restaurant");
  }
  
}

//**************tab more info page over view  *****************************

function bmoreinfo()
{
//alert("ggfhgf");
getpagedata1(3);
}
var TT=true;
function savelistingbytab()
    {
   lid= document.getElementById('lsno').value;
   ptype=document.getElementById('propType').value;
   TT=false;
  // alert(ptype);
   checkCookie(lid,ptype);
  // alert(lid);
    }
    
function call_savesearch()
    {
     grayDivShow();
     document.getElementById('savesearchdiv').style.display='block';   
     document.getElementById('txtsearchtitle').focus();
  // document.getElementById('txtsearchtitle').select(); 
    }
 function btnResetSearch_Click()
 {
 document.getElementById('txtsearchtitle').value="";
 document.getElementById('txtsearchtitle').focus();
 }
function btnsavesearch_click()
    {
        if(document.getElementById('txtsearchtitle').value=="")
       {
        alert("Search title can not be empty.");
         document.getElementById('txtsearchtitle').focus();
       }
       else
       { 
        document.getElementById('savesearchdiv').style.display='none';
        var title=document.getElementById('txtsearchtitle').value;
        var url = "TomlinsonService.asmx/insert_tblsavedSearches";
		//title,string posturl,string qtype
		POSTURL=POSTURL.replace(/&/g,'@');
		
		//var postStr = "txtsearchtitle="+title+"&txtposturl=" + POSTURL +"&txtqtype="+TYPE;
		//alert(postStr);
		//makeRequest1(url, postStr,insert_Response);
               
              /////////  
                
                username=getCookie('tomlinson')
	        if (username!=null && username!="")
            {	   
        	  var postStr = "txtsearchtitle="+title+"&txtposturl=" + POSTURL +"&txtqtype="+TYPE+"&uniqueid="+username;
        	  makeRequest1(url, postStr,insert_Response);
	        }	
	        else // If First time saving or no cookie present on the client machine
	        {
		        var tomID = Math.random();
		        setCookie('tomlinson',tomID,365,"/");
        		
		         var postStr = "txtsearchtitle="+title+"&txtposturl=" + POSTURL +"&txtqtype="+TYPE+"&uniqueid="+tomID;
        	     makeRequest1(url, postStr,insert_Response);
        		
		        //var url = "TomlinsonService.asmx/savelistings";
		        //var postStr = "uniqueid="+tomID+"&listingid="+LID+"&ptype="+ptype;
		        //makeRequest(url, postStr,cookieResponse);
	        }
                
             ///////   
        
        
       
		}
    
    }
    
function btncancel_click()
    {
   document.getElementById('savesearchdiv').style.display='none';  
   grayDivHide()
    }    

function insert_Response()
        {
        grayDivHide()
       // alert("Saved");
        waitingdivnone();
        document.getElementById('txtsearchtitle').value="";
        }
        
  
  function grayDivShow()
  {
  disableddl('true');
  document.getElementById("greyPopup").style.display="block";
  }
  function grayDivHide()
  {
  disableddl('');
  document.getElementById("greyPopup").style.display="none";
  }      
/*  ------------------------------ Map Navigation -----------------------------------  

Left Right Top Bottom pan function
    ------------------------------------------------------------------------------  */
    
       function DoPanUp()
      {
	    map.vemapcontrol.ContinuousPan(0, -10, 20, false);  
      }
      
      function DoPanDown()
      {
        map.vemapcontrol.ContinuousPan(0, 10, 20, false);  
      }
      
      function DoPanLeft()
      {
	    map.vemapcontrol.ContinuousPan(-10, 0, 20, false);  
      }
      
      function DoPanRight()
      {
	    map.vemapcontrol.ContinuousPan(10, 0, 20, false);  
      }
      
      function BackHome()
      {
       var point = new VELatLong(44.45,-96.96);
       map.SetCenterAndZoom(point,8);
       MouseHandler();
      }
      
 ////******************* displaymarkerEndpan ********************************
 
 function displayEndpan()
{

 SEARCHED = true;
 closeErrorMoreRecordsDiv();
var no_of_records=0;
//alert(receiveReq.readyState);
  if(receiveReq.readyState == 4) 
  {
        document.getElementById('divwaiting').style.display='none';
	    document.getElementById('greyPopup').style.display='none';
	    var xmlDoc = receiveReq.responseXML;
	
	    var data = xmlDoc.getElementsByTagName('Price');	    
	    var countrw = xmlDoc.getElementsByTagName('Cnt');    	
	  
	    NO_OF_RECORDS=data.length;
	   // alert(NO_OF_RECORDS);
	    if(countrw.length > 0 )
	    {
	    map.DeleteAllPushpins();	
	    no_of_records = parseInt(countrw[0].firstChild.nodeValue);
	     NO_OF_RECORDS=no_of_records;
	    emptyPropertyDiv();
	    //alert(NO_OF_RECORDS);	   
	    }
         no_ofrecords(NO_OF_RECORDS);
	     emptyPropertyDiv();
	    if(no_of_records <= limitForNoOfRecords)
	    {	
	            if(data.length >0)
	                {	                 
	                 closeErrorMoreRecordsDiv();
	                 SEARCHED = true;
	                 generateEndpan(xmlDoc);	
	                 }
	                    else
	                {
		                map.DeleteAllPushpins();		             
		               document.getElementById('divNoOfRecords').innerHTML='<div class="recordDiv"> <span>'+no_of_records+'</span> Records Found&nbsp;</div>';
		                emptyPropertyDiv();
		                document.getElementById('txtSearch').focus();
		                myalert();
		               // alert("No records found !");
		                closeErrorMoreRecordsDiv();
		                 SEARCHED = false;
	                }          
         }
         else
         {
         SEARCHED = false;
         document.getElementById('errorMoreRecordsDiv').style.display="block";
        // alert("please Refine your search at present record is:: "+no_of_records);
         }
   } 
      else if(receiveReq.readyState == 1 || receiveReq.readyState == 2 || receiveReq.readyState == 0 || receiveReq.readyState == 3 )
        {
         document.getElementById('divwaiting').style.display='block';
         document.getElementById('greyPopup').style.display='block';
        }
}
function myalert()
{
document.getElementById('DivAlert').style.display = "block";
setTimeout('document.getElementById("DivAlert").style.display = "none"',1600);
}

function generateEndpan(xmlDoc)
{
  	map.DeleteAllPushpins();
  	xml=xmlDoc;
	var A_id = xmlDoc.getElementsByTagName("ListingID");
	var A_price = xmlDoc.getElementsByTagName("Price");
	var A_add = xmlDoc.getElementsByTagName("Address");
	var A_sqft = xmlDoc.getElementsByTagName("AssessedSqFt");
	var A_bed = xmlDoc.getElementsByTagName("Bedrooms");
	var A_bath = xmlDoc.getElementsByTagName("Bathrooms");
	var A_city = xmlDoc.getElementsByTagName("CityName");
	var A_acre = xmlDoc.getElementsByTagName("Acreage");
	var A_lat = xmlDoc.getElementsByTagName("Latitude");
	var A_lng = xmlDoc.getElementsByTagName("Longitude");	
	var A_type = xmlDoc.getElementsByTagName("TBSubPropTypeName");	
	
	locs.length = 0;
	for(i=0; (i< A_id.length && i< 100); i++)
	{
		var B_mid = parseInt(A_id[i].firstChild.nodeValue);
		var B_price = parseInt(A_price[i].firstChild.nodeValue);
		var B_add = String(A_add[i].firstChild.nodeValue);
		//alert(B_sqft);
		var B_sqft = parseFloat(A_sqft[i].firstChild.nodeValue);
		
		var B_bed = parseInt(A_bed[i].firstChild.nodeValue);
		var B_bath = parseInt(A_bath[i].firstChild.nodeValue);
		var B_city = String(A_city[i].firstChild.nodeValue); 
		var B_acre = parseFloat(A_acre[i].firstChild.nodeValue);
		var B_lat = String(A_lat[i].firstChild.nodeValue);
		var B_lng = String(A_lng[i].firstChild.nodeValue);
	    var B_type = String(A_type[i].firstChild.nodeValue);       
		var point = new VELatLong(B_lat,B_lng);
        locs[i] = point;
		var marker = createMarker(point, B_mid,B_price,B_add, B_city, B_bed, B_bath, B_acre, B_sqft,'home.gif',B_type);
	    map.AddPushpin(marker);
	}	
	 map.SetMapView(locs);
	//showData(pageNum);
	setTimeout("SEARCHED = false;",2500);
}

/*   *********************************** tell a friend  ************************      */  
var txtlink="";
function frm_tellafrdSubmit()
{
return false;
}
function frm_savedSearche()
{
return false;
}
  function opentellafriend(lnk)
      {
      grayDivShow();
      txtlink="http://www.tomlinsonrealestategroup.com/psmap/main.aspx?ListingID=";
      txtlink+=lnk;
      document.getElementById('tellAFrienddiv').style.display='block';
      document.getElementById('yourName').focus();
      btnReSet_click();
      }    
      
  function closetellafriend()
      {
      grayDivHide();
      document.getElementById('tellAFrienddiv').style.display='none';
      }      
  function btnReSet_click()
      {
        document.getElementById('yourName').value="";
        document.getElementById('yourEmail').value="";
        document.getElementById('msgBody').value="";
        document.getElementById('friend01').value="";
        document.getElementById('friend02').value="";
        document.getElementById('friend03').value="";
        document.getElementById('friend04').value="";         
        document.getElementById('yourName').focus();
      }
     
  function btntellafriend_submit()
      {
      var yourname=document.getElementById('yourName').value; 
      var eFrom=document.getElementById('yourEmail').value;
      var eTo=document.getElementById('friend01').value;
      var eBody =document.getElementById('msgBody').value;
      var frd2= document.getElementById('friend02').value;
      var frd3= document.getElementById('friend03').value;
      var frd4=    document.getElementById('friend04').value;
      
         if( yourname ==""  )
         {
            alert("Please Enter your name.");
            document.getElementById('yourName').focus();            
            return false;
         }
         
          if(eFrom =="")
            {
            alert("Please Enter your email address." );
            document.getElementById('yourEmail').focus();
            return false;
         }
         else
            {
                    if(echeck(eFrom)==false)
                    {                     
                     alert("Your E-mail ID is Invalid");
                     document.getElementById('yourEmail').focus();
                    }else
                   if( eTo == "" )
                     {
                        alert("Please enter first email address." );
                        document.getElementById('friend01').focus();
                        return false;
                     }else
                     if(echeck(eTo)==false)
                     {
                     alert("First email address is invalid.");
                      document.getElementById('friend01').focus();
                      return false;
                     }
                     else                     
                     {
                     if( frd2 !="")
                         {
                            if(echeck(frd2) == false )
                             {
                             alert("Second email address is invalid.");
                             document.getElementById('friend02').focus();
                             return false;
                             }
                         }
                       if( frd3 !="")
                         {
                            if(echeck(frd3) == false )
                             {
                             alert("Thired email address is invalid.");
                             document.getElementById('friend03').focus();
                             return false;
                             }
                         }
                         if( frd4 !="")
                         {
                            if(echeck(frd4) == false )
                             {
                             alert("Fourth email address is invalid.");
                             document.getElementById('friend04').focus();
                             return false;
                             }
                         }              
                     
                      var url = "tellafriend.aspx?txtlink="+txtlink+"&yourname="+yourname+"&eFrom="+ eFrom +"&eTo="+eTo+"&eBody="+eBody+"&frd2="+frd2+"&frd3="+frd3+"&frd4="+frd4;		
	                  var postStr ="eFrom="+ eFrom +"&eTo="+eTo+"&eBody="+eBody ;			
	                  makeRequest(url, postStr,getResult);       
                      document.getElementById('tellAFrienddiv').style.display='none';
                      grayDivHide();
                      waitingdivnone();
                     }
                     
                     
            }  
          
      }  
  
 
      
 function getselecttxt(textid)
      {
     
      document.getElementById(''+ textid +'').className="txtOnActive";
      document.getElementById(''+ textid +'').value="";
      // alert( document.getElementById(''+ textid +'').className);
      } 
      
      
 function  getResult()
     {
    // alert("response of mail");
     
      if(receiveReq.readyState == 4) 
        {
        alert(receiveReq.responseText);
        }
     
     }  
   
   //email
   function echeck(str) 
   {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		  // alert(msg)
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   //alert(msg);
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   // alert(msg)
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		  // alert(msg)
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   // alert(msg)
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   // alert(msg)
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		  // alert(msg)
		    return false
		 }

 		 return true					
	}

     
     
     
 //////**********************************code for rouite **************
function toHere(id)
{    //id=listing id
   var fromDiv="fromDiv"+id;
   var headerDivInfo= "headerDivInfo"+id;
   var tohere="txtTo"+id;
   var toDiv="toDiv"+id;    
   document.getElementById(headerDivInfo).innerHTML='To here -  <a id='+id+' href="javascript:void(0)" onclick="fromHere('+id+');" >From here </a>';  
   document.getElementById(toDiv).style.display='block';
   document.getElementById(fromDiv).style.display='none';
 // alert(document.getElementById(toDiv).innerHTML)
  //alert(tohere);
   document.getElementById(tohere).focus();
   
}
function fromHere(id)
{
    //id=listing id
   var fromDiv="fromDiv"+id;
   var headerDivInfo= "headerDivInfo"+id;
   var txtval="txtFrom"+id;
   var toDiv="toDiv"+id;   
   document.getElementById(headerDivInfo).innerHTML=' <a href="javascript:void(0)" onclick="toHere('+id+');"   >To here </a> - From here ';   
   document.getElementById(toDiv).style.display='none';
   document.getElementById(fromDiv).style.display='block';
   ///alert(document.getElementById(fromDiv).innerHTML)
 // alert(txtval);
   document.getElementById(txtval).focus();
}

/////////////
