/**
 * Who: Joshua McGinnis, Intuit QuickBase
 * What: Feedback Survey
 */
	  	$(document).ready(function(){ 
			
			var ffBox  = $("#feedback-box");
			var ffButton = $("#ff-button");
			var ffBoxClose = $("#feedback-close");
			var ffThankYou = $("#ff-thankyou");
			var ffSubmit = $("#feedbackSubmit");
			var ffForm = $("form#feedback-form");
			var ffComment = $("form#feedback-form textarea");
			var ffUrl = document.location.protocol + "//" + document.domain + "/includes/ffSurvey.php";
			var winLoc = window.location;
							
			ffButton.click(function(){
				$("body").append("<div id='ff-overlay'></div>");
				ffBox.fadeIn();
				ffButton.hide();
			});
		
			ffBoxClose.click(function(){
				ffBox.fadeOut();
				$("#ff-overlay").fadeOut().remove();
				ffButton.fadeIn();
			});
			
			ffComment.focus(function(){
				if(ffComment.val() == 'Enter your comments here.'){
					ffComment.html('');
				}
			});
			
			ffComment.blur(function(){
				if(ffComment.val() == ''){
					ffComment.html('Enter your comments here.');
				}
			});			
		
			ffSubmit.click(function(){
				var custBool = $("form#feedback-form input[name='customerBool']:checked").val();	
				if (!custBool) {
					alert('Please let us know if you are an existing customer.');
					return false;
				}
				
				var ffcommentType = $("form#feedback-form select[name='commentType']").val();			
				if (!ffcommentType) {
					if (ffComment.val() !== 'Enter your comments here.') {
						alert('Please choose a topic for your comments.');
						return false;
					}
				}
					
	    		var str = ffForm.serialize();				
				
				$.ajax({
					type: "POST",
					url: ffUrl,
					data: str + "&browser=" + navigator.userAgent + "&page=" + winLoc,
					success: function(data){	
									
					ffSubmit.hide();
					ffForm.hide();
					ffBox.css("background","none");
					
					ffThankYou.fadeIn(500).fadeTo(1000, 1, function(){
						ffThankYou.fadeOut(1000)
						ffBox.fadeOut(500);
						$("#ff-overlay").remove();					
					});					
					}
				});
			
			return false;
    		});
 	});
