 $(document).ready(function() {
	 	//Hide the labels
	 	$(".text label, .select label, .email label").css({
			"text-indent": "-9999px",
			"height": "0",
			"font-size": "0",
			"line-height": "0",
			"display": "block"
		});
		
		
		//Set the value of the text boxes to the value of the associated label.
		$(".text input, .email input").val(function(){
			return $(this).prev("label").text();
		});
		
		//Clear the text boxes, if the form field = label
		$(".text input, .email input").focus(function(){
			if($(this).val() == $(this).prev("label").text()){
				$(this).val("");
			}
		});
		
		//Set text back to black on blur for text input elements if label has been changed from default
		$(".text input, .email input").blur(function(){
			if($(this).val()==""){
				$(this).val($(this).prev("label").text());
				$(this).css("color", "#666");
			}
			else if ($(this).val() != $(this).prev("label").text()) {
				$(this).css("color", "#000");
			}
		});
		
		//Set text back to black on blur for select input elements if label has been changed from default
		$(".select select").blur(function(){
			if ($(this).val() != "") {
				$(this).css("color", "#000");
			}
		});
		
		//On submit, set values to blank if same as labels
		$("#comp-form").submit(function(){
			$(".text input, .email input").val(function(){
				if($(this).val() == $(this).prev("label").text()){
					
					return "";
				}else{
					return $(this).val();
				}
			});
		
		});	
		
		
		
		//Validate form (resetting blank fields back to label if invalid, and fading error box in)
		$("#comp-form").validate({
			
			errorPlacement: function(error, element) {
				error.appendTo(element.closest("div.form-row").children("div.error-messages").fadeIn());
			},
			
			


			invalidHandler: function(form, validator){
				$("input").val(function(){
					if($(this).val() == ""){
						return $(this).prev("label").text();
					}else{
						return $(this).val();
					}
					
				});
				$("input.required, select.required").addClass(function(){
					if($(this).val() == ""||$(this).val() == $(this).prev("label").text()){
						return "error";
					}else{
						return "valid";
					}
					
				});
				
			},
			errorClass: "error",
			validClass: "valid"


		}); 
			
 });
		 
		 
		 