function checkEmail(email) {
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
	return (!r1.test(email) && r2.test(email));
}

$(document).ready(function(){
	$('#generalContactForm').submit(function(){
		
		var flag = 0;
		
		$('#generalContactForm input').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#generalContactForm select').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#generalContactForm textarea').each(function(i){
			$(this).removeClass('errorInput');
		});
		if( $('#name').get(0).value == '' ){
//			$('#name').get(0).focus();
			$("#name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#name").addClass('errorInput');
			flag = 1;
//			return false;
		}
		if( $('#phone').get(0).value == '' ){
//			alert('Enter yout phone.');
			$("#phone").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#phone").addClass('errorInput');
//			$('#phone').get(0).focus();
//			return false;
			flag = 1;
		}
		if( $('#email').get(0).value == '' || !checkEmail($('#email').get(0).value)){
//			alert('Enter a valid email.');
//			$('#email').get(0).focus();
			$("#email").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#email").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( flag == 1 ) return false;
		return true;
		
	});
	$('#registerProductForm').submit(function(){
		
		var flag = 0;
		
		$('#registerProductForm input').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#registerProductForm select').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#registerProductForm textarea').each(function(i){
			$(this).removeClass('errorInput');
		});
		
		if( $('#dealer_name').get(0).value == '' ){
//			alert('Please Enter the dealer`s name.');
			$('#dealer_name').get(0).focus();
			$("#dealer_name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#dealer_name").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#delaer_address').get(0).value == '' ){
//			alert('Please Enter the dealer`s address.');
			$('#delaer_address').get(0).focus();
			$("#delaer_address").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#delaer_address").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#model').get(0).value == '' ){
//			alert('Please Enter the product model.');
			$('#model').get(0).focus();
			$("#model").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#model").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#size').get(0).value == '' ){
//			alert('Please Enter the size of the product.');
			$('#size').get(0).focus();
			$("#size").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#size").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#guarantee').get(0).value == '' ){
//			alert('Please Enter the guarantee period.');
			$('#guarantee').get(0).focus();
			$("#guarantee").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#guarantee").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#buy_date').get(0).value == '' ){
//			alert('Please Enter the buying date.');
			$('#buy_date').get(0).focus();
			$("#buy_date").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#buy_date").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#sticker_number').get(0).value == '' ){
//			alert('Please Enter the product number.');
			$('#sticker_number').get(0).focus();
			$("#sticker_number").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#sticker_number").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#cl_email').get(0).value == '' || !checkEmail($('#cl_email').get(0).value)){
//			alert('Please Enter the product number.');
			$('#cl_email').get(0).focus();
			$("#cl_email").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#cl_email").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#client_name').get(0).value == '' ){
//			alert('Please Enter the product number.');
			$('#client_name').get(0).focus();
			$("#client_name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#client_name").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#address_client').get(0).value == '' ){
//			alert('Please Enter the product number.');
			$('#address_client').get(0).focus();
			$("#address_client").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#address_client").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#phone').get(0).value == '' ){
//			alert('Please Enter the product number.');
			$('#phone').get(0).focus();
			$("#phone").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#phone").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( flag == 1 ) return false;
		return true;
	});
	
	$('#partnersProspectForm').submit(function(){
		var flag = 0;
		$('#partnersProspectForm input').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#partnersProspectForm select').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#partnersProspectForm textarea').each(function(i){
			$(this).removeClass('errorInput');
		});
		
		if( $('#juri_name').get(0).value == '' ){
//			alert('Please Enter the Juridical name.');
			$('#juri_name').get(0).focus();
			$("#juri_name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#juri_name").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#email').get(0).value == '' || !checkEmail($('#email').get(0).value) ){
//			alert('Please Enter a valid email.');
			$('#email').get(0).focus();
			$("#email").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#email").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#contact_person').get(0).value == '' ){
//			alert('Please Enter a contact person.');
			$('#contact_person').get(0).focus();
			$("#contact_person").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#contact_person").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#category').get(0).value == '' ){
//			alert('Please select a category.');
			$('#category').get(0).focus();
			$("#category").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#category").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#phone').get(0).value == '' ){
//			alert('Please enter a phone number.');
			$('#phone').get(0).focus();
			$("#phone").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#phone").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( flag == 1 ) return false;
		return true;
	});
	
	$('#buildMatressForm').submit(function(){
		var flag = 0;
		$('#buildMatressForm input').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#buildMatressForm select').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#buildMatressForm textarea').each(function(i){
			$(this).removeClass('errorInput');
		});
		
		if( $('#name').get(0).value == '' ){
//			alert('Please enter a name.');
			$('#name').get(0).focus();
			$("#name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#name").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#phone').get(0).value == '' ){
//			alert('Please enter a phone number.');
			$('#phone').get(0).focus();
			$("#phone").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#phone").addClass('errorInput');
//			return false;
			flag = 1;
		}
//		if( $('#mobile').get(0).value == '' ){
////			alert('Please enter a mobile phone number.');
//			$('#mobile').get(0).focus();
//			$("#mobile").animate({
//			  left: 50, opacity: 'show'
//			}, 800,"slow", "easein");
//			
//			return false;
//		}
//		if( $('#fax').get(0).value == '' ){
////			alert('Please enter a fax number.');
//			$('#fax').get(0).focus();
//			$("#fax").animate({
//			  left: 50, opacity: 'show'
//			}, 800,"slow", "easein");
//			
//			return false;
//		}
		if( $('#email').get(0).value == '' ||  !checkEmail($('#email').get(0).value)){
//			alert('Please enter a valid email.');
			$('#email').get(0).focus();
			$("#email").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#email").addClass('errorInput');
//			return false;
			flag = 1;
		}
//		if( $('#person').get(0).value == '' ){
////			alert('Please enter a contact person.');
//			$('#person').get(0).focus();
//			$("#person").animate({
//			  left: 50, opacity: 'show'
//			}, 800,"slow", "easein");
//			
//			return false;
//		}
		
		if( $('#location').get(0).value == '' ){
//			alert('Please enter the location of the building.');
			$('#location').get(0).focus();
			$("#location").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#location").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#stage').get(0).value == '' ){
//			alert('Please enter the stage of construction.');
			$('#stage').get(0).focus();
			$("#stage").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#stage").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( flag == 1 ) return false;
		return true;
	});
	
	$('#hotelRequestForm').submit(function(){
		var flag = 0;
		$('#hotelRequestForm input').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#hotelRequestForm select').each(function(i){
			$(this).removeClass('errorInput');
		});
		$('#hotelRequestForm textarea').each(function(i){
			$(this).removeClass('errorInput');
		});
		
		if( $('#name').get(0).value == '' ){
//			alert('Please enter a name.');
			$('#name').get(0).focus();
			$("#name").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#name").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#phone').get(0).value == '' ){
//			alert('Please enter a phone number.');
			$('#phone').get(0).focus();
			$("#phone").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#phone").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#mobile').get(0).value == '' ){
//			alert('Please enter a mobile phone number.');
			$('#mobile').get(0).focus();
			$("#mobile").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#mobile").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#fax').get(0).value == '' ){
//			alert('Please enter a fax number.');
			$('#fax').get(0).focus();
			$("#fax").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#fax").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#email').get(0).value == '' ||  !checkEmail($('#email').get(0).value)){
//			alert('Please enter a valid email.');
			$('#email').get(0).focus();
			$("#email").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#email").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#person').get(0).value == '' ){
//			alert('Please enter a contact person.');
			$('#person').get(0).focus();
			$("#person").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#person").addClass('errorInput');
//			return false;
			flag = 1;
		}
		
		if( $('#location').get(0).value == '' ){
//			alert('Please enter the location of the building.');
			$('#location').get(0).focus();
			$("#location").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#location").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( $('#stage').get(0).value == '' ){
//			alert('Please enter the stage of construction.');
			$('#stage').get(0).focus();
			$("#stage").animate({
			  left: 50, opacity: 'show'
			}, 800,"slow", "easein");
			$("#stage").addClass('errorInput');
//			return false;
			flag = 1;
		}
		if( flag == 1 ) return false;
		return true;
	});
	
});
