function ajaxManager(){
	var args = ajaxManager.arguments;
	switch (args[0]){
		case "load_page":	
			if (document.getElementById){
				var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			}
			if (x){
				
				x.onreadystatechange = function(){
					if (x.readyState == 4){
						el = document.getElementById(args[2]);
						el.innerHTML = x.responseText;	
						if(args[3]){
							eval(args[3]);	
						}
					}
				}				
				var el;
				el= document.getElementById(args[2]);
				el.innerHTML = "<table witdh=\"100%\" align=\"center\"><tr><td align=\"center\"><img src=\"images/loading.gif\"/></td></tr></table>";
				
				x.open("GET", args[1], true);
				x.send(null);
			}
			break;
			case "load_command":	
			if (document.getElementById){
				var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
			}
			if (x){
				
				x.onreadystatechange = function(){
					if (x.readyState == 4){
						if(args[3]){
							eval(args[3]);	
						}
					}
				}				
				var el;
				
				x.open("GET", args[1], true);
				x.send(null);
			}
			break;
		case "start_main":
//			ajaxManager('load_page', 'header.html', 'masthead');
			break;
		
	}
}


function cargarFormulario(form, commandName,outputDiv){
	var formulario=document.getElementById(form);
	stringParams="";
	for(x=0;x<formulario.elements.length;x++){
		if(formulario.elements[x].name==''){
			continue;
		}
		tipoInput=formulario.elements[x].type;
		if(tipoInput=="radio"||tipoInput=="checkbox"){
			if(!(formulario.elements[x].checked)){
				continue;
			}
		}
		if(x>0){
		stringParams+="&";
		}
		stringParams+=formulario.elements[x].name+"="+formulario.elements[x].value;
	}
	if(stringParams!=""){
		stringParams="&"+stringParams;
	}

	//alert(stringParams);
	if(outputDiv==""){
		window.location='?do='+commandName+stringParams;
	}
	else{
		ajaxManager('load_page','?do='+commandName+stringParams,outputDiv);
	}
	return false;
}



function loadPage(url,params,idDiv,showLoading,showLoaded,personalFunction){
	var httpRequest = false;
	if(window.XMLHttpRequest){
		// Si es Mozilla, Safari etc
		httpRequest= new XMLHttpRequest();
	}else if(window.ActiveXObject){
		// pero si es IE
		try{
			httpRequest = new ActiveXObject ("Msxml2.XMLHTTP");
		}catch (e){
			// en caso que sea una versión antigua
			try{
				httpRequest = new ActiveXObject ("Microsoft.XMLHTTP");
			}catch (e){
			}
		}
	}else{
		return false;
	}
	httpRequest.onreadystatechange = function(){
		contenedor=document.getElementById(idDiv);
		if(httpRequest.readyState==1 && showLoading){
			altura=contenedor.offsetHeight;
			contenedor.innerHTML=showLoading;
			try{
				contenedor.style.removeProperty('height');
				contenedor.style.height=altura;
			}catch(e){
			}
		}else if(httpRequest.readyState==4){
			try{
				contenedor.style.removeProperty('height');
			}catch(e){
			}
			txt=httpRequest.responseText;
			if(showLoaded){
				contenedor.innerHTML=txt;
				mostrarDiv(contenedor);
			}
			if(txt.indexOf("<script")!=-1 ||txt.indexOf("<SCRIPT")!=-1){
				//truco para que iexplore interprete los scripts incluidos
				var objNodeDiv=document.createElement("div");
				objNodeDiv.innerHTML="<div style=\"display: none\">&nbsp;</div>\n"+txt;
				executeJavascript(objNodeDiv);
			}
			if(personalFunction){
				personalFunction.call();
			}
		}
	}
	httpRequest.open ('POST', url, true);		
	httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	httpRequest.send(params);
}
function executeJavascript(divElement){
	arrayScript=divElement.getElementsByTagName("script");
	jsCode="";
	for(x=0;x<arrayScript.length;x++){
		jsCode+=arrayScript[x].innerHTML+"\n";
	}
	eval(jsCode);
}
function submitForm(formulario, commandName,outputDiv){
	stringParams="";
	for(x=0;x<formulario.elements.length;x++){
		if(formulario.elements[x].name==''){
			continue;
		}
		tipoInput=formulario.elements[x].type;
		if(tipoInput=="radio"||tipoInput=="checkbox"){
			if(!(formulario.elements[x].checked)){
				continue;
			}
		}
		if(x>0){
		stringParams+="&";
		}
		stringParams+=formulario.elements[x].name+"="+formulario.elements[x].value;
	}
	//por defecto el resultado del formulario reemplaza a este (si no se especifica outputDiv)
	idContenedor=formulario.parentNode.id;
	if(outputDiv){
		idContenedor=outputDiv;
	}
	loadPage('index.php?do='+commandName,stringParams,idContenedor,'Enviando información...',false);
	return false;
}
function ocultarDiv(divName){
	if(typeof(divName)!='object'){
		divName=document.getElementById(divName);
	}
	divName.style.display="none";
}
function mostrarDiv(divName,inline){
	if(typeof(divName)!='object'){
		divName=document.getElementById(divName);
	}
	if(inline){
		divName.style.display="inline";
	}else{
		divName.style.display="block";
	}
}
function toggleDiv(divName){
	if(typeof(divName)!='object'){
		divName=document.getElementById(divName);
	}
	if(divName.style.display=="none"){
		mostrarDiv(divName);
	}else{
		ocultarDiv(divName);
	}
}
/*metodo util para conocer propiedades y metodos de objetos*/
function getProp(obj,div){
	var txt="<pre>[["+obj+"]]\n\n";
	for(x in obj){
		try{
			txt+= x+"="+eval("obj."+x)+"\n";
		}catch(e){
			txt+= x+".()\n";//+eval("obj."+x)
		}
	}
	txt+="_______________________________________</pre>";
	document.getElementById(div).innerHTML=txt;
}
