// JavaScript Document
/**
*	Script for manipulate xmlhttp request (AJAX)
*
*	Create by NZK
*/
function AjaxNzk()
{
	this.assincr = true;
	this.method = "GET";
	this.val = "";
	this.tp = "HTML";
	this.xmlhttp = null;
	
	
	/**
	*
	* Inicia o objeto http request
	* 
	**/
	
	try
	{
		this.xmlhttp =  new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e)
	{
		try{
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex)
		{
			try{
				this.xmlhttp = new XMLHttpRequest();
			}
			catch(exc)
			{
				alert("Esse browser não tem recursos para uso do Ajax");
				this.xmlhttp = null;
			}
		}
	}
	
	/**
	* loadResult
	*
	* Carrega o conteúdo em um elemento HTML
	*
	**/		
	this.loadResult = function(url, target, param)
	{
		if(this.xmlhttp) 
		{
			var ajax = this.xmlhttp;
			//
			this.xmlhttp.open(this.method, url , this.assincr);
			//
			if(this.method == 'POST')
			{				
				this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				this.xmlhttp.setRequestHeader("Content-length", param.length);
				this.xmlhttp.setRequestHeader("Connection", "close");
			}
			
			if(this.method == 'GET')
			{
				this.xmlhttp.send(null);	
			}
			else
			{
				this.xmlhttp.send(param);
			}
			
			//
			if(this.assincr)
			{
				this.xmlhttp.onreadystatechange = function()
				{
					if(ajax.readyState == 4)
					{
						if(ajax.status == 200)
						{
							target.innerHTML = ajax.responseText;
						}						
					}
				}
				
			}
			else
			{
				target.innerHTML = ajax.responseText;
			}
			
		}

	}
	
	this.loadEval = function(url, fct, param)
	{
		if(this.xmlhttp) 
		{
			var ajax = this.xmlhttp;
			//
			this.xmlhttp.open(this.method, url , this.assincr);
			//
			if(this.method == 'POST')
			{				
				this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				this.xmlhttp.setRequestHeader("Content-length", param.length);
				this.xmlhttp.setRequestHeader("Connection", "close");
			}
			//
			
			if(this.method == 'GET')
			{
				this.xmlhttp.send(null);	
			}
			else
			{
				this.xmlhttp.send(param);
			}
			
			//
			
			var tp = this.tp;
			if(this.assincr)
			{
				this.xmlhttp.onreadystatechange = function()
				{
					if(ajax.readyState == 4)
					{
						if(ajax.status == 200)
						{
							try
							{
								if(tp == "HTML")
								{									
									eval(fct+'(\"'+ajax.responseText+'\");');
								}
								else
								{									
									eval(fct)(ajax.responseXML);
								}
							}
							catch(e)
							{
								alert(e);	
							}
						}						
					}
				}
				
			}
			else
			{
				eval(fct+'(\"'+ajax.responseText+'\")');
			}
			
		}

	}
}