var container;
var timeout;
var display_field;

function sendAjaxRequest(str, div, delay, field) {

	container = div;
	timeout = delay
	display_field = field;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
  		alert ("Your browser does not support AJAX!");
  		return;
  	} 
	var url="ajax.php";
	url=url+"?"+str;
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


function GetXmlHttpObject() {
	var xmlHttp=null;
	try	{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
	  	try {
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
	    	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	}
	  
	return xmlHttp;
}

function stateChanged() { 
	showLoader(container);
	setTimeout("stateChangedResult();", timeout);
	
}

function stateChangedResult() 
{ 

	if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading") {
		showLoader(container);
	} else if (xmlHttp.readyState == 4) { 
		
		if (display_field == 'gallery') {
			document.getElementById(container).innerHTML = xmlHttp.responseText;
		} else {			
			document.getElementById(container).innerHTML = xmlHttp.responseText;
		}
	}	
}



function showLoader(divid) { 

	if (display_field == 'gallery') {
		document.getElementById(divid).innerHTML = "<div style='width:100%;padding-top:180px;' align='center'><img src='htdocs/images/index/ajax-loader.gif' width='32' height='32' /></div>";	
	} else {
		document.getElementById(divid).innerHTML = "<div style='width:100%;padding-top:180px;' align='center'><img src='htdocs/images/index/ajax-loader.gif' width='32' height='32' /></div>";	
	}
}