function initSendReminder(opened, focus){
	validateForm();
	initCheckBox(opened);
	if(focus){
			$("#name").focus();  
	}
}  


function validateForm(){
	var validator = $("#reminderForm").validate({
		rules: {
			name: "required", 
			email: { required: true,	email: true},
			address1: { required:{ depends: function(element) {return $("#sampleCheckbox").is(":checked")}}},
			county: { required:{ depends: function(element) {return $("#sampleCheckbox").is(":checked")}}},
			postcode: { required:{ depends: function(element) {return $("#sampleCheckbox").is(":checked")}}}						
		},
		messages: {
			name: "Please enter your name.", 
			email: {
				required: "Please enter your email.", 
				email: "Please enter a valid email address."
			},
			address1: "Please enter you address.",
			county: "Please enter your county.",
			postcode: "Please enter you postcode."
		}, 
		errorClass: "invalid",
		errorLabelContainer: "#errorRemainderContainer", 
		errorElement: "li",
		submitHandler: function() {                          
					var url = "backend/ajax_data.php?a=sign_up_for_updates";  	    	 					                             
					var data = new Object();  
					
					data.name = $("#name").val();  
					data.email = $("#email").val();     					
					data.kencoInformationCheckbox = $("#kencoInformationCheckbox").is(":checked")? "1":"0";
					data.kraftInformationCheckbox = $("#kraftInformationCheckbox").is(":checked")? "1":"0";
					data.penguinInformationCheckbox = $("#penguinInformationCheckbox").is(":checked")? "1":"0";				 				 
					
					data.address1 = $("#address1").val();
					data.address2 = $("#address2").val();
					data.county = $("#county").val();
					data.postcode = $("#postcode").val();                                             
					data.noInformationByPostCheckbox = $("#noInformationByPostCheckbox").is(":checked")? "1":"0";   
					
					if($("#sampleCheckbox").is(":checked")){
						   pageTracker._trackPageview("/sample-form-submited" );
					}else{
						 pageTracker._trackPageview("/reminder-form-submited" );
					} 
					
					$('#submitedRemainderContainer').load(url, data, function(){ 
						$(this).html("<p>Thank you for signing up for our reminders.</p>");
						 $("#submitedRemainderContainer").css({'display':'block'});
						 setTimeout (function(){
							$("#submitedRemainderContainer").hide("fast", function(){$("#submitedRemainderContainer").css({'display':'none'});});
							}, 4000 );
					});	
					
					$("#name").val("");
					$("#email").val("");
					$("#kencoInformationCheckbox").attr('checked', false);
					$("#kraftInformationCheckbox").attr('checked', false);
					$("#penguinInformationCheckbox").attr('checked', false);
					   
					$("#address1").val("");
					$("#address2").val("");
					$("#county").val("");
					$("#postcode").val("");
					$("#noInformationByPostCheckbox").attr('checked', false);
		}
	});
}          

function initCheckBox(opened){
	$("#sampleCheckbox").click(function() {  	
		if($("#sampleCheckbox").is(":checked")){
			$("#sampleForm").slideDown('slow');
			$("#send").css({'height': 'auto'});
		}else{
			$("#sampleForm").slideUp('slow');
			$("#send").css({'height': 'auto'}); 
			$("#address1").val("");
			$("#address2").val("");
			$("#county").val("");
			$("#postcode").val("");  
		}                                                   
	});    
	if(opened){
		$("#sampleCheckbox").attr('checked', true); 
	}else{
		$("#sampleForm").hide();
	}                                  
}