/******************************************************************************/
/*                    Funciones de control para login                         */
/******************************************************************************/

// REQUIRES common/request.js
// REQUIRES common/utils.js
// REQUIRES common/mensajes.js

//
// callbackLogin
//
function callbackLogin(req){
  //eval(req.responseText);
  callbackOk(req);
}

//
// submitLogin
//
function submitLogin(e) 
{ 
  showMessage(MSG_INFO,"Comprobando credenciales ...", true);
  
  var pUser = document.getElementById("pUser").value;
  var pPassword = document.getElementById("pPassword").value;

  var vRequest=new Request("login","POST");
  
  vRequest.addParameter("pUser",pUser);
  vRequest.addParameter("pPassword",pPassword);
  sendRequest(vRequest, callbackLogin, callbackError);
  
  return noPropagateEvent(e);
}

//
// submitSolicitar
//
function submitSolicitar(e)
{
  location.href = "solicitar.jsp";

  return noPropagateEvent(e);
}

//
// ValidCredentials
//
function ValidCredentials() {
  location.href="app/menu.jsp";
}

//
// invalidCredentials
//
function InvalidCredentials() {
  showMessage(MSG_ERROR,"Usuario o clave no válidas", true);
}

function onLoadHandler() {
  document.getElementById("pUser").focus();
  document.getElementById("pUser").select();
  
  createMessageDiv();
  
  switch(getParameter("pCode")){
    case '1':      
      showMessage(MSG_WARNING, "Error al validar la cookie. Vuelva a identificarse.", true);      
      break;
    case '2':
      showMessage(MSG_WARNING, "Antes de acceder a la aplicación ha de identificarse.", true);
      break;
    default:
  }  
}

if (window.addEventListener) window.addEventListener("load",onLoadHandler,false);
else if (window.attachEvent) window.attachEvent("onload",onLoadHandler);
