/*
 *
 *     validator = new formValidator( [formid] ); - create a validator object
 *     validator.addRule ( [element id] , callback); - adds a rule to the validator.
 *                                                     the callback returns the message to display or
 *                                                     an empty string for no error.
 *     validator.checkForm();   - validates the form
 *     validator.setError( [element id], [ message ] );
 *     validator.clearError( [ element id ]);
 *
 *     validator attribute tags;
 *
 *     reqtype:     req
 *                  len:[number]
 *                  nopunc
 *                  currency
 *                  phone
 *                  email
 *                  int
 *                  date (mm/dd/yyyy format)
 *
 *     vinfo:       contains the element id of where validation error is displayed
 *
 *     sample:
 *
 *     <td>Account Name:</td>
 *     <td><input reqtype="req,len:32,nopunc" vinfo="account_info" type="text" name="accountname" id="accountname" title="account name" /></td>
 *     <td><span class="validationerror" id="account_info"></span></td>
 *
 *
 */

function formValidator(formid)
{
    if (! document.getElementById(formid)) {
        alert("FormValidator Init Error.  " + formid + " does not exist.");
        return null;
    }

    this.id = formid;
    this.checkForm = formValidator.prototype.checkelements;
    this.setupForm = formValidator.prototype.setupform;
    //this.failcolor = "#F3E6E6";
    this.failcolor = "#FFFFC0";
    this.passcolor = "#FFFFFF";
    this.failbordercolor = "#AA0000";
    this.passbordercolor = "#333333";
    this.rules = new Array();

    this.setupForm();

    return this;
}

formValidator.prototype.isInteger = function(s)
{
    var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (! (i == 0 && (c == "-" || c == "+"))) {
            if (((c < "0") || (c > "9"))) return false;
        }
    }
    // All characters are numbers.
    return true;
}

formValidator.prototype.stripCharsInBag = function(s,bag)
{
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

formValidator.prototype.daysInFebruary = function (year)
{
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

formValidator.prototype.DaysArray = function(n)
{
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
    }
    return this;
}

formValidator.prototype.isDate = function(dtStr)
{
    var s = "";

    if (dtStr.length == 0) {
        s = "Is not a valid date.";
        return s;
    }

    var dtCh= "/";
    var d = new Date();
    var curr_year = d.getFullYear();

    var minYear=curr_year;
    var maxYear=curr_year + 2;
    minYear = 0;

    var daysInMonth = this.DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strMonth=dtStr.substring(0,pos1)
    var strDay=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear

    if (strYr.length > 4) {
        s = "Your year contains too many digits.  Date format should be : mm/dd/yyyy.";
    }
    if (strYr.length < 4) {
        s = "Your year contains too few digits.  Date format should be : mm/dd/yyyy.";
    }
    if (strMonth.length > 2) {
        s = "Your month contains too many digits.  Date format should be : mm/dd/yyyy.";
    }

    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }

    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)

    if (pos1==-1 || pos2==-1){
        s = "Date format should be : mm/dd/yyyy.";
    }

    if (strMonth.length<1 || month<1 || month>12){
        s = "Month is not a valid value.";
    }

    if (strDay.length<1 || day<1 || day>31 || (month==2 && day > this.daysInFebruary(year)) || day > daysInMonth[month]){
        s = "Day value is not valid.";
    }

    if (minYear != 0) {
        if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
            s = "Year value should be between "+minYear+" and "+maxYear+".";
        }
    }

    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || this.isInteger(this.stripCharsInBag(dtStr, dtCh))==false){
        s = "Invalid date.";
    }

return s;

}

formValidator.prototype.containsPunctuation = function(value)
{
    var Chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (var i = 0; i < value.length; i++)
    {
        if (Chars.indexOf(value.charAt(i)) == -1)
        {
            return true;
        }
    }
    return false
}

formValidator.prototype.validCurrency = function(temp_value)
{
    if (temp_value == "")
    {
        return false;
    }

    var Chars = "0123456789.,$";
    for (var i = 0; i < temp_value.length; i++)
    {
        if (Chars.indexOf(temp_value.charAt(i)) == -1)
        {
            return false;
        }

        if ( i > 0 && temp_value.charAt(i) == "$" ) {
            return false;
        }
    }
    return true
}

formValidator.prototype.isUrl = function (s)
{
        var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
        //var regexp = / (http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/;
        //var regexp = /^(http|https)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/
        //var regexp = '^((ht|f)tp(s?)\:\/\/|~/|/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((/?\w+/)+|/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?';
        //var regexp = '/^(http(s?):\/\/{1})((\w+\.){1,})\w{2,}(\/?)$/i';
        return regexp.test(s);
}

formValidator.prototype.validEmail = function (email)
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) {
        return false;
    }

    return true;
}

formValidator.prototype.isRequired = function(a)
{
    var op = a.split(",");
    for (j=0;j<op.length;j++) {
        if (op[j]=="req") {
            return true;
        }
    }
    return false;
}

formValidator.prototype.setupform = function()
{
    var self = this;

    if (! document.getElementById(this.id)) return false;

    var tags = document.getElementById(this.id).getElementsByTagName("*")
    var len = tags.length;

    for (var i=0;i < len;i++) {

        var a = tags[i].getAttribute("reqtype");
        var v = tags[i].getAttribute("vinfo");

        if (a && (a != "")) {

            var id = trim(tags[i].id);

            if ( id != "" ) {
                var elem = document.getElementById(id);

                elem.onchange = function() { self.checkelement(this.id)};
                elem.onkeyup = function() { self.checkelement(this.id)};

                if (!v || (v==null) || (v == "")) {
                    var verr = document.createElement("span");
                    verr.setAttribute("class", "validationerror");
                    verr.setAttribute("id", "info_"+id);
                    elem.setAttribute("vinfo","info_"+id);
                    elem.parentNode.appendChild(verr)
                    v = "info_"+id;
                }

                if ( this.isRequired(a)) {
                    if (v && (v != "")) {
                        document.getElementById(v).innerHTML = "required";
                    }
                }
            }
        }
    }

    return true;
}

formValidator.prototype.addRule = function(name, rule)
{
    this.rules[name] = rule;
}

formValidator.prototype.getRule = function(name)
{
    return this.rules[name];
}

formValidator.prototype.setError = function(id,msg)
{
    if ( id && (id != "") && (msg != "") ) {
        var elem = document.getElementById(id);
        if ( elem && (elem != "") ) {
            elem.style.backgroundColor = this.failcolor;
            var vinfo = elem.getAttribute("vinfo");
            inlineMsg(vinfo,msg);
        }
    }
}

formValidator.prototype.clearError = function(id)
{
    if ( id && (id != "") ) {
        var elem = document.getElementById(id);
        if ( elem && (elem != "") ) {
            elem.style.backgroundColor = this.passcolor;
            elem.style.borderColor = this.passbordercolor;
            var vinfo = elem.getAttribute("vinfo");
            inlineMsg(vinfo,"");
        }
    }
}

formValidator.prototype.checkelements = function()
{
    var ret = true;
    var valid = true;
    var id = this.id;

    if (! document.getElementById(id)) return false;

    var tags = document.getElementById(id).getElementsByTagName("*")

    for (var i=0;i < tags.length;i++) {
        valid = this.checkelement(tags[i].id);
        if ( valid == false ) {
            ret = false;
        }
    }

    return ret;
}

formValidator.prototype.checkelement = function(id)
{
    var ret = true;

    if ( id == "" ) return true;

    if (document.getElementById(id)) {

        elem = document.getElementById(id);
        var vinfo = elem.getAttribute("vinfo");
        var a = elem.getAttribute("reqtype");
        if (a && (a != "")) {

            hideMsg(vinfo);
            elem.style.backgroundColor = this.passcolor;
            elem.style.borderColor = this.passbordercolor;
            var v = trim(elem.value);
            var n = trim(elem.title);
            if (n.length == 0) {
                n = trim(elem.name);
            }

            var op = a.split(",");
            for (j=0;j<op.length;j++) {

                if ( op[j]=="optional" && v =="" ) {
                    break;
                }

                if (op[j]=="req" && v=="") {
                    msg = "required"
                    elem.style.backgroundColor = this.failcolor;
                    elem.style.borderColor = this.failbordercolor;
                    inlineMsg(vinfo,msg);
                    ret = false;
                    break;
                }

                if (op[j].indexOf("int") != -1) {
                    if (! this.isInteger(v)) {
                        msg = "must be a number";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("posint") != -1) {
                    if (! this.isInteger(v)) {
                        msg = "must be a positive number";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                    if (parseInt(v) < 0) {
                        msg = "must be a positive number";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("negint") != -1) {
                    if (! this.isInteger(v)) {
                        msg = "must be a negative number";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                    if (parseInt(v) >= 0) {
                        msg = "must be a negative number";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("gt:") != -1) {
                    var vlen = op[j].split(":");
                    if (parseInt(v) <= parseInt(vlen[1])) {
                        msg = "must be a number greater than " + vlen[1];
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("lt:") != -1) {
                    var vlen = op[j].split(":");
                    if ( parseInt(v) >= parseInt(vlen[1]) ) {
                        msg = "must be a number less than " + vlen[1];
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("gte:") != -1) {
                    var vlen = op[j].split(":");
                    if ( parseInt(v) < parseInt(vlen[1]) ) {
                        msg = "must be a number greater than or equal to " + vlen[1];
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("lte:") != -1) {
                    var vlen = op[j].split(":");
                    if (parseInt(v) > parseInt(vlen[1])) {
                        msg = "must be a number less than or equal to " + vlen[1];
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("len:") != -1) {
                    var vlen = op[j].split(":");
                    if (v.length > parseInt(vlen[1])) {
                        msg = "must be no longer than " + vlen[1] + " characters";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("minlen:") != -1) {
                    var minlen = op[j].split(":");
                    if (v.length < parseInt(minlen[1])) {
                        msg = "must be longer than " + minlen[1] + " characters";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("cmp:") != -1) {
                    var cmp = op[j].split(":");
                    var vcmp = trim(document.getElementById(cmp[1]).value);
                    if (v != vcmp) {
                        msg = "does not match " + cmp[1];
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("nopunc") != -1) {
                    if (this.containsPunctuation (v)) {
                        msg = "cannot contain spaces or punctuation characters";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j].indexOf("email") != -1) {
                    if (! this.validEmail (v)) {
                        msg = "invalid email address";
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j]=="url") {
                    if ( v != "" && this.isUrl(v) == false ) {
                        msg = "not a valid site URL"
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j]=="select") {
                    if (v == "") {
                        msg = "required"
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j]=="currency") {

                    if (! this.validCurrency(v)) {
                        msg = "must be a currency value"
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j]=="date") {
                    var tmp = this.isDate(v);
                    if (tmp != "") {
                        msg = tmp;
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                if (op[j]=="phone") {
                    if (v.length < 7) {
                        msg = "invalid phone number.  phone numbers should be at least 7 digits long"
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }

                var rule = this.getRule(op[j]);
                if (rule) {
                    msg = rule(elem.id,v,"info_"+elem.id);
                    if (msg != "") {
                        elem.style.backgroundColor = this.failcolor;
                        elem.style.borderColor = this.failbordercolor;
                        setTimeout(function() {elem.focus();},500);
                        inlineMsg(vinfo,msg);
                        ret = false;
                        break;
                    }
                }
            }
        }
    }

    return ret;
}

// build out the divs, set attributes and call the fade function //
function inlineMsg(v,string)
{
    if (v && (v != "")) {
        var vinfo = document.getElementById(v);
        if ( typeof(vinfo) != "undefined" && vinfo != null ) {
            vinfo.innerHTML = string;
        }
    }
}

function hideMsg(v)
{
    if (v && (v != "")) {
        var vinfo = document.getElementById(v);
        if ( typeof(vinfo) != "undefined" && vinfo != null ) {
            vinfo.innerHTML = "";
        }
    }
}


function form_validator(formid)
{
    if (! document.getElementById(formid)) {
        alert("For Validator Init Error.  " + formid + " does not exist.");
        return false;
    }

    this.id = formid;
    this.checkForm = checkelements;
    this.setupForm = setupform;
    this.failcolor = "#FFFFC0";
    this.passcolor = "#FFFFFF";


    setuprequired(formid);

    function isInteger(s){
        var i;
        for (i = 0; i < s.length; i++){
            // Check that current character is number.
            var c = s.charAt(i);
            if (((c < "0") || (c > "9"))) return false;
        }
        // All characters are numbers.
        return true;
    }

    function isFloat(s){
        var i;
        for (i = 0; i < s.length; i++){
            // Check that current character is number.
            var c = s.charAt(i);
            if (( (c < "0") || (c > "9")) && (c != "." )  ) return false;
        }
        // All characters are numbers.
        return true;
    }

    function stripCharsInBag(s, bag){
        var i;
        var returnString = "";
        // Search through string's characters one by one.
        // If character is not in bag, append to returnString.
        for (i = 0; i < s.length; i++){
            var c = s.charAt(i);
            if (bag.indexOf(c) == -1) returnString += c;
        }
        return returnString;
    }

    function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }

    function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
            this[i] = 31
            if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
            if (i==2) {this[i] = 29}
        }
        return this;
    }

    function isDate(dtStr)
    {
        var s = "";

        if (dtStr.length == 0) {
            s = "Is not a valid date.";
            return s;
        }

        var dtCh= "/";
        var d = new Date();
        var curr_year = d.getFullYear();

        var minYear=curr_year;
        var maxYear=curr_year + 2;
        minYear = 0;

        var daysInMonth = DaysArray(12)
        var pos1=dtStr.indexOf(dtCh)
        var pos2=dtStr.indexOf(dtCh,pos1+1)
        var strMonth=dtStr.substring(0,pos1)
        var strDay=dtStr.substring(pos1+1,pos2)
        var strYear=dtStr.substring(pos2+1)
        strYr=strYear

        if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
        if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

        for (var i = 1; i <= 3; i++) {
            if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
        }

        month=parseInt(strMonth)
        day=parseInt(strDay)
        year=parseInt(strYr)

        if (pos1==-1 || pos2==-1){
            s = "Date format should be : mm/dd/yyyy.";
        }

        if (strMonth.length<1 || month<1 || month>12){
            s = "Month is not a valid value.";
        }

        if (strDay.length<1 || day<1 || day>31 || (month==2 && day > daysInFebruary(year)) || day > daysInMonth[month]){
            s = "Day value is not valid.";
        }

        if (minYear != 0) {
            if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                s = "Year value should be between "+minYear+" and "+maxYear+".";
            }
        }

        if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
            s = "Invalid date.";
        }

    return s;

    }

    function validCurrency( temp_value )
    {
        if (temp_value == "")
        {
            return false;
        }

        var Chars = "0123456789.,$";
        for (var i = 0; i < temp_value.length; i++)
        {
            if (Chars.indexOf(temp_value.charAt(i)) == -1)
            {
                return false;
            }
        }
        return true
    }

    function validEmail (email)
    {
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (!filter.test(email)) {
            return false;
        }

        return true;
    }

    function settags(id, el, attr)
    {
        var tags = document.getElementById(id).getElementsByTagName(el)
        for (var i=0;i < tags.length;i++) {
            var a = tags[i].getAttribute(attr);
            if(a == "1") {
                tags[i].innerHTML = "<span style=\"color:#C00000;font-weight:bold;\">*</span>" + tags[i].innerHTML
            }
        }
    }

    function setuprequired(id)
    {
        settags(id,"*","reqtag");
    }

    function setupform(err)
    {
        if (! document.getElementById(this.id)) return false;

        var tags = document.getElementById(this.id).getElementsByTagName("*")

        for (var i=0;i < tags.length;i++) {

            var a = tags[i].getAttribute("reqtype");
            if (a && (a != "")) {

                var n = trim(tags[i].name);
                if (err.indexOf(n) != -1) {
                    tags[i].style.backgroundColor = this.failcolor;
                }
            }
        }
    }

    function checkelements()
    {
        var s = ""
        var id = this.id;

        if (! document.getElementById(id)) return s;

        var tags = document.getElementById(id).getElementsByTagName("*")

        for (var i=0;i < tags.length;i++) {

            var a = tags[i].getAttribute("reqtype");
            if (a && (a != "") && tags[i].disabled==false) {

                tags[i].style.backgroundColor = this.passcolor;
                var v = trim(tags[i].value);
                var n = trim(tags[i].name);
                n = n.replace(/_/gi," ");

                var op = a.split(",");
                for (j=0;j<op.length;j++) {

                    if (op[j]=="req" && v=="") {
                        s = s + n + ": Is required.\n"
                        tags[i].style.backgroundColor = this.failcolor;
                        continue;
                    }

                    if (op[j]=="email") {
                        if (! validEmail(v)) {
                            s = s + n + ": Not a valid email address.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }

                    if (op[j]=="select") {
                        if (v == "") {
                            s = s + n + ": Is required.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }

                    if (op[j]=="currency") {

                        if (! validCurrency(v)) {
                            s = s + n + ": Must be a currency value.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }

                    if (op[j]=="number") {

                        if (! isFloat(v)) {
                            s = s + n + ": Must be a number.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }

                    if (op[j]=="positivenumber") {

                        if (! isFloat(v)) {
                            s = s + n + ": Must be a number.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }

                        if (parseFloat(v) < 0) {
                            s = s + n + ": Must be a positive number.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }

                    }

                    if (op[j]=="date") {
                        var tmp = isDate(v);
                        if (tmp != "") {
                            s = s + n + ": " + tmp + "\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }

                    if (op[j]=="phone") {
                        if (v.length < 7) {
                            s = s + n + ": Invalid phone number.  Phone numbers should be at least 7 digits long.\n"
                            tags[i].style.backgroundColor = this.failcolor;
                            continue;
                        }
                    }
                }
            }
        }

        return s;
    }
}

