// Lambert contact form
$(document).ready(function(){
						   
	$("#fbox1").fancybox({
			'titlePosition'				: 'inside',
			'transitionIn'				: 'none',
			'transitionOut'				: 'none', 
					'overlayOpacity'			:	'0.6',
			'margin'					: 0,
			'padding'					: 0,
			'showCloseButton'			: true,
			'hideOnContentClick'	: false
	});
	$("#fbox2").fancybox({
		'titlePosition'				: 'inside',
		'transitionIn'				: 'none',
		'transitionOut'				: 'none', 
		'padding'				: 0,
		'margin'				: 12,
		'height'				: 650,
		'scrolling'				: 'no',
		'showCloseButton'			: true,
		'autoDimensions'		: true,
		'hideOnContentClick'	: false
	});
	$("#fbox3").fancybox({
		'titlePosition'				: 'inside',
		'transitionIn'				: 'none',
		'transitionOut'				: 'none', 
		'padding'				: 0,
		'margin'				: 0,
		'showCloseButton'			: true,
		'hideOnContentClick'	: false
	});

	$("a#sidingb1").fancybox();
	$("a#sidinga1").fancybox();
	$("a#sidingb1b").fancybox();
	$("a#sidinga1b").fancybox();
	
	$("a#portex1").fancybox();
	$("a#portex2").fancybox();
	$("a#portex3").fancybox();
	$("a#portex4").fancybox();
	$("a#portex5").fancybox();
	$("a#portex6").fancybox();
	$("a#portex7").fancybox();
	$("a#portex8").fancybox();
	$("a#portex9").fancybox();

	
	var defaultfname = $("#fname").val();
	var defaultlname = $("#lname").val();
	var defaultemail = $("#textemail").val();
	var defaultcomment = $("#textcomment").val();
	
	var defaultfname2 = $("#fname2").val();
	var defaultlname2 = $("#lname2").val();
	var defaultemail2 = $("#textemail2").val();
	var defaultcomment2 = $("#textcomment2").val();
	
	var defaultfname3 = $("#fname3").val();
	var defaultlname3 = $("#lname3").val();
	var defaultemail3 = $("#textemail3").val();
	
	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);

	$("#fname").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultfname ){
			$(this).val('')
		}
	});
	$("#fname").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultfname);
		}
	});
	$("#lname").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultlname ){
			$(this).val('')
		}
	});
	$("#lname").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultlname);
		}
	});
	$("#textemail").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultemail ){
			$(this).val('')
		}
	});
	$("#textemail").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultemail);
		}
	});
	
	$("#textcomment").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultcomment ){
			$(this).val('')
		}
	});
	$("#textcomment").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultcomment);
		}
	});
	
	
	
	
	$("#fname2").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultfname2 ){
			$(this).val('')
		}
	});
	$("#fname2").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultfname2);
		}
	});
	$("#lname2").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultlname2 ){
			$(this).val('')
		}
	});
	$("#lname2").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultlname2);
		}
	});
	$("#textemail2").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultemail2 ){
			$(this).val('')
		}
	});
	$("#textemail2").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultemail2);
		}
	});
	
	$("#textcomment2").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultcomment2 ){
			$(this).val('')
		}
	});
	$("#textcomment2").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultcomment2);
		}
	});
	
	
	
	
	$("#fname3").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultfname3 ){
			$(this).val('')
		}
	});
	$("#fname3").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultfname3);
		}
	});
	$("#lname3").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultlname3 ){
			$(this).val('')
		}
	});
	$("#lname3").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultlname3);
		}
	});
	$("#textemail3").focusin(function() {
		var fieldvalue = $(this).val();
		$(this).css('color','black');
		if( fieldvalue == defaultemail3 ){
			$(this).val('')
		}
	});
	$("#textemail3").focusout(function(){
		var fieldvalue = $(this).val();
		if( fieldvalue == '' ){
			$(this).css('color','#999');
			$(this).val(defaultemail3);
		}
	});
	
	
	
	//var thankuUrl = "http://localhost/smuckerthenametoknow.com/contact_success.php";
	var thankuUrl = "/contact_success.php";
	//var prcfileUrl = "http://localhost/smuckerthenametoknow.com/process/";
	var prcfileUrl = "/process/";
	
	$("#estimateform").submit(function()
	{	
			var flag;
			var fname = $("#fname").val();
			var lname = $("#lname").val();
			var textemail = $("#textemail").val();
					
			if( fname == defaultfname ){
				$("#errorfname").css('color','black');
				flag = true;
			}
			if( lname == defaultlname ){
				$("#errorlname").css('color','black');
				flag = true;
			}	
			if( !pattern.test(textemail) ){
				$("#erroremail").css('color','black');
				flag = true;
			}	
			
			if( flag == true ){
					$("#msgConEstimate").css('display','block');
					//var new_position = $("#estimateform").offset();
					//window.scrollTo(new_position.left,new_position.top);
				return false;
			}
			/*
			$("#fname").css('color','#999');
			$("#fname").val(defaultfname);
			$("#lname").css('color','#999');
			$("#lname").val(defaultlname);
			$("#textemail").css('color','#999');
			$("#textemail").val(defaultemail);
			*/
			var request_type = $("#request_type").val();
			
			var qstring = "fname="+fname+"&lname="+lname+"&email="+textemail+"&request_type="+request_type+"&ajaxsubmit=yes";
			var qsbytype = "";
			var handler = "process_leadgen.php";
			thankuUrl = "/thank_you_estimate.php";
			
			
			var textcomment = $("#textcomment").val();
			if( textcomment == defaultcomment )
				textcomment = "No Comments";
			
			var txtcompany = $("#txtcompany").val();
			var txtaddress = $("#txtaddress").val();
			var txtcity = $("#txtcity").val();
			var txtstate = $("#txtstate").val();
			var txtzip = $("#txtzip").val();
			var textphone = $("#textphone").val();
			
			qsbytype = "&comments="+textcomment+"&txtcompany="+txtcompany+"&txtaddress="+txtaddress+"&txtcity="+txtcity+"&txtstate="+txtstate+"&txtzip="+txtzip+"&textphone="+textphone;
			
			//alert("MSG defined => "+success_msg);
			//alert(qstring + qsbytype);
			
			$.ajax({ 
				type: "POST", 
				url: prcfileUrl + handler, 
				data: qstring + qsbytype, 
				success: function(msg){
											//alert("Success => "+msg);
											if(msg == success_msg){
												window.location.href = thankuUrl;// + '?sm=1';
											}
											else{
												$("#ajaxmsgEstimate").html(msg);
												$("#ajaxmsgEstimate").css('display','block');
												$("#msgConEstimate").css('display','block');
											}
									}
			});
			
			return false;
	});
	
	
	
	$("#serviceform").submit(function()
	{					  
			var flag2;
			var fname2 = $("#fname2").val();
			var lname2 = $("#lname2").val();
			var textemail2 = $("#textemail2").val();		
					
					
			if( fname2 == defaultfname2 ){
				$("#errorfname2").css('color','black');
				flag2 = true;
			}
			if( lname2 == defaultlname2 ){
				$("#errorlname2").css('color','black');
				flag2 = true;
			}	
			if( !pattern.test(textemail2) ){
				$("#erroremail2").css('color','black');
				flag2 = true;
			}	
			
			if( flag2 == true ){
				//$("#msgConService").css('display','block');
				//var new_position = $("#estimateform").offset();
				//window.scrollTo(new_position.left,new_position.top);
				return false;
			}
			/*
			$("#fname2").css('color','#999');
			$("#fname2").val(defaultfname2);
			$("#lname2").css('color','#999');
			$("#lname2").val(defaultlname2);
			$("#textemail2").css('color','#999');
			$("#textemail2").val(defaultemail2);
			*/
			var request_type2 = $("#request_type2").val();
			
			var qstring = "fname="+fname2+"&lname="+lname2+"&email="+textemail2+"&request_type="+request_type2+"&ajaxsubmit=yes";
			var qsbytype = "";
			var handler = "process_leadgen.php";
			thankuUrl = "/thank_you_service.php";
			
			var textcomment2 = $("#textcomment2").val();
			if( textcomment2 == defaultcomment2 )
				textcomment2 = "No Comments";
			
			var txtcompany2 = $("#txtcompany2").val();
			var txtaddress2 = $("#txtaddress2").val();
			var txtcity2 = $("#txtcity2").val();
			var txtstate2 = $("#txtstate2").val();
			var txtzip2 = $("#txtzip2").val();
			var textphone2 = $("#textphone2").val();
			
			qsbytype = "&comments="+textcomment2+"&txtcompany="+txtcompany2+"&txtaddress="+txtaddress2+"&txtcity="+txtcity2+"&txtstate="+txtstate2+"&txtzip="+txtzip2+"&textphone="+textphone2;
				
			
			if(request_type2 == "Service")
			{
				if($('#roof_inspection').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#roof_inspection:checked').val();
					
				if($('#single_roof_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#single_roof_repair:checked').val();
					
				if($('#slate-wood_shake_roof_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#slate-wood_shake_roof_repair:checked').val();
					
				if($('#flat_roof_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#flat_roof_repair:checked').val();
					
				if($('#spouting_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#spouting_repair:checked').val();
					
				if($('#gutter_clean_out').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#gutter_clean_out:checked').val();
					
				if($('#window-door_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#window-door_repair:checked').val();
					
				if($('#siding_repair').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#siding_repair').val();
				
				if($('#other').is(':checked'))
					qsbytype = qsbytype+"&services[]="+$('#other').val();
				
				
				//handler = "process_leadgen.php";
				//thankuUrl = "/thank_you_estimate.html";
			}
			
			//alert(qstring + qsbytype);
			
			$.ajax({ 
				type: "POST", 
				url: prcfileUrl + handler, 
				data: qstring + qsbytype, 
				success: function(msg){
											//if(msg == "We have received your inquiry and will contact you soon"){
											if(msg == success_msg){
												//alert(msg);	
												window.location.href = thankuUrl;// + '?sm=2';
											}
											else{
												$("#ajaxmsgService").html(msg);
												$("#ajaxmsgService").css('display','block');
												$("#msgConService").css('display','block');
											}
									}
			});
			
			return false;
	});
	
	
	
	
	$("#nLetterform").submit(function()
	{					  
			var flag3 = false;
			var fname3 = $("#fname3").val();
			var lname3 = $("#lname3").val();
			var textemail3 = $("#textemail3").val();		
					
					
			if( fname3 == defaultfname3 ){
				$("#errorfname3").css('color','black');
				flag3 = true;
			}
			if( lname3 == defaultlname3 ){
				$("#errorlname3").css('color','black');
				flag3 = true;
			}	
			if( !pattern.test(textemail3) ){
				$("#erroremail3").css('color','black');
				flag3 = true;
			}	
			
			
			
			if( flag3 == true ){
				//$("#msgConNLetter").css('display','block');
				//var new_position = $("#estimateform").offset();
				//window.scrollTo(new_position.left,new_position.top);
				//alert(" caught me here Fill the Fields ");
				return false;
			}
			
			//alert(" caught me here Files are Filled Go Ahead");
			/*
			$("#fname3").css('color','#999');
			$("#fname3").val(defaultfname3);
			$("#lname3").css('color','#999');
			$("#lname3").val(defaultlname3);
			$("#textemail3").css('color','#999');
			$("#textemail3").val(defaultemail3);
			*/
			var request_type3 = $("#request_type3").val();
			
			var qstring = "fname="+fname3+"&lname="+lname3+"&email="+textemail3+"&request_type="+request_type3+"&ajaxsubmit=yes";
			var qsbytype = "";
			var handler = "process_leadgen.php";
			thankuUrl = "/thank_you_newsletter.php";
			
			//alert(qstring + qsbytype);
			
			$.ajax({ 
				type: "POST", 
				url: prcfileUrl + handler, 
				data: qstring + qsbytype, 
				success: function(msg){
											//if(msg == "We have received your inquiry and will contact you soon"){
											if(msg == success_msg){
												//alert(msg);
												window.location.href = thankuUrl;// + '?sm=3';
											}
											else{
												$("#ajaxmsgNLetter").html(msg);
												$("#ajaxmsgNLetter").css('display','block');
												$("#msgConNLetter").css('display','block');
											}
									} 
			});
			
			return false;
	});
	
	
});

