//This function is come into action  when we click on the 'Next' or 'Previous' link button, It call the another function from it 'function enableButton(a,b,c,d,e,f)'.//   

function displaynextpre(tc)
   {
	   totalpagecount=parseInt(document.getElementById('hdntotalcount').value)/parseInt(Maxcount);
	   if ((totalpagecount-parseInt(totalpagecount))>0)
				totalpagecount=parseInt(totalpagecount)+1;
	   else
	  		totalpagecount=parseInt(totalpagecount);
			
			
			//alert(totalpagecount +"------------------"+linkimageId);
	
	   if (linkimageId>totalpagecount)
	   {
		   alert("There is some internal error, so map will be reset."+'\n'+"Sorry for inconvenient ");
		   initSearch();
		   IsError=1;
	   }
	   else
	   {
		   if (isNaN(totalpagecount)==true)
	  		{
				document.getElementById("query-results").style.display="block";
				document.getElementById('showvalue').innerHTML="Record Not Found.";
			}
			else
			{
				document.getElementById("query-results").style.display="block";
				document.getElementById('showvalue').innerHTML="Page " +  linkimageId +  " of " +totalpagecount + ".";
			}
			
			if (isNaN(totalpagecount)==true)
			{
				
				enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
				
				return;
			}
		
			if ( linkimageId>=totalpagecount && totalpagecount==1)
				{
				
				     
					enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
				}
			else if (linkimageId<= 1)
				{
		   
					 enableButton('dprevd.png',true,'default','dnext.png',false,'pointer');
				}
				 
				else if ( linkimageId>=totalpagecount && totalpagecount!=1)
				{
		                      
					enableButton('dprev.png',false,'pointer','dnextd.png',true,'default');
				}
				else  if ( linkimageId>totalpagecount)
				{
					enableButton('dprev.png',true,'pointer','dnext.png',true,'default');
				}
				else
				{
		            enableButton('dprev.png',false,'pointer','dnext.png',false,'pointer');
				}
	  }	
   }
 
   //This function is used from the 'displaynextpre(a)'.//  
   
   function enableButton(preclsname,predisable,prepointer,nextclsname,nextdisable,nextpointer)
   {
	 if (dir=="nopath")
	    {
			document.getElementById('imgpre').src="images/"+preclsname;
	   		document.getElementById('imgpre').style.cursor=prepointer;
	 		document.getElementById('imgpre1').src="images/"+preclsname;
	  		document.getElementById('imgpre1').style.cursor=prepointer;
	   		document.getElementById('imgnext').src="images/"+nextclsname;
	   		document.getElementById('imgnext').style.cursor=nextpointer;
	   		document.getElementById('imgnext1').src="images/"+nextclsname;
	   		document.getElementById('linknext1').style.cursor=nextpointer;
		}
	else
    	{
		   document.getElementById('imgpre').src=dir + "images/"+preclsname;
	   	   document.getElementById('imgpre').style.cursor=prepointer;
	  	   document.getElementById('imgpre1').src=dir +"images/"+preclsname;
	   	   document.getElementById('imgpre1').style.cursor=prepointer;
	   	   document.getElementById('imgnext').src=dir +"images/"+nextclsname;
	   	   document.getElementById('imgnext').style.cursor=nextpointer;
	   	   document.getElementById('imgnext1').src=dir +"images/"+nextclsname;
	   	   document.getElementById('linknext1').style.cursor=nextpointer;
	  }
	  
   }
//this function is used to create the header in which order we want to show the record. After creating the header all the record will show below this header//

function CreateHeaderResult()
{
	var d1;
	
	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="Office 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","loc");
	d1.innerHTML="Location";
	d.appendChild(d1);
	*/
	
	d1=document.createElement("div");
	d1.setAttribute("id","state");
	d1.innerHTML="Location";
	d.appendChild(d1);
	
	d1=document.createElement("div");
	d1.setAttribute("id","cont");
	d1.innerHTML="Contact";
	d.appendChild(d1);

	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);
}
// This Function is used to 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;
	}
}

//By this function we call ajaxdataadmin.php to fatch the record from the database. This function is call from the various function for showing the record.//

 function doWork()
   {
	   var Location =trim(document.getElementById('location').value.replace("&", "^"));	
//	   var pcode=trim(document.getElementById('pcode').value.replace("&", "^")) ; // changes by praveen
	   var Technique=trim(document.getElementById('techniques').value.replace("&", "^")) 
//	   	   alert(Location+":"+Technique+":"+dir);
	   if (dir!="nopath")
	   {
			if (pcode=="..SEARCH" || pcode=="")
			{
				pcode="";
			}
			var CurrentValue;
			var t;
			  CurrentValue=parseInt(document.getElementById('currentvalue').value);
			  t=document.getElementById('hdntotalcount').value;
			  //alert(t);
			  enableButton('dprevd.png',true,'default','dnextd.png',true,'default');
				try{document.getElementById('linkupperdiv').style.display="none";
				document.getElementById('linkbottomdiv').style.display="none";}catch(e){}
					
				httpObject = getHTTPObject();
				var dt =new Date();
				var dtime=dt.getSeconds();
				var url="ajaxdataadmin.php?dt="+dtime+  "&IsCount=" + IsCount + "&CurrentValue=" + CurrentValue + "&lastlimit=" + ll + "&totalcount="+ parseInt(t)+"&pcode="+pcode;
				//alert(url);
				if (httpObject != null)
					{
						httpObject.open("GET", url, true); 
						httpObject.send(null);
						httpObject.onreadystatechange = setOutput;
					} 
	   }
	   else
	   {

				GetCityORPcode("","");
	   }
 }

//This function come in to action when we click on the search button. In this method we have to pass  one parameter for checking whether Isdrag is true or not. At first time  IsDrag is 'false'. When we drag on the map all the default point,latlng has been changed  and at that time Isdrag will true and DragReloadLoad() will call. //

function CheckCity(Isdrag)
   {
	   var Location=trim(document.getElementById('location').value.replace("&", "^") );
	   var Technique=trim(document.getElementById('techniques').value.replace("&", "^") );
		if (Location=="All" )
	    {
		    Location="";
			if (Isdrag=="true")
			{
				linkimageId=1;
				createCookie("IsDrageed",Isdrag,365);
				DragReloadLoad();
			}
			else
			{   
			    createCookie("IsDrageed",Isdrag,365);
			    finddata1();
			}
	    }
	    else
	    {
			if (Isdrag=="true")
			{
				linkimageId=1;
				DragReloadLoad();
			}
			else
			{  
				finddata1(); 
			}
	    } 
	    
  }
 var xxx=0;
 
 // For making the new entry or record when we add new record. If it cann't get the latlng of the neew record then by defualt it will take 'SYDENY' as a point//
 
function MakePointOnMap(response)
	{
		var StateVal=trim(document.getElementById("tbxState").value.replace("&", "^"));/*state*/
		if (StateVal!="ENTER STATE" && StateVal!="")
		{
			if (xxx == 0)
			{
			   xxx = 1;
				
			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.78383),parseFloat(-84.369606));
				var marker = new GMarker(newpp, markerOptions);
				
				map.addOverlay(marker);
				map.setCenter(newpp,9);
				CurrentMarker=marker;	
				document.getElementById("tbxLat").value="33.78383";
				document.getElementById("tbxLng").value="-84.369606";
				IsnotFound=true;
				GEvent.addListener(marker, 'dragend', function(overlay, point) {
					var c= marker.getPoint();
					document.getElementById("tbxLat").value=c.lat();
					document.getElementById("tbxLng").value=c.lng();
					});
				}
				}
	}
 
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 )
		{
			CurrentAddressLocation=parseInt(CurrentAddressLocation) +1;
			geocoder.getLocations(AddressArray[CurrentAddressLocation],SaveNewRecord);
		}
		else
		{    
			MakePointOnMap(response);
		}
	}
	else 
	{
		if (xxx==0)
		{
			xxx=1;
				if (CurrentMarker)
			map.removeOverlay(CurrentMarker);
				var place1 = response.Placemark[0];
			document.getElementById("tbxLat").value=place1.Point.coordinates[1];
			document.getElementById("tbxLng").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("tbxLat").value=c.lat();
					document.getElementById("tbxLng").value=c.lng();
					});
			
		}
	}
}

function GetUpdateAddress(response)
{
	if (CurrentMarker)
		map.removeOverlay(CurrentMarker);
	if (!response || response.Status.code != 200) 
	{

		if (CurrentAddressLocation<5)
		{
			CurrentAddressLocation=parseInt(CurrentAddressLocation) +1;
			geocoder.getLocations(AddressArray[CurrentAddressLocation],GetUpdateAddress);
		}
		else
		{
			MakePointOnMap(response);
		}
	}
	else 
	{
		var place1 = response.Placemark[0];
		document.getElementById("tbxLat").value=place1.Point.coordinates[1];
		document.getElementById("tbxLng").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("tbxLat").value=c.lat();
				document.getElementById("tbxLng").value=c.lng();
				});
		CurrentAddressLocation=0;
	}
}

//This function is used to find the latlng of the city, when we add new record.//

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("location").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]);

	}

}
// This function is call from the DragReloadLoad(), By this funtion we try to find out the latlng point after drag on the map. In that method we have pass two parameter//

 function DragReloadLoadNext(nlat,nlng)
    {
	      if (nlat==null && nlng==null)
	    {
	      GetCityORPcode("","");
	    }
	    else
	    {
	      GetCityORPcode(nlat,nlng);
	    } 
    }

// This function is called from the DragReloadLoadNext(a,b) to check the searching query is valid or not. If itis valid then the new function is call 'function GetajaxData(State,Store,pcode,pcodelat,pcodelng)'. In that function we have to pass 5 parameter. //  

   function GetCityORPcode(pcodelat1,pcodelng1)
   {
	  //alert("ggG"); 	
	  var Location=trim(document.getElementById('location').value.replace("&", "^")) ;
      var Techniques=trim(document.getElementById('techniques').value.replace("&", "^")) ;

	var Isdrag1=readCookie("IsDrageed");

	  if (Location=="All")
		  Location=""; 
	  if (Techniques=="All")
		    Techniques="";
	  if(IsClickonSearch==false)
	    {
				 	Location=trim(document.getElementById('location').value.replace("&", "^"));
	  				Techniques=trim(document.getElementById('techniques').value.replace("&", "^")) ;
	     }
		GetajaxData(Location,Techniques,pcodelat1,pcodelng1);    
   }
   
  //This function is used to show the Data from the database by using AJAX function. In this function we call another pag for executing the query//
  
   function GetajaxData(State,Store,pcodelat,pcodelng)
   {     
		var Location=trim(document.getElementById('location').value.replace("&", "^")) ;
		 var Techniques=trim(document.getElementById('techniques').value.replace("&", "^")) ;
		 if(Location=="All")
		 	Location="";
		 if(Techniques=="All")
		 	Techniques="";

		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="ajaxdata1.php?dt="+dtime+"&Location="
			    +Location + "&Technique=" +Techniques + "&IsCount=" + IsCount + "&CurrentValue=" + CurrentValue + "&lastlimit=" + ll + "&totalcount="+ parseInt(t) +"&Clat="+pcodelat + "&Clng="+ pcodelng;

			if (httpObject != null)
		    {
				httpObject.open("GET", url, true); 
			    httpObject.send(null);
			    httpObject.onreadystatechange = setOutput;
		    } 
   }
   
   //This function is used to show the result output//
   
   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)
	      {
			  if (trim(httpObject.responseText)!="Not found")
		      {
				try
				{
				document.getElementById('linkupperdiv').style.display="block";
				document.getElementById('linkbottomdiv').style.display="block";}catch(e){}
			    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 displayaddr="";
			      if (temp.length>0)
			      {   
				      
					  document.getElementById("divlist").innerHTML="";
				      ImageCount=0;
				      IsError=0;
					  //alert("dd");
				      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('#');
						  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;
						  }
					      if (temp2.length>0)
					      {
							   var CityandPcode="";
						     if(temp2[0] && temp2[2])
                              CityandPcode=trim(temp2[2]) +" "+ trim(temp2[0]);
							  else if(temp2[2])
							  CityandPcode=trim(temp2[2]);
							  else
							  CityandPcode=trim(temp2[0]);
							 
							  var SState="";
						      var GeoLocation = trim(temp2[17]);
						      SState=trim(temp2[15]);
							   if(temp2[0] && temp2[2])
                              SearchAddress=trim(temp2[2])+","+trim(temp2[0])+","+SState;
							  else if(temp2[2])
							  SearchAddress=trim(temp2[2])+","+SState;
							  else
							   SearchAddress=trim(temp2[0])+","+SState;
						     
						      SearchAddress=trim(SearchAddress);
						    
						      addr="";
						      for (var j=3;j<6;j++)
						      {
							      if(temp2[j])
							      { 
								      addr=addr +"<div id=\"address"+j+i+"\">" + trim(temp2[j]) +"</div>";
							      }
						      }

						      addr=trim(addr);
							  if(trim(temp2[2])!="")
							  	  addr=addr+trim(temp2[2]);
							  if(SState!="")
							      addr=addr+","+SState;	
							  
							  displayaddr="";
							  
						      for (var j=3;j<6;j++)
						      {
							      if(temp2[j])
							      { 
								      displayaddr=displayaddr +"<div>" + trim(temp2[j]) +"</div>";
							      }
						      }
							
							  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=trim(temp2[11]);
						      if(temp2[12])
							      Locpointlng=trim(temp2[12]);
						      var LocpointHas=trim(temp2[13]);
							  var StoreType='';
							  var displayemail='';
							  var displayweb='';

							// alert(temp2[10]);
							var officename=trim(temp2[1]);
						      SearchArray[i]=SearchAddress+"#"+temp2[10]+"#"+parseInt(i+1)+"#"+officename+"#"+addr+"#"+CityandPcode+"#"+cont +"#"+Locpointlat+"#"+Locpointlng+"#"+LocpointHas +"#"+temp2[14]+"#"+email+"#"+phone+"#"+website+"#"+GeoLocation+"#"+displayaddr+"#"+StoreType+"#"+displayemail+"#"+displayweb;
							
					      }  	 
				      } 
				 	 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();
						}

			      } 
                  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*/
	//alert("gghfgH"+BEditId);
	var Pcode=trim(document.getElementById("tbxPcode").value.replace("&", "^"));/*pcode*/
	//var StoreType=trim(document.getElementById("StoreType").value.replace("&", "^"));/*StoreType*/
	var Location=trim(document.getElementById("tbxLocation").value.replace("&", "^"));/*location*/
	var Address1=trim(document.getElementById("tbxAddress1").value.replace("&", "^"));/*address1*/
	var Address2=trim(document.getElementById("tbxAddress2").value.replace("&", "^"));/*address2*/
	var Address3=trim(document.getElementById("tbxAddress3").value.replace("&", "^"));/*address3*/
	var Store=trim(document.getElementById("tbxofficename").value.replace("&", "^"));/*store*/
	var Email=trim(document.getElementById("tbxEmail").value.replace("&", "^"));/*email*/
	var Phone=trim(document.getElementById("tbxPhone").value.replace("&", "^"));/*phone*/
	var Website=trim(document.getElementById("tbxWebsite").value.replace("&", "^"));/*website*/
	
	var Lat=trim(document.getElementById("tbxLat").value.replace("&", "^"));/*lat*/
	var Lng=trim(document.getElementById("tbxLng").value.replace("&", "^"));/*lng*/
	var State=trim(document.getElementById("tbxState").value.replace("&", "^"));/*country*/
	var Region=trim(document.getElementById("tbxRegion").value.replace("&", "^"));/*country*/	
	
	if(Store=="ENTER OFFICE NAME" || Store=="")
		Store="";
	if(Address1=="ENTER ADDRESS1")
		Address1="";
	if(Address2=="ENTER ADDRESS2")
		Address2="";
	if(Address3=="ENTER ADDRESS3")
		Address3="";
	if(Pcode=="ENTER ZIP CODE")
		Pcode="";
	if(Location=="ENTER CITY" )
    	Location="";
	
	if(Email=="ENTER EMAIL")
		Email="";
    if(Phone=="ENTER PHONE")
		Phone="";
	if(Website=="ENTER WEB SITE")
		Website="";
	if(State=="ENTER STATE")
		State="";
	if(Region=="ENTER LOCATION")
		Region="";
	if (Lat=="LATITUDE" ||Lat=="" ||Lat=="NOT FOUND")Lat=0;
	if (Lng=="LONGITUDE" ||Lng=="" ||Lng=="NOT FOUND")Lng=0;
	
url="updatedataadmin.php?dt="+ dtime+ "&Pcode=" + Pcode+"&Location=" + Location+"&Address1=" + Address1+"&Address2=" + Address2+"&Address3=" + Address3+"&officeName=" + Store+"&Email=" + Email+"&Phone=" + Phone+"&Website=" + Website+"&Lat=" + Lat+"&Lng=" +Lng+"&State=" + State+"&EditOk=aaaa";
	//alert
	//alert("save");
	//alert(url);
	insertobj=null;		
	insertobj = getHTTPObject();
      
	if (insertobj!= null) 
	{
		insertobj.open("GET",url , true); 
		insertobj.send(null);
		insertobj.onreadystatechange = Isinsert;
		//alert("ddd"); 
	}
}
	  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";

		//alert(url);	 
		updateobj[Ipointer] = getHTTPObject();
        locupdate=updateobj[Ipointer];
		if (updateobj[Ipointer] != null) 
		{
		updateobj[Ipointer].open("GET",url , true); 
		updateobj[Ipointer].send(null);
		updateobj[Ipointer].onreadystatechange = Isupdate1;
	}
}

function Isupdate1()
{
	var isup;
	
	if(locupdate.readyState == 4)
	{
		isup = locupdate.responseText;
	}
}
//This function is basically is to update the existing record. For update the record it call another link and fatch the record. From this function it call the AJAX object.//   

function UpdateDataBaseInfo(EditOk)
     {
		var url;
		var dt =new Date();
		var dtime=dt.getSeconds();
		var BEditId=trim(document.getElementById("BEditId").value);/*Id*/
		//alert(BEditId);
	
	if (EditOk=="false")
	{
		url="updatedataadmin.php?dt="+dtime+"&BEditId=" + BEditId+"&EditOk=" + EditOk;
		//alert(url);
	}
	else
	{
		var Store=trim(document.getElementById("tbxofficename").value.replace("&", "^"));/*store*/
		var Pcode=trim(document.getElementById("tbxPcode").value.replace("&", "^"));/*pcode*/
		//var StoreType=trim(document.getElementById("StoreType").value.replace("&", "^"));/*pcode*/
		var Location=trim(document.getElementById("tbxLocation").value.replace("&", "^"));/*location*/
		var Address1=trim(document.getElementById("tbxAddress1").value.replace("&", "^"));/*address1*/
		var Address2=trim(document.getElementById("tbxAddress2").value.replace("&", "^"));/*address2*/
		var Address3=trim(document.getElementById("tbxAddress3").value.replace("&", "^"));/*address3*/
		
		var Email=trim(document.getElementById("tbxEmail").value.replace("&", "^"));/*email*/
		var Phone=trim(document.getElementById("tbxPhone").value.replace("&", "^"));/*phone*/
		var Website=trim(document.getElementById("tbxWebsite").value.replace("&", "^"));/*website*/
		
		var Lat=trim(document.getElementById("tbxLat").value.replace("&", "^"));/*lat*/
		var Lng=trim(document.getElementById("tbxLng").value.replace("&", "^"));/*lng*/
		var State=trim(document.getElementById("tbxState").value.replace("&", "^"));/*country*/
		var Region=trim(document.getElementById("tbxRegion").value.replace("&", "^"));/*country*/		
	
		if(Store=="ENTER OFFICE NAME")
		  	Store="";
		if(Address1=="ENTER ADDRESS1")
		  Address1="";
		if(Address2=="ENTER ADDRESS2")
			Address2="";
		if(Address3=="ENTER ADDRESS3")
			Address3="";
	
	    if(Pcode=="ENTER ZIP CODE")
			Pcode="";
		if(Location=="ENTER CITY" )
     		Location="";
		if(State=="ENTER STATE")
			State="";
		if(Region=="ENTER LOCATION")
			Region="";
		if(Email=="ENTER EMAIL")
			Email="";
    	if(Phone=="ENTER PHONE")
			Phone="";
		if(Website=="ENTER WEB SITE")
			Website="";
		if (Lat=="LATITUDE" ||Lat=="")Lat=0;
		
		if (Lng=="LONGITUDE" ||Lng=="")Lng=0;
		url="updatedataadmin.php?dt="+dtime+"&OfficeName=" + Store+"&BEditId=" + BEditId+"&Pcode=" + Pcode;

			url=url +"&Location=" + Location+"&Address1=" + Address1+"&Address2=" + Address2;

			url=url+"&Address3=" + Address3+"&Email=" + Email+"&Phone="+ Phone;

			url=url+"&Website=" + Website+"&Lat=" +Lat+"&Lng=" +Lng;

			url=url+"&State=" + State+"&EditOk=" + EditOk;

			}
	//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;
  }
   
// This function is used to check whether the record is update or not.//

function Isupdate()
{
	var isup;
	if(updateobj.readyState == 4)
	{
		isup = updateobj.responseText;
		//alert(isup);
		
		if (trim(isup)=="OK")
		{
			var techniquesArr = document.getElementsByName("chkTechniques");
			var techID="";
			for(var j=0;j<techniquesArr.length;j++)
			{
				if(techniquesArr[j].checked==true)
				{
					if(techID=="")
						techID=techniquesArr[j].value;
					else
						techID=techID+","+techniquesArr[j].value;
				}
			}
			var offID=document.getElementById("BEditId").value;
			$.get("saveOfficeTechniques.php?offid="+offID+"&techID="+techID);
			
			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();
		}
	}
}
//this function is used to check whether new record is insert successfully or not//

function Isinsert()
{
	var isup;
	if(insertobj.readyState == 4)
	{
		//alert("2");
		var arr = insertobj.responseText;
		var arr1 = arr.split("#");
		//alert(insertobj.responseText);
		isup=arr1[0];

		var offID=arr1[1];
		var techniquesArr = document.getElementsByName("chkTechniques");
		//alert(techniquesArr.length);
		var techID="";
		for(var j=0;j<techniquesArr.length;j++)
		{
			if(techniquesArr[j].checked==true)
			{
				if(techID=="")
					techID=techniquesArr[j].value;
				else
					techID=techID+","+techniquesArr[j].value;
			}
		}
		
		$.get("saveOfficeTechniques.php?offid="+offID+"&techID="+techID,function(data){//alert(data);
																							 });
		
		if (trim(isup)=="OK")
		{
			 alert("record save sucessfully.");
			 currentposition(linkimageId);
			 resettextbox();
		}
		IsnotFound=false;
//		doWork();
	}
}

