var gross = {
	
	formCheck: false,
	emailCheck: false,
	form2Check: false,
	
	init: function(){
		gross.colorBox();
		gross.validateForm1();
		gross.validateForm2();
	},
	
	validateForm1: function(){
		$('#submit1').click(function(event){
			$('form .required').each(function(i){
				if($(this).hasClass('email')){
					if($(this).val() != $(this).val().match(/.+@.+\..+/)){
						event.preventDefault();
						$(this).css('border-color', '#f87f14');
						$('form p.error-message').html('Please fill out the required fields');
						gross.emailCheck = false;
					}else{
						$(this).css('border-color', '#a2a2a2');
						//gross.emailCheck = true;
					}
				}else if($(this).val() == ''){
					event.preventDefault();
					$(this).css('border-color', '#f87f14');
					$('form p.error-message').html('Please fill out the required fields');
					gross.formCheck = false;
				}else{
					$(this).css('border-color', '#a2a2a2');
					//gross.formCheck = true;
				}
			});
		});
	},
	
	validateForm2: function(){
		$('#submit2').click(function(event){
			$('form .required').each(function(i){
				event.preventDefault();
				if($(this).val() == ''){
					$(this).css('border-color', '#f87f14');
					$('form p.error-message').html('Please fill out the required fields');
					gross.form2Check = false;
				}else{
					$(this).css('border-color', '#a2a2a2');
					gross.form2Check = true;
				}
			});
			if(gross.form2Check == true){
					var formData = $('form').serializeArray();
					$.post('http://grossman.ovrdrv.com/php/process.php?hardcopy-form=true', formData, function(){
						$('#hardcopy-form').css('background','url(http://grossman.ovrdrv.com/images/hardcopy-form-bg-thank-you.jpg) no-repeat');
						$('#hardcopy-form').html('<p class="thankyou">You will receive your hard copy in the mail in the next 2-4 weeks.</p>');
					});
			}
		});
	},
	
	colorBox: function(){
		$('a.lightbox').click(function(event){
			event.preventDefault();
			$(this).colorbox({opacity:.8});
		});
	}
}

$(document).ready(function(){
	
	gross.init();
	
	
});
