/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();
var paginas = new Array("../admin_arvios/index.html", "../arvios_donwload/index.html");
/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
var tipo;
function login() {
// Optional: Show a waiting message in the layer with ID ajax_response
div = document.getElementById('apDiv1').getElementsByTagName("input");
val1=div[0].value;
val2=div[1].value;
document.getElementById('apDiv1').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var nick = encodeURI(val1);
var pass = encodeURI(val2);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'php/autentica.php?nick='+nick+'&pass='+pass+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}
function loginReply() {
if(http.readyState == 4){
var response = http.responseText;

if(response == 0){
// if login fails
document.getElementById('apDiv1').innerHTML = 'Acceso denegado! Verifique Usuario y contraseña';
setTimeout ("descargaPagina3('html/inicio.html?query=0')", 2000);
// else if login is ok show a message: "Welcome + the user name".
} else {
document.getElementById('apDiv1').innerHTML = '<table width="25%" border="0"><tr><td><div align="center"><img src="../../IMG/logo_carga.png" width="170" height="72" /></div></td></tr><tr><td ><div class="cont" align="center">Bienvenido al Colegio Europeo</div></td></tr></table>';

setTimeout ("descargaPagina2('php/registrado.php?query=0')", 2000);

}
}
}
function salir() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('apDiv1').innerHTML = "Loading..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'php/salir.php?salir=1'+nocache);
http.onreadystatechange = operacionSalir;
http.send(null);
}
function operacionSalir() {
if(http.readyState == 4){
var response = http.responseText;
alert(response)
if(response == 1){
// if login fails
document.getElementById('apDiv1').innerHTML = 'Sesion Finalizada con Exito';
setTimeout ("descargaPagina3('html/inicio.html?query=0')", 2000);
// else if login is ok show a message: "Welcome + the user name".
} else {
document.getElementById('apDiv1').innerHTML = 'Fallo en la Operacion';

setTimeout ("descargaPagina3('html/inicio.html?query=0')", 2000);

}
}
}
function redireccionaPagina(ruta) {
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'php/redirect.php?pag='+ruta+'&nocache = '+nocache);
http.onreadystatechange = procesaRedireccion;
http.send(null);
}
function procesaRedireccion() {
if(http.readyState == 4){
var response = http.responseText;

if(response == 0){
descargaPagina3('html/restringido.html?query=0');
// else if login is ok show a message: "Welcome + the user name".
} else {
descargaPagina(response+'?query=0');

}
}
}
function redireccionar(pagina) 
{
location.href=pagina
} 

