﻿function chk_Login() {
    var chk;
    var imgHTTP = getreq();
    var username = document.getElementById('txtemail').value;
    var password = document.getElementById('txtpass').value;
    if (document.getElementById('chktop').checked == true)
         chk = "true";
    else
         chk = "false";
    if (trim(username) == '') {
        alert('Please enter your email address');
        document.getElementById('txtemail').focus();
        return;
    }
   else if (checkEmail(username) == false) {
        alert("Please enter valid email address");
        document.getElementById('txtemail').focus();
        return;
    }
  else if (trim(password) == '')
   {
            alert('Please enter your password');
            document.getElementById('txtpass').focus();
            return;
        }
      else {

          var url = "/ajax/checklogin.aspx";
          url = url + "?email=" + document.getElementById("txtemail").value + "&pass=" + document.getElementById("txtpass").value + "&chk=" + chk;
        imgHTTP.open('GET', url, false);
        imgHTTP.send(null);
        if (imgHTTP.responseText == '0') 
        {
            alert("The username and/or password invalid");
            document.getElementById('txtemail').focus();
            return ;
        }
        else {
            
            document.location = 'https://normedica.co.uk/app/myaccount.aspx';
            //document.location = 'http://localhost/app/myaccount.aspx';
             return true;
         }


    }
  
}

function checkEmail(strReceived) {
    var emailRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (!emailRegex.test(strReceived)) {
        return false;
    }
    return true;
}

function getreq() { // returns false if exists
    if (window.ActiveXObject) { // if IE
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                return;
            }
        }
    }
    else if (window.XMLHttpRequest) { // if Mozilla, Safari, etc.
        return new XMLHttpRequest();
    }
}


