
function isAlphaOnly(elmid)
{
        var elm = getElm(elmid);

		var accepted="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        var blnresult=true;

        for (var iter=0; iter<elm.value.length; iter++)
        {

                if (accepted.indexOf(elm.value.charAt(iter)) == -1)
                {
                        return false;
                }
        }

        return blnresult;
}


function hasSpaces(elmid)
{
        var elm=getElm(elmid);

        if (elm.value.indexOf(" ") != -1)
        {
                return true;
        } else {
                return false;
        }

}
function isBlank(elmid)
{

        var elm = getElm(elmid);


        if (elm.value.length == 0)
        {
                return true;
        }
}

function isAtLeast(elmid,elmsize)
{

        var elm = getElm(elmid);

        if (elm.value.length < parseInt(elmsize))
        {
                return true;
        } else {
                return false;
        }
}

function compareElms(elmid1,elmid2)
{

        var elm1 = getElm(elmid1);
        var elm2 = getElm(elmid2);

        if (elm1.value != elm2.value)
        {
                return true;
        } else {
                return false;
        }
}



// checks an email address. Returns true if it is ok,
// false otherwise.
function check_email(elmid)
{
        var strval = document.getElementById(elmid).value;
        var atpos="";
        var dotpos="";

        // at least six characters, an @ and a dot

        // if there is no at sign, save us the trouble
        if ((atpos = strval.indexOf("@")) == -1) return false;
        // if there is no dot in the email, also save us the trouble.
        if ((dotpos = strval.lastIndexOf(".")) == -1) return false;
        // if the email is not at least six characters (x@x.com), save us the trouble
        if (strval.length < 6) return false;

  // disallow special characters
        var specialchars = new Array("\'","\"", "!", "#", "$", "%", "^", "&", "*", "(", ")", "=", "+", "{", "}", "[", "]", " ", "|", "\\", "~", "`", ",","/", "?");

        for (var iter = 0; iter < specialchars.length; iter++)
        {
                if (strval.indexOf(specialchars[iter]) != -1)
                {
                        return false;
                }
        }


        return true;

}

// function should verify that a phone # has 11 characters,
// all numeric. Spaces should be removed prior to checking
function check_phone(elmid)
{

        var phoneval = getElm(elmid).value;
        phoneval = stripSpaces(phoneval);

        if (!isNumeric(elmid)) return false;

        if (phoneval.length < 11)
        {
                return false;
        } else {
                return true;
        }
}

// function returns the string passed in after removing spaces
function stripSpaces(strval)
{
        var retval = strval.replace(" ", "");
        return retval;

}

function isNumeric(elmid)
//  check for valid numeric strings
{
        var strString = getElm(elmid).value;

        var strValidChars = "0123456789/\\ .-";
        var strChar;
        var blnResult = true;

        if (strString.length == 0) return false;

        //  test strString consists of valid characters listed above
        for (i = 0; i < strString.length && blnResult == true; i++)
                {
                strChar = strString.charAt(i);
                if (strValidChars.indexOf(strChar) == -1)
                         {
                         blnResult = false;
                         }
                }
        return blnResult;
}


function blankField(elmid, message)
{
        if (isBlank(elmid))
        {
                error_message(elmid, message);
                return false;
        } else {
                return true;
        }
}

function isSingleChar(elmid)
{
		var elm = getElm(elmid);

        if (elm.value.length == 1)
        {
                return true;
        }

        return false;
}

