
  $(document).ready(function(){

	jQuery.each(jQuery.validator.messages, function(i) {
 		 jQuery.validator.messages[i] = "Required";
		});
	$("#exam_form").validate({
			  highlight: function(element, errorClass) {
				 $(element).addClass(errorClass);
				 $(element.form).find("label[for=" + element.id + "]")
								.addClass(errorClass);
			
			  },
			  unhighlight: function(element, errorClass) {
				 $(element).removeClass(errorClass);
				 $(element.form).find("label[for=" + element.id + "]")
								.removeClass(errorClass);
			  },

			errorElement: "div",
			errorPlacement: function(error, element) {
     			error.appendTo( element.parent().parent(".row_field"));
   			},

			  groups: {
				home_location: "home_city home_state home_zip",
    			company_location: "company_city company_state company_zip",
				highschool: "high_school hs_degree",
				highschool_location: "hs_city hs_state",
				supervisor_contact: "supervisor supervisor_phone",
				employment: "employment_from_months employment_from_years employment_to_months employment_to_years"
  			}

		
		
		
		
		});

		path = window.location.pathname;
		
		$("#accept_yes").click(function(){
		
			// exam for and online renewal form use same script
			// exception is that online renewal form needs to calculate total credits before submitting			
			if (path == "/acdis/cdi_recertform.cfm")
				{
				creditsSatisfied = isEnough();				
				if (creditsSatisfied) {
					$("#submit").removeAttr("disabled");
					}
				else
					{
					$("#submit").attr("disabled","disabled");
					}
				}
			// perform regular action (remove disabled)
			else
				{
				$("#submit").removeAttr("disabled");	
				}									
		});
		
		$("#accept_no").click(function(){
			$("#submit").attr("disabled","disabled");
		});
		
		if (path == "/acdis/cdi_recertform.cfm")
			{				
				$(".credits").live("keyup",function(){
					creditsSatisfied = isEnough();
					if (creditsSatisfied)
						{
						if ( $('#accept_yes').attr('checked') == true )
							{
							$("#submit").removeAttr("disabled");
							}
						else
							{
							$("#submit").attr("disabled","disabled");
							}
						}
					else 
						{
							$("#submit").attr("disabled","disabled");
						}	
					});
			}
		
});

function isEnough() {
	satisfyRequirement = false;
	totalCredit = 0;
	floatCredit = "";
	//	credit fields have "credits" for a class
	$(".credits").each(function(){
		floatCredit = parseFloat($(this).val());
		if (!isNaN(floatCredit))
			{
			totalCredit = totalCredit + floatCredit;
			}
		});	
	if (totalCredit >= 20) {
		satisfyRequirement = true;
		}
	return satisfyRequirement;
}

