 $(document).ready(function() {

  $("#register").validate({

	 onkeyup:false,
		rules: {
			firstname: {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
					   },
			lastname: {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
					   },
			email: {
				required:true,
				email:true,
				maxlength:255
						},
			emailconfirm: {
				required:true,
				email:true,
				maxlength:255,
				equalTo: "#email"
						},
			telephone: {
				required:true,
				number:true,
				maxlength:15,
				minlength:11
					   },
			password: {
				required:true,
				minlength:6,
				maxlength:20
					   },
			'password-confirm': {
				required:true,
				minlength:6,
				maxlength:20,
				equalTo: "#password"
							  }
				  },

messages: {

              firstname: {
                  required: "First Name is required.",
                  minlength: jQuery.format("First Name must be at least {0} characters in length."),
                  maxlength: jQuery.format("First Name can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  
			  lastname: {
				required: "Surname is required.",
				minlength: jQuery.format("Surname must be at least {0} characters in length."),
				maxlength: jQuery.format("Surname must can not exceed {0} characters in length."),
				validChars: "Please supply valid characters only."
					   },

              email: {
                  required: "Email address is required.",
                  email: "Email address must be valid.",
                  maxlength: jQuery.format("Email address can not exceed {0} characters in length.")
              },
			  
			  emailconfirm: {
                  required: "Confirmation Email address is required.",
                  email: "Confirmation Email address must be valid.",
                  maxlength: jQuery.format("Email address can not exceed {0} characters in length."),
				  equalTo: "Confirmed email does not match."
              },

			  telephone: {
				number: "Telephone number must be numeric.",
				maxlength: jQuery.format("Telephone number can not exceed {0} characters in length."),
				minlength: jQuery.format("Telephone number must be at least {0} characters in length.")
					   },
					   
              password: {
                  required: "Password is required.",
                  minlength: jQuery.format("Password must be between 6 and 20 characters."),
                  maxlength: jQuery.format("Password must be between 6 and 20 characters.")
             },

              'password-confirm': {
                  required: "Confirmed password is required.",
				  minlength: jQuery.format("Confirmed password must be between 6 and 20 characters."),
                  maxlength: jQuery.format("Confirmed password must be between 6 and 20 characters."),
                  equalTo: "Confirmed password does not match."
              }
          }
      });


$("#Login").validate({
onkeyup:false,
		rules: {
			Email: {
				required:true,
				email:true,
				maxlength:255
						},
			Password: {
				required:true,
				minlength:5,
				maxlength:128
					   }
				},
			
		messages: {
		
              Email: {
                  required: "Email address is required.",
                  email: "Email address must be valid.",
                  maxlength: jQuery.format("Email address can not exceed {0} characters in length.")
              },
		      
			  Password: {
                  required: "Password is required.",
                  minlength: jQuery.format("Password must be at least {0} characters in length."),
                  maxlength: jQuery.format("Password can not exceed {0} characters in length.")
             }
			}
		});

$("#CreateListing").validate({
onkeyup:false,
		rules: {
			Price: {
				required:true,
				maxlength:8,
				min: 0.01
						},
			UserText: {
				maxlength:50
					   }
				},
			
		messages: {
		
              Price: {
                  required: "The price is required to create a listing.",
                  maxlength: jQuery.format("The price can not exceed &pound;99999.99"),
				  min: $.format("Please enter a value greater than or equal to {0}.")
              },
		      
			  UserText: {
                  maxlength: jQuery.format("The notes can not exceed {0} characters in length.")
             }
			}
		});
	
$("#CreateAddress").validate({
onkeyup:false,
		rules: {
			'first-name': {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
						},
			'last-name': {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
					   },
			address1:{
				required:true,
				maxlength:150
				},
			address2:{
				required:false,
				maxlength:150
				},
			city:{
				required:true,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			county: {
				required:false,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			postcode: {
				required:true,
				minlength:5,
				maxlength:10
				}
				},
				
				
		messages: {
		
              'first-name': {
				  required: "First Name is a required field.",
                  minlength: jQuery.format("First Name must be at least {0} characters in length."),
                  maxlength: jQuery.format("First Name can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
		      
			  'last-name': {
				  required: "Surname is a required field.",
                  minlength: jQuery.format("Surname must be at least {0} characters in length."),
                  maxlength: jQuery.format("Surname can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
             },
			 address1: {
				  required: "Address line 1 is a required field.",
                  minlength: jQuery.format("Address line 1 must be at least {0} characters in length."),
                  maxlength: jQuery.format("Address line 1 can not exceed {0} characters in length.")
              },
			  city: {
				  required: "City is a required field.",
                  minlength: jQuery.format("City must be at least {0} characters in length."),
                  maxlength: jQuery.format("City can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  county: {
                  minlength: jQuery.format("County must be at least {0} characters in length."),
                  maxlength: jQuery.format("County can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  postcode: {
				  required: "Postcode is a required field.",
                  minlength: jQuery.format("Postcode must be at least {0} characters in length."),
				  maxlength: jQuery.format("Postcode can not exceed {0} characters in length.")

              }
			 
			}
		});
		

$("#EditAddress").validate({
onkeyup:false,
		rules: {
			FirstName: {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
						},
			LastName: {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
					   },
			Address1:{
				required:true,
				maxlength:150
				},
			Address2:{
				required:false,
				maxlength:150
				},
			City:{
				required:true,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			County: {
				required:false,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			Postcode: {
				required:true,
				minlength:5,
				maxlength:10
				}
				},
				
				
		messages: {
		
              FirstName: {
				  required: "First Name is a required field.",
                  minlength: jQuery.format("First Name must be at least {0} characters in length."),
                  maxlength: jQuery.format("First Name can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
		      
			  LastName: {
				  required: "Surname is a required field.",
                  minlength: jQuery.format("Surname must be at least {0} characters in length."),
                  maxlength: jQuery.format("Surname can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
             },
			 Address1: {
				  required: "Address line 1 is a required field.",
                  minlength: jQuery.format("Address line 1 must be at least {0} characters in length."),
                  maxlength: jQuery.format("Address line 1 can not exceed {0} characters in length.")
              },
			  City: {
				  required: "City is a required field.",
                  minlength: jQuery.format("City must be at least {0} characters in length."),
                  maxlength: jQuery.format("City can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  	  County: {
                  minlength: jQuery.format("County must be at least {0} characters in length."),
                  maxlength: jQuery.format("County can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  Postcode: {
				  required: "Postcode is a required field.",
                  minlength: jQuery.format("Postcode must be at least {0} characters in length."),
                  maxlength: jQuery.format("Postcode can not exceed {0} characters in length.")
              }
			 
			}
		});
		
$("#PaymentBuyListing").validate({
onkeyup:false,
		rules: {
			cardholder: {
				required:true,
				minlength:2,
				maxlength:50,
				validChars:true
						},
			address1:{
				required:true,
				maxlength:150
				},
			address2:{
				required:false,
				maxlength:150
				},
			city:{
				required:true,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			county: {
				required:false,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			postcode: {
				required:true,
				minlength:5,
				maxlength:10
				}, 
			cardnumber: {
				required:true,
				creditcard:true
				},
			cvscode: {
				required:true,
				maxlength:3,
				minlength:2
				},
			issuenumber: {
				required:false,
				maxlength:3
				},
			expyear: {
				required:true,
				minlength:3,
				maxlength:4
				},
			startyear: {
				required:false,
				minlength:3,
				maxlength:4
					}
				},
							
		messages: {
		
              cardholder: {
				  required: "First Name is a required field.",
                  minlength: jQuery.format("First Name must be at least {0} characters in length."),
                  maxlength: jQuery.format("First Name can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
		      
			 address1: {
				  required: "Address line 1 is a required field.",
                  minlength: jQuery.format("Address line 1 must be at least {0} characters in length."),
                  maxlength: jQuery.format("Address line 1 can not exceed {0} characters in length.")
              },
			  city: {
				  required: "City is a required field.",
                  minlength: jQuery.format("City must be at least {0} characters in length."),
                  maxlength: jQuery.format("City can not exceed {0} characters in length.")
              },
			  county: {
                  minlength: jQuery.format("County must be at least {0} characters in length."),
                  maxlength: jQuery.format("County can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  postcode: {
				  required: "Postcode is a required field.",
                  minlength: jQuery.format("Postcode must be at least {0} characters in length."),
                  maxlength: jQuery.format("Postcode can not exceed {0} characters in length.")
              }, 
			  cvscode: {
				required: "The CSV number is a 3 digit code printed on the BACK of your card in the signature panel. If there are more than 3 digits, the CSV is always the LAST 3. This is a required field.",
				maxlength: jQuery.format("The CSV number is a 3 digit code printed on the BACK of your card in the signature panel. If there are more than 3 digits, the CSV is always the LAST 3. Please enter 3 digits"),
				minlength: jQuery.format("The CSV number is a 3 digit code printed on the BACK of your card in the signature panel. If there are more than 3 digits, the CSV is always the LAST 3. Please enter 3 digits")
				},
			expyear: {
				  minlength: jQuery.format("Must be in the YYYY format."),
                  maxlength: jQuery.format("Must be in the YYYY format.")
				},
			startyear: {
			      minlength: jQuery.format("Must be in the YYYY format."),
                  maxlength: jQuery.format("Must be in the YYYY format.")
			}
			 
			}
		});
		
$("#SeatingDetails").validate({
onkeyup:false,
		rules: {
			BlockNumber1: {
				required:true,
				maxlength:10
						},
			SeatNumber1: {
				required:true,
				maxlength:4
					   },
			RowNumber1: {
				required:true,
				maxlength:4
			},
						BlockNumber2: {
				required:true,
				maxlength:10
						},
			SeatNumber2: {
				required:true,
				maxlength:4
					   },
			RowNumber2: {
				required:true,
				maxlength:4
			},
						BlockNumber3: {
				required:true,
				maxlength:10
						},
			SeatNumber3: {
				required:true,
				maxlength:4
					   },
			RowNumber3: {
				required:true,
				maxlength:4
			},
						BlockNumber4: {
				required:true,
				maxlength:10
						},
			SeatNumber4: {
				required:true,
				maxlength:4
					   },
			RowNumber4: {
				required:true,
				maxlength:4
			},
						BlockNumber5: {
				required:true,
				maxlength:10
						},
			SeatNumber5: {
				required:true,
				maxlength:4
					   },
			RowNumber5: {
				required:true,
				maxlength:4
			},
						BlockNumber6: {
				required:true,
				maxlength:10
						},
			SeatNumber6: {
				required:true,
				maxlength:4
					   },
			RowNumber6: {
				required:true,
				maxlength:4
			},
						BlockNumber7: {
				required:true,
				maxlength:10
						},
			SeatNumber7: {
				required:true,
				maxlength:4
					   },
			RowNumber7: {
				required:true,
				maxlength:4
			},
						BlockNumber8: {
				required:true,
				maxlength:10
						},
			SeatNumber8: {
				required:true,
				maxlength:4
					   },
			RowNumber8: {
				required:true,
				maxlength:4
			},
						BlockNumber9: {
				required:true,
				maxlength:10
						},
			SeatNumber9: {
				required:true,
				maxlength:4
					   },
			RowNumber9: {
				required:true,
				maxlength:4
			},
						BlockNumber10: {
				required:true,
				maxlength:10
						},
			SeatNumber10: {
				required:true,
				maxlength:4
					   },
			RowNumber10: {
				required:true,
				maxlength:4
			}
				},
			
		messages: {
			 BlockNumber1: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber1: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber1: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber2: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber2: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber2: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber3: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber3: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber3: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber4: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber4: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber4: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber5: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber5: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber5: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber6: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber6: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber6: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber7: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber7: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber7: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber8: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber8: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber8: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber9: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber9: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber9: {
                  maxlength: jQuery.format("No more than 4 characters")
             }, 
			 			 BlockNumber10: {
					maxlength: jQuery.format("No more than 10 characters")
					},
		
              SeatNumber10: {
                  maxlength: jQuery.format("No more than 4 characters")
              },
		      
			  RowNumber10: {
                  maxlength: jQuery.format("No more than 4 characters")
             }
			}
		});
		
$("#select-address").validate({
				onkeyup:false,
				onsubmit : true,

				rules: {
			'first-name': {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
						},
			'last-name': {
				required:true,
				minlength:2,
				maxlength:30,
				validChars:true
					   },
			address1:{
				required:true,
				maxlength:150
				},
			address2:{
				required:false,
				maxlength:150
				},
			city:{
				required:true,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			county: {
				required:false,
				minlength:2,
				maxlength:50,
				validChars:true
				},
			postcode: {
				required:true,
				minlength:5,
				maxlength:10
				}
				},
				
				
		messages: {
		
              'first-name': {
				  required: "First Name is a required field.",
                  minlength: jQuery.format("First Name must be at least {0} characters in length."),
                  maxlength: jQuery.format("First Name can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
		      
			  'last-name': {
				  required: "Surname is a required field.",
                  minlength: jQuery.format("Surname must be at least {0} characters in length."),
                  maxlength: jQuery.format("Surname can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
             },
			 address1: {
				  required: "Address line 1 is a required field.",
                  minlength: jQuery.format("Address line 1 must be at least {0} characters in length."),
                  maxlength: jQuery.format("Address line 1 can not exceed {0} characters in length.")
              },
			  city: {
				  required: "City is a required field.",
                  minlength: jQuery.format("City must be at least {0} characters in length."),
                  maxlength: jQuery.format("City can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  county: {
                  minlength: jQuery.format("County must be at least {0} characters in length."),
                  maxlength: jQuery.format("County can not exceed {0} characters in length."),
                  validChars: "Please supply valid characters only."
              },
			  postcode: {
				  required: "Postcode is a required field.",
                  minlength: jQuery.format("Postcode must be at least {0} characters in length."),
				  maxlength: jQuery.format("Postcode can not exceed {0} characters in length.")

              }
			}
		});
	
		$("input[@name='select-address']").change(function(){
    if ($("input[@name='select-address']:checked").val() !== '0')
			jQuery('#select-address').unbind('submit');
	});
	
	}); // END


	
 // check for unwanted characters

  $.validator.addMethod('validChars', function (value) {
     var result = true;
      // unwanted characters
      var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
      for (var i = 0; i < value.length; i++) {
         if (iChars.indexOf(value.charAt(i)) != -1) {
              return false;
          }
 }
return result;
 }, 
 
 '');

 (function($) {
	
	$.fn.formatCurrency = function(settings) {
		settings = jQuery.extend({
		    name: "formatCurrency",
		    useHtml: false,
		    global: true
		}, settings);
		
		return this.each(function() {
		    var num = "0";
		    num = $(this)[settings.useHtml ? 'html' : 'val']();
		    num = num.replace(/\£|\,/g, '');
		    if (isNaN(num))
		        num = "0";
		    sign = (num == (num = Math.abs(num)));
		    num = Math.floor(num * 100 + 0.50000000001);
		    pence = num % 100;
		    num = Math.floor(num / 100).toString();
		    if (pence < 10)
		        pence = "0" + pence;
		    //for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		      // num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
		
		    $(this)[settings.useHtml ? 'html' : 'val'](((sign) ? '' : '-') + num + '.' + pence);
		});
	};

})(jQuery);

				

