function ajaxRequest() {
	var xmlHttp;
	try {
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
		if(xmlHttp.overrideMimeType)
			xmlHttp.overrideMimeType('text/html');
	}catch(err) {
		//IE
		try {
			xmlHttp = new ActiveXObject("Msxml13.XMLHTTP");
		}catch(err) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(err) {
				alert("Your browser does not support AJAX requests!");
				return false;
			}
		}
	}
	return xmlHttp;
}

function noCache() {
	var tm = new Date();
	return "&t="+tm.getTime();
}

function ajaxPoster(elem,formToPost,callBackFunction) {
	var xmlHttp = ajaxRequest();
	xmlHttp.onreadystatechange=function() {	
		if(xmlHttp.readyState==2) {		
			
		}
		if(xmlHttp.readyState==4) {					
			if(callBackFunction)
			{
				if(!xmlHttp.responseText.match('fail'))
				{					
					callBackFunction(xmlHttp.responseText);					
				}
				else
				{
					alert('fail');
				}				
			}
			else
			{
				if(targ=document.getElementById(elem)) {					
					targ.innerHTML = xmlHttp.responseText;
				}
			}
		}
	}

	var parameters = serializeForm(formToPost);

	xmlHttp.open("POST",formToPost.action,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection","close");
	xmlHttp.send(parameters);
}

function serializeForm(elem) {
	var postStr = "";	
	var first = true;
	for(var i=0;i<elem.length;i++) {		
		if(!elem[i].type.match("button")) {
			if(!first)
			{
				postStr += ("&" + elem[i].name + "=" + encodeURIComponent(elem[i].value));
			}
			else 
			{
				postStr += (elem[i].name + "=" + encodeURIComponent(elem[i].value));
				first = false;
			}
		}		
	}
	return postStr;
}

function ajaxTouch(url,callBackFunction) 
{	
	var xmlHttp = ajaxRequest();
	if(xmlHttp) 
	{
		xmlHttp.onreadystatechange=function() 
		{			
			if(xmlHttp.readyState==4) 
			{						
				if(callBackFunction)
				{
					callBackFunction();		
				}
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else 
	{
		return false;
	}
}

function ajaxSubmitRequest(url,callBackFunction) 
{	
	var xmlHttp = ajaxRequest();
	if(xmlHttp) 
	{
		xmlHttp.onreadystatechange=function() 
		{
			if(xmlHttp.readyState==2) 
			{
				//waiting for response code can be insert here
			}
			if(xmlHttp.readyState==4) 
			{						
				if(callBackFunction)
				{						
					callBackFunction(xmlHttp.responseText);
				}						
			}
		}
	
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else 
	{
		return false;
	}
}

