// JavaScript Document
addEvent(window,'load',inicializarEventosLost,false);

function inicializarEventosLost()
{
  var ob;
  if (document.getElementById('idSend')){
  	ob=document.getElementById('idSend');
  	addEvent(ob,'click',enviarDatosLost,false);
  }
}

function enviarDatosLost(e)
{
  if (window.event)
    window.event.returnValue=false;
  else
    if (e)
      e.preventDefault();
      presionOpcionLost();
}

function retornarDatosLost()
{
  var cad='';
  var username = '';

  username = document.getElementById('username').value;


  cad ='username='+encodeURIComponent(username)
  //cad = cad + '&inputPwd='+encodeURIComponent(inputPwd);
  return cad;

}

var conexionLost;
function presionOpcionLost()
{
  conexionLost=crearXMLHttpRequest();
  conexionLost.onreadystatechange = procesarEventosLost;
  conexionLost.open("POST","../../../modules/login/php/sendRecoveryKey.php", true);
  conexionLost.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  conexionLost.send(retornarDatosLost());
}

function procesarEventosLost() {
    var detalles = document.getElementById("message");
    if(conexionLost.readyState == 4) {
       detalles.innerHTML = "";
       OKmsg= conexionLost.responseText.indexOf("OK"); //En este caso login tiene que retornar OK
       //detalles.innerHTML = conexion1.responseText;  /*test comentar*/
       if (OKmsg > 0) {
                //window.alert("Updated");
            detalles.innerHTML = conexionLost.responseText;
       } else {
            //Si periodicity retorna algo distinto a OK (algun error)
            detalles.innerHTML = conexionLost.responseText;
       }
    }
    else {
       // detalles.innerHTML = "Loading";
       // detalles.style.display='block';
    }
}

//***************************************
//Funciones comunes a todos los problemas
//***************************************
function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest()
{
  var xmlHttp=null;
  if (window.ActiveXObject)
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else
    if (window.XMLHttpRequest)
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}


