//This is the ajax callback function file
var xmlHttp;
var url;
var hres;
function GetXMLHttpObject()
{
	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()
{
	
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		var responseobj=xmlHttp.responseText;
		eval(hres+'('+'responseobj'+')');
	}

}

function sendAjaxRequest(action,querystring,method,responsehandler)
{
     GetXMLHttpObject();
     hres=responsehandler;
     timeStamp = new Date();

          if(xmlHttp!=null)
                  	  {
			        	var url=action;			        				        	
			      		url=url + querystring ;
			      		url = (url.indexOf("?")>0)?(url+"&time='"+timeStamp+"'"):(url+"time='"+timeStamp+"'");
			      		xmlHttp.onreadystatechange=statechanged;
			      		xmlHttp.open(method,url,true);
			      		xmlHttp.send(null);
                  	  }
}

function getProvince(province){

$('#selectProvince').getSetSSValue(ltrim(rtrim(province)));

}
function ltrim(text)
{
	return text.replace(/^\s+/,"");
}
function rtrim(text)
{
	return text.replace(/\s+$/,"");
}
//Populates the province and sector dropdown with appropiate values from the flash.
function getSector(str1,str2){
	if(str2=="All Provinces")
	{
		str2="All";
	}
	if(ltrim(rtrim(str1))=="Total")
	{
		str1="All";
	}
	var sectorName = ltrim(rtrim(str1));
	sectorName =sectorName.replace(/\'/g,'-fff-');
	sectorName =sectorName.replace(/\"/g,'-ddd-');
	
	$('#selectProvince').getSetSSValue(ltrim(rtrim(str2)));
	$('#selectSector').getSetSSValue(sectorName);
	$('#selectStatus').getSetSSValue('All');
	$('#selectGovtLevel').getSetSSValue('All');
}
//This is a custom Replace All function
String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
    var temp = this;
    var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
}
