﻿function alphanumericWithoutBlankSpace(evtGet) {
    if ((evtGet.which == 39) || (evtGet.which == 34) || (evtGet.which == 32)) evtGet.preventDefault();
    else return;
}

function alphanumeric(e) {
    if ((e.which > 47 && e.which < 58) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 9) || (e.which == 32) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function alphanumericWithSpace(e) {
    if ((e.which > 47 && e.which < 58) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 9) || (e.which == 32) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function alphanumericWithOutSpace(e) {
    if ((e.which > 47 && e.which < 58) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 9) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function alphanumericwithAstrick(e) {
    if ((e.which > 47 && e.which < 58) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 9) || (e.which == 32) || (e.which == 8) || (e.which == 0) || (e.which == 13) || (e.which == 42)) return;
    else e.preventDefault();
}

function alphanumeric1(e) {
    if ((e.which > 47 && e.which < 58) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 9) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function alphabeticOnly(e) {
    if (e.which != 'undefined') {
        if ((e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
        else e.preventDefault();
    }
}

function NumericDataOnly(e) {
    if ((e.which > 47 && e.which < 58) || (e.which == 8) || (e.which == 16) || (e.which == 9) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function alphanumericWithoutQuotesSearchVal(e) {
    if ((e.which == 34) || (e.which == 39)) return;
    else evtGet.preventDefault();
}

function requiredField(un, str) {
    var fldVal = jQuery.trim(un.val());
    if (fldVal == "") {
        alert(str);
        un.focus();
        return false;
    }
    return true;
}

function validMobileNo(un, str) {
    var fldVal = jQuery.trim(un.val());
    if(fldVal.indexOf("0")==0 || fldVal.indexOf("+91")>-1)
    {
        alert(str);
        un.focus();
        return false;
    }
    return true;
}

function oneAlphabetic(controlID, message) {
    var controlVal = jQuery.trim(controlID.val());
    var pwdchar = 0;
    for (var j = 0; j < controlVal.length; j++) {
        var pchar = controlVal.charAt(j);
        var pcode = pchar.charCodeAt(0);
        if ((pcode > 64 && pcode < 91) || (pcode > 96 && pcode < 123)) {
            pwdchar++;
        }
    }
    if (pwdchar > 0) {} else {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function oneNumeric(controlID, message) {
    var controlVal = jQuery.trim(controlID.val());
    var c = 0;
    var lgnchar = 0;
    for (var j = 0; j < controlVal.length; j++) {
        var pchar = controlVal.charAt(j);
        var pcode = pchar.charCodeAt(0);
        if ((pcode > 47 && pcode < 58)) {
            c++;
        }
    }
    if (c > 0) {} else {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function oneSpecialChar(controlID, message) {
    var controlVal = jQuery.trim(controlID.val());
    var spl = 0;
    var pwdchar = 0;
    for (var j = 0; j < controlVal.length; j++) {
        var pchar = controlVal.charAt(j);
        var pcode = pchar.charCodeAt(0);
        if (pcode == 33 || (pcode > 34 && pcode < 39) || (pcode > 39 && pcode < 48) || (pcode > 57 && pcode < 65) || (pcode > 90) && (pcode < 97) || (pcode > 122) && (pcode < 127)) {
            spl++;
        }
    }
    if (spl > 0) {} else {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function MustBe6Char(controlID, message) {
    var controlVal = jQuery.trim(controlID.val());
    if (controlVal.length < 6) {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function ValidEmailID(controlID, message) {
    var EmailId = jQuery.trim(controlID.val());
    var regExp = /^(([A-Za-z0-9]+_{1})|([A-Za-z0-9]+-{1})|([A-Za-z0-9]+[.]{1})|([A-Za-z0-9]+[+]{1}))*([A-Za-z0-9])+@((([A-Za-z0-9]+-{1})|([A-Za-z0-9]+[.]{1}))*([A-Za-z0-9])*)+[.][a-zA-Z]{2,6}$/;
    if (!EmailId.match(regExp)) {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function ValidatePAN(controlID, message) {
    var PAN = jQuery.trim(controlID.val());
    var regExp = /^[A-Za-z]{5}[0-9]{4}[A-Za-z]{1}$/;
    if (!PAN.match(regExp)) {
        alert(message);
        controlID.focus();
        return false;
    }
    return true;
}

function matchPasswordConfirm(controlID, controlID1, str) {
    var controlValPass = jQuery.trim(controlID.val());
    var controlValConfirm = jQuery.trim(controlID1.val());
    if (controlValPass != controlValConfirm) {
        alert(str);
        controlID1.focus();
        controlID1.select();
        return false;
    }
    return true;
}

function confirmCancel() {
    if (confirm('Are you sure you want to cancel? Click OK to confirm.')) return true;
    else return false;
}

function AlphabeticSpace(e) {
    if ((e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 32) || (e.which == 8) || (e.which == 0) || (e.which == 13)) return;
    else e.preventDefault();
}

function AllExcept(e) {
    if ((e.which == 39) || (e.which == 34)) e.preventDefault();
    else return;
}

function NumericWithDot(e) {
    if ((e.which > 47 && e.which < 58) || (e.which == 8) || (e.which == 16) || (e.which == 9) || (e.which == 0) || (e.which == 13) || (e.which == 46)) return;
    else e.preventDefault();
}

function NumericWithBrace(e) {
    if ((e.which > 47 && e.which < 58) || (e.which == 8) || (e.which == 16) || (e.which == 9) || (e.which == 0) || (e.which == 13) || (e.which == 40) || (e.which == 41) || (e.which == 45)) return;
    else e.preventDefault();
}

function ValidateMinLengh(ControlID, str, min) {
    var controlVal = jQuery.trim(ControlID.val());
    if ((controlVal.length < min)) {
        alert(str);
        ControlID.focus();
        return false;
    }
    else return true;
}

function ValidateMaxLenght(ControlID, str, min) {
    var controlVal = jQuery.trim(ControlID.val());
    if ((controlVal.length > min)) {
        alert(str);
        ControlID.focus();
        return false;
    }
    else return true;
}

function validateDate(drpDate, drpMonth, drpYear) {
    var dt = drpDate.val();
    var mnth = drpMonth.val();
    var year = drpYear.val();
    var dt1 = new Date();
    if ((mnth == 1) || (mnth == 3) || (mnth == 5) || (mnth == 7) || (mnth == 8) || (mnth == 10) || (mnth == 12)) {
        if ((dt < 1) || (dt > 31)) {
            alert("BirthDate should be between 1 to 31.");
            return false;
        }
    }
    else if ((mnth == 4) || (mnth == 6) || (mnth == 9) || (mnth == 11)) {
        if ((dt < 1) || (dt > 30)) {
            alert("BirthDate should be between 1 to 30.");
            return false;
        }
    }
    else if ((mnth == 2)) {
        if (year % 4 == 0) {
            if ((dt > 29) || (dt < 1)) {
                alert("BirthDate should be between 1 to 29.");
                return false;
            }
        }
        else if ((dt > 28) || (dt < 1)) {
            alert("BirthDate should be between 1 to 28.");
            return false;
        }
    }
    var bdate = mnth + "/" + dt + "/" + year;
    var bdtNew = new Date(bdate);
    var mnth = dt1.getMonth() + 1;
    var today = mnth + "/" + dt1.getDate() + "/" + dt1.getFullYear();
    var curDate = new Date(today);
    if (bdtNew > curDate) {
        alert("BirthDate should not be future Date.");
        return false;
    }
    return true;
}

function validateFutureDate(drpDate, drpMonth, drpYear, msg) {
    var dt = drpDate.val();
    var mnth = drpMonth.val();
    var year = drpYear.val();
    var dt1 = new Date();
    if ((mnth == 1) || (mnth == 3) || (mnth == 5) || (mnth == 7) || (mnth == 8) || (mnth == 10) || (mnth == 12)) {
        if ((dt < 1) || (dt > 31)) {
            alert("Date should be between 1 to 31.");
            return false;
        }
    }
    else if ((mnth == 4) || (mnth == 6) || (mnth == 9) || (mnth == 11)) {
        if ((dt < 1) || (dt > 30)) {
            alert("Date should be between 1 to 30.");
            return false;
        }
    }
    else if ((mnth == 2)) {
        if (year % 4 == 0) {
            if ((dt > 29) || (dt < 1)) {
                alert("Date should be between 1 to 29.");
                return false;
            }
        }
        else if ((dt > 28) || (dt < 1)) {
            alert("Date should be between 1 to 28.");
            return false;
        }
    }
    var bdate = mnth + "/" + dt + "/" + year;
    var bdtNew = new Date(bdate);
    var mnth = dt1.getMonth() + 1;
    var today = mnth + "/" + dt1.getDate() + "/" + dt1.getFullYear();
    var curDate = new Date(today);
    if (bdtNew < curDate) {
        alert(msg);
        return false;
    }
    return true;
}

function validateRange(ControlID, msg, minval, maxval) {
    var ControlVal = ControlID.val();
    if (ControlVal < 0 || ControlVal > 100) {
        alert(msg);
        return false;
    }
    return true;
}

function AlphabeticWithHyphen(e) {
    if ((e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123) || (e.which == 8) || (e.which == 0) || (e.which == 45)) return;
    else e.preventDefault();
}

function validFileName(e) {
    if ((e.which == 34) || (e.which == 32) || (e.which == 47) || (e.which == 92) || (e.which == 124) || (e.which == 42) || (e.which == 63) || (e.which == 60) || (e.which == 62)) e.preventDefault();
    else return;
}

function ValidFileFormat(txtFileName, str, fileExtensions) {
    var txtFileNameVal = jQuery.trim(txtFileName.val());
    var Extensions = fileExtensions.split(",");
    var tbool = false;
    var FileVal = txtFileNameVal.split(".");
    for (var j = 0; j < Extensions.length; j++) {
        if (FileVal[1] == Extensions[j]) {
            tbool = true;
        }
    }
    if (tbool == false) {
        alert(str);
        txtFileName.val("");
        txtFileName.focus();
        return false;
    }
    else return true;
}
var popupstatus = 0;

function disablePopup(controlId) {
    if (popupstatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        if (controlId != "all") $(controlId).fadeOut("slow");
        else {
            $("#loader").fadeOut("slow");
            $("#ConfirmBox").fadeOut("slow");
            $("#ConfirmDeleteBox").fadeOut("slow");
            $("#userDetails").fadeOut("slow");
            $("#stateDetails").fadeOut("slow");
            $("#PaymentGatewayDetails").fadeOut("slow");
            $("#ViewInterface").fadeOut("slow");
            $("#ViewDetails").fadeOut("slow");
            $("#MailServerDetails").fadeOut("slow");
            $("#resetPassword").fadeOut("slow");
            $("#changeUserName").fadeOut("slow");
            $("#upgradeVersion").fadeOut("slow");
            $("#deactivateRemark").fadeOut("slow");
        }
        popupstatus = 0;
    }
}

function centerPopup(controlId) {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    if (eval(windowHeight) == 0) windowHeight = document.body.clientHeight;
    if (eval(windowWidth) == 0) windowWidth = document.body.clientWidth;
    var popupHeight = $(controlId).height();
    var popupWidth = $(controlId).width();
    $(controlId).css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    $("#backgroundPopup").css({
        "height": windowHeight
    });
    $("#backgroundPopup").css({
        "width": windowWidth
    });
}

function loadPopup(controlId) {
    if (popupstatus == 0) {
        popupstatus = 1;
        $("#backgroundPopup").css({
            "opacity": "0.8"
        });
        $("#backgroundPopup").fadeIn("slow");
        centerPopup(controlId);
        $(controlId).fadeIn("slow");
    }
}
$(document).ready(function () {
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popupstatus == 1) {
            disablePopup("all");
        }
    });
});
