$(document).ready(function() {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

	$("#contactFormForm").submit(function(){
		var flag;
		var textname = $("#textname").val();
		var textemail = $("#textemail").val();
		var textphone = $("#textphone").val();
		var textaddress = $("#textaddress").val();
		var textcity = $("#textcity").val();
		var textstate = $("#textstate").val();
		var textzip = $("#textzip").val();

		$("#errorname").css('display','none');
		$("#erroremail").css('display','none');
		$("#errorphone").css('display','none');
		$("#erroraddress").css('display','none');
		$("#errorcity").css('display','none');
		$("#errorstate").css('display','none');
		$("#errorzip").css('display','none');

		if( textname == '' ){
			$("#errorname").css('display','inline');
			flag = true;
		}
		if( !pattern.test(textemail) ){
			$("#erroremail").css('display','inline');
			flag = true;
		}
		if( textphone == '' ){
			$("#errorphone").css('display','inline');
			flag = true;
		}
		if( textaddress == '' ){
			$("#erroraddress").css('display','inline');
			flag = true;
		}
		if( textcity == '' ){
			$("#errorcity").css('display','inline');
			flag = true;
		}
		if( textstate == '' ){
			$("#errorstate").css('display','inline');
			flag = true;
		}
		if( textzip == '' ){
			$("#errorzip").css('display','inline');
			flag = true;
		}
		if( flag == true ){
			return false;
		}
		$.ajax({ 
			type: "GET", 
			url: "procform.php", 
			data: "name="+textname+"&email="+textemail+"&phone="+textphone+"&address="+textaddress+"&state="+textstate+"&city="+textcity+"&zip="+textzip+"&ajaxsubmit=yes", 
			success: function(msg){
				//alert(msg);
				if(msg == "We have recieved your request"){
					//alert(msg);	
					window.location.href = "thank-you.html";
				}
				else{
				
					$("#ajaxmessage").html(msg);
					$("#ajaxmessage").css('display','inline').fadeOut(1200, function(){
						$.fancybox.close();
					});
				}
			} 
		});
		return false;
	});

	$("#lightbox").click(function(){
		$("#videoimbed").hide();
	}).fancybox({
		'titlePosition'				: 'inside',
		'transitionIn'				: 'none',
		'transitionOut'				: 'none',
		'padding'							: '0', 
		'overlayOpacity'			:	'0.55',
		'overlayColor'				: '#111',
		'opacity'							: true,
		'showCloseButton'			: true,
		'hideOnContentClick'	: false,
		'onCleanup'	: function(){
			$("#videoimbed").show();
		}
	});
});

