var xmlHttp;
var working="<img src='images/working.gif' align='center'>";

function GetXmlHttpObject()
{
	var obj=null;
	try
	{
		 // Firefox, Opera 8.0+, Safari
		 obj=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			obj=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			obj=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return obj;
}

function executerequest(url,param)
{ 
	//alert(param);
	document.getElementById("ajax").innerHTML=working;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}

function stateChanged()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//alert(xmlHttp.status);
		if(xmlHttp.status==200)
		{
			//alert(xmlHttp.responseText);
			document.getElementById("ajax").innerHTML=xmlHttp.responseText;
		}
		else
		{
			document.getElementById("ajax").innerHTML="Response Satus = " +xmlHttp.status;
		}
	} 
}

function executerequestsearch(url,param)
{ 
	document.getElementById("search").innerHTML=working;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedsearch;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", param.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(param);
}

function stateChangedsearch()
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//alert(xmlHttp.status);
		if(xmlHttp.status==200)
		{
			//alert(xmlHttp.responseText);
			document.getElementById("search").innerHTML=xmlHttp.responseText;
		}
	} 
}

//$$$$$$$$$$$$$$$$$$$$$ TRINING FUNCTION $$$$$$$$$$$$$$$$$$$$$$$$$

function LTrim( value )
{	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value ) 
{	
	return LTrim(RTrim(value));	
}