var mailHttp;

function mailCheck(obj) {
      if(obj.value) {

      mailHttp = null;
      if (window.XMLHttpRequest) {// code for Firefox, Mozilla, IE7, etc.
            mailHttp = new XMLHttpRequest();
      }
      else if (window.ActiveXObject) {// code for IE6, IE5
            mailHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      
      if (mailHttp != null) {
            mailHttp.onreadystatechange = function() {
                  if (mailHttp.readyState == 4) {// 4 = "loaded"
                        if (mailHttp.status == 200) {// 200 = "OK"
                              if(mailHttp.responseText == 'ok') {
                                    document.getElementById('emailOK').className = 'ok';
                              } else {
                                    document.getElementById('emailOK').className = 'notok';
                              }
                        }
                  }
            }
            mailHttp.open("GET", "/ajax/checkmail.php?email=" + obj.value, true);
            mailHttp.send(null);
      }

      } else {
            document.getElementById('emailOK').className = 'empty';
      }
}

function mailFocus(obj) {
      if(obj.value == 'Jūsu epasts') {
            obj.value = '';
            document.getElementById('emailOK').className = 'empty';
      } else {
            mailCheck(obj);
      }
}

function mailBlur(obj) {
      if(obj.value == '') {
            obj.value = 'Jūsu epasts';
            document.getElementById('emailOK').className = 'empty';
      } else {
            mailCheck(obj);
      }
}

function mailSubmit() {
      if(document.getElementById('emailOK').className == 'ok') return true;
      return false;
}

function showLogForm(forma) {
      document.getElementById('parole').style.display = forma == 'parole' ? 'block' : 'none';
      document.getElementById('ienakt').style.display = forma != 'parole' ? 'block' : 'none';
}

