function clsAJAX(){
	this.URL="";
	this.objContenedor="";
	this.scriptFinal="";
	this.Parametros="";
	this.newObject=function(){
		var xmlhttp=false;
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	
		if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
			xmlhttp = new XMLHttpRequest();
		}
		return xmlhttp;
	}
	this.GET=function(){
		var newObj= new this.newObject();
		newObj.open("GET", this.URL + this.Parametros,true); 
		var miURL=this.URL;
		var objCont=document.getElementById(this.objContenedor);
		var miScript=this.scriptFinal;
		newObj.onreadystatechange=function(){
			if(newObj.readyState==1){
				objCont.innerHTML = msgLoad();
			}else if(newObj.readyState==4){
				if(newObj.status==200){
					objCont.innerHTML = newObj.responseText;
					eval(miScript);
				}else if(newObj.status==404){
					objCont.innerHTML = "Page not Found";
				}else{
					objCont.innerHTML = "<b>Error...:</b> Error # " + newObj.status;
					alert("Error al procesar la solicitud: Error # " + newObj.status);
				}
			}
		}
		newObj.send(null);
	}
	function msgLoad(){
		return "<div id='cLoadingIndicator'><img src='../images/load.gif' style='vertical-align:bottom'/><span style='padding-left:5px;'>Processing...</span></div>";
	}


	this.POST=function(){
		var newObj= new this.newObject();
		newObj.open("POST", this.URL,true); 

		var miURL=this.URL;
		var objCont=document.getElementById(this.objContenedor);
		var miScript=this.scriptFinal;
		var misParametros=this.Parametros;
		
		newObj.onreadystatechange=function(){
			if(newObj.readyState==1){
				objCont.innerHTML = msgLoad();
			}else if(newObj.readyState==4){
				if(newObj.status==200){
					objCont.innerHTML = newObj.responseText;
					eval(miScript);
				}else if(newObj.status==404){
					objCont.innerHTML = "Page not Found...";
				}else{
					objCont.innerHTML = "<b>Error...:</b> Error # "+newObj.status; 
				}
			}
		}
		newObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		newObj.setRequestHeader("Content-length", this.Parametros.Length);
		newObj.setRequestHeader("Connection", "close");
		newObj.send(this.Parametros);
	}
}
function encodeNameAndValue(sName, sValue) {
	var sParam = encodeURIComponent(sName);
	sParam += "=";
	sParam += encodeURIComponent(sValue);
	return sParam;
}
function getRequestBody(oForm) {
	var aParams = new Array();
	for (var i=0 ; i < oForm.elements.length; i++) {
		var oField = oForm.elements[i];
		
		switch (oField.type) {
			case "button":
			case "submit":
			case "reset":
				break;
			case "checkbox":
			case "radio":
				if (!oField.checked) break;
			case "text":
			case "hidden":
			case "password":
				aParams.push(encodeNameAndValue(oField.name, oField.value));
				break;
			default:
				switch(oField.tagName.toLowerCase()) {
					case "select":
						aParams.push(encodeNameAndValue(oField.name,oField.options[oField.selectedIndex].value));
						break;
					default:
						aParams.push(encodeNameAndValue(oField.name,oField.value));
				}
		}
	}
	return aParams.join("&");
}

