// JavaScript Document
function AJAX(url,metodo,params,processa,modo) {
	this.url = url;
	this.metodo = (metodo) ? metodo : 'GET';
	this.params = (metodo = 'GET') ? null : params;
	this.processaresultado = processa;
	this.Header = new Array();
	this.modo = (modo) ? modo : 'T';
	if(this.modo!='T'&&this.modo!='X') {
		this.modo = 'T';
	}
	this.conectar();
}
AJAX.prototype = {
	addHeader:	function(h,v) {
					this.Header[h] = v;
				},
	delHeader:	function(h) {
					delete(this.Header[h]);
				},
	setHeader:	function() {
					if(this.httprequest==null) { return;}
					for(h in this.Header) {
						this.httprequest.setRequestHeader(h,this.Header[h]);
					}
				},
	conectar:			function() {

							if(this.url==undefined||this.url=='') {
								return;
							}
							this.httprequest = null;
						   	if (window.XMLHttpRequest) { // Mozilla, Safari,...
					         	this.httprequest = new XMLHttpRequest();
				        	} else if (window.ActiveXObject) { // IE
					         	try {
							     	 this.httprequest = new ActiveXObject("Msxml2.XMLHTTP");
				    	     	} catch (e) {
				               		try {
		        		           	 this.httprequest = new ActiveXObject("Microsoft.XMLHTTP");
									} catch (e) {}
								}
							}
							if(this.httprequest!=null&&this.httprequest!=undefined) {
								var obj = this;
								this.httprequest.onreadystatechange = 	function() {
																			obj.processaretorno.call(obj);
																		}
								if(this.metodo==undefined||this.metodo=='') { this.metodo = 'GET';}
                                this.httprequest.open(this.metodo,this.url, true);
								//this.setHeader();
								this.httprequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						        this.httprequest.send(this.params);
							}
						},
	processaretorno:	function() {
							if(this.httprequest.readyState==4) {
								if(this.httprequest.status==200) {
									var resp = (this.modo=='T') ?
												this.httprequest.responseText :
												this.httprequest.responseXML;
									if(this.processaresultado!=null) {
										this.processaresultado(resp);
									} else {
										document.write(resp);
									}
								} else {
									this.processaerro();
								}
							}
						},
	processaerro:		function() {
							alert(this.httprequest.status + '-' + this.httprequest.statusText + ' :-> ' + this.url);
						}
}
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
function ajax_padrao(obj,div)
{
	obj.processaresultado = function(r){
        document.getElementById(div).innerHTML =  r;
    }
}
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
function atualizarDiv(div,strPost,pag,func){

    atualizarDiv(div,strPost,pag,func,"");
}
function atualizarDiv(div,strPost,pag,func,parametros){

    //--------------------------------
	var objajax = new AJAX;
	objajax.url    = pag;
	objajax.metodo = 'POST';
	objajax.params = strPost;
	
    //fazer arguments
	if(!parametros){
		eval(func + "(objajax,'" + div + "')");
	}else if(parametros != "undefined"){
		eval(func + "(objajax,'" + div + "'," + parametros + ")");
	}
	objajax.conectar();
	//--------------------------------
}

//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=

// url_encode version 1.0 
 function url_encode(str) { 
	  var hex_chars = "0123456789ABCDEF"; 
	  var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	  var n, strCode, hex1, hex2, strEncode = ""; 

	  for(n = 0; n < str.length; n++) { 
			if (noEncode.test(str.charAt(n))) { 
				 strEncode += str.charAt(n); 
			} else { 
				 strCode = str.charCodeAt(n); 
				 hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
				 hex2 = hex_chars.charAt(strCode % 16); 
				 strEncode += "%" + (hex1 + hex2); 
			} 
	  } 
	  return strEncode; 
 } 
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
 // url_decode version 1.0 
 function url_decode(str) { 
	  var n, strCode, strDecode = ""; 

	  for (n = 0; n < str.length; n++) { 
			if (str.charAt(n) == "%") { 
				 strCode = str.charAt(n + 1) + str.charAt(n + 2); 
				 strDecode += String.fromCharCode(parseInt(strCode, 16)); 
				 n += 2; 
			} else { 
				 strDecode += str.charAt(n); 
			} 
	  } 

	  return strDecode; 
 } 
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=

//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=
