/*
		this function sends an ajax request to a specified url 
		
		strUrl: relative or abosulute page url
		query_string: posted parameters to url (formatted as get parameters)
		obj_id: container_id to display the result output (if empty then displays nothing)
		oncomplete: javascript instruction or function to be executed when Ajax request finishes
		is_input: specifies if obj_id is textbox or div in order to use obj.value or obj.innerHTML  
*/


function Ajax(strURL, query_string, obj_id, on_complete, is_input) 
{
    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) 
        {
             response = self.xmlHttpReq.responseText;
             
             if (obj_id != '')
             {
             	obj = document.getElementById(obj_id);
				 	
				 	if (is_input) 
				 		obj.value = response;
				 	else
				 		obj.innerHTML = response;
				 }
				 
				 eval(on_complete);	             
        }
    };
    self.xmlHttpReq.send(query_string);
}



/*
	this function sends an ajax request to a specified url 
	it is a more apropriate implementation if Ajax() function
	
	strUrl: relative or abosulute page url
	query_string: posted parameters to url (formatted as get parameters)
	oncomplete: javascript function to be executed when Ajax request finishes
*/


	function AjaxRequest(strURL, query_string, onComplete) 
	{
		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) 
			{
				response = self.xmlHttpReq.responseText;
			    
				if (typeof(onComplete) == 'function')
					onComplete(response);             
			}
		};
		
		self.xmlHttpReq.send(query_string);
		
		return self.xmlHttpReq;
	}


