﻿function checknumberdecimal(e) {
    
    var ev = e ? e : window.event;
    if (!ev) { return false; }
    var targ = ev.target ? ev.target : ev.srcElement;
    var which = -1;
    if (ev.which) { which = ev.which; }
    else if (ev.keyCode) { which = ev.keyCode; }

   
    if (which == 8 || which == 9) {
        return true;
    }

    else if (which > 47 && which < 58) {
        return true;
    }
//    else if (which == 59) {
//        return true;
   // }
    else {
        return false;
    }
}
function checknumberdecimal1(e, id,w) {

    var ev = e ? e : window.event;
    if (!ev) { return false; }
    var targ = ev.target ? ev.target : ev.srcElement;
    var which = -1;
    if (ev.which) { which = ev.which; }
    else if (ev.keyCode) { which = ev.keyCode; }


    if (which == 8 || which == 9) {
        return true;
    }

    else if (which > 47 && which < 58) {
        return true;
    }
    else {
        id.value = id.value.replace(valid.r[w], '');
        return false;
    }
}



function keyhandlerArabic(e) {
//    if (document.layers)
//        Key = e.which;
//    else
//        Key = window.event.keyCode;

    var ev = e ? e : window.event;
    if (!ev) { return false; }
    var targ = ev.target ? ev.target : ev.srcElement;
    var Key = -1;
    
    if (ev.which) { Key = ev.which; }
    else if (ev.keyCode) { Key = ev.keyCode; }
    
    if (Key == 8 || Key == 9) {
        return true;
    }
    if (Key > 1547 && Key < 1619) {
        return true;
    }
    if (Key >= 47 && Key <= 58) {
        return true;
    }
    if (Key ==32) {
        return true;
    }
    else {
        return false;
    }
}

function keyhandlerArabic(e) {
    //    if (document.layers)
    //        Key = e.which;
    //    else
    //        Key = window.event.keyCode;

    var ev = e ? e : window.event;
    if (!ev) { return false; }
    var targ = ev.target ? ev.target : ev.srcElement;
    var Key = -1;

    if (ev.which) { Key = ev.which; }
    else if (ev.keyCode) { Key = ev.keyCode; }

    if (Key == 8 || Key == 9) {
        return true;
    }
    if (Key > 1547 && Key < 1619) {
        return true;
    }
    if (Key >= 47 && Key <= 58) {
        return true;
    }
    if (Key == 32) {
        return true;
    }
    else {
        return false;
    }
}   

function keyhandlerEnglish(e) {
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;
    
    if (Key > 64 && Key < 91) {
        return true;
    }
    else if (Key > 96 && Key < 123) {
        return true;
    }
    else if (Key == 32) {
        return true;
    }
    else {
        return false;
    }
}


function keyhandlerLetters(e) {




    var ev = e ? e : window.event;
    if (!ev) { return false; }
    var targ = ev.target ? ev.target : ev.srcElement;
    var Key = -1;
    if (ev.which) { Key = ev.which; }
    else if (ev.keyCode) { Key = ev.keyCode; }

    //alert(Key);
    if (Key == 8 || Key == 9) {
        return true;
    }
    else if (Key > 1547 && Key < 1619) {
        return true;
    }
    else if (Key == 32) {
        return true;
    }
    else if (Key > 64 && Key < 91) {
        return true;
    }
    else if (Key > 96 && Key < 123) {
        return true;
    }
    else {
        return false;
    }
   
}



function CheckEmail() {

    str = document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").value;
    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
        alert('Invalid Email format');
        return false
    }
    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {

        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
        
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
        
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
        
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
        
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
       
    }

    if (str.indexOf(" ") != -1) {
        alert('Invalid Email format');
        document.getElementById("ctl00_ContentPlaceHolder1_txtEmail").focus();
    }
    

    return false


}


function ValidateForm() {
    var emailID = document.frmSample.txtEmail

    if ((emailID.value == null) || (emailID.value == "")) {
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    if (echeck(emailID.value) == false) {
        emailID.value = ""
        emailID.focus()
        return false
    }
    return true
}


function valid(o, w) {
    o.value = o.value.replace(valid.r[w], '');

   
}
valid.r = {

    'Arabic': /[\a-zA-Z|\0-9|\""|\""|\!|\@|\#|\%|\^|\:|\&|\*|\(|\(|\)|\_|\+|\?|\=|\,|\.|\<|\>|\/|\;|\:|\~|\`|\[|\]|\{|\}|\$|\'']/g,
    'English': /[\u0600-\u06FF\d-]/g,
    'numbers': /[\a-zA-Z|\""|\""|\!|\@|\#|\%|\^|\:|\&|\*|\(|\(|\)|\_|\+|\?|\=|\,|\.|\<|\>|\/|\;|\:|\~|\`|\[|\]|\{|\}|\$|\''|\u0600-\u06FF]/g,
    'numbers1': /[0-9|\""|\""|\!|\@|\#|\%|\^|\&|\*|\(|\(|\)|\_|\+|\?|\=|\,|\.|\<|\>|\/|\;|\:|\~|\`|\[|\]|\{|\}|\$|\'']/g //

}



function validDate(o) {

    o.value = o.value.replace(o.value, '');
}


function ArabicExpressionValidator(obj, digit) {
    var regex;
    if (digit) {
        regex = new RegExp("^[\u0600-\u06FF0-9 ][\u0600-\u06FF0-9\- ]*$");
    }
    else {
        regex = new RegExp("^([\u0600-\u06FF\s-]{1,25})$");
    }

    if (obj.value.match(regex) == null) {
        obj.value = '';
    }
}


function GetCharValid(o, w) {
    o.value = o.value.replace(valid.r[w], '');
}
valid.r =
            {
                'ar': /[\a-zA-Z]/g,
                'en': /[\u0600-\u06FF\d-]/g,
                'num': /[\0-9]/g
            }

            
