﻿var xmlhttp

function findStores()
{
var City=document.getElementById("sfsearch_city").value;
//var City_=document.getElementById("sfsearch_city");
var State=document.getElementById("sfsearch_state").value;
/*
if (City.length==0) {
	State=document.getElementById("sfsearch_state2").value;
	City=document.getElementById("sfsearch_city2").value;
	//var City_=document.getElementById("sfsearch_city2");
}

if (City.length==0) {
	State=document.getElementById("sfsearch_state3").value;
	City=document.getElementById("sfsearch_city3").value;
	//var City_=document.getElementById("sfsearch_city3");
}
*/

//if (State.length==0) State=document.getElementById("sfsearch_state2").value;
//if (State.length==0) State=getCookie('State');
//alert ("Your browser does not support XMLHTTP!"+City+State);
var Zip=document.getElementById("sfsearch_zip").value;
/*
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip2").value;
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip3").value;
//if (Zip.length==0) Zip=getCookie('Zip');
*/
//alert (State);
if (City.length==0 && State=="--")
  {
	  if (Zip.length==0) Zip=getCookie('Zip');
	  if (Zip.length==0) 
	  {
	  	City=getCookie('City');
		State=getCookie('State');
		

		if (City.length>0 || State.length>0)
		{
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
		  	{
		  		alert ("Your browser does not support XMLHTTP!");
		  		return;
		  	}
			var url="FindCity.php";
			url=url+"?City="+City+"&State="+State;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}
	  
	  	//alert ("No zip value!"+Zip);
	  	return;
	  } else 
	  {
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
	  		{
	  			alert ("Your browser does not support XMLHTTP!");
	  			return;
	  		}
	  		var url="FindZip.php";
			url=url+"?Zip="+Zip;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
			setCookie('Zip',Zip,365);
			setCookie('City',"", 365);
			setCookie('State',"", 365);
			

	  }
  } else 
  {
	  	xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support XMLHTTP!");
	  		return;
	  	}
		var url="FindCity.php";
		url=url+"?City="+City+"&State="+State;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		setCookie('City',City,365);
		setCookie('State',State,365);
		setCookie('Zip',"", 365);

  
  }
  
  //document.getElementById("sfsearch_city").text="";
  //document.getElementById("sfsearch_city2").text="";
  //document.getElementById("sfsearch_city3").text="";
  //document.getElementById("sfsearch_zip").text="";
  //document.getElementById("sfsearch_zip2").text="";
  //document.getElementById("sfsearch_zip3").text="";
  //var txt = '';
  //City_.value = txt;
  //ZIP_ = txt;

  
  
  //document.getElementById("txtHint").innerHTML="";
  
}

function findStores2()
{
var City=document.getElementById("sfsearch_city2").value;
//var City_=document.getElementById("sfsearch_city");
var State=document.getElementById("sfsearch_state2").value;
/*
if (City.length==0) {
	State=document.getElementById("sfsearch_state2").value;
	City=document.getElementById("sfsearch_city2").value;
	//var City_=document.getElementById("sfsearch_city2");
}

if (City.length==0) {
	State=document.getElementById("sfsearch_state3").value;
	City=document.getElementById("sfsearch_city3").value;
	//var City_=document.getElementById("sfsearch_city3");
}

*/
//if (State.length==0) State=document.getElementById("sfsearch_state2").value;
//if (State.length==0) State=getCookie('State');
//alert ("Your browser does not support XMLHTTP!"+City+State);
var Zip=document.getElementById("sfsearch_zip2").value;
/*
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip2").value;
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip3").value;
//if (Zip.length==0) Zip=getCookie('Zip');
*/

//if (City.length==0 || State.length==0)
if (City.length==0 && State=="--")
  {
	  if (Zip.length==0) Zip=getCookie('Zip');
	  if (Zip.length==0) 
	  {
	  	City=getCookie('City');
		State=getCookie('State');
		

		if (City.length>0 || State.length>0)
		{
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
		  	{
		  		alert ("Your browser does not support XMLHTTP!");
		  		return;
		  	}
			var url="FindCity.php";
			url=url+"?City="+City+"&State="+State;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}
	  
	  	//alert ("No zip value!"+Zip);
	  	return;
	  } else 
	  {
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
	  		{
	  			alert ("Your browser does not support XMLHTTP!");
	  			return;
	  		}
	  		var url="FindZip.php";
			url=url+"?Zip="+Zip;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
			setCookie('Zip',Zip,365);
			setCookie('City',"", 365);
			setCookie('State',"", 365);
			

	  }
  } else 
  {
	  	xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support XMLHTTP!");
	  		return;
	  	}
		var url="FindCity.php";
		url=url+"?City="+City+"&State="+State;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		setCookie('City',City,365);
		setCookie('State',State,365);
		setCookie('Zip',"", 365);

  
  }
  
  //document.getElementById("sfsearch_city").text="";
  //document.getElementById("sfsearch_city2").text="";
  //document.getElementById("sfsearch_city3").text="";
  //document.getElementById("sfsearch_zip").text="";
  //document.getElementById("sfsearch_zip2").text="";
  //document.getElementById("sfsearch_zip3").text="";
  //var txt = '';
  //City_.value = txt;
  //ZIP_ = txt;

  
  
  //document.getElementById("txtHint").innerHTML="";
  
}


function findStores3()
{
var City=document.getElementById("sfsearch_city3").value;
//var City_=document.getElementById("sfsearch_city");
var State=document.getElementById("sfsearch_state3").value;
/*
if (City.length==0) {
	State=document.getElementById("sfsearch_state2").value;
	City=document.getElementById("sfsearch_city2").value;
	//var City_=document.getElementById("sfsearch_city2");
}

if (City.length==0) {
	State=document.getElementById("sfsearch_state3").value;
	City=document.getElementById("sfsearch_city3").value;
	//var City_=document.getElementById("sfsearch_city3");
}
*/

//if (State.length==0) State=document.getElementById("sfsearch_state2").value;
//if (State.length==0) State=getCookie('State');
//alert ("Your browser does not support XMLHTTP!"+City+State);
var Zip=document.getElementById("sfsearch_zip3").value;
/*
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip2").value;
if (Zip.length==0) Zip=document.getElementById("sfsearch_zip3").value;
//if (Zip.length==0) Zip=getCookie('Zip');
*/

if (City.length==0 && State=="--")
  {
	  if (Zip.length==0) Zip=getCookie('Zip');
	  if (Zip.length==0) 
	  {
	  	City=getCookie('City');
		State=getCookie('State');
		

		if (City.length>0 || State.length>0)
		{
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
		  	{
		  		alert ("Your browser does not support XMLHTTP!");
		  		return;
		  	}
			var url="FindCity.php";
			url=url+"?City="+City+"&State="+State;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
		}
	  
	  	//alert ("No zip value!"+Zip);
	  	return;
	  } else 
	  {
		  	xmlhttp=GetXmlHttpObject();
			if (xmlhttp==null)
	  		{
	  			alert ("Your browser does not support XMLHTTP!");
	  			return;
	  		}
	  		var url="FindZip.php";
			url=url+"?Zip="+Zip;
			url=url+"&sid="+Math.random();
			xmlhttp.onreadystatechange=stateChanged;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
			setCookie('Zip',Zip,365);
			setCookie('City',"", 365);
			setCookie('State',"", 365);
			

	  }
  } else 
  {
	  	xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)
	  	{
	  		alert ("Your browser does not support XMLHTTP!");
	  		return;
	  	}
		var url="FindCity.php";
		url=url+"?City="+City+"&State="+State;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		setCookie('City',City,365);
		setCookie('State',State,365);
		setCookie('Zip',"", 365);

  
  }
  
  //document.getElementById("sfsearch_city").text="";
  //document.getElementById("sfsearch_city2").text="";
  //document.getElementById("sfsearch_city3").text="";
  //document.getElementById("sfsearch_zip").text="";
  //document.getElementById("sfsearch_zip2").text="";
  //document.getElementById("sfsearch_zip3").text="";
  //var txt = '';
  //City_.value = txt;
  //ZIP_ = txt;

  
  
  //document.getElementById("txtHint").innerHTML="";
  
}




function stateChanged()
{
if (xmlhttp.readyState==4)
  {  
  document.getElementById("content").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
