function validFileGreeting(obj, error)
{
    var re = /(\.wav|\.mp3)$/gi;
    value = obj.value;
    if (!re.test(value)){
        //alert("Your uploading file is in the incorrect format. The file must be a WAV or MP3 file.");
        alert("Missing or invalid file.");
        obj.focus();
        return false;
    }
    return true;
}

function isOnlyDigits(value)
{
    var re = /^\d+$/;
    return re.test(value);
}

function isValidEmail (emailStr) {
    // for domain names 
    var emailPat=/^(.+)@(.+)$/
    var allowedSymbolsDomain   =  "[a-zA-Z0-9]+"
    var allowedSymbolsDomain_middle   =  "[a-zA-Z0-9\-]+"
    var atom_domain = "(" +allowedSymbolsDomain +"|" +allowedSymbolsDomain+allowedSymbolsDomain_middle+allowedSymbolsDomain+")";
    var domainPat=new RegExp("^" + atom_domain + "(\\." + atom_domain +")*$")
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

    // login name
    var validChars="[a-zA-Z0-9]"
    var atom=validChars + '+'
    var word = "(" + atom + ")";
    var userPat=new RegExp("^" + word + "([\\.\\-\\_]?" + word + ")*" + "$");
    if (emailStr.length > 320 ||  emailStr.length < 5)
        return false;
    var matchArray=emailStr.match(emailPat)
    if (matchArray==null)
        return false;
        
    var user=matchArray[1]
    var domain=matchArray[2]

    // See if "user" is valid 
    if (user.match(userPat)==null)
        return false

    /* if the e-mail address is at an IP address (as opposed to a symbolic
       host name) make sure the IP address is valid. */
    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {
        // this is an IP address
          for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
                //alert("Destination IP address is invalid!")
            return false;
            }
        }
        return true;
    }

    // Domain is symbolic name
    var domainArray=domain.match(domainPat)
    if (domainArray==null)
        return false
    /* domain name seems valid, but now make sure that it ends in a
       three-letter word (like com, edu, gov) or a two-letter word,
        representing country (uk, nl), and that there's a hostname preceding 
       the domain or country. */

    var atomPat=new RegExp(allowedSymbolsDomain,"g")
    var domArr=domain.match(atomPat)
    var len=domArr.length
    if (domArr[domArr.length-1].length<2 || 
        domArr[domArr.length-1].length>4) {
           return false;
    }
    // Make sure there's a host name preceding the domain.
    if (len<2) {
       return false
    }

return true;
}

function isValidCreditCard(type, obj, error)
{
    var ccnum = obj.value;
    if (ccnum.length == 0){
        alert(error +" is required.");
        obj.focus();
        return false;
    }   
    var re = /^\d{1,}$/;
    if (!re.test(ccnum))
    {
        alert(error +" is invalid. The credit card number must contain only digits.");
        obj.focus();
        return false;
    }       
    return true;
}

/*
function isValidCreditCard(type, obj, error)
{
    var ccnum = obj.value;
    if (ccnum.length == 0){
        alert(error +" is required.");
        obj.focus();
        return false;
    }   
    if (type == "Visa")
    {
        // Visa: length 16, prefix 4, dashes optional.
        var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
        if (!re.test(ccnum))
        {
            alert(error +" is invalid. The first digit must be 4 and the credit card number must contain 16 digits (dashes optional).");
            obj.focus();
            return false;
        }       
    } else if (type == "Master Card")
    {
        // Mastercard: length 16, prefix 51-55, dashes optional.
        var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
        if (!re.test(ccnum))
        {
            alert(error +" is invalid. The first two digits must be from 51 to 55 and the credit card number must contain 16 digits (dashes optional).");
            obj.focus();
            return false;
        }       
    } else if (type == "American Express") {
        // American Express: length 15, prefix 34 or 37.
        var re = /^3[4,7]\d{13}$/;
        if (!re.test(ccnum))
        {
            alert(error +" is invalid. The first two digits must be from 34 or 37 and the credit card number must contain 15 digits.");
            obj.focus();
            return false;
        }       
    } 

    // Remove all dashes for the checksum checks to eliminate negative numbers
    ccnum = ccnum.split("-").join("");
    // Checksum ("Mod 10")
    // Add even digits in even length strings or odd digits in odd length strings.
    var checksum = 0;
    for (var i=(2-(ccnum.length % 2)); i<=ccnum.length; i+=2) {
        checksum += parseInt(ccnum.charAt(i-1));
    }
    // Analyze odd digits in even length strings or even digits in odd length strings.
    for (var i=(ccnum.length % 2) + 1; i<ccnum.length; i+=2) {
        var digit = parseInt(ccnum.charAt(i-1)) * 2;
        if (digit < 10) { checksum += digit; } else { checksum += (digit-9); }
    }
    if ((checksum % 10) == 0)
    {
        return true;
    } else
    {
        alert(error + " is invalid.");
        obj.focus();
        return false;
    }
}
*/