// Begin Script
// XMLHTTPRequest Library
//
// Author :	Jayme Jeffman Filho
// Created :	Feb, 01 2006
// Updated :  Feb, 01 2006
// Comment : Contains XMLHTTPRequest object API
//----------------------------------------------------------------------
function setMethod(mtd)
{
	if(mtd == "") mtd = 'POST';
	this.method = mtd;
}
//----------------------------------------------------------------------
function setURL(url)
{
	this.url = url;
}
//----------------------------------------------------------------------
function setCharset( cSet )
{
	this.charset = cSet;
}
//----------------------------------------------------------------------
function setQueryString(text)
{
	this.qString = text ;
}
//----------------------------------------------------------------------
function setReadyHandle(fnc)
{
	if(fnc != "") this.httpreq.onreadystatechange = fnc ;
	else this.httpreq.onreadystatechange = defaultHandle ;
}
//----------------------------------------------------------------------
function setHeader(text)
{
	this.header = text;
}
//----------------------------------------------------------------------
function setHeaderType(text)
{
	this.headerType = text;
}
//----------------------------------------------------------------------
function send()
{
	var header = this.header;
	
	if(this.charset != "") header += (';charset=' + this.charset) ;
	try{ this.httpreq.open(this.method, this.url, true);} 
	catch(e){
		alert("Open Error\n"+"Method: "+this.method+"\nURL: "+this.url+"\n"+e); 
		return;
	}
  try{this.httpreq.setRequestHeader(this.headerType, header);} 
  catch(e){
  	alert("Header Error\n"+"Method: "+this.method+"\nURL: "+this.url+"\n"+e); 
  	return;
  }
  try{this.httpreq.send(this.qString ); } 
  catch(e){
  	alert("Send Error\n"+"Method: "+this.method+"\nURL: "+this.url+"\n"+e); 
  	return;
  }
}
//----------------------------------------------------------------------
function JJHttpRequest()
{
	var xmlHttp = null;
	if(window.ActiveXObject){	
		try{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e){
			try{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){}
		}
	}
	else if(window.XMLHttpRequest) {
			try{ xmlHttp = new XMLHttpRequest();}
			catch(e){}
	}
	else if(window.createRequest){
			try{ xmlHttp = window.createRequest();}
			catch(e){}
	}
	// properties
	this.header											= 'application/x-www-form-urlencoded';
	this.headerType									= 'Content-Type';
	this.method 										= 'POST';
	this.url 												= "";
	this.charset 										= 'iso-8859-1';
	this.qString 										= "" ;
	// methods
	this.setHeaderType							= setHeaderType;
	this.setHeader    							= setHeader;
	this.setURL 										= setURL;
	this.setCharset 								= setCharset ;
	this.setMethod 									= setMethod;
	this.setQueryString 						= setQueryString;
 	this.setReadyHandle 						= setReadyHandle;
	this.httpreq 										= xmlHttp ;
	this.send 											= send;
	return this ;
}
//----------------------------------------------------------------------
function fnGetUrl(url, fn)
{
	// The url passed should have the "query string" in it
  xmlhttp = new JJHttpRequest();
	if (xmlhttp) 
	{
		xmlhttp.setMethod("GET");
		xmlhttp.setURL(url);
   	xmlhttp.setReadyHandle(fn);
   	xmlhttp.send();
  } 
  else { alert( "XMLHTTPRequest was not created !");}
}
//----------------------------------------------------------------------
function fnPostUrl(url,txt,fn,type,enc)
{
  var xmlhttp = new JJHttpRequest(); // the default method is "POST"
	if (xmlhttp) 
	{
		xmlhttp.setURL(url);
		xmlhttp.setQueryString(txt);
   	xmlhttp.setReadyHandle(fn);
   	if (enc)
   	{ 
   		xmlhttp.setHeaderType(enc);
   		xmlhttp.setHeader(enc);
   	}
   	else if(type)
   		xmlhttp.setHeader(type);
   	xmlhttp.send();
  } 
  else { alert( "XMLHTTPRequest was not created !");}
}
//----------------------------------------------------------------------
/*
<?PHP
//
 // * HTTP Protocol defined status codes
 // * @param int $num
 // 
function HTTPStatus($num) {
  
   static $http = array (
       100 => "HTTP/1.1 100 Continue",
       101 => "HTTP/1.1 101 Switching Protocols",
       200 => "HTTP/1.1 200 OK",
       201 => "HTTP/1.1 201 Created",
       202 => "HTTP/1.1 202 Accepted",
       203 => "HTTP/1.1 203 Non-Authoritative Information",
       204 => "HTTP/1.1 204 No Content",
       205 => "HTTP/1.1 205 Reset Content",
       206 => "HTTP/1.1 206 Partial Content",
       300 => "HTTP/1.1 300 Multiple Choices",
       301 => "HTTP/1.1 301 Moved Permanently",
       302 => "HTTP/1.1 302 Found",
       303 => "HTTP/1.1 303 See Other",
       304 => "HTTP/1.1 304 Not Modified",
       305 => "HTTP/1.1 305 Use Proxy",
       307 => "HTTP/1.1 307 Temporary Redirect",
       400 => "HTTP/1.1 400 Bad Request",
       401 => "HTTP/1.1 401 Unauthorized",
       402 => "HTTP/1.1 402 Payment Required",
       403 => "HTTP/1.1 403 Forbidden",
       404 => "HTTP/1.1 404 Not Found",
       405 => "HTTP/1.1 405 Method Not Allowed",
       406 => "HTTP/1.1 406 Not Acceptable",
       407 => "HTTP/1.1 407 Proxy Authentication Required",
       408 => "HTTP/1.1 408 Request Time-out",
       409 => "HTTP/1.1 409 Conflict",
       410 => "HTTP/1.1 410 Gone",
       411 => "HTTP/1.1 411 Length Required",
       412 => "HTTP/1.1 412 Precondition Failed",
       413 => "HTTP/1.1 413 Request Entity Too Large",
       414 => "HTTP/1.1 414 Request-URI Too Large",
       415 => "HTTP/1.1 415 Unsupported Media Type",
       416 => "HTTP/1.1 416 Requested range not satisfiable",
       417 => "HTTP/1.1 417 Expectation Failed",
       500 => "HTTP/1.1 500 Internal Server Error",
       501 => "HTTP/1.1 501 Not Implemented",
       502 => "HTTP/1.1 502 Bad Gateway",
       503 => "HTTP/1.1 503 Service Unavailable",
       504 => "HTTP/1.1 504 Gateway Time-out"       
   );
  
   header($http[$num]);
}
?>
*/
//End Script 