﻿// 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
    }
}
// Accepts only Numeric for date and allow up to 31
//Included by Sakthi on 27-Jul-2011
function chkNumeric_only_ForDate(e,id) {
    debugger;
    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;
    }

  


 
    
