﻿

function checkLogin(usr, pwd, btn) {

   document.getElementById('tbl_loader')  .style.display = 'block';       
   document.getElementById('tbl_login') .style.display = 'none';
   var u;
   var p;

   if(typeof(usr)=="object")
   {
     btn.style.display = "none";
     u = escape( usr.value);
     p = escape( pwd.value);
   }
   else
   {
        document.getElementById(btn).style.display = "none";
        u = escape( document.getElementById(usr).value);
        p = escape( document.getElementById(pwd).value);
   }
//   var Host = (("https:" == document.location.protocol) ? "https://" : "http://");

//   url = Host + window.location.hostname + "/webservice/validate_user.ashx?usr=" + u.toString() + "&pwd=" + p.toString() + "&ChurchID=" + DefaultChurchID;
//   alert(url);
  var url = "webservice/validate_user.ashx?usr=" + u.toString() + "&pwd=" + p.toString()+"&ChurchID="+DefaultChurchID;

  $.ajax({
      type: "get",
      url: url,
      data: "{}",

      success: function(responseText) {
     
          if (responseText == "Successful") {
              window.location.href = "LoginTransfer.aspx?UserName=" + u.toString();
          }
          else {
              if (typeof (pwd) == "object") {
                  pwd.value = "";
              }
              else {

                  document.getElementById(pwd).value = "";
              }
              //$(btn).style.display = "block";
              alert("Invalid account");
              document.getElementById('tbl_loader').style.display = 'none';
              document.getElementById('tbl_login').style.display = 'block';

              if (typeof (usr) == "object") {
                  usr.focus();
              }
              else {

                  document.getElementById(usr).focus();
              }

          }

      },
      error: function(msg) { //alert("testtt" + msg.statusText);
       }


  });    
 }                      


function openModal() {	
 
    bod = document.getElementsByTagName('body')[0];
    bod.style.height = "100%";
    bod.style.overflow = "hidden";
	
    htm = document.getElementsByTagName('html')[0];
    htm.style.height = "100%";
    htm.style.overflow = "hidden";
    document.getElementById('overlay').style.display = "block";
    document.getElementById('lightbox').style.display = "block";	
     

}
function logme(myfield,e,id)
        {
 
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;
 
       
        
//        if(usr.value=="") return true;
//        if(pwd.value=="") return true;
        
        if (keycode == 13)
        {
         
            checkLogin(usr, pwd,btn) 
           // document.getElementById('ctl00_btn_login').click();
            return false;
        }
        else
            return true;
    }
