/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

//otras funciones

//funcion que hace el include para las paginas internas administrativas

function admin(url, divin){
	var myConn = new XHConn();
 
 //si no existe da error
 if (!myConn) alert("XMLHTTP Su explorador es muy antigua, por favor use Internet Explorer 6.0 o Firefox 1.5");
 
 //funcion que se llama luego del include
 var include_terminado = function (oXML) { document.getElementById(divin).innerHTML = oXML.responseText; };
include_dinamico2(url);

 function include_dinamico2 (url)
 {
	  //que hace mientras esta corriendo el script, pone una imagen de loading
  document.getElementById(divin).innerHTML = "<center><br><img src=\"imgs/wait.gif\"><br>Cargando...<br></center>";

  //AJAX, llamo a la pagina y le mando los parametros
  myConn.connect("include.php", "GET", "variable="+url, include_terminado);
 }
}









//funcion que hace el include para la pagina principal
function mainpage(url, divmain){
	//inicializamos la libreria
 var myConn = new XHConn();
 
 //si no existe da error
 if (!myConn) alert("XMLHTTP Su explorador es muy antigua, por favor use Internet Explorer 6.0 o Firefox 1.5");
 
 //funcion que se llama luego del include
 var include_terminado = function (oXML) { document.getElementById(divmain).innerHTML = oXML.responseText; };
include_dinamico(url, divmain);

 function include_dinamico (url)
 {
	  //que hace mientras esta corriendo el script, pone una imagen de loading
  document.getElementById(divmain).innerHTML = "<center><br><img src=\"imgs/wait.gif\"><br>Cargando...<br></center>";

 
  //AJAX, llamo a la pagina y le mando los parametros
  myConn.connect("include.php", "GET", "variable="+url, include_terminado);
 }
}
 
 
 
 //funcion que hace el include para la pagina administrativa
 
 function mainadmin(url){
	 	//inicializamos la libreria
 var myConn = new XHConn();
 
 //si no existe da error
 if (!myConn) alert("XMLHTTP Su explorador es muy antigua, por favor use Internet Explorer 6.0 o Firefox 1.5");
 
 //funcion que se llama luego del include
 var include_terminado = function (oXML) { document.getElementById('divcon').innerHTML = oXML.responseText; };

include_dinamico1(url);
 
  function include_dinamico1 (url)
 {
	  //que hace mientras esta corriendo el script, pone una imagen de loading
  
DocHeight = document.documentElement.clientHeight;

  divbloq=document.createElement('div');
  divbloq.id='tapa';
  divbloq.style.width='100%';
  divbloq.style.height=DocHeight+'px';
  divbloq.style.zIndex='10';
  divbloq.style.position='absolute';
  divbloq.style.cssfloat='auto';
  divbloq.style.verticalAlign='middle';
  divbloq.style.left='0px';
  divbloq.style.top='0px';
  
  //position: absolute; bottom: 0; right: 15; z-index: 30;
  //divbloq.style.backgroundColor='#000000';
 /* divbloq.style.filter='alpha(opacity=\'20\')';
  divbloq.style.opacity='0.2';*/
 
  divbloq.style.backgroundImage='url(imgs/fondotrans.gif)';
  divbloq.style.backgroundRepeat='repeat';
  divbloq.style.backgroundPosition='0 0';
  document.body.appendChild(divbloq); 
 

 
  tabla = document.createElement("TABLE");
  ctabla = document.createElement("TBODY");
  fila = document.createElement("TR");
  celda = document.createElement("TD");
	tabla.setAttribute('border', '0');
	//tabla.style.opacity='1';
	tabla.setAttribute('align', 'center');
	celda.setAttribute('align', 'center');
	celda.setAttribute('valing', 'middle');
	
	tabla.setAttribute('width', '100%');
	tabla.setAttribute('height', '100%');
	fila.appendChild(celda);
  ctabla.appendChild(fila);
  tabla.appendChild(ctabla);
  divbloq.appendChild(tabla);
  
  //alert('remover');
  
  
 
  divcon = document.createElement('div');
  divcon.id='divcon';
  //divcon.style.backgroundColor='#ffffff';
  divcon.style.zindex='20';
  divcon.style.opacity='1.0';
  celda.appendChild(divcon);
  document.getElementById('divcon').innerHTML = "<center><br><img src=\"imgs/wait.gif\"><br>Cargando...<br></center>";
  //alert('boton');

 
  //AJAX, llamo a la pagina y le mando los parametros
  myConn.connect("include.php", "GET", "variable="+url, include_terminado);
 	}
 }
 
 
 function remover(){
	 /*div1=document.getElementById('tapa');
	 tab1=document.getElementById(nombre);
	 div1.removeChild(tab1);*/
	 //alert(nombre);
	 cuerpo = document.getElementsByTagName('body').item(0);
	 //ifr = document.getElementById('frcon');
	 //alert(ifr);
	 //cuerpo.removeChild(ifr);
	 
	 cuerpo.removeChild(divbloq);
	 //alert('removido');
 }