jQuery(document).ready(function(){
	var lowerBound = 1;
	var upperBound = 10;
	// to generate random numbers between a range that starts somewhere other than
	// zero use this formula where m is the lowest possible integer value of the range
	// and n equals the top number of the range.
	// Math.floor(Math.random() * (n - m + 1)) + m
	
	// generate random numbers between lowerBound and upperBound (inclusive)
	var a = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
	var b = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
	var token;
	
	jQuery("label#arithmetic-expression").html(a + " + " + b + " = ");
	jQuery("input#eqtn_soln").val(a+b);	

	jQuery("form#Information").validate({
				success: "valid",
				errorClass: "invalid",
				rules: {
					client_name: "required",
					email: {
						required: true,
						email: true
					},
					city: "required",
					province: "required",
					sum: {
						required: true,
						equalTo: "input#eqtn_soln"
					}								
				},
				messages: {
					client_name: "Please fill in the Name field",
					email: {
						required: "Please fill in the Email Address field",	
						email: "Please make sure that email address is valid. e.g. john_smith@hotmail.com"								},
					city: "Please fill in the City field",
					province: "Please fill in the Province/State field",
					sum: {
						required: "please answer the equation",
						equalTo: "please answer the equation correctly"
					}					
				}			
	});
	
	 jQuery.ajax({
	   type: "POST",
	   url: "http://www.paintedpony.ca/cgi-bin/feedback.cgi",
	   success: function(msg){
	     token = msg;
	   }
	 });
	 
	 jQuery("form#Information").submit(function () {
	 	jQuery("input#rti_token").val(token);
	 });	
});
