function toupper(elmid)
{
        var elm = document.getElementById(elmid);
        elm.value=elm.value.toUpperCase();
        return;
}

function isSingleChar(elmid)
{
        return false;
}




function isAlphaOnly(elmid)
{
        var elm = getElm(elmid);
        var nums="1234567890";
        var blnresult=true;

        for (var iter=0; iter<elm.value.length; iter++)
        {

                if (nums.indexOf(elm.value.charAt(iter)) != -1)
                {
                        return false;
                }
        }

        return blnresult;
}

function getSecurityNum(secfield)
{
        switch (secfield)
        {
                case "sec_town":
                        return 1;
                        break;
                case "sec_tele":
                        return 3;
                        break;
        case "sec_mmaiden":
                        return 5;
                        break;
                case "sec_eyecolour":
                        return 6;
                        break;
        case "sec_fatherfore":
                        return 7;
                        break;
                case "sec_natinsure":
                        return 8;
                        break;
        case "sec_passport":
                        return 9;
                        break;
        }



}

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 getElm(elmid)
{
        return document.getElementById(elmid);
}

function error_message(elmid, message)
{
        alert(message);
        getElm(elmid).focus();
        return;
}

// 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 verifies that a value has 7 or 8 digits, returns true if
// it does, false if it does not
function check_post(elmid)
{
        var post=stripSpaces(getElm(elmid).value);
        if (post.length < 5 || post.length > 7)
        {
                return false;
        }

        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 checkdate(elmid)
{
        // check for and use mm/dd/yyyy format
        var datestr = getElm(elmid).value;
        var datearray = datestr.split("/");

        if (datestr.length != "10")
                return false;

        if (datearray.length != "3")
                return false

        return true;
}
