﻿function isAlphabet(txtBox) {
    var strLength = txtBox.value.length;
    var lchar = txtBox.value.charAt((strLength) - 1);

    var alphaExp = /^[a-zA-Z ]+$/;
    if (!lchar.match(alphaExp)) {
        var tempText = txtBox.value;
        txtBox.value = tempText.replace(lchar, '')
        return false;
    }
}
function checkNumberAllowDecimalPointAndMinus(txtBox) {
    var strLength = txtBox.value.length;
    var lchar = txtBox.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);



    /* Check if the keyed in character is a number
    do you want alphabetic UPPERCASE only ?
    or lower case only just check their respective
    codes and replace the 48 and 57 */

    if (cCode != 45 && cCode != 46 && (cCode < 48 || cCode > 57)) {
        var myNumber = txtBox.value.substring(0, (strLength) - 1);
        txtBox.value = myNumber;
    }
    return false;
}
function checkNumberAllowDecimalPoint(txtBox) {
    var strLength = txtBox.value.length;
    var lchar = txtBox.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);

    /* Check if the keyed in character is a number
    do you want alphabetic UPPERCASE only ?
    or lower case only just check their respective
    codes and replace the 48 and 57 */

    if (cCode != 46 && (cCode < 48 || cCode > 57)) {
        var myNumber = txtBox.value.substring(0, (strLength) - 1);
        txtBox.value = myNumber;
    }
    return false;
}
function checkNumber(txtBox) {
    var strLength = txtBox.value.length;
    var lchar = txtBox.value.charAt((strLength) - 1);
    var cCode = CalcKeyCode(lchar);

    /* Check if the keyed in character is a number
    do you want alphabetic UPPERCASE only ?
    or lower case only just check their respective
    codes and replace the 48 and 57 */

    if (cCode < 48 || cCode > 57) {
        var myNumber = txtBox.value.substring(0, (strLength) - 1);
        txtBox.value = myNumber;
    }
    return false;
}
function CalcKeyCode(aChar) {
    //var character = aChar.substring(0,1);
    //var code = aChar.charCodeAt(0);
    //return code;
    return aChar.charCodeAt(0);
}
function copySurnames(surname) {
    if (!surname) { return; }

    var i = 0;
    var inputs = document.getElementsByTagName("input");
    for (i = 0; i < inputs.length; i++) {
        if (inputs[i].type == "text" && inputs[i].id.indexOf('txtlast') > -1) {
            if (inputs[i].value == "") { inputs[i].value = surname.value; }
        }
    }
}

function convertToTitleCase(txtBox) {
    txtBox.value = txtBox.value.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}

function hideMe(element) {
    element.style.display = 'none';
}
