/**
 * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
 *
 * @example jQuery.validator.methods.date("01/01/1900")
 * @result true
 *
 * @example jQuery.validator.methods.date("01/13/1990")
 * @result false
 *
 * @example jQuery.validator.methods.date("01.01.1900")
 * @result false
 *
 * @example <input name="pippo" class="{dateITA:true}" />
 * @desc Declares an optional input element whose value must be a valid date.
 *
 * @name jQuery.validator.methods.dateITA
 * @type Boolean
 * @cat Plugins/Validate/Methods
 */
jQuery.validator.addMethod(
	"dateITA",
	function(value, element) {
		var check = false;
		var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
		if( re.test(value)){
			var adata = value.split('/');
			var gg = parseInt(adata[0],10);
			var mm = parseInt(adata[1],10);
			var aaaa = parseInt(adata[2],10);
			var xdata = new Date(aaaa,mm-1,gg);
			if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
				check = true;
			else
				check = false;
		} else
			check = false;
		return this.optional(element) || check;
	}, 
	"Please enter a correct date"
);


$(document).ready(function(){
	$("#ContactDetailsForm").validate({
  		rules: {
    		contact_email: {
      			required: true,
      			email: true
    			},
    		contact_name: {
    			required:true
    			},
    		c1_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c1_firstname:filled"			
       		 	}, 	
    		c2_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c2_firstname:filled"	
    			},
      		c3_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c3_firstname:filled"  				
    			},
    		c4_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c4_firstname:filled" 				
    			},
    		c5_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c5_firstname:filled"				
    			},
      		c6_yob:{ 
    			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c6_firstname:filled"
    			},
       		c7_yob:{ 
       			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c7_firstname:filled"				
       			},
       		c8_yob:{ 
       			digits: true,
    			minlength: 4,
    			maxlength: 4,
    			required: "#c8_firstname:filled" 				
       			}
  			}
	});
	
	
	
	$("#c1_firstname").click(function() {
		  $("#c1_yob").valid();
		});
	$("#c2_firstname").click(function() {
		  $("#c2_yob").valid();
		});
	$("#c3_firstname").click(function() {
		  $("#c3_yob").valid();
		});
	$("#c4_firstname").click(function() {
		  $("#c4_yob").valid();
		});
	$("#c5_firstname").click(function() {
		  $("#c5_yob").valid();
		});
	$("#c6_firstname").click(function() {
		  $("#c6_yob").valid();
		});
	$("#c7_firstname").click(function() {
		  $("#c7_yob").valid();
		});
	$("#c8_firstname").click(function() {
		  $("#c8_yob").valid();
		});
	
	$("#ReviewPaymentForm").validate({
		rules: {
		
			payment_type:{
				required: true
				},
			payment_reference: {
				required: true
				},
			payment_date:{
				required: true,
				dateITA: true
				}
			}
	}); 
});



