﻿// JScript File


//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}


function PostData(requestUrl,strFilter)
{
  
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange =HandleResponse;
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("Post", requestUrl,  true);	
		XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        XmlHttp.setRequestHeader("Content-length", strFilter.length);
        XmlHttp.setRequestHeader("Connection", "close");	
		//Sends the request to server
		//alert(strFilter);
		XmlHttp.send(strFilter);		
	}
	else 
	 alert("This browser does not support. Try in some other browser."); 
	
}

//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
		    if (XmlHttp.responseText=="Success")
		    {
		        document.frmContact.Name.value ="";document.frmContact.txtCompany.value="";
		        document.frmContact.txtEmail.value="";document.frmContact.txtTelephone.value="";
		    }
			alert(XmlHttp.responseText);
		}
		else
		{
			alert("Problem with retrieving data from server." );
		}
	}
}


