// JavaScript Document
function displaynextpre(tc)
   {
	  // alert(document.getElementById('hdntotalcount').value);
	  //alert(parseInt(Maxcount));
	   // alert(linkimageId);
	   totalpagecount=parseInt(document.getElementById('hdntotalcount').value)/parseInt(Maxcount);
	   if ((totalpagecount-parseInt(totalpagecount))>0)
				totalpagecount=parseInt(totalpagecount)+1;
	  		else
		  		totalpagecount=parseInt(totalpagecount);
		//alert(totalpagecount);		
	   if (linkimageId>totalpagecount)
	   {
		   alert("There is some internal error, so map will be reset."+'\n'+"Sorry for inconvenient ");
		   initSearch();
		   IsError=1;
	   }
	   else
	   {
	  		
    			document.getElementById("query-results").style.display="block";
			document.getElementById('showvalue').innerHTML="Page " +  linkimageId +  " of " +totalpagecount + ".";

			
				 if (linkimageId< 1)
				 {
			                
					 enableButton('dprevd.png',true,'default','dnext.png',false,'pointer');
				}
				else if ( linkimageId>=totalpagecount && totalpagecount==1)
				{
				     
					enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
				}
				else if ( linkimageId>=totalpagecount && totalpagecount!=1)
				{
		                      
					enableButton('dprev.png',false,'pointer','dnextd.png',true,'default');
				}
				else  if ( linkimageId>totalpagecount)
				{

					enableButton('dprevd.png',false,'pointer','dnext.png',true,'default');
				}
				else
				{
		                      
					enableButton('dprev.png',false,'pointer','dnext.png',false,'pointer');
				}
	
				
			
			
				
				
	   }	
   }
   function enableButton(preclsname,predisable,prepointer,nextclsname,nextdisable,nextpointer)
   {
	 if (dir=="nopath")
	    {
			document.getElementById('imgpre').src="images/"+preclsname;
	  // document.getElementById('imgpre').disabled=predisable;
	   document.getElementById('imgpre').style.cursor=prepointer;
	  // document.getElementById('imgpre1').disabled=predisable;
	   document.getElementById('imgpre1').src="images/"+preclsname;
	   document.getElementById('imgpre1').style.cursor=prepointer;
	     document.getElementById('imgnext').src="images/"+nextclsname;
	   //document.getElementById('imgnext').disabled=nextdisable;
	   document.getElementById('imgnext').style.cursor=nextpointer;
	   //document.getElementById('imgnext1').disabled=nextdisable;
	   document.getElementById('imgnext1').src="images/"+nextclsname;
	   document.getElementById('linknext1').style.cursor=nextpointer;
		}
else
    {
			document.getElementById('imgpre').src=dir + "images/"+preclsname;
	  // document.getElementById('imgpre').disabled=predisable;
	   document.getElementById('imgpre').style.cursor=prepointer;
	  // document.getElementById('imgpre1').disabled=predisable;
	   document.getElementById('imgpre1').src=dir +"images/"+preclsname;
	   document.getElementById('imgpre1').style.cursor=prepointer;
	     document.getElementById('imgnext').src=dir +"images/"+nextclsname;
	   //document.getElementById('imgnext').disabled=nextdisable;
	   document.getElementById('imgnext').style.cursor=nextpointer;
	   //document.getElementById('imgnext1').disabled=nextdisable;
	   document.getElementById('imgnext1').src=dir +"images/"+nextclsname;
	   document.getElementById('linknext1').style.cursor=nextpointer;
	}
	  
   }
   function Checkall()
  {
     var chkall =document.getElementById('chkall');
     var chk=document.getElementsByName('chk');
     var i;

     if(chkall.checked==true)
                   {
      for(i=0;i<chk.length;i++)
           {

                       chk[i].checked=true;

           }
  }
  else
      {
          for(i=0;i<chk.length;i++)
           {

                       chk[i].checked=false;

           }
      }
  }
  function ValueOfCheck()
  {
      var chk=document.getElementsByName("chk");
      var v='';
      var i;
      for(i=0;i<chk.length;i++)
          {
              if(chk[i].checked==true)
                  {
                    v=v+chk[i].value+",";
                  }
          }
          if(v)
              {
          v=trim(v.substring(0,v.length-1));
         // alert(v);
          document.getElementById("BEditId").value=v;
        if(document.getElementById("BEditId").value!='')
            return true;
              }
              else
                 {
                     alert("Select at least one Record");
                 }
        return  false;

  }
  function UncheckBox()
  {
      var chk=document.getElementsByName('chk');
      var i;
      var j=0;
      for(i=0;i<chk.length;i++)
          {
              if(chk[i].checked==false)
                  {
                   j=j+1;
                  }
          }
          //alert(i+" -----"+j);
          if(j==i)
              {
                  document.getElementById('chkall').checked=false;
              }
  }
  function DeleteSelectedRecord()
  {
      if(ValueOfCheck()==true)
         {
             if(window.confirm("Do you want to delete all selected record(s)?")==true){
             UpdateDataBaseInfo("false");
             }
         }
  }
function CreateHeaderResult()
{
	var d1;
    var d2;
	var dmain=document.createElement("div");
	dmain.setAttribute("id","query-head");
	var d=document.createElement("div");
	d.setAttribute("class","newhead");

	d1=document.createElement("div");
	d1.setAttribute("id","stname");
	d1.innerHTML="Store Name";
	d.appendChild(d1);
	d1=document.createElement("div");
	d1.setAttribute("id","add");
	d1.innerHTML="Address";
	d.appendChild(d1);
	d1=document.createElement("div");
	d1.setAttribute("id","state");
	d1.innerHTML="State";
	d.appendChild(d1);
	d1=document.createElement("div");
	d1.setAttribute("id","cont");
	d1.innerHTML="Contact";
	d.appendChild(d1);
   // create check box div
   d1=document.createElement("input");
    d1.setAttribute("type","checkbox");
    d1.setAttribute("id", "chkall");
    d1.setAttribute("onclick", "Checkall();");
    d2=document.createElement("div");
	d2.setAttribute("id","chkboxdel");
        if (dir!="nopath"){
	d2.appendChild(d1);
        }
    d.appendChild(d2);
    //end checkbox
    // create delete
    d3=document.createElement("div");
	d3.setAttribute("id","recorddel");
    d1=document.createElement("a");
    d1.setAttribute("href", "#");
    d1.setAttribute("title", "click here to delete selected record");
    d1.setAttribute("onClick", "DeleteSelectedRecord()");
    d2=document.createElement("img");
    d2.setAttribute("border", "0");
    d2.setAttribute("src", "../images/ddel.png");
    d1.appendChild(d2);
    if (dir!="nopath"){
d3.appendChild(d1);
        }
    
    d.appendChild(d3);
    //end delete
	dmain.appendChild(d);
	var dline=document.createElement("div");
	dline.setAttribute("class","newhead");		
	d1=document.createElement("div");
	d1.setAttribute("id","bord");
	dline.appendChild(d1);
	document.getElementById("divlist").appendChild(dmain);
	document.getElementById("divlist").appendChild(dline);


}
   // Get the HTTP Object
function getHTTPObject()
{
	if (window.ActiveXObject) 
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) 
		return new XMLHttpRequest();
	else {
		alert("Your browser does not support AJAX.");
		return null;
	}
}

 function doWork()
   {

	   var pcode=trim(document.getElementById('pcode').value.replace("&", "^")) ;
	   if (dir!="nopath")
	   {
		if (pcode=="..SEARCH" || pcode=="")
	    {
		    pcode="";
		}
		var CurrentValue;
	    var t;
	            CurrentValue=parseInt(document.getElementById('currentvalue').value);
		    t=document.getElementById('hdntotalcount').value;
		    	enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
				
		    httpObject = getHTTPObject();
		    var dt =new Date();
		    var dtime=dt.getSeconds();
		    var url="ajaxdataadmin.php?dt="+dtime+ "&pcode=" +pcode + "&IsCount=" + IsCount + "&CurrentValue=" + CurrentValue + "&lastlimit=" + ll + "&totalcount="+ parseInt(t);
		    if (httpObject != null)
		    {

			    httpObject.open("GET", url, true); 
			   // alert(url);
			    httpObject.send(null);

			    httpObject.onreadystatechange = setOutput;

		    } 
	   }
	   else
	   {
	     //alert(sGeobytesLatitude +" dfjkdfjkl "+ sGeobytesLongitude);
	    if (pcode=="ENTER CITY OR POSTCODE" || pcode=="")
	    {
		    pcode="";
		    GetCityORPcode(sGeobytesLatitude,sGeobytesLongitude);
	    }
	    else
	    {
		    var	CityName=readCookie("pcode");
		    var	Citylat=readCookie("Citylat");
		    var	Citylng=readCookie("Citylng");
                   //  alert(CityName)
		//	     alert(Citylat);
		   // alert(Citylng);
		    if (CityName!=pcode)
		    {
			    geocoder.getLocations(pcode+",Australia",GetCityPoint);
		    } 
		    else
		    {
			    GetCityORPcode(Citylat,Citylng);
		    }      
	    } 
	   }
	  
	  
	
   }
 function CheckCity(Isdrag)
   {

	   var pcode=trim(document.getElementById('pcode').value.replace("&", "^") );
	 //  alert(Isdrag);
	 
	  
	   if (pcode=="ENTER CITY OR POSTCODE" || pcode=="")
	    {
		    pcode="";

	    	if (Isdrag=="true")
		{
			linkimageId=1;
			createCookie("IsDrageed",Isdrag,365);
		//	 alert("cookie Is Dargeed : " + readCookie("IsDrageed"));
			DragReloadLoad();
		}
		else
		{   //alert("hi");
		    createCookie("IsDrageed",Isdrag,365);
		    // alert("cookie Is Dargeed : " + readCookie("IsDrageed"));
		    finddata1(); }
	    }
	    else
	    {
		    var	CityName=readCookie("pcode");
		    var	Citylat=readCookie("Citylat");
		    var	Citylng=readCookie("Citylng");
              	    if (CityName!=pcode)
		    {
			    geocoder.getLocations(pcode+",Australia",FindCityLatLng);
		    } 
		    else
		    {
			        createCookie("IsDrageed",Isdrag,365);
	    			if (Isdrag=="true")
				{
					linkimageId=1;
					DragReloadLoad();
				}
				else
				{  // alert("no change in city");
		    		    finddata1(); 
				}
		    } 
	    } 
	    
	  
	  
	
   }
   
  var xxx=0;
function 	MakePointOnMap(response)
	{
		 
			var BStateVal=trim(document.getElementById("BState").value.replace("&", "^"));/*state*/
			
			if (BStateVal!="ENTER STATE NAME" && BStateVal!="")
			{
				
				if (xxx == 0)
				{
				   xxx = 1;
				//alert("fdf");
				
					if (CurrentMarker)
		        map.removeOverlay(CurrentMarker);
			   
				alert("Sorry, we are unable to find lat and lng for entered location . Setting Marker to default location(SYDNEY), please reenter or set marker at desire location by dragging." );
				var icon0 = new GIcon();
				icon0.image =  "../images/pointerblack1.png";
				icon0.shadow = "../images/pshade.png";
				icon0.iconSize =new GSize(28,30);
				icon0.iconAnchor = new GPoint(13, 28);
				icon0.infoWindowAnchor = new GPoint(13, 28);
				markerOptions = {   icon:icon0, draggable: true};
				var newpp=new GLatLng(parseFloat(-33.867139),parseFloat(151.207114));
				var marker = new GMarker(newpp, markerOptions);
				//var marker = new GMarker(newpp,  {draggable: true});
				//ew[Idnum2] = new EWindow(map, E_STYLE_7);
				map.addOverlay(marker);
				map.setCenter(newpp,15);
				CurrentMarker=marker;	
				document.getElementById("BLat").value="-33.867139";
				document.getElementById("BLng").value="151.207114";
				IsnotFound=true;
				GEvent.addListener(marker, 'dragend', function(overlay, point) {
						var c= marker.getPoint();
						document.getElementById("BLat").value=c.lat();
						document.getElementById("BLng").value=c.lng();
						});
				}
				//alert(IsDragMarkerOnMap);
				//document.getElementById("btnref1").style.display="block";
			  }
		 
			
	}
  
function SaveNewRecord(response)
{
	
	 
	                  if(MarkerArray)
				      {
					      for(var j=0;j<MarkerArray.length;j++)
					      {
						      if(MarkerArray[j])
						      {
							      map.removeOverlay(MarkerArray[j]);
							     
						      }
					      }
				      }
	
	
	if (!response || response.Status.code != 200) 
	{
		if (CurrentAddressLocation<5 )
		{
		//document.getElementById("msg").innerHTML=document.getElementById("msg").innerHTML+"Pointer : "+ CurrentAddressLocation+ "xxx:" + xxx;
			//xxx=0;
			//alert(AddressArray[CurrentAddressLocation]);
			CurrentAddressLocation=parseInt(CurrentAddressLocation) +1;
			geocoder.getLocations(AddressArray[CurrentAddressLocation],SaveNewRecord);
		}
		else
		{    
		      
		   			MakePointOnMap(response);
				//document.getElementById("msg").innerHTML=document.getElementById("msg").innerHTML+" After:-> Pointer : "+ CurrentAddressLocation+ "xxx:" + xxx;
		}
	}
	else 
	{
		if (xxx==0)
		{
			xxx=1;
				if (CurrentMarker)
			map.removeOverlay(CurrentMarker);
				var place1 = response.Placemark[0];
			document.getElementById("BLat").value=place1.Point.coordinates[1];
			document.getElementById("BLng").value=place1.Point.coordinates[0];
			var icon0 = new GIcon();
			icon0.image =  "../images/pointerblack1.png";
			icon0.shadow = "../images/pshade.png";
			icon0.iconSize =new GSize(28,30);
			icon0.iconAnchor = new GPoint(13, 28);
				icon0.infoWindowAnchor = new GPoint(13, 28);
			markerOptions = {   icon:icon0 , draggable: true};
			var newpp=new GLatLng(parseFloat(place1.Point.coordinates[1]),parseFloat(place1.Point.coordinates[0]));
			var marker = new GMarker(newpp, markerOptions);
			//ew[Idnum2] = new EWindow(map, E_STYLE_7);
			map.addOverlay(marker);
			map.setCenter(newpp,15);
			CurrentMarker=marker;
			GEvent.addListener(marker, 'dragend', function(overlay, point) {
					var c= marker.getPoint();
					document.getElementById("BLat").value=c.lat();
					document.getElementById("BLng").value=c.lng();
					});
			//document.getElementById("btnref1").style.display="block";
			//CurrentAddressLocation=0;
			
		}
	}
}
function GetUpdateAddress(response)
{
	if (CurrentMarker)
		map.removeOverlay(CurrentMarker);
	if (!response || response.Status.code != 200) 
	{
		//alert(CurrentAddressLocation);
		if (CurrentAddressLocation<5)
		{
			// alert(AddressArray[CurrentAddressLocation]);
			CurrentAddressLocation=parseInt(CurrentAddressLocation) +1;
			geocoder.getLocations(AddressArray[CurrentAddressLocation],GetUpdateAddress);
		}
		else
		{
			MakePointOnMap(response);
		}
	}
	else 
	{
		var place1 = response.Placemark[0];
		document.getElementById("BLat").value=place1.Point.coordinates[1];
		document.getElementById("BLng").value=place1.Point.coordinates[0];
		var icon0 = new GIcon();
		icon0.image =  "../images/pointerblack"+ parseInt( parseInt(CurrentId)+1) +".png";
		icon0.shadow = "../images/pshade.png";
		icon0.iconSize =new GSize(28,30);
		icon0.iconAnchor = new GPoint(13, 28);
				icon0.infoWindowAnchor = new GPoint(13, 28);
		markerOptions = {   icon:icon0, draggable: true };
		var newpp=new GLatLng(parseFloat(place1.Point.coordinates[1]),parseFloat(place1.Point.coordinates[0]));
		var marker = new GMarker(newpp, markerOptions);
		//ew[Idnum2] = new EWindow(map, E_STYLE_7);
		map.addOverlay(marker);
		map.setCenter(newpp,15);
		MarkerArray[CurrentId]=marker;
		GEvent.addListener(marker, 'dragend', function(overlay, point) {
				var c= marker.getPoint();
				document.getElementById("BLat").value=c.lat();
				document.getElementById("BLng").value=c.lng();
				});
		CurrentAddressLocation=0;
	}
}

function FindCityLatLng(response) 
{
	var Isdrag3=readCookie("IsDrageed");
	if (Isdrag3==null)
	{
		Isdrag3="false";
		createCookie("IsDrageed",Isdrag3,365);
	}
	if (!response || response.Status.code != 200) 
	{
		alert("Sorry, we are unable to find city or postcode entered, please reenter ");
		document.getElementById("pcode").focus();
	}
	else 
	{
		var place1 = response.Placemark[0];
		createCookie("Citylat",place1.Point.coordinates[1],365);
		createCookie("Citylng",place1.Point.coordinates[0],365);
		
		if (Isdrag3=="true")
		{
			linkimageId=1;
			DragReloadLoad();
		}
		else
		        finddata1();
		

	}

}
function GetCityPoint(response) 
{
	if (!response || response.Status.code != 200) 
	{
		alert("Sorry, we are unable to find city or postcode entered, please reenter ");
		document.getElementById("pcode").focus();
                finddata1();
	}
	else 
	{
		var place1 = response.Placemark[0];
		createCookie("Citylat",place1.Point.coordinates[1],365);
		createCookie("Citylng",place1.Point.coordinates[0],365);
		GetCityORPcode(place1.Point.coordinates[1],place1.Point.coordinates[0]);

	}

}

 function DragReloadLoadNext(nlat,nlng)
    {
	    // alert(nlat +" point "+ nlng);
	    if (nlat==null && nlng==null)
	    {
	      GetCityORPcode(sGeobytesLatitude,sGeobytesLongitude);
	    }
	    else
	    {
	      GetCityORPcode(nlat,nlng);
	    } 
    }
	
   function GetCityORPcode(pcodelat1,pcodelng1)
   {
	  var State1=trim(document.getElementById('State').value.replace("&", "^")) ;
          var Store1=trim(document.getElementById('Store').value.replace("&", "^")) ;
	  var pcode1=trim(document.getElementById('pcode').value.replace("&", "^")) ;
	  var Isdrag1=readCookie("IsDrageed");
	  if (Store1=="ENTER STORE NAME")
		  Store1=""; 
	   if (pcode1=="ENTER CITY OR POSTCODE")
	    {
		    pcode1="";
	    }
	    if(IsClickonSearch==false)
	    {
	      stateCookei=readCookie("state");
	      storeCookei=readCookie("store");
	      pcodeCookei=readCookie("pcode");
		  if(stateCookei==null)
		  stateCookei="All"
		  if(storeCookei==null)
		  storeCookei=""
		  if(pcodeCookei==null)
		  pcodeCookei=""
		  
	      //alert(State1+"="+stateCookei +" and "+Store1+"="+storeCookei+" and "+pcode1+"="+pcodeCookei);
	      if (stateCookei!=null && storeCookei!=null && pcodeCookei!=null) 
	      {
		      // alert("Your filtering or sorting critria has been changed"+'\n'+"do u want to continue with new change please click on search button.")
		       if (stateCookei!=State1 || (storeCookei!=Store1) || pcodeCookei!=pcode1) 
		       {  alert("Your filtering or sorting critria has been changed"+'\n'+"do u want to continue with new change please make change again and click on search button.");
		        }
		       document.getElementById('State').value=trim(stateCookei);
		         if (storeCookei=="")
				 document.getElementById('Store').value="ENTER STORE NAME";
			 else
				 document.getElementById('Store').value=trim(storeCookei);
		       if(pcodeCookei=="")
			       document.getElementById('pcode').value="ENTER CITY OR POSTCODE";
		       else
			       document.getElementById('pcode').value=trim(pcodeCookei);

				 	State1=trim(document.getElementById('State').value.replace("&", "^"));
	  				Store1=trim(document.getElementById('Store').value.replace("&", "^")) ;
	  				pcode1=trim(document.getElementById('pcode').value.replace("&", "^")) ;
                                       
	      }
	    } 
		GetajaxData(State1,Store1,pcode1,pcodelat1,pcodelng1);    
           
   }
   function GetajaxData(State,Store,pcode,pcodelat,pcodelng)
   {     
	        
	   createCookie("state",trim(document.getElementById("State").value),365);	               
	   if (trim(document.getElementById("pcode").value)=="ENTER CITY OR POSTCODE")
	        createCookie("pcode","",365);
	   else
		createCookie("pcode",document.getElementById("pcode").value,365);
                 if (trim(document.getElementById("Store").value)=="ENTER STORE NAME")		  
			 createCookie("store","",365);
		 else
			 createCookie("store",trim(document.getElementById("Store").value),365);
	    var CurrentValue;
	    var t;
	            CurrentValue=parseInt(document.getElementById('currentvalue').value);
		    t=document.getElementById('hdntotalcount').value;
		    	enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
		    if (Store=="ENTER STORE NAME")
			    Store="";

		    httpObject = getHTTPObject();
		    var dt =new Date();
		    var dtime=dt.getSeconds();
		    var url="ajaxdata.php?dt="+dtime+"&state="
			    +State + "&store=" +Store + "&IsCount=" + IsCount + "&CurrentValue=" + CurrentValue + "&lastlimit=" + ll + "&totalcount="+ parseInt(t) +"&Clat="+pcodelat + "&Clng="+ pcodelng;
		    if (httpObject != null)
		    {

			    httpObject.open("GET", url, true); 
			   // alert(url);
			    httpObject.send(null);

			    httpObject.onreadystatechange = setOutput;

		    } 
   }
   
   function setOutput()
      {
              
	      document.getElementById("divlist").innerHTML=""; 
	      document.getElementById("middlelinks").innerHTML=""; 
	       if(MarkerArray)
				      {
					      for(var j=0;j<MarkerArray.length;j++)
					      {
						      if(MarkerArray[j])
						      {
							      map.removeOverlay(MarkerArray[j]);
								  if(dir=="nopath")
							      ew[j].hide();
						      }
					      }
				      }
	      if(httpObject.readyState == 4)

	      {
		  //  alert(httpObject.responseText);
		      if (trim(httpObject.responseText)!="Not found")
		      {
			      var newtemp=httpObject.responseText.split('~');
			      var temp = newtemp[0].split('^');
			      fl= newtemp[1];
			      ll= newtemp[2];
			      var tc=newtemp[3];   
			      if (tc!="")
			      {
				      document.getElementById('hdntotalcount').value=tc;
				      if(IsCount=="Y" && Isadmin=="N")
					      Maxcount=ll;
			      }
			     
			      var temp2="";
			      var SearchAddress ="";
			      var addr="";
			      var cont="";
                   var dispalyaddr="";
			      if (temp.length>0)
			      {   
				     

				      document.getElementById("divlist").innerHTML="";
				      ImageCount=0;
				      IsError=0;
				      displaynextpre(tc);
				      if ( IsError==1)
				      {
					 return false;
				      }     
				      CreateHeaderResult();
				      SearchArray=new Array();
					  UpdateValueArray=new Array();
				      ResponseArray=new Array();
				      updateobj=new Array();
				      PointArray=new Array();
				      ew=new Array();
				      MarkerArray=new Array();
				      CheckAllPointLoad=false;
				      document.getElementById('divmainNote').style.display='block'; 
				      for (var i=0;i<temp.length;i++)
				      {
					      temp2="";
					      SearchAddress="";
					      temp2 = temp[i].split('#');
						  // for retrive updation values start
						  if (dir!="nopath")
						  {
						  	var upval="";
						  	for(var l=0;l<temp2.length;l++)
						  	{
							  upval=upval+temp2[l]+"#";
						    }
						    upval=trim(upval.substring(0,upval.length-1));
						    UpdateValueArray[i]=upval;
						  }
					  // for retrive updation values end
					       var Sstate="";
					      if (temp2.length>0)
					      {
						      for (var k=2;k>=1;k--)
						      {
							      if(temp2[k])
							      { 
								      SearchAddress=SearchAddress + temp2[k] +",";
							      }
						      }
						      Sstate=temp2[15];
						      SearchAddress=trim(SearchAddress.substring(0,SearchAddress.length-1));
						      SearchAddress=SearchAddress+","+temp2[15];
						      SearchAddress=trim(SearchAddress);
						     //alert(SearchAddress);
						      addr="";
						      for (var j=3;j<6;j++)
						      {
							      if(temp2[j])
							      { 
								      addr=addr +"<div id=\"address"+j+i+"\">" + trim(temp2[j]) +"</div>";
							      }
						      }
//alert(addr);
						      addr=trim(addr.substring(0,addr.length-1));
							  dispalyaddr="";
						      for (var j=3;j<5;j++)
						      {
							      if(temp2[j])
							      { 
								      displayaddr=dispalyaddr +"<div>" + trim(temp2[j]) +"</div>";
							      }
						      }
//alert(addr);
						      dispalyaddr=trim(dispalyaddr.substring(0,addr.length-1));
						      cont="";
						      var email="";
						      var phone="";
						      var website="";
 							if(temp2[7])
							{ 
							      email=trim(temp2[7]);
							}
							if(temp2[8])
							{ 
							      phone=trim(temp2[8]);
							}
							if(temp2[9])
							{ 
							      website=trim(temp2[9]);
							}
						      for (var j=7;j<10;j++)
						      {

							      if(temp2[j])
							      { 
								      cont=cont +"<div>" +trim(temp2[j]) +"</div>";
							      }
						      }
						      var Locpointlat=0;    
						      var Locpointlng=0;

						      if(temp2[11])
							      Locpointlat=temp2[11];
						      if(temp2[12])
							      Locpointlng=temp2[12];
						      var LocpointHas=temp2[13];    	       
						     
                                                         
						      SearchArray[i]=SearchAddress+"#"+temp2[10]+"#"+parseInt(i+1)+"#"+temp2[6]+"#"+addr+"#"+temp2[1]+"#"+cont +"#"+Locpointlat+"#"+Locpointlng+"#"+LocpointHas +"#"+temp2[14]+"#"+email+"#"+phone+"#"+website+"#"+Sstate+"#"+dispalyaddr;


					      }  //inner if close	 
				      }  //if close
				      IsFirstPoint=true;
				      Ipointer=0;
				      maxlat=-85.0;
				      maxlng=-180.0;
				      minlat=85.0;
				      minlng=180.0;
				      ImageCount=0;
				      
				      IsPointOnmap=false;
					  if (dir=="nopath")
				      {Showpoints();}
					  else
                     {  ShowGrid();}

			      } // for loop close
                              else
			      {
				      document.getElementById('showvalue').innerHTML="No results found.";
					 if (dir=="nopath")
                      setZoomOfMap();
			      }
		      }
		       else
		       {	document.getElementById('showvalue').innerHTML="No results found.";
				     if (dir=="nopath")
					  setZoomOfMap();
		       } 
	      }	
      }
	  
function SaveNewInfo()  
{
	var url;
	var dt =new Date();
	var dtime=dt.getSeconds();
	var BEditId=trim(document.getElementById("BEditId").value);/*Id*/
	var BPcode=trim(document.getElementById("BPcode").value.replace("&", "^"));/*pcode*/
	var BState=trim(document.getElementById("BState").value.replace("&", "^"));/*state*/
	var BLocation=trim(document.getElementById("BLocation").value.replace("&", "^"));/*location*/
	var BAddress1=trim(document.getElementById("BAddress1").value.replace("&", "^"));/*address1*/
	var BAddress2=trim(document.getElementById("BAddress2").value.replace("&", "^"));/*address2*/
	var BAddress3=trim(document.getElementById("BAddress3").value.replace("&", "^"));/*address3*/
	var BStore=trim(document.getElementById("BStore").value.replace("&", "^"));/*store*/
	var BEmail=trim(document.getElementById("BEmail").value.replace("&", "^"));/*email*/
	var BPhone=trim(document.getElementById("BPhone").value.replace("&", "^"));/*phone*/
	var BWebsite=trim(document.getElementById("BWebsite").value.replace("&", "^"));/*website*/
	
	var BLat=trim(document.getElementById("BLat").value.replace("&", "^"));/*lat*/
	var BLng=trim(document.getElementById("BLng").value.replace("&", "^"));/*lng*/
	var BCountry=trim(document.getElementById("BCountry").value.replace("&", "^"));/*country*/
	
	if(BStore=="ENTER STORE NAME" || BStore=="")
	  BStore="";
	if(BAddress1=="ENTER ADDRESS1")
	  BAddress1="";
	if(BAddress2=="ENTER ADDRESS2")
	BAddress2="";
	if(BAddress3=="ENTER ADDRESS3")
	BAddress3="";
	if(BState=="ENTER STATE NAME")
	BState="";
    if(BPcode=="ENTER PCODE")
	BPcode="";
	if(BLocation=="ENTER LOCATION" )
     BLocation="";
	
	if(BEmail=="ENTER EMAIL")
	BEmail="";
    if(BPhone=="ENTER PHONE")
	BPhone="";
	if(BWebsite=="ENTER WEB SITE")
	BWebsite="";
	if (BLat=="LATITUDE" || BLat=="" || BLat=="NOT FOUND")
	BLat=0;
	if (BLng=="LONGITUDE" || BLng=="" || BLng=="NOT FOUND")
	BLng=0;
			url="updatedataadmin.php?dt="+dtime+"&BPcode=" + BPcode+"&BState=" + BState+"&BLocation=" + BLocation+"&BAddress1=" + BAddress1+"&BAddress2=" + BAddress2+"&BAddress3=" + BAddress3+"&BStore=" + BStore+"&BEmail=" + BEmail+"&BPhone=" + BPhone+"&BWebsite=" + BWebsite+"&id=" + BEditId+"&BLat=" + BLat+"&BLng=" + BLng+"&BCountry=" + BCountry+"&EditOk=aaaa";
			//alert("save");
			//alert(url);
	insertobj=null;		
	insertobj = getHTTPObject();
        
	if (	insertobj!= null) 
	{
		insertobj.open("GET",url , true); 
		insertobj.send(null);
		insertobj.onreadystatechange = Isinsert;
	}
}
	  function UpdateDataBase()
     {
	var url;
	var dt =new Date();
	var dtime=dt.getSeconds();	
	if (ResponseArray[Ipointer])
	{
		place = ResponseArray[Ipointer].Placemark[0];
		place.Point.coordinates[1], place.Point.coordinates[0];
		url="updatedata.php?dt="+dtime+"&id=" + SearchArray[Ipointer].split('#')[1]+ "&lat="+place.Point.coordinates[1] + "&lng="+place.Point.coordinates[0]+"&pointHas=Y";
	}
	else
		url="updatedata.php?dt="+dtime+"&id=" + SearchArray[Ipointer].split('#')[1]+"&lat=0"+ "&lng=0"+"&pointHas=Y";

			 
	updateobj[Ipointer] = getHTTPObject();
        locupdate=updateobj[Ipointer];
	if (	updateobj[Ipointer] != null) 
	{
		updateobj[Ipointer].open("GET",url , true); 
		updateobj[Ipointer].send(null);
		updateobj[Ipointer].onreadystatechange = Isupdate;
	}
}

function Isupdate()
{
	var isup;
//	alert(locupdate.readyState);
	if(locupdate.readyState == 4)
	{
	//	alert(locupdate.responseText);
		isup = locupdate.responseText;
	}
}

 function UpdateDataBaseInfo(EditOk)
     {
		 
	var url;
	var dt =new Date();
	var dtime=dt.getSeconds();
	var BEditId=trim(document.getElementById("BEditId").value);/*Id*/
	
	
	if (EditOk=="false")
			url="updatedataadmin.php?dt="+dtime+"&id=" + BEditId+"&EditOk=" + EditOk;
			else
			{
				var BPcode=trim(document.getElementById("BPcode").value.replace("&", "^"));/*pcode*/
	var BState=trim(document.getElementById("BState").value.replace("&", "^"));/*state*/
	var BLocation=trim(document.getElementById("BLocation").value.replace("&", "^"));/*location*/
	var BAddress1=trim(document.getElementById("BAddress1").value.replace("&", "^"));/*address1*/
	var BAddress2=trim(document.getElementById("BAddress2").value.replace("&", "^"));/*address2*/
	var BAddress3=trim(document.getElementById("BAddress3").value.replace("&", "^"));/*address3*/
	var BStore=trim(document.getElementById("BStore").value.replace("&", "^"));/*store*/
	var BEmail=trim(document.getElementById("BEmail").value.replace("&", "^"));/*email*/
	var BPhone=trim(document.getElementById("BPhone").value.replace("&", "^"));/*phone*/
	var BWebsite=trim(document.getElementById("BWebsite").value.replace("&", "^"));/*website*/
	
	var BLat=trim(document.getElementById("BLat").value.replace("&", "^"));/*lat*/
	var BLng=trim(document.getElementById("BLng").value.replace("&", "^"));/*lng*/
	var BCountry=trim(document.getElementById("BCountry").value.replace("&", "^"));/*country*/
	
	if(BStore=="ENTER STORE NAME" || BStore=="")
	  BStore="";
	if(BAddress1=="ENTER ADDRESS1")
	  BAddress1="";
	if(BAddress2=="ENTER ADDRESS2")
	BAddress2="";
	if(BAddress3=="ENTER ADDRESS3")
	BAddress3="";
	if(BState=="ENTER STATE NAME")
	BState="";
    if(BPcode=="ENTER PCODE")
	BPcode="";
	if(BLocation=="ENTER LOCATION" )
     BLocation="";
	
	if(BEmail=="ENTER EMAIL")
	BEmail="";
    if(BPhone=="ENTER PHONE")
	BPhone="";
	if(BWebsite=="ENTER WEB SITE")
	BWebsite="";
	if (BLat=="LATITUDE" || BLat=="") 
	BLat=0;
	if (BLng=="LONGITUDE" || BLng=="")
	BLng=0;
			url="updatedataadmin.php?dt="+dtime+"&BPcode=" + BPcode+"&BState=" + BState;
			//alert("updatedataadmin.php?dt="+dtime+"&BPcode=" + BPcode+"&BState=" + BState);
			url=url +"&BLocation=" + BLocation+"&BAddress1=" + BAddress1+"&BAddress2=" + BAddress2;
			//alert("&BLocation=" + BLocation+"&BAddress1=" + BAddress1+"&BAddress2=" + BAddress2);
			url=url+"&BAddress3=" + BAddress3+"&BStore=" + BStore+"&BEmail=" + BEmail+"&BPhone="+ BPhone;
			//alert("&BAddress3=" + BAddress3+"&BStore=" + BStore+"&BEmail=" + BEmail+"&BPhone="+ BPhone);
			url=url+"&BWebsite=" + BWebsite+"&id=" + BEditId+"&BLat=" + BLat+"&BLng=" + BLng;
			//alert("&BWebsite=" + BWebsite+"&id=" + BEditId+"&BLat=" + BLat+"&BLng=" + BLng);
			url=url+"&BCountry=" + BCountry+"&EditOk=" + EditOk;
			//alert("&BCountry=" + BCountry+"&EditOk=" + EditOk);
			}
			//alert("update");
			//alert(url);
			
	updateobj = getHTTPObject();
        
	if (	updateobj!= null) 
	{
		updateobj.open("GET",url , true); 
		updateobj.send(null);
		updateobj.onreadystatechange = Isupdate;
	}
}
function currentposition(cur)
   {
	   //alert(cur);
	   var newcenterlat5=readCookie("CenterPointLat");
		 var newcenterlng5=readCookie("CenterPointLng");
		
		 IsCount="Y";
	     Isadmin="Y";
		 ImageCount=1;
		 document.getElementById("divlist").innerHTML="";
		 if (parseInt(cur)==1)
		 {
			fl=1;
			ll=parseInt(Maxcount);
		 }
		 else if(parseInt(cur)==totalpagecount)
		 {
			         fl=(parseInt(cur)-2)*parseInt(Maxcount)+parseInt(Maxcount)+1;
			 	 ll=totalpagecount*10;
		 }
		 else
		 {
			 fl=(parseInt(cur)-2)*parseInt(Maxcount)+parseInt(Maxcount)+1;
			 ll=parseInt(cur)*parseInt(Maxcount); 
		 }
		
		 document.getElementById('currentvalue').value=fl;
		 linkimageId=parseInt(cur);
		 	IsClickonSearch=false;
		   //alert(fl + "middle: fl + LL" + ll);
		 	if (IsDrageed=="true")
			{
	                       
		
		 DragReloadLoadNext(newcenterlat5,newcenterlng5);
			}
			else
			{
			//	initialize() ;
				createCookie("IsDrageed",false,365); 
				
		 		doWork();
			}
		 return false;
	
   }
 
function Isupdate()
{
	var isup;
//	alert(locupdate.readyState);
	if(updateobj.readyState == 4)
	{
	
		isup = updateobj.responseText;
		//alert(updateobj.responseText);
		if (trim(isup)=="OK")
		{
		  alert("record update sucessfully.");
        currentposition(linkimageId);
		resettextbox();
		}
		if (trim(isup)=="DELOK")
		{
		  alert("record deleted sucessfully.");
        if ( linkimageId==totalpagecount && totalpagecount!=1 )
		currentposition(parseInt(linkimageId-1));
		else
		currentposition(linkimageId);
		resettextbox();
		}

	}
}

function Isinsert()
{
	var isup;
//	alert(locupdate.readyState);
	if(insertobj.readyState == 4)
	{
	
		isup = insertobj.responseText;
		//alert(insertobj.responseText);
		if (trim(isup)=="OK")
		{
		 alert("record save sucessfully.");
		 currentposition(linkimageId);
		resettextbox();
		
		}
		IsnotFound=false;
	}
}

