function crOrderSubmit(btn) {
    var valid = true;
    $('.requiredInput').each(function() {
        var val = $.trim($(this).val());
        if (val.length == 0) {
            valid = false;
            $(this).addClass('missingValue');
        } else {
            $(this).removeClass('missingValue');
        }
    });
    $('select.formFills').each(function() {
        var val = $('option:selected', this).val();
        if (val.length == 0) {
            valid = false;
            $(this).addClass('missingValue');
        } else {
            $(this).removeClass('missingValue');
        }
    });
    if (valid) {
        btn.disabled = true;
        btn.form.submit();
        btn.disabled = false;
        return true;
    } else {
        alert('Highlighted fields are required');
    }
    return false;
}


function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.
function verify(f)
{

    var msg;
    var empty_fields = "";
    var errors = "";


    // Loop through the elements of the form, looking for all 
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.
    
    for(var i = 0; i < f.length; i++) 
    {
        var e = f.elements[i];
        	
        if (((e.type == "text") || (e.type == "textarea") ||  (e.type =="select-one")) && !e.optional) 
        {
        	
 
            // first check if the field is empty
            if ((e.value == null) || (e.value == "") || isblank(e.value)) 
            {
                empty_fields += "\n          " + e.realname;                		
                continue;
            }

            // Now check for fields that are supposed to be numeric.
            var min = (e.min != null)? parseFloat(e.min):null;
            var max = (e.max != null)? parseFloat(e.max):null;
            if (e.numeric || ((min != null) && !isNaN(min)) || ((max != null) && !isNaN(max))) 
            { 
                var v = parseFloat(e.value);
                if ( isNaN(v) || isNaN(e.value) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) 
                {
                    errors += "- The field " + e.realname + " must be a number";                    		
                }
            }
            	
            if (e.email)
            {
            	
                if(e.value.indexOf("@") == -1)
                {
                    errors += e.realname + " Must be a valid email address";            		
                }
            }            	            	      
            	
            	
            if (e.type =="select-one")
            {			
                if (e.selectedIndex == 0)
                {				
                    empty_fields += "\n          " + e.realname;						
                    continue;
                }
				
            }
        	
        }
    }


    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields && !errors) return true;

    msg  = "______________________________________________________\n\n"
    msg += "The form was not submitted because of the following error(s).\n";
    msg += "Please correct these error(s) and re-submit.\n";
    msg += "______________________________________________________\n\n"

    if (empty_fields) 
    {
        msg += "- The following required field(s) are empty:" + empty_fields + "\n\n\n";

        if (errors) msg += "\n";
    }
    msg += errors;

    alert(msg);
    return false;
}

