
    /*$RCSfile: validateValidWhen.js,v $ $Rev: 376673 $ $Date: 2007/12/04 14:15:02 $ */
    /**
    *  Check to see if fields must contain a value.
    * Fields are not checked if they are disabled.
    * <p>
    * @param form The form validation is taking place on.
    */

    function validateValidWhen(form) {
       var isValid = true;
        var focusField = null;
        var i = 0;
        var fields = new Array();
        var lib_tmp = null;
        var msg ="";

        var oRequired = eval('new ' + jcv_retrieveFormName(form) +  '_validwhen()');

        for (var x in oRequired) {
            if (!jcv_verifyArrayElement(x, oRequired[x])) {
                continue;
            }
            var field = form[oRequired[x][0]];
            
            if (field != null){
			
				if (field.className.indexOf("_ERROR") > 0){
				       	lib_tmp = "lib_" + field.name;
	                	if (document.getElementById(lib_tmp) != null){
	                		document.getElementById(lib_tmp).className = document.getElementById(lib_tmp).className.substr(0,document.getElementById(lib_tmp).className.indexOf("_ERROR"));
						}
						field.className = field.className.substr(0,field.className.indexOf("_ERROR"));
				}
	
				var test = oRequired[x][2]("test");
				
				var toReplaceOr = /\ or /g;
				var toReplaceAnd = /\ and /g;
				
				test = test.replace(toReplaceOr, " || ");
				test = test.replace(toReplaceAnd, " && ");
				
				
				//test = test.replace(" and "," && ");
				//test = test.replace(" or "," || ");
							
				if (!eval(test) == true){
	                lib_tmp = "lib_" + field.name;
	                if (document.getElementById(lib_tmp) != null){
	                	document.getElementById(lib_tmp).className = document.getElementById(lib_tmp).className + '_ERROR';
					}
					field.className = field.className + '_ERROR';
					msg = msg + oRequired[x][1] + "\n";
					field.focus();
					//alert(focusField.value);
					//jcv_handleErrors(msg, focusField);
					isValid=false;
	           }
           
           }
           
           
           
        }
     	if (isValid == false){
     		alert(msg);
     	}
     
     	
     
        return isValid;
    }
    
    // Trim whitespace from left and right sides of s.
    function trim(s) {
        return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
    }
