var req = objetoAjax(); 
function objetoAjax()
{ var req = false;
  try  { req = new XMLHttpRequest(); }
  catch(err1)  
  { try  { req = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(err2)
    { try  { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(err3)
      { req = false; }
    }
  }
  return req;
}

function cargaGET(url, div, nvar)
{ miAleatorio=parseInt(Math.random()*99999999);
  if (nvar==null){ r= "?rand="; }
  else { r="&rand";  }
  req.open("GET", url+ r + miAleatorio, true);
  req.onreadystatechange = function (){ respuestaAjax(div); }
  req.send(null);
}

function cargaPOST(url,div,sw)
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open('POST', url, true);
  req.onreadystatechange = function() { respuestaAjax(div);  }
  req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  if (sw!='')
  { var nom = document.getElementById("nom").value;
    req.send(url+'&estu='+nom+'&rand='+miAleatorio);
  }
  else req.send(url+'&rand='+miAleatorio);
}

function respuestaAjax(div)
{ var detalles = document.getElementById(div);
  if(req.readyState == 4) 
  { if(req.status == 200) 
    { detalles.innerHTML = req.responseText; }
    else { detalles.innerHTML = 'Ha ocurrido un error: ' + req.statusText; }
  }
  else { detalles.innerHTML = ' <img  src="images/cargando.gif" align="middle" /> Cargando...'; }
}

function cargaLOGIN(url)
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open('POST', url, true);
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  req.onreadystatechange = 
  function() { if (req.readyState == 4)
    		   { actualizar(req.responseText);} 
  			 }
  req.send(url+"&rand="+miAleatorio);
}

function actualizar(str)
{ if(str=="ok")
  { document.location="ventana.php";
  }
  else 
  { var detalles = document.getElementById("cuerpo");
  	if(str=="cc")
      detalles.innerHTML = mensaje("CUENTA O CLAVE INVALIDA!!  <BR>Por favor Ingrese nuevamente la Cuenta y/&oacute; Clave(en min&uacute;sculas)","E");
    else 
  	  if(str=="co") 
  	    detalles.innerHTML = mensaje("CODIGO DE SEGURIDAD INVALIDO!!  <BR>Por favor Ingrese nuevamente el Codigo de Seguridad","E");
  	  else 
  	  {  if (str!="") cargaGET('debe.php?deuda='+str,'cuerpo');  }
  }
}
         
function conectarse()
{ var cue = document.getElementById("cuenta").value;
  var cla = document.getElementById("clave").value;
  var ctr = document.getElementById("control").value;
  cargaLOGIN("conectar.php?cuenta="+cue+"&clave="+cla+"&control="+ctr);
} 


function confiGET(url)
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open("GET", url+"&rand="+miAleatorio, true);
  req.onreadystatechange = 
  function() { if(req.readyState == 4){ ver(req.responseText);}}
  req.send(null);
}

function ver(str)
{ if(str=="ok")
    cargaGET('control/emodimat.php?ing=3','cuerpo');
  else
    document.getElementById("cuerpo").innerHTML = mensaje("<BR>La Transacci&oacute;n no se pudo Completar","E");
}

/// ------- cambiar clave 
function cargaCLAVE(url)
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open('POST', url, true);
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  req.onreadystatechange = function() { if (req.readyState == 4)
    		   							{ direccionar(req.responseText);} 	 }
  req.send(url+"&rand="+miAleatorio);
}

function cambiarclave()
{ var ca = document.getElementById('ca').value;
  var c1 = document.getElementById('c1').value;
  var c2 = document.getElementById('c2').value;
  cargaCLAVE("control/usuario.php?op=2&c1="+c1+"&c2="+c2+"&ca="+ca);
} 

function direccionar(str)
{ var msg='';
  if(str=="ok")   msg = mensaje("Su Clave Ha Sido Cambiada Exitosamente!!  <BR>Por favor No olvide su Nueva Clave","C"); 
  else 
    if(str=="cc") msg = mensaje("CLAVE ACTUAL INCORRECTA !!!  <BR>Por favor Ingrese nuevamente la Clave Actual(en min&uacute;sculas)","E");
    else msg = mensaje("LA NUEVA CLAVE ES INCORRECTA!! <BR>Por favor Verifique que Sean iguales","E");
  document.getElementById("error").innerHTML = msg;
}
//// fin de cambiar clave

//pestanas
function activeTab(tab,n,link)
{ for(var i=1;i<=n;i++) 
  {  document.getElementById("tab"+i).className = ""; }
  document.getElementById("tab"+tab).className = "active";
  cargaGET(link, 'content');
}
//fin de pesta�as

// seleccionar materia cargar la session
function cargaMateria(sig,par)
{ window.location.reload(); 
  cargaGET("control/matepar.php?op=3&mat="+sig+"&par="+par,"cuerpo","x");
}
//cargar lista de estudiantes
function cargaSelect(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/matepar.php?op=3&mat="+y.substring(0,7)+"&par="+y.substring(7,8),"listado","x");
}

//cargar detalle de la materia
function cargaMate(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/docente.php?op=22&mat="+y,"listado","x");
}

function cargaDesgin(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  ///cargaGET("control/docente.php?op=3&sujeto="+y+"&director=1","listado","x");
  cargaGET("control/docente.php?op=21&doc="+y,"listado","x");
}

function cargaPlan(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/docente.php?op=17&plan="+y+"","listado","x");
}

function cargabloque(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/docente.php?op=16&aula="+y+"","listado","x");
}
function cargaEgre(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/docente.php?op=24&gestion="+y,"listado","x");
}

/*para las estadisticas*/
function cargaEstPlan(idselect)
{ var x=document.getElementById(idselect);
  var y=x.options[x.selectedIndex].value;
  cargaGET("control/docente.php?op=31&plan="+y+"&nomplan="+x.value,"listado","x");
}

/*fin*/
function cerrarSession()
{ window.location.href='http://sisin.fni.edu.bo/';
  cargaGET("control/usuario.php?op=3");
}

//mensajes de error en javascritp
function mensaje(msg,tipo)
{ // Mensage de Error 
  switch (tipo)
  { case 'E': titulo='ERROR !'; 	   break;
    case 'A': titulo='ADVERTENCIA ?';  break;
    case 'C': titulo='CONFIRMACION ?'; break;
  }
  return '<TABLE width="300" align=center bordercolor="#337EC1" bgcolor="#337EC1">'+
  '<TR><TD bgcolor="#337EC1" align=center >'+
  '      <FONT color="#FFFFFF" size="4">'+titulo+'</FONT></DIV></TD></TR>'+
  '<TR><TD bgcolor="#FFFFFF" align=center>'+
  '		 <FONT color="#000000">'+msg+'</FONT></TD>'+
  '</TR></TABLE>';
}

function cargaING(url)// join on that the web ing
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open('POST', url, true);
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  req.onreadystatechange = function() { if (req.readyState == 4){ dirING(req.responseText);} 	 }
  req.send(url+"&rand="+miAleatorio);
}

function ingresar()
{ var ca = document.getElementById('ca').value;
  cargaING("control/usuario.php?op=6&ca="+ca);
} 

function dirING(str)
{ if (str=="ok") 
  { cargaGET('control/emodimat.php?ing='+str,'cuerpo'); }
  else { document.getElementById("error").innerHTML = 'Clave Incorrecta, Intente Nuevamente '; }
}
////end ing

function cargaAC(url)// join on 
{ var miAleatorio=parseInt(Math.random()*99999999);
  req.open('POST', url, true);
  req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  req.onreadystatechange = function() { if (req.readyState == 4){ dirING(req.responseText);} 	 }
  req.send(url+"&rand="+miAleatorio);
}

function aceptar()
{ var ca = document.getElementById('ca').value;
  cargaING("control/usuario.php?op=8&ca="+ca);
} 

function dirAC(str)
{ if (str=="ok") 
  { cargaGET('control/emodimat.php?ing='+str,'cuerpo'); }
  else { document.getElementById("error").innerHTML = 'Clave Incorrecta, Intente Nuevamente '; }
}





