var xmlHttp
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

//=====================================================================================================
//===================gets the client data in the database, if the client already exists in the database.The criterion: the email address of the client===========================================
var url_client = "include/get_client.php?email="; 
function get_client() 
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var email = document.getElementById("email").value; 
	var part = document.getElementById("part").value; 

	xmlHttp.open("GET", url_client + email + "&part=" + part, true); 
	xmlHttp.onreadystatechange = handleHttpResponse_client; 
	xmlHttp.send(null);
}

function handleHttpResponse_client() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		xmlDoc=xmlHttp.responseXML;
		//alert("val  = "+xmlDoc.getElementsByTagName("fname")[0].childNodes[0].nodeValue);

		document.book.title.value = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
		if(xmlDoc.getElementsByTagName("fname")[0].childNodes[0].nodeValue != 0)
		{
			document.book.existing_client.value = 'yes';
			document.book.fname.value = xmlDoc.getElementsByTagName("fname")[0].childNodes[0].nodeValue;
		}

		if(xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue != 0)
		{
			document.book.lname.value = xmlDoc.getElementsByTagName("lname")[0].childNodes[0].nodeValue;
		}

		if(xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue != 0)
		{
			document.book.city.value = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
		}

		if(xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue != 0)
		{
			document.book.country.value = xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue;
		}

		if(xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue != 0)
		{
			document.book.phone.value = xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue;
		}

		if(xmlDoc.getElementsByTagName("mobile")[0].childNodes[0].nodeValue != 0)
		{
			document.book.mobile.value = xmlDoc.getElementsByTagName("mobile")[0].childNodes[0].nodeValue;
		}

		//alert("val = "+xmlHttp.responseXML.getElementsByTagName("title")[0].childNodes[0].nodeValue);
	} 
	
} 
