var CierroSes=0;
//alert(self.location.href);
function CerrarSesion(){
	CierroSes=1;
	LGN_xmlhttpPost('login/envio-login.php')
}

function LGN_xmlhttpPost(strURL) {
    var LGN_xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.LGN_xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.LGN_xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.LGN_xmlHttpReq.open('POST', strURL, true);
    self.LGN_xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.LGN_xmlHttpReq.onreadystatechange = function() {
    if (self.LGN_xmlHttpReq.readyState < 4) 
		{
		LGN_procesando("PROCESANDO...");
		}
	else
		{
		LGN_procesando("");
		LGN_updatepage(self.LGN_xmlHttpReq.responseText);
		}
    }
    self.LGN_xmlHttpReq.send(LGN_getquerystring());
}

function LGN_getquerystring() {
	//alert(CierroSes)
	if(CierroSes==1)
		{
		qstr ='CierroSesion=' + escape(CierroSes); 
		}
	else
		{
		var form = document.forms['frmDatos'];
		var Usuario = form.Usuario.value;
		var Clave = form.Clave.value;
		qstr ='Usuario=' + escape(Usuario) + '&Clave=' + escape(Clave); 
		}

	 //alert('-'+qstr);
    return qstr;
}

function LGN_updatepage(str){
	tipo = str.substr(0, 1);
	str = str.substr(1);
	//alert(str);
	if(tipo=='1')// RESULTADO SIN ERROR
		{		
	    document.getElementById("Resultado").innerHTML = str+' - <a href="JavaScript:CerrarSesion()">Cerrar Sesion</a> - <a href="'+document.location.href+'">Actualizar</a>';
		document.location.href='ver-ot.php'
		}
	else if(tipo=='0')// RESULTADO CON ERROR
		{		
		LGN_procesando(str + ' - <a href="JavaScript:RestablecerForm()">Login</a>');
		}
	else //CIERRO SESION
		{
		document.location.href=self.location.href;
//		RestablecerForm():
		LGN_procesando(str);
		}
	
	
}

function LGN_procesando(str) {
	document.getElementById("Resultado").innerHTML = str;
}

