// post a request
function xmlhttpPost(strURL,target,callback){
	
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage(self.xmlHttpReq.responseText,target,callback);
		}
	}
	self.xmlHttpReq.send(getquerystring());
}
function getquerystring(){
	qstr = 'w=' + escape('test');  // NOTE: no '?' before querystring
	return qstr;
}

function updatepage(str,target,callback){
	//str = trim(str);
	if(str != '' && target != ''){
		document.getElementById(target).innerHTML = str;
	}
	
	// call a callback function if it exists
	if(callback != ''){
		eval(callback);
	}
	/*
	if(window.ajax_callback){
		ajax_callback();
	}
	*/
}

// perform the request
function ajax_request(url,target,message){
	// reveal a message if one exists
	if(message != ''){
		document.getElementById(target).innerHTML = message;		
	}
	
	// post the request
	xmlhttpPost(url,target);
}

/* --------------------- */

// post a request
function xmlhttpPost_field(strURL,target,callback){
	
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage_field(self.xmlHttpReq.responseText,target,callback);
		}
	}
	self.xmlHttpReq.send(getquerystring());
}

function updatepage_field(str,target,callback){
	//str = trim(str);
	if(str != '' && target != ''){
		document.getElementById(target).value = str;
	}
	
	// call a callback function if it exists
	if(callback != ''){
		eval(callback);
	}
	/*
	if(window.ajax_callback){
		ajax_callback();
	}
	*/
}
