$(document).ready(function(){ 

//Global
	$.validator.messages.required = "* Required";
	$("#quotation-form").validate({
		errorElement: "span"
	});
	
	$("#emailaddress").rules("add", {
	 required: true,
	 email: true,
	 messages: {
	   required: "* Required",
	   email: jQuery.format("Invalid email")
	 }
	});
	$(".req").addClass("red-border");
	
	$('input[type="text"]').focus(function(){
		if($(this).is("#date_of_birth")){
			$(this).removeClass("red-border");
		}
		$(this).addClass("focus");
	});
	
	$('input[type="text"]').blur(function(){
		if($(this).hasClass("red-border") && $(this).val() ==""){
			$(this).addClass("red-border");	
		}
		else {
			$(this).removeClass("red-border");	
		}
		
		$(this).removeClass("focus");	 
	});
	
	$("#slider div.popup, #slider .form-banner").css("display", "block");
	
	// Help Popup
	$("div.popup > span.popup-position-above").append('<img src="../images/quotation-form/arrow-above.png" alt="" />');
	$("div.popup > span.popup-position-below").append('<img src="../images/quotation-form/arrow-below.png" alt="" />');
	$("div.popup > span.popup-position-right").append('<img src="../images/quotation-form/arrow-right.png" alt="" />');
	
	$("div.popup").hover(function() {
		$(this).children("span").stop().css({display: "block", zIndex: 2000});
	}, function() {
		$(this).children("span").stop().css({display: "none", zIndex: 1000});
	});
	
	// jQuery UI
	$("#court_filing_date").datepicker({
			buttonText: "Please select a date",
			changeMonth: true,
			changeYear: true,
			dateFormat: "dd/mm/yy",
			showOn: 'both',
			buttonImage: '../images/quotation-form/datepicker.png',
			buttonImageOnly: true
		});
	$("#date_of_birth, #Abstinent_Date").datepicker({
			buttonText: "Please select a date",
			yearRange: "-100:-0",
			changeMonth: true,
			changeYear: true,
			dateFormat: "dd/mm/yy",
			showOn: 'both',
			buttonImage: '../images/quotation-form/datepicker.png',
			buttonImageOnly: true

	});
	$("#contact_date").datepicker({
			buttonText: "Please select a date",
			yearRange: "+0:+10",
			changeMonth: true,
			changeYear: true,
			dateFormat: "dd/mm/yy",
			showOn: 'both',
			buttonImage: '../images/quotation-form/datepicker.png',
			buttonImageOnly: true

	});

// Page 2

	$("#split-invoicing-yes").change(function(){
		$("#split-invoicing-info").slideDown();
	})
	
	$("#split-invoicing-no").change(function(){
		$("#split-invoicing-info").slideUp();
	})
	

	$("#hide-one, #hide-two").hide();

	// slideToggle once checkbox is checked
	$("#same-as-above").change(function(){

		$("#hide-one").slideDown(function(){
			$("#slider").animate({height: $("#slider").children("div.current").height() + "px"}); // Adjust Slider Height
		});
			
		$("#NameSent").val($("#name_sent").val());
		$("#PostSent").val($("#post_code").val());
		$("#OrganisationSent").val($("#organisation").val());
		$("#TelSent").val($("#tel_no").val());
		$("#FaxSent").val($("#fax_no").val());
		$("#AdressSent").val($("#address").val());
		$("#kitemail").val($("#emailaddress").val());
	});
	
	$("#new-details").change(function(){
		$("#hide-one").slideDown(function(){
			$("#slider").animate({height: $("#slider").children("div.current").height() + "px"}); // Adjust Slider Height
		});
		$("#hide-one input").val("") 
	});
	
	// slideToggle once checkbox2 is checked
	$("#hide-two-toggle").change(function(){
		$("#hide-two").slideToggle(function(){
			$("#slider").animate({height: $("#slider").children("div.current").height() + "px"});
		});
	});
	
// Page 3
	$("#duration_of_drug_testing-other").hide();
	
	$('#duration_of_drug_testing').change(function() {
		if($(this).val() == "other") {
			$("#duration_of_drug_testing-other").fadeIn();
		}
		else {
			$("#duration_of_drug_testing-other").val("").css("display", "none");
		}
	});
	
	// If this is filled in, check the box automatically
	$("li input.input-other").blur(function(){
		
		if($(this).val() == ""){
			$("#drugs-to-be-tested-other-check").attr("checked", false);
		}
		else{
			$("#drugs-to-be-tested-other-check").attr("checked", true);
		}

	});

//Page 5
	// If yes is clicked, more info slides down
	$(".nurse-yes").hide();
	$("#nurse-yes").click(function() {
		$(".nurse-yes").show();
		$("#slider").animate({height: $("#slider").children("div.current").height() + "px"}); // Adjust Slider Height
	});
	$("#nurse-no").click(function() {
		$(".nurse-yes input").val("");
		$(".nurse-yes").fadeOut(function() {
			$("#slider").animate({height: $("#slider").children("div.current").height() + "px"}); // Adjust Slider Height
		});
	});
		
}); 
