﻿     var ctl = 'ctl00' //'_ctl0'
     
    function dologin() 	{
			var obju=control("txtUser");
			var objp=control("txtPassword");
 	  var lerr=''
			if(obju.value.replace(/ /g,"")=='')
			{
				lerr='Username is required!\n';
				obju.focus();
			}
			if(objp.value.replace(/ /g,"")=='')
			{
				if(lerr=='') objp.focus();
				lerr+='Password is required!';				
			}
			if(lerr!='')
			{
				alert(lerr);}
	 			else{
				validatelogin();				
				}
	 		}
 
function control(id) {
    var obj = document.getElementById(id);
    if (obj) {
        return obj;
    } else {
        obj = document.forms[0].elements[id];
        if (obj) {
            return obj;
        }
        obj = document.getElementById(ctl + '_' + id);
        if (obj) {
            return obj;
        }  
    }
}
    function validatelogin() {

      control("lblValidate").innerHTML = "Validating...";

      var obju = control("txtUser");
      var objp = control("txtPassword");
      var ajax = new AJAX();
      ajax.setEventHandler("login_result");
      ajax.getAJAX('ValidateLogin.aspx?user=' + obju.value + '&pass=' + objp.value);
    }
    function login_result(res, success) {
      var arr;
 
	var err=control('lblValidate');
	
			if(success){
				err.innerHTML='';
				arr=res.response.split('||');
  				if(arr[0]=='S'){
					location.href=arr[1];
				}else{
					if(arr[0]=='F'){
						err.innerHTML=arr[1];
	 				}
				}
			}else{
				//err.innerHTML=res.response;
			}
    }

    function dokeypress(event) {
      if (event == null) event = window.event;

      if (event.keyCode == 13) {
        if (dologin() == true) {          
          loginvalidation();
        }
      }
    }
		
function isEmail(email){
  var rExp=new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
	return rExp.test(email);
}

        function forgotpassword() {
      var lwidth = 550;
      var lheight = 210;
      var lleft = (screen.availWidth / 2) - (lwidth / 2);
      var ltop = (screen.availHeight / 2) - (lheight / 2);
      window.open("./popup/forgotpassword.aspx", "Forgotpassword", "left=" + lleft + ",width=" + lwidth + ",top=" + ltop + ",height=" + lheight + ",toolbar=no,menubar=no,location=no,status=no,resizable=yes");
  }

  function Privacy_Terms(type) {
      var lwidth = 550;
      var lheight = 550;
      var lleft = (screen.availWidth / 2) - (lwidth / 2);
      var ltop = (screen.availHeight / 2) - (lheight / 2);
      window.open("Privacy_Terms.aspx?type=" + type, "Privacy_Terms", "left=" + lleft + ",width=" + lwidth + ",top=" + ltop + ",height=" + lheight + ",toolbar=no,menubar=no,location=no,status=no,resizable=yes");
  }
