﻿var AJAX_INIT = 0;
var AJAX_OPEN = 1;
var AJAX_SENT = 2;
var AJAX_RECEIVING = 3;
var AJAX_LOADED = 4;

function getXmlHttp()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();    
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp = null;
				//alert("Errors occurred while processing your request. Please try again.");        
			}
		}
    }
    return xmlHttp;
 }
 
 var xmlHttp = getXmlHttp();
 
 function sendAjaxRequest(sUrl, sMethod, sSendStr, bAsync, callbackfunc)
 {	
 
	if (xmlHttp == null) {
		alert("Your request could not be processed. Please reload the page and try again.");
	}
	
	var AjaxUrl = String(sUrl);
	
	if (AjaxUrl.indexOf('?')>0) 
		AjaxUrl = sUrl + '&sid=' +Math.random();
	else
		AjaxUrl = sUrl + '?sid=' +Math.random();
  
	xmlHttp.onreadystatechange = callbackfunc; 
	try {
		xmlHttp.open(sMethod, AjaxUrl, bAsync);
		xmlHttp.send(sSendStr);  
	}
	catch(e) {
		//something went wrong!
		alert("Errors occurred while sending your request. Please try again.");        
	}  
}

//this function can be used as a basis for actual handleAjaxResponse() function
function sampleHandleResponse(){	
	if (xmlHttp.readyState == AJAX_LOADED) {	
		//request is complete
		var response = xmlHttp.responseText;  
	}  	  
}
