/* Browser-independent function to get the character that was entered
 * by a keyboard event. 
 * from http://www.codeproject.com/useritems/keyboard_restrict_spanish.asp
 */
function getKeyCode(event)
{
    if (window.event) {
        return window.event.keyCode;
    } else if (event) {
        return event.which;
    } else {
        return null;
    }
}

/* function to indicate if a given key press represents a valid
 * character according to the (case-insensitive) chars in validchars.
 * from http://www.codeproject.com/useritems/keyboard_restrict_spanish.asp
 */
function keyRestrict(e, validchars) 
{
    if (! validchars) {
        return true;
    }
    validchars = validchars.toLowerCase();
    
    
    var key='', keychar='';
    key = getKeyCode(e);
    if (key == null) {
        return true;
    }
    
    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();
    
    if (validchars.indexOf(keychar) != -1) {
        return true;
    }
    
    if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 ) {
        return true;
    }
    
    return false;
}

/* returns true if the character in the current event is numeric.
 */
function restrictToNum(event)
{
    return keyRestrict(event, "1234567890");
}

/* returns true if the character in the current event is a character.
 */
function restrictToAlpha(event)
{
    return keyRestrict(event, "abcdefghijklmnopqrstuvwxyz");
}

function restrictToAlphaNum(event)
{
    return keyRestrict(event, "01234567890abcdefghijklmnopqrstuvwxyz");
}

/* returns true if the character in the current event is a valid character
 * for a phone number of (xxx) xxx-xxxx or xxx-xxx-xxxx or xxx.xxx.xxxx
 * or xxxxxxxxxx or xxx xxx xxxx
 */
function restrictToPhone(event)
{
    return keyRestrict(event, "()- 0123456789.");
    if (textInput && isNumeric(textInput.value))	 {
        alert("returning true");
        return true;
    } else {
        alert("returning false");
        return false;
    }
}