function CreateHTTPRequest()
{
	var xmlHttp;
	try
	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	return xmlHttp;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
	  { 
	  Char = sText.charAt(i); 
	  if (ValidChars.indexOf(Char) == -1) 
		 {
		 IsNumber = false;
		 }
	  }
   
   return IsNumber;
}

function CheckIDExist(reg_warranty_id)
{
	var xmlHttp = CreateHTTPRequest();
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			var response_str = xmlHttp.responseText;
			
			if(xmlHttp.status == 200)
			{
				document.getElementById("check_id_lock").value = response_str;
				
				if(response_str == "1")
					document.getElementById("warranty_id_result").innerHTML = "Warranty ID Already Exists! Please enter another Warranty ID.";
				else
					document.getElementById("warranty_id_result").innerHTML = "";
			}
			else if(xmlHttp.status == 500)
			{
				alert("Error at Server Side Script.");
				document.write(response_str);
			}
		}
	}
	
	if(IsNumeric(reg_warranty_id))
	{
		document.getElementById("warranty_id_result").innerHTML = "";
		
		var parameters = "reg_warranty_id=" + reg_warranty_id;
	
		xmlHttp.open('POST', 'check_id_exist.php', true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", parameters.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(parameters);
	}
	else
	{
		document.getElementById("warranty_id_result").innerHTML = "Warranty ID must be numeric value.";
	}
}