function ajaxInit()
{
	var AJAX = null;
	try
	{    
		// Firefox, Opera 8.0+, Safari    
		AJAX = new XMLHttpRequest();    
	}
  	catch (e)
    	{    
		// Internet Explorer    
		try
      		{      
			AJAX = new ActiveXObject("Msxml2.XMLHTTP");      
		}
    		catch (e)
      		{      
			try
        		{        
				AJAX = new ActiveXObject("Microsoft.XMLHTTP");        
			}
      			catch (e)
        		{        
				return null;        
			}      
		}    
	}
	return AJAX;
}
function ajaxObject(url, obj, cb) 
{
	var that=this;      
  	this.updating = false;

  	this.update = function(passData,postMethod) 
	{ 
    		if (that.updating==true) 
		{ 
			return false; 
		}
    		that.updating=true;                       
    		var AJAX = ajaxInit();                    
    		if (AJAX == null) 
		{                             
      			return false;                               
    		} 
		else 
		{
      			AJAX.onreadystatechange = function() 
			{  
        			if (AJAX.readyState==4) 
				{             
          				that.updating=false;
					if (that.object != null)
					{
						that.object.innerHTML = AJAX.responseText;
					}                
					else
					{
          					that.callback(AJAX.responseText,AJAX.status,AJAX.responseXML);
					}        
          				delete AJAX;                                         
        			}                                                      
      			}                                                        
      			var timestamp = new Date();                              
      			if (postMethod=='POST') 
			{
        			var uri=urlCall;
        			AJAX.open("POST", uri, true);
        			AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
				AJAX.setRequestHeader("Content-length", passData.length);
				AJAX.setRequestHeader("Connection", "close");
        			AJAX.send(passData);
      			} 
			else 
			{
        			var uri=urlCall+'?'+passData;
        			AJAX.open("GET", uri, true);                             
        			AJAX.send(null);                                         
      			}              
      			return true;                                             
    		}                                                                           
  	}
  	var urlCall = url;
	this.object = obj; 
  	this.callback = cb || function () { };
} 
function ajaxAttachScriptCb(responseText, responseStatus) 
{
	if (responseStatus==200) 
	{
		eval(responseText);
	}
}
function ajaxGetParams(obj) 
{
	var getstr = "";
      	for (i=0; i<obj.childNodes.length; i++) 
	{
        	if (obj.childNodes[i].tagName == "INPUT") 
		{
			if (obj.childNodes[i].type == "hidden") 
			{
               			getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
            		}
            		else if (obj.childNodes[i].type == "text") 
			{
               			getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
            		}
            		else if (obj.childNodes[i].type == "checkbox") 
			{
               			if (obj.childNodes[i].checked) 
				{
                  			getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
               			} 
				else 
				{
                  			getstr += obj.childNodes[i].name + "=&";
               			}
            		}
            		else if (obj.childNodes[i].type == "radio") 
			{
               			if (obj.childNodes[i].checked) 
				{
                  			getstr += obj.childNodes[i].name + "=" + escape(obj.childNodes[i].value) + "&";
               			}
            		}
         	}   
         	else if (obj.childNodes[i].tagName == "SELECT") 
		{
            		var sel = obj.childNodes[i];
            		getstr += sel.name + "=" + escape(sel.options[sel.selectedIndex].value) + "&";
         	}
		else if (obj.childNodes[i].tagName == "TEXTAREA") 
		{
			var area = obj.childNodes[i];
			getstr += area.name + "=" + escape(area.value) + "&";
         	}
      	}
      	return getstr;
}
function ajaxPostMe(url,form,target,cb)
{
	var params = ajaxGetParams(form);
	var f = new ajaxObject(url,target,cb);
	f.update(params,'POST');
}
function ajaxGetMe(url,params,target,cb)
{
	var f = new ajaxObject(url,target,cb);
	f.update(params,'GET');
}

