/*
 * CAPTCHA FOR /members/membership-application
 */

 jQuery.validator.addMethod("captcha",
                              function (value)
                              {
                                 var AjaxTmp = $.ajax({
                                                       type: "GET",
                                                       url: 'http://ococean.com/assets/js/jquery-validate/captcha/process.php?captcha=' + value,
                                                       async : false
                                 });

                                 if (AjaxTmp.responseText == "true")
                                    return true;
                                 else
                                    return false;
                                 }, "Invalid Captcha.");


$(function(){

	$("#refreshimg").click(function(){
	$.post('newsession.php');
		$("#captchaimage").load('image_req.php');
		return false;
	});
	

// CHANGE THIS LINE TO WHATEVER THE CURRENT FORM ID IS ( found in site/forms/XXX.tpl2 )
	$("#data_form_membership_application_form").validate({
		rules: {
			captcha: {
				required: true,
                                captcha: $('#captcha').val()
			},
//                      Email: { required: true, email: true },
                        BusinessName: { required: true, minlength: 2 },
                        BusinessDisplayName: { required: true, minlength: 2 },
                        PrimaryService: { required: true },
                        BusinessOwner: { required: true, minlength: 2 },
                        BusinessOwner_Address: { required: true, minlength: 2 },
                        BusinessOwner_City: { required: true, minlength: 2 },
                        BusinessOwner_State: { required: true, minlength: 2 },
                        BusinessOwner_ZipCode: { required: true, minlength: 5, number: true },
                        PrimaryContact_FirstName: { required: true, minlength: 2 },
                        PrimaryContact_LastName: { required: true, minlength: 2 },
                        PrimaryContact_Address: { required: true, minlength: 2 },
                        PrimaryContact_City: { required: true, minlength: 2 },
                        PrimaryContact_State: { required: true },
                        PrimaryContact_ZipCode: { required: true, minlength: 2 },
                        PrimaryContact_Phone: { required: true, minlength: 10, number: true },
                        BillingContact_FirstName: { required: true, minlength: 2 },
                        BillingContact_LastName: { required: true, minlength: 2 },
                        BillingContact_Address: { required: true, minlength: 2 },
                        BillingContact_City: { required: true, minlength: 2 },
                        BillingContact_State: { required: true },
                        BillingContact_ZipCode: { required: true, minlength: 5, number: true },
                        BillingContact_Phone: { required: true, minlength: 10, number: true },
                        ZipCode: { required: true, minlength: 5, number: true }

		},
		messages: {
			captcha: "Correct captcha is required."	
		},
		onkeyup: false
	});

	
});
