// Accept only Characters
function chkCharacter_only(e) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if (((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 45) || (c == 32)) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37)
    { return true; }
    else { return false; }
}
// Phone & Mobile No. Validation
function chkPhoneMobile(e) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    // Phone & Mobile Validation - Numeric with Hyphen -(45) & Plus + (43)
    // Phone & Mobile No should not start with Hyphen and + symbol should be only at the beginning 
    // Checking if the Hyphen (-) is at the beginning
    if (c == 45 && e == '') { return false; }
    // Checking if the Plus (+) is in the middle
    if (c == 43 && e != '') { return false; }
    if (e.shiftKey && c == 37) return false;
    // Allow the Numbers & Hyphen in the middle
    if ((c > 47 && c < 58) || (c == 45) || (c == 43) ||
    (c == 41) || (c == 40) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37)
    { return true; }
    return false;
}

// Accepts only Characters and Numbers without white spaces inbetween
function chkAlphaNumericWithoutSpace(e) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c > 47 && c < 58) || (c == 45) || (c == 47) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else { return false; }
}
// Accepts Characters and Numbers with white spaces inbetween
//function chkAlphaNumericWithSpace(e, object, MaxLength) {
//    if (!e) e = window.event;
//    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
//    if (e.charCode != null) {
//        if (e.charCode == 0) {
//            return true;
//        }
//    }
//    if (e.shiftKey && c == 37) return false;
//    if (c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || (c == 45) || (c == 47) || c == 37 || c == 46) {
//        return true;
//    }
//    if (object.value.length > MaxLength) {
//        return false;
//    }

//    if (((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 32) || (c > 47 && c < 58))){
//        return true;
//    }
//    else { return false; }
//}
function chkAlphaNumericWithSpace(e, object, MaxLength) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if (c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37) {
        return true;
    }
    if (object.value.length > MaxLength) {
        return false;
    }
    if (((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 32) || (c > 47 && c < 58))) {
        return true;
    }
    else { return false; }
}

// Accepts only Numeric
function chkNumeric_only(e) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if ((c > 47 && c < 58) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37) {
        return true
    }
    else {
        return false
    }
}

function chkContactNo(e) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if ((c > 47 && c < 58) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 45) {
        return true
    }
    else {
        return false
    }
}

// Accepts only Numeric for date and allow up to 31
//Included by Sakthi on 27-Jul-2011
function chkNumeric_only_ForDate(e, id) {
    var val = document.getElementById(id).value;
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if ((c > 47 && c < 58) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37) {
        if (val.length != 0) {
            if (parseInt(val, 10) == 3) { if (c > 47 && c < 50) { return true; } else { return false; } }
            else { return true; }
        }
        else {
            if (c > 47 && c < 52) { return true; }
            else { return false; }
        }
    }
    else {
        return false;
    }
}
//Accepts only Numeric and 0 should not be in the Beginning
function chkNumeric_WithoutStartingZero(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;

    if (e.shiftKey && c == 37) return false;
    // Checking if the 0 is in the beginning
    if (event.keyCode == 48 && e == '') {
        return false;
    }

    if ((c > 47 && c < 58) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else { return false; }
}
function chkNumber_WithoutStartingZero(e) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    var selection = document.selection.createRange();
    var selected_text = selection.text;
    if ((keycode == 46)) {
        return true;
    }
    //keycodes allowed but not in the beginning - 0
    if ((keycode == 48 || keycode == 96) && (selected_text != "")) {
        return false;
    }
    if ((!(keycode >= 48 && keycode <= 57) || !(keycode >= 96 && keycode <= 105)) && (keycode != 13)) {
        return false;
    }
    else return true;
}
// Accepts Characters, Numbers, Underscore (_) and Dot (.) with white spaces inbetween and
// Underscore and dot will not allowed in the beginning
function ValidateUserName(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;
    // Checking if the Underscore, Dot and White Space is in the beginning
    if ((c == 95 || c == 45 || c == 46 || c == 32) && e == '') {
        return false;
    }
    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 95) || (c == 45) || (c == 45) || (c == 47) || (c == 46) || (c == 32) || (c > 47 && c < 58) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else { return false; }
}
// Accepts only Characters and Dot (.) with white spaces inbetween and
// dot will not allowed in the beginning
function chkCharWithDot(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;
    // Checking if the Dot and White Space is in the beginning
    if ((c == 46 || c == 32) && e == '') {
        return false;
    }
    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 46) || (c == 32) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else return false;
}
// Accepts only Numbers and Dot (.) without white spaces inbetween 
// Accept Decimal Numbers
function chkDecNums(e, obj) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = (window.event) ? e.keyCode : e.which;
    if (e.shiftKey && c == 37) return false;
    if (c == 46 && obj.value.indexOf(".") != -1) {
        return false;
    }
    if ((c >= 48 && c <= 57) || c == 0 || c == 8 || c == 46 || c == 13 || c == 9 || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
        return true;
    else
        return false;
}

// Accepts only Characters and Dot (.) with white spaces inbetween and
// dot will not allowed in the beginning
function chkCharWithDotAndUnderScore(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;
    // Checking if the Dot and White Space is in the beginning
    if ((c == 46 || c == 32) && e == '') {
        return false;
    }
    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c == 95) || (c == 46) || (c == 32) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else return false;
}
// Accepts all keys except white spaces and Less than Symbol
function chkPassword(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if ((e.shiftKey && c == 37)) return false;
    if (!(c == 32 || c == 60 || c == 34 || c == 39) || (c == 45) || (c == 47) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46) {
        return true;
    }
    else { return false; }
}
function chkAlphaNumericWithSpaceDesc(e, object, MaxLength) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    if (c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37) {
        return true;
    }
    if (object.value.length > MaxLength) {
        return false;
    }
    if (((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c == 32) || (c > 47 && c < 58))) {
        return true;
    }
    else { return false; }
}
// Restrict the character < - 60 for Descriptions
function chkDescription(e, object, MaxLength) {
    if (!e) e = window.event;
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    if (e.shiftKey && c == 37) return false;
    // Check the length of the Description
    if (c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || (c == 45) || (c == 47) || c == 127 || c == 37 || c == 46 || c == 38 || c == 40) {
        return true;
    }
    if (object.value.length > MaxLength) return false;
    if (c == 60 || c == 39 || c == 34) return false;
    else return true;
}
// Restrict the Script Tag '<' in the Description Fields
function disallowScriptTags(txtDescription) {
    var temp = new String(txtDescription.value);
    var charIdx = temp.indexOf("<");
    while (charIdx > -1) {
        temp = temp.replace("<", "");
        charIdx = temp.indexOf("<");
    }
    temp = temp.replace(/(^\s*)|(\s*$)/gi, "");
    temp = temp.replace(/[ ]{2,}/gi, " ");
    temp = temp.replace(/\n /, "\n");
    txtDescription.value = temp;
}
function setFocus(event, control) {
    if (event.keyCode == 9) {
        document.getElementById(control).focus();
        return false;
    }
    else {
        return true;
    }
}
function LoadOrgLogo(id) {
    //if (validateUploadLogo(id)) {
    document.getElementById('hdnOrgLogo').value = '';
    document.getElementById('hdnOrgLogo').value = document.getElementById('fuOrgLogo').value;
    document.getElementById('btnLoadLogo').click();
    //}
}
//function validateUploadLogo(obj) {
//    var fileName = new String();
//    var fileExtension = new String();
//    var validFile = ".jpg,.jpeg";
//    var validFileExtensions = validFile.split(',');
//    var flag = false;
//    // store the file name into the variable
//    fileName = document.getElementById(obj).value;
//    // extract and store the file extension into another variable
//    fileExtension = fileName.substr(fileName.lastIndexOf('.'), fileName.length);
//    // Check over the valid file extensions to compare them with uploaded file
//    for (var i = 0; i < validFileExtensions.length; i++) {
//        if (fileExtension.toLowerCase() == validFileExtensions[i].toString().toLowerCase()) {
//            flag = true;
//        }
//    }
//    // display the alert message box according to the flag value
//    if (flag == false) {
//        alert('Please upload only JPG/JPEG files.');
//        var file = document.getElementsByName('<%=fpDriver.UniqueID %>')[0];
//        file.value = "";
//        var file1 = file.cloneNode(false);
//        file1.onchange = file.onchange;
//        file.parentNode.replaceChild(file1, file);
//        return false;
//    }
//    else {
//        return true;
//    }
//}
function chkTempNums(e, obj) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = (window.event) ? e.keyCode : e.which;
    if (e.shiftKey && c == 37) return false;
    if (c == 46 && obj.value.indexOf(".") != -1) {
        return false;
    }
    if (obj.value.length == 0 && (c == 45 || c == 43)) {
        return true;
    }

    if ((c >= 48 && c <= 57) || c == 0 || c == 8 || c == 46 || c == 13 || c == 9 || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
        return true;
    else
        return false;
}
function chkDialNo(e, obj) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = (window.event) ? e.keyCode : e.which;
    if (e.shiftKey && c == 37) return false;
    if (c == 46 && obj.value.indexOf(".") != -1) {
        return false;
    }
    if (obj.value.length == 0 && c == 43) {
        return true;
    }
    if ((c >= 48 && c <= 57))
        return true;
    else
        return false;
}

function ValidateVehiclePurchaseDate(sender, args) {
    var fromDate = new Date();
    // Subtract 20 yrs from Current Date
    fromDate.setYear(fromDate.getYear() - 20);

    if (sender._selectedDate >= new Date()) {
        alert("Please select current or past date.");
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
    else if (sender._selectedDate < fromDate) {
        alert("Selected Vehicle's Purchase Date is too past.");
        sender._selectedDate = new Date();
        sender._textbox.set_Value("");
    }
}

// Accepts only Characters and Hyphen with UnderScore 
function chkCharWithHyphenAndUnderScore(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;
    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c == 95) || (c == 32) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 45)
    { return true; }
    else return false;
}

// Accepts Alpahnumeric with Whitespace only
function chkAlphaNumeric(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;

    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c == 95) || (c == 32) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37)
    { return true; }
    else return false;

}

// Accepts Characters and number with dot (.) with white spaces inbetween 
function chkCharNumWithDot(e) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = e.keyCode ? e.keyCode : e.which;  //event.keyCode;
    if (e.shiftKey && c == 37) return false;

    if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c == 95) || (c == 32) || c == 8 || c == 9 || c == 13 || c == 0 || c > 60000 || c == 127 || c == 37 || c == 46)
    { return true; }
    else return false;
}

// Accepts only Numbers and Dot (.) and minus without white spaces inbetween 
// Accept Decimal Numbers
function chkDecNumsWithMinus(e, obj) {
    if (!e) e = window.event;
    if (e.charCode != null) {
        if (e.charCode == 0) {
            return true;
        }
    }
    var c = (window.event) ? e.keyCode : e.which;
    
    if (e.shiftKey && c == 37) return false; 
    if (c == 46 && obj.value.indexOf(".") != -1) {
        return false;
    }

    if (c == 45 && obj.value.indexOf("-") != -1) {
        return false;
    }
//    if (c == 45 && obj.value.charAt(0) != "") {
//        return false;
//    }
    if ((c >= 48 && c <= 57) || c == 0 || c == 8 || c == 46 || c == 13 || c == 9 || c > 60000 || c == 127 || c == 37 || c == 45)
        return true;
    else
        return false;
}
function CalendarTab(e) {

    if (!e) e = window.event;

    var c = e.keyCode ? e.keyCode : e.which;

    if (c == 9) {

        return true;
    }
    else {

        return false;
    }
}
// Function for Allowing Only Alpha numeric with  one Space between Characters
function ChkText(key, obj) {
    //getting key code of pressed key
    var keycode = (key.which) ? key.which : event.keyCode;

    //comparing pressed keycodes
    if ((obj.value.length == 0) && keycode == '32') {
        return false;
    }
    else {
        var strText = obj.value;
        if (strText !== " " || strText !== null) {

            var n = strText.length - 1;
            var s = strText[n];
            if (s == " ") {
                if (((keycode >= '65') && (keycode <= '90')) || ((keycode >= '97') && (keycode <= '122')) || (keycode == '46') || (keycode == '8') || (keycode == '13') || (keycode == '64') || (keycode == '95') || (keycode >= '48') && (keycode <= '57') || (keycode == '9')) {

                    return true;
                }
                else { return false; }
            }
            else {
                if (((keycode >= '65') && (keycode <= '90')) || (((keycode >= '42') || (keycode <= '47')) || (keycode >= '97') && (keycode <= '122')) || (keycode == '46') || (keycode == '8') || (keycode == '13') || (keycode == '32') || (keycode == '64') || (keycode == '95') || (keycode >= '48') && (keycode <= '57') || (keycode == '9')) {
                    return true;
                }
                else {
                    return false;
                }
            }

        }

        else {
            if (((keycode >= '65') && (keycode <= '90')) || ((keycode >= '42') || (keycode <= '47')) || ((keycode >= '97') && (keycode <= '122')) || (keycode == '46') || (keycode == '8') || (keycode == '13') || (keycode == '64') || (keycode == '95') || (keycode >= '48') && (keycode <= '57') || (keycode == '9')) {

                return true;
            }
            else {
                return false;
            }
        }
    }
}

function validateEmail(elementValue) {
    var emailPattern = /^([a-zA-Z0-9])(([a-zA-Z0-9])*([\._-])?([a-zA-Z0-9]))*@(([a-zA-Z0-9\-])+(\.))+([a-zA-Z]{2,4})+$/;
    ///^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    return emailPattern.test(elementValue);
}

function RemoveSpaces(fieldName) {
    var s;
    if (typeof (fieldName) == 'object') {
        s = fieldName.value;
    }
    else {
        s = fieldName;
    }
    s = s.replace(/(^\s*)|(\s*$)/gi, "");
    s = s.replace(/[ ]{2,}/gi, " ");
    s = s.replace(/\n /, "\n");
    if (typeof (fieldName) == 'object') {
        fieldName.value = s;
    }
    return s;
}

function CheckIsSelected(dropdownvalue) {
    return dropdownvalue != '- Select -' ? true : false;
}
// Trim function removes extra spaces 
function Trim(str) {
    while (true) {
        if (str.charAt(0) == ' ')
            str = str.substr(1);
        else
            break;
    }

    while (true) {
        if (str.charAt(str.length - 1) == ' ')
            str = str.substr(0, str.length - 1);
        else
            break;
    }
    return (str);
}


function validateTime(evt, el) {
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (el.value.indexOf(".") > 2 || el.value.indexOf(".") == -1 || el.value.length - el.value.indexOf(".") - 1 > 2) {
        TrinetraCustomAlerts('Invalid Time Duration kindly enter the duration as hh.mm!');
        el.value = '';
        return false;
    }
    var vlue = el.value.split(".");
    var err = ((vlue[0] > 5) ? true : (vlue[1] > 60) ? true : false);
    if (err) {
        TrinetraCustomAlerts('Invalid Time!');
        el.value = '';
        return false;
    }
    return true;
}

function fun_CheckDecimal(Obj, left, right) {
    var value = Obj.value;
    var len = value.length;
    var AddDecimal = value;
    var index_of_num = value.indexOf(".");
    var After_Decimal = index_of_num + 1;
    var total_decnum = left + right + 1;
    if (index_of_num >= 0) {
        var right_numval = value.substr(After_Decimal, total_decnum);
        var right_numval_Length = right_numval.length;
        if (right_numval_Length > right) {
            var tot_val = index_of_num + right_numval_Length;
            var final_val = value.substr(0, tot_val);
            document.getElementById(Obj.id).value = final_val;
            return false;
        }
    }
    else if (len > left) {
        if (len == left + 1) {
            var value_of_leftnum = value.substring(0, left);
            var index_of_rightnum = value.substring(left, total_decnum);
            AddDecimal = value_of_leftnum + "." + index_of_rightnum;
        }
        document.getElementById(Obj.id).value = AddDecimal;
    }
}
function ValidateFileEmpty(obj,Flupctrl) {
    var file = document.getElementById(Flupctrl);
    if (file.value == "") {
        TrinetraCustomAlerts("Please choose the file to import the Details.");
        return false;
    }
}
function checkEmail(cont, str) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (!re.test(str)) {
        //cont.focus();
        //document.getElementById(cont).focus();
        TrinetraCustomAlerts("Please enter a valid email address");
        return false;
    }
}
