
function Get(thepage,target){
	
	var CRequest = new XRequest(APPPATH, "func=get&theitem=" + thepage, target);
	if(CRequest)
		CRequest.sendRequest();
}

function Save(APPPATH, item, path){
//			'edit.php','rates','index'
	var t = document.getElementById(item);
	updateTextArea(item);
	var thesource = t.value;
	var CRequest = new XRequest(APPPATH, "func=save&theitem=" + thesource + "&thepath=" + path + "&thesection=" + item, '');
	if(CRequest)
		CRequest.sendRequest();
}

function Login(thepath){
	window.location.href=thepath;
}

function XRequest(theurl, theparams, thetarget){
	
	var url = theurl;
	var req = null;
	var params = theparams;
	var target = thetarget;
	
	this.onReadyStateChange = function(){
		//alert('State Change - req: ' + this.req.readyState);
		//alert('State Change - req: ' + req.readyState);
		if(req.readyState == 4){
			if(req.status == 200){
				try{
					//var response = decodeURIComponent(req.responseText);
					var response = req.responseText;
					//var ans = response.split("=");
					
					//target = document.getElementById('actionnotice');
					//target.innerHTML = response;
					
					//setTimeout("clearActionnotice()", 5500);
					
				}
					catch(e){
						alert("Error:\n" + e.toString());
				}
			}
		}
	}
	
	
	this.sendRequest = function(){
		req = this.getHttpRequestObject();
		if(!req){
			alert("Cannot instantiate request object!");
			return false;
		}
		//alert('SendRequest Values - URL: ' + this.url + ';  PARAMS: ' + this.params + ';  TARGET: ' + this.target);
		req.onreadystatechange = this.onReadyStateChange;	
		
		req.open("POST",url,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send(params);
		return true;
	}
		
	this.getHttpRequestObject = function(){
		var txhp;
		try
		{
			txhp = new XMLHttpRequest();
		}
		catch(e)
		{
			try
			{
				txhp = new ActiveXObject("Microsoft.XMLHttp");
			}
			catch(e2)
			{
				try
				{
					txhp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e3)
				{
					return false;
				}
			}
		}
		return txhp;
	}
	
	//return xhp;
}
