function textIsEntered(id) {
    var txt;
    txt = document.getElementById(id);
    if (txt) {
        if (trim(txt.value) != '') {
            return true;
        }
    }
    return false;
}

function optionIsSelected(id) {
    var ddl;
    ddl = document.getElementById(id);
    if (ddl) {
        if (ddl.options[ddl.selectedIndex].value != '') {
            return true;
        }
    }
    return false;
}

function isValidateEmail(id) {
    var txt
    txt = document.getElementById(id);
    str = trim(txt.value)
    var bIsEmail = true
    var at = '@';
    var dot = '.';
    var lat = parseInt(str.indexOf(at));
    var ldot = parseInt(str.lastIndexOf(dot));
    var lstr = parseInt(str.length);

    //no '@' or '@' is first character or '@' is the last character
    if ((lat <= 0) || (lat == parseInt(lstr - 1)))
        bIsEmail = false;

    //no '.' or '.' is first character or '.' is the last character
    if (bIsEmail && (ldot <= 0) || (ldot == parseInt(lstr - 1)))
        bIsEmail = false;

    //presence of another '@'
    if (bIsEmail && str.indexOf(at, parseInt(lat + 1)) != -1)
        bIsEmail = false;

    //presence of '.' before or after '@'
    if (bIsEmail && (str.substr(parseInt(lat - 1), 1) == dot) || (str.substr(parseInt(lat + 1), 1) == dot))
        bIsEmail = false;

    //check '.' is at least one character after '@'
    if (bIsEmail && str.indexOf(dot, parseInt(lat + 2)) == -1)
        bIsEmail = false;

    //check for blank
    if (bIsEmail && str.indexOf(" ") != -1)
        bIsEmail = false;

    //check the length after the last '.' is not less than 2 characters
    if (bIsEmail && str.substr(parseInt(ldot + 1)).length < 2)
        bIsEmail = false;

    if (bIsEmail && !isAlphaNumeric(str.substr(ldot + 1)))
        bIsEmail = false;

    if (bIsEmail) {
        return true;
    }
    else {
        return false;
    }
}

function isAlphaNumeric(str) {
    for (i = 0; i < str.length; i++) {
        if (!((str.charCodeAt(i) >= 97) && (str.charCodeAt(i) <= 122)) && !((str.charCodeAt(i) >= 65) && (str.charCodeAt(i) <= 90)) && !((str.charCodeAt(i) >= 48) && (str.charCodeAt(i) <= 57))) {
            return false;
        }
    }
    return true;
}

function trim(inputString) {
    var retValue = inputString;
    var ch = retValue.substring(0, 1);

    while (ch == " ") { // Check for space at the start of the string
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }

    ch = retValue.substring(retValue.length - 1, retValue.length);

    while (ch == " ") { // Check for spaces at the end of the string
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }

    return retValue;
}