$(function () {

	//registration form validation
	// validate signup form on keyup and submit
	$("#signup").validate({
		rules: {
			first_name: {
				required: true,
				letters: true
			},
			last_name: {
				required: true,
				letters: true
			},
			pass1: {
				required: true,
				minlength: 5
			},
			pass2: {
				required: true,
				minlength: 5,
				equalTo: "#pass1"
			},
			email: {
				required: true,
				email: true
			},
			company_name: {
				required: "#usec:checked"
			},
			company_bulstat: {
				required: "#usec:checked"
			},
			company_mol: {
				required: "#usec:checked",
				letters: true
			},
			company_address: {
				required: "#usec:checked"
			},			
			telephone: {
				required: true,
				phone: true,
				minlength: 5
			},
			address: {
				required: true 
			},
			city: {
				required: true,
				letters: true,
				minlength: 3
				
			}
			
		},
		messages: {
			first_name: {
				required: "Моля въведете името си"
			},
			last_name: {
				required: "Моля въведете фамилията си"
			},
			pass1: {
				required: "Моля въведете парола",
				minlength: "Паролата трявба да е минимум 5 символа"
			},
			pass2: {
				required: "Моля въведете паролата отново",
				minlength: "Паролата трявба да е минимум 5 символа",
				equalTo: "Паролите не съвпадат"
			},
			
			address: "Моля въведете адрес за доставка",
			city: "Моля въведете град",
			email: "Моля въведете валиден email адрес",
			company_name: "Моля въведете името на фирмата",
			company_mol: "Моля въведете МОЛ",
			company_bulstat: "Моля въведете булстат",
			company_address: "Моля въведете адрес",
			telephone: "Моля въведете телефон или GSM"
		
		}
	});
		
	//adress form validation
	// validate address form on keyup and submit
	$("#address").validate({
		rules: {
			first_name: {
				required: true,
				letters: true
			},
			last_name: {
				required: true,
				letters: true
			},
			email: {
				required: true,
				email: true
			},
			telephone: {
				required: true,
				phone: true,
				minlength: 5
			},
			address: {
				required: true 
			},
			city: {
				required: true,
				letters: true,
				minlength: 3
				
			}
			
		},
		messages: {
			first_name: {
				required: "Моля въведете името си"
			},
			last_name: {
				required: "Моля въведете фамилията си"
			},
			
			address: "Моля въведете адрес за доставка",
			city: "Моля въведете град",
			email: "Моля въведете валиден email адрес",
			telephone: "Моля въведете телефон или GSM"
		
		}
	});
	
	
	
	jQuery.validator.addMethod("phone", function(value, element) {
	return this.optional(element) || /^[0-9- ()\/\s]+$/i.test(value);
}, "Телефонен номер само числа - и интервал");  

jQuery.validator.addMethod("letters", function(value, element) {
	return this.optional(element) || /^[a-z-а-я. \s]+$/i.test(value);
}, "само букви и интервал");  
		
});