// JavaScript Document
var peticion = false; 
if (window.XMLHttpRequest) {
      peticion = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
peticion = new ActiveXObject("Microsoft.XMLHTTP");
peticion.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

function ObtenerDatos(datos,divID,volver_a) { 
if(peticion) {
     var obj = document.getElementById(divID); 
     peticion.open("POST", datos); 
     peticion.onreadystatechange = function()  { 
          if (peticion.readyState == 4) { 
		  if ((Left(datos,7)=="validar" && peticion.responseText == "Login_exitoso")||(datos=="cerrar_sesion.asp"))
				{
				window.location.reload();
				}
		  if (Left(datos,13)=="proceso_datos" && peticion.responseText == "alta_exitosa")
				{
				ObtenerDatos('validar_login.asp?email='+document.getElementById('email').value+'&contrasenia='+document.getElementById('password').value,'Div_Login_msg');
				return;
				}
				if(divID == 'Div_Register')
				{
				if(peticion.responseText=="alta_exitosa")
				{
				ObtenerDatos(volver_a,'Div_Register','');
				return;
				}
				}
  
               obj.innerHTML = peticion.responseText; 
          } 
     }
peticion.send(null); 
}
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

