function createREQ() {
	try {
		 req = new XMLHttpRequest(); /* p.e. Firefox */
		 } catch(err1) {
		   try {
		   req = new ActiveXObject('Msxml2.XMLHTTP'); /* algunas versiones IE */
		   } catch (err2) {
			 try {
			 req = new ActiveXObject("Microsoft.XMLHTTP"); /* algunas versiones IE */
			 } catch (err3) {
			  req = false;
			 }
		   }
		 }
		 return req;
}
function requestGET(url, query, req) {
	myRand=parseInt(Math.random()*99999999);
	req.open("GET",url+'?'+'query'+'&rand='+myRand,true);
	req.send(null);
}
function requestPOST(url, query, req) {
	req.open("POST", url,true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.send(query);
}
function doCallback(callback,item) {
	eval(callback + '(item)');
}

function doAjax(url,query,callback,reqtype,getxml) {
	// crea la instancia del objeto XMLHTTPRequest 
	var myreq = createREQ();
	
	myreq.onreadystatechange = function() {
	if(myreq.readyState == 4) { 
	   if(myreq.status == 200) {
		  var item = myreq.responseText;
		  if(getxml==1) {
			 item = myreq.responseXML;
		  }
		  doCallback(callback, item);
		}
	  }else{
		  parent.document.getElementById("contenido").innerHTML="<img src='images/loading.gif'>";
	  }
	}
	
	if(reqtype=='post') {
	requestPOST(url,query,myreq);
	} else {
	requestGET(url,query,myreq);
	}
}
function doAjax2(capa,url,query,callback,reqtype,getxml) {
	// crea la instancia del objeto XMLHTTPRequest 
	var myreq = createREQ();
	
	myreq.onreadystatechange = function() {
	if(myreq.readyState == 4) {
	   if(myreq.status == 200) {
		  var item = myreq.responseText;
		  if(getxml==1) {
			 item = myreq.responseXML;
		  }
		  doCallback(callback, item);
		}
	  }else{
		  parent.document.getElementById(capa).innerHTML="<img src='images/loading.gif'>";
	  }
	}
	
	if(reqtype=='post') {
	requestPOST(url,query,myreq);
	} else {
	requestGET(url,query,myreq);
	}
}

function doAjax3(url,query,callback,reqtype,getxml) { 
	// crea la instancia del objeto XMLHTTPRequest 
	var myreq = createREQ();
	var item = null; 
	myreq.onreadystatechange = function() {
		if(myreq.readyState == 4) { 
			if(myreq.status == 200) {
				item = myreq.responseText;
				if(getxml==1) {
					item = myreq.responseXML;			
				} 
			doCallback(callback, item);
		   }
		   else if(myreq.status == 404){ 
			   doCallback(callback, "Error interno cod: 1");
		   }
		   else if(myreq.status == 403){
			   doCallback(callback, "Error interno cod: 2");
		   }
		}
	}
	if(reqtype=='post') {
		requestPOST(url,query,myreq);
	} 
	else {
		requestGET(url,query,myreq);
	}
}

function arreglaTexto(texto){
	return unescape(texto.replace(/\+/gi," "));
}
function cargaCapa(html){
	var capa=parent.document.getElementById("contenido");
	capa.innerHTML=arreglaTexto(html);
}
function carga(direccion){
	cargaCapa("<div align=left><img src='images/loading.gif'></div>");	
	doAjax(direccion,'', 'cargaCapa', 'get' , 0);
}

function cargaCapo(html){	
	parent.document.getElementById('contenido').innerHTML= arreglaTexto(html);	
}

function entrar(formu){
	if((formu.idinscrito.value=="")||(formu.pass.value=="")){
		alert("ERROR: Faltan campos obligatorios");
		return false;
	}else{
		var capa=parent.document.getElementById("infouser");
		doAjax2(capa,'scripts/identificacion.scr.php','idinscrito='+formu.idinscrito.value+'&pass='+formu.pass.value+'','acceso','post',0);
	}
}	
function acceso(html){
	parent.document.getElementById('infouser').innerHTML= arreglaTexto(html);
	window.location.reload();
}
function salir(){
	var capa=parent.document.getElementById("infouser");
	doAjax2(capa,'scripts/identificacion.scr.php','','acceso','post',0);
}

function cargaOpAdmin(direccion){ 
	cargaOpAdmin_("<div align=left><img src='images/loading.gif'></div>");	
	doAjax3(direccion,'', 'cargaOpAdmin_', 'get' , 0);
}

function cargaOpAdmin_(html){ 
	parent.document.getElementById('panel2').innerHTML=html;	
}

