


///////////////////////////////////////////////////////////////////////////

var url;
var searchType, resultType;
var xmlHttpState, xmlHttpCity, xmlHttpConfirm;
var m_xmlHttpState, m_xmlHttpCity, m_xmlHttpConfirm;
var f_xmlHttpState, f_xmlHttpCity, f_xmlHttpConfirm;
//global declarations

function statesearch(_params, _type)
{
	if(_type == "common")
	{
		url = "state.php?"+_params;
		searchType = "state";
	}
	else if(_type == "male")
	{
		url = "m_state.php?"+_params;
		searchType = "m_state";
	}
	else if(_type == "female")
	{
		url = "f_state.php?"+_params;
		searchType = "f_state";
	}
	 	
	process(); 
}

function citysearch(_params, _type)
{
	if(_type == "common")
	{
		url = "citysearch.php?"+_params;
		searchType = "searchcity";
	}
	else if(_type == "male")
	{
		url = "m_citysearch.php?"+_params;
		searchType = "m_searchcity";
	}
	else if(_type == "female")
	{
		url = "f_citysearch.php?"+_params;
		searchType = "f_searchcity";
	}
	
	process(); 
}

function confirmcity(_params, _type)
{
	url = "confirmcity.php?"+_params;
	
	if(_type == "common")
		searchType = "confirm";
	else if(_type == "male")
		searchType = "m_confirm";
	else if(_type == "female")
		searchType = "f_confirm";
	
	process(); 
}

///////////////////////////////////////////////////////////////////////////
// retrieves the XMLHttpRequest object

function createXmlHttpRequestObject()
{
	var reqHttp;
	
	if(window.ActiveXObject)
	{
		try
		{
			reqHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			reqHttp = false;
		}
	}
	// if running Mozilla or other browsers
	else
	{
		try
		{
			reqHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			reqHttp = false;
		}
	}
	
	if (!reqHttp)
		alert("Error creating the XMLHttpRequest object.");
	else
		return reqHttp;
}
//////////////////////////////////////////////////////////////////////

function process()
{
	// proceed only if the xmlHttp object isn't busy
	if (searchType=='state')
	{
		xmlHttpState = createXmlHttpRequestObject();
		
		if (xmlHttpState.readyState == 4 || xmlHttpState.readyState == 0)
		{
			xmlHttpState.open("GET",url,true);
			xmlHttpState.onreadystatechange = handleServerResponse;
			xmlHttpState.send(null);
		}
		else
		{
			// if the connection is busy, try again after one second
			t = setTimeout('process()', 1000);
		}
	}
	if (searchType == 'm_state')
	{
		m_xmlHttpState = createXmlHttpRequestObject();
		
		if (m_xmlHttpState.readyState == 4 || m_xmlHttpState.readyState == 0)
		{
			m_xmlHttpState.open("GET",url,true);
			m_xmlHttpState.onreadystatechange = handleServerResponse;
			m_xmlHttpState.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	if (searchType == 'f_state')
	{
		f_xmlHttpState = createXmlHttpRequestObject();
		
		if (f_xmlHttpState.readyState == 4 || f_xmlHttpState.readyState == 0)
		{
			f_xmlHttpState.open("GET",url,true);
			f_xmlHttpState.onreadystatechange = handleServerResponse;
			f_xmlHttpState.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'searchcity')
	{
		xmlHttpCity = createXmlHttpRequestObject();
		if (xmlHttpCity.readyState == 4 || xmlHttpCity.readyState == 0)
		{
			xmlHttpCity.open("GET",url,true);
			xmlHttpCity.onreadystatechange = handleServerResponse;
			xmlHttpCity.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'm_searchcity')
	{
		m_xmlHttpCity = createXmlHttpRequestObject();
		if (m_xmlHttpCity.readyState == 4 || m_xmlHttpCity.readyState == 0)
		{
			m_xmlHttpCity.open("GET",url,true);
			m_xmlHttpCity.onreadystatechange = handleServerResponse;
			m_xmlHttpCity.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'f_searchcity')
	{
		f_xmlHttpCity = createXmlHttpRequestObject();
		if (f_xmlHttpCity.readyState == 4 || f_xmlHttpCity.readyState == 0)
		{
			f_xmlHttpCity.open("GET",url,true);
			f_xmlHttpCity.onreadystatechange = handleServerResponse;
			f_xmlHttpCity.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'confirm')
	{
		xmlHttpConfirm = createXmlHttpRequestObject();
		
		if (xmlHttpConfirm.readyState == 4 || xmlHttpConfirm.readyState == 0)
		{
			xmlHttpConfirm.open("GET",url,true);
			xmlHttpConfirm.onreadystatechange = handleServerResponse;
			xmlHttpConfirm.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'm_confirm')
	{
		m_xmlHttpConfirm = createXmlHttpRequestObject();
		
		if (m_xmlHttpConfirm.readyState == 4 || m_xmlHttpConfirm.readyState == 0)
		{
			m_xmlHttpConfirm.open("GET",url,true);
			m_xmlHttpConfirm.onreadystatechange = handleServerResponse;
			m_xmlHttpConfirm.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
	else if (searchType == 'f_confirm')
	{
		f_xmlHttpConfirm = createXmlHttpRequestObject();
		
		if (f_xmlHttpConfirm.readyState == 4 || f_xmlHttpConfirm.readyState == 0)
		{
			f_xmlHttpConfirm.open("GET",url,true);
			f_xmlHttpConfirm.onreadystatechange = handleServerResponse;
			f_xmlHttpConfirm.send(null);
		}
		else
		{
			t = setTimeout('process()', 1000);
		}
	}
}
// executed automatically when a message is received from the server
function handleServerResponse()
{
	if (searchType == 'state')
	{
		if (xmlHttpState.readyState == 4)
		{
			// status of 200 indicates the transaction completed successfully
			if (xmlHttpState.status == 200)
			{
				_data =  xmlHttpState.responseText;
				document.getElementById("dvstate").innerHTML =_data ;
				document.getElementById("lblstate").style.visibility ='visible' ;
				
				
		 	}
			else	// a HTTP status different than 200 signals an error
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	if (searchType == 'm_state')
	{
		if (m_xmlHttpState.readyState == 4)
		{
			if (m_xmlHttpState.status == 200)
			{
				_data =  m_xmlHttpState.responseText;
				document.getElementById("m_dvstate").innerHTML =_data ;
				document.getElementById("lblstate").style.visibility ='visible' ;
		 	}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	if (searchType == 'f_state')
	{
		if (f_xmlHttpState.readyState == 4)
		{
			if (f_xmlHttpState.status == 200)
			{
				_data =  f_xmlHttpState.responseText;
			
				document.getElementById("f_dvstate").innerHTML =_data ;
				document.getElementById("lblstatef").style.visibility ='visible' ;
		 	}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'searchcity')
	{
		if (xmlHttpCity.readyState == 4)
		{
			if (xmlHttpCity.status == 200)
			{
				_data =  xmlHttpCity.responseText;
				
				if(_data != '')
				{
					document.getElementById("search_suggest").style.visibility = "visible";
					document.getElementById("search_suggest").innerHTML = _data;
					
				}
				else
				{
					document.getElementById("search_suggest").innerHTML = "";
					document.getElementById("search_suggest").style.visibility = "hidden";
				}
		 	}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'm_searchcity')
	{
		if (m_xmlHttpCity.readyState == 4)
		{
			if (m_xmlHttpCity.status == 200)
			{
				_data =  m_xmlHttpCity.responseText;
				
				if(_data != '')
				{
					document.getElementById("m_search_suggest").style.visibility = "visible";
					document.getElementById("m_search_suggest").innerHTML = _data;
				}
				else
				{
					document.getElementById("m_search_suggest").innerHTML = "";
					document.getElementById("m_search_suggest").style.visibility = "hidden";
				}
		 	}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'f_searchcity')
	{
		if (f_xmlHttpCity.readyState == 4)
		{
			if (f_xmlHttpCity.status == 200)
			{
				_data =  f_xmlHttpCity.responseText;
				
				if(_data != '')
				{
					document.getElementById("f_search_suggest").style.visibility = "visible";
					document.getElementById("f_search_suggest").innerHTML = _data;
				}
				else
				{
					document.getElementById("f_search_suggest").innerHTML = "";
					document.getElementById("f_search_suggest").style.visibility = "hidden";
				}
		 	}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'confirm')
	{
		if (xmlHttpConfirm.readyState == 4)
		{
			if (xmlHttpConfirm.status == 200)
			{
				var _data = xmlHttpConfirm.responseText;
				arr = _data.split(",");
				
				document.getElementById("longdeg").value = arr[0];
				document.getElementById("longmin").value = arr[1];
				document.getElementById("longdir").value = arr[2];
				document.getElementById("latdeg").value = arr[3];
				document.getElementById("latmin").value = arr[4];
				document.getElementById("latdir").value = arr[5];
				document.getElementById("timezone").value = arr[6];
			}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'm_confirm')
	{
		if (m_xmlHttpConfirm.readyState == 4)
		{
			if (m_xmlHttpConfirm.status == 200)
			{
				var _data = m_xmlHttpConfirm.responseText;
				arr = _data.split(",");
				
				document.getElementById("m_longdeg").value = arr[0];
				document.getElementById("m_longmin").value = arr[1];
				document.getElementById("m_longdir").value = arr[2];
				document.getElementById("m_latdeg").value = arr[3];
				document.getElementById("m_latmin").value = arr[4];
				document.getElementById("m_latdir").value = arr[5];
				document.getElementById("m_timezone").value = arr[6];
			}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
	else if (searchType == 'f_confirm')
	{
		if (f_xmlHttpConfirm.readyState == 4)
		{
			if (f_xmlHttpConfirm.status == 200)
			{
				var _data = f_xmlHttpConfirm.responseText;
				arr = _data.split(",");
				
				document.getElementById("f_longdeg").value = arr[0];
				document.getElementById("f_longmin").value = arr[1];
				document.getElementById("f_longdir").value = arr[2];
				document.getElementById("f_latdeg").value = arr[3];
				document.getElementById("f_latmin").value = arr[4];
				document.getElementById("f_latdir").value = arr[5];
				document.getElementById("f_timezone").value = arr[6];
			}
			else
			{
				//t = setTimeout('handleServerResponse()', 1000);
				// alert("There was a problem accessing the server: " + xmlHttp.statusText);
			}
		}
	}
}

////////////////////////////////////////////////////

/*
var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject()
{
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++)
	{
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}
*/

 

///////////////////////////////////////////////////////////////////////////

/*
var xmlHttp = createXmlHttpRequestObject();
//global declarations

function statesearch(strparams)
{
   
  alert('hello');
   //url = "state.php?"+strparams;
   url="state.php";
  // process(url, document.getElementById('searchstate')); 
  process(url); 
}

///////////////////////////////////////////////////////////////////////////
// retrieves the XMLHttpRequest object

function createXmlHttpRequestObject()
{
var reqHttp;
if(window.ActiveXObject)
{
	try
	{
		reqHttp = new ActiveXObject("Microsoft.XMLHTTP");
		
	}
	catch (e)
	{
		reqHttp = false;
	}
}
// if running Mozilla or other browsers
else
{
	try
	{
		reqHttp = new XMLHttpRequest();
		
	}
	catch (e)
	{
		reqHttp = false;
	}
}
if (!reqHttp)
	alert("Error creating the XMLHttpRequest object.");
else
	return reqHttp;
}
//////////////////////////////////////////////////////////////////////

function process(url)
{
// proceed only if the xmlHttp object isn't busy
alert('process');
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		alert('process11');
		xmlHttp.open("GET",url,true);
		xmlHttp.onreadystatechange = handleServerResponse();
		xmlHttp.send(null);
	
	}
	else
	{
// if the connection is busy, try again after one second
 		t = setTimeout('process()', 1000);
	}
}
// executed automatically when a message is received from the server
function handleServerResponse()
{
alert('handleServerResponse');	
	if (xmlHttp.readyState == 4)
	{
// status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200)
		{
		
			alert('b4request');
			_data =  xmlHttp.responseText;
		  alert('afterrequest');
		
		  alert(_data);
		  myelementId.innerHTML =_data ;
		}
// a HTTP status different than 200 signals an error
	}
	else
	{
		//t = setTimeout('handleServerResponse()', 1000);
		 alert("There was a problem accessing the server: " + xmlHttp.statusText);
	}
}
*/
////////////////////////////////////////////////////

 
