function TrimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function IsDomain(domain) {
    if (domain.match(/^[A-Za-z0-9_\.\-]+$/g)) {    // matches a-z, A-Z, 0-9, ., -, _
        if (domain.match(/^\-|^\./) || domain.match(/\-$|\.$/)) {
            return false;
        }
        if (domain.indexOf(".") == -1) {
            return false;
        }
        return true;
    }
    else {
        return false;
    }
}

function IsEmail(email)
{
    var theStr = new String(email);
    var index = theStr.indexOf("@");
    if (index >= 1)
    {
        /*
        // commented by cheryl - 05 Aug 2004
        var pindex = theStr.indexOf(".",index);
        if ((pindex > index+2) && (theStr.length > pindex+2))
            return true;
        */

        // check first part of email
        var szEmail = theStr.substring(0, index);
        if (szEmail.match(/^[A-Za-z0-9_\.\-]+$/g)) {
            if (szEmail.match(/^\./) || szEmail.match(/\.$/)) {
                return false;
            }
            // check domain
            var szDomain = theStr.substr(index+1);
            if (IsDomain(szDomain)) {
                return true;
            }
        }
    }
    return false;
}

function IsAlphaNumeric(str)
{
    // if-else added by cheryl - 12/May/04
    if (str.match(/\W/)) { // matches other than a-z, A-Z, 0-9, _
        return false;
    }
    else {
        return true;
    }

    var i;
    for(i=0; i < str.length; i++)
    {
        if(!(((str.charAt(i) <= '9') && (str.charAt(i) >= '0')) ||
            ((str.charAt(i) <= 'z') && (str.charAt(i) >= 'a')) ||
            (str.charAt(i) == ' ') || (str.charAt(i) == '-') ||
    /*  (str.charAt(i) == '???') || (str.charAt(i) == '???') ||
            (str.charAt(i) == '???') || (str.charAt(i) == '???') ||
            (str.charAt(i) == '???') || (str.charAt(i) == '???') ||
            (str.charAt(i) == '???') || (str.charAt(i) == '???') || */
            (str.charAt(i) == '.') || (str.charAt(i) == '_') ||
            (str.charAt(i) == '*') ||
            (str.charAt(i) == '@') || ((str.charAt(i) <= 'Z') && (str.charAt(i) >= 'A')) ))
            return(false);
    }
    return(true);
}
