/* - - - - - - - - - - - - - - - - - - - - - - -
 michal@bajer.net.pl
 2009-06-03,11
 2009-08-03
 2009-09-02
 2009-10-07
 - - - - - - - - - - - - - - - - - - - - - - - */
//<!--
var xmlhttpLogin;
//var hiddenForm;
var isLogged=false;
function loginAction(login,password)
{
if (login.length==0) return false;
if (password.length==0) return false;
//hiddenForm='<form action="'+'/info/profil,'+sessid+'.html'+'" method="POST" name="loginForm"><input type="text" name="login" value="'+login+'"><input type="password" name="password" value="'+password+'"><input type="submit" value="1" id="submitLogin"></form>';
xmlhttpLogin=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttpLogin=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttpLogin=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttpLogin!=null)
  {

               //_('loginArea').innerHTML='<div class="inprogress">'+TEXT_IN_PROGRESS+'</div>';
               _('loginArea').style.visibility='hidden';
               var newdiv = document.createElement('div');
               newdiv.setAttribute('id','loginResult');
               _('loginPanel').appendChild(newdiv);
               _('loginResult').style.visibility='visible';
               _('loginResult').innerHTML='<div class="inprogress">'+TEXT_IN_PROGRESS+'</div>';

          var url = '/ajax/login.php';
          var params = 'login='+login+'&password='+password+'&sessid='+sessid;
          xmlhttpLogin.open("POST", url, true);

          //Send the proper header information along with the request
          xmlhttpLogin.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-2");
          xmlhttpLogin.setRequestHeader("Content-length", params.length);
          xmlhttpLogin.setRequestHeader("Connection", "close");

          xmlhttpLogin.onreadystatechange = loginStateChange;
          xmlhttpLogin.send(params);

  }
else
  {
  alert("Your browser does not support XMLHTTP.");
  }
  return false;
}


function loginStateChange()
{
//alert(xmlhttpLogin.readyState);
if (xmlhttpLogin.readyState==4)
  {// 4 = "loaded"
  if (xmlhttpLogin.status==200)
    {// 200 = "OK"
            //alert(xmlhttpLogin.responseText);
            logSaveAction(xmlhttpLogin.responseText);
            if (xmlhttpLogin.responseText.length==0){
                return;
            }
            if (xmlhttpLogin.responseText=='null'){
            }

            //var result=cmsAjaxResultDecode(xmlhttpLogin.responseText);
            var result=unserialize(xmlhttpLogin.responseText);
            if (result['error']!=null){
               _('loginResult').className='error';
               _('loginResult').innerHTML='<div class="error">'+result['error']+'</div>';
               setTimeout('reload()', 3*1000);
               isLogged=false;
            }
            if (result['success']!=null){
               //_('hiddenArea').innerHTML=hiddenForm;
               //_('loginArea').innerHTML='<div class="success">'+result['success']+'</div>';
               //_('loginArea').style.visibility='hidden';
               //_('loginArea').innerHTML=hiddenForm;
               //_('loginArea').innerHTML='<form action="'+'/info/profil,'+sessid+'.html'+'" method="POST" name="loginForm">'+_('loginArea').innerHTML+'</form>';
               //_('loginArea').style.visibility='hidden';
               //var newdiv = document.createElement('div');
               //newdiv.setAttribute('id','loginResult');
               //_('loginPanel').appendChild(newdiv);
               //_('loginResult').style.visibility='visible';
               _('loginResult').innerHTML='<div class="success">'+result['success']+'</div>';
               //alert(_('loginPanel').innerHTML);
               setTimeout('redirect()', 3*1000);
               isLogged=true;
            }
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttpLogin.statusText);
    }
  }
}
function reload(){
              window.location='/info/main,page,'+sessid+'.html';
}
function redirect(){
              //window.location='/info/profil,'+sessid+'.html';
              //document.loginForm.submit();
              //_('submitLogin').click();
              //document.loginForm.submit();
              document.loginForm.submitLogin.click();
}
 function keypress(e)
 {
     var Ucode=e.keyCode? e.keyCode : e.charCode
     if (Ucode == 13)
     {
         //write the code for submit
         loginAction(_('loginField').value,_('passwordField').value);
     }
 }
 function loginSubmit(){
    if (!isLogged){
       loginAction(_('loginField').value,_('passwordField').value);
       return false;
    }else{
       return true;
    }
 }
// -->