(function(a){a.fn.clearOnFocus=function(){function c(d){if(a(this).val()==a(this).data("clearOnFocus")){a(this).val("")}}function b(d){if(a.trim(a(this).val())==""){a(this).val(a(this).data("clearOnFocus"))}}return this.each(function(){a(this).data("clearOnFocus",a(this).attr("value"));a(this).unbind("focus",c);a(this).unbind("blur",b);a(this).bind("focus",c);a(this).bind("blur",b)})}})(jQuery);

jQuery(document).ready(function($) {
	$('#full-quote input.text, #full-quote textarea, #quick-quote.lead input.text, #quick-quote.lead textarea').val('');
	$('#quick-quote input.text, #quick-quote textarea, .clear-on-focus').clearOnFocus();
	$('.hide-if-no-js').removeClass('hide-if-no-js');
	
	$('#quote-form').submit(function(event) {
		var $name = $('#quote-name');
		var $email = $('#quote-email');
		var $details = $('#quote-details');
		var hasErrors = false;
		
		if($name.val() == '' || $name.val() == 'Name') {
			hasErrors = true;
			$name.addClass('error');
		} else {
			$name.removeClass('error');
		}
		if($email.val() == '' || $email.val() == 'Email') {
			hasErrors = true;
			$email.addClass('error');
		} else {
			$email.removeClass('error');
		}
		if($details.val() == '' || $details.val() == 'Project Details') {
			hasErrors = true;
			$details.addClass('error');
		} else {
			$details.removeClass('error');
		}
		
		if(hasErrors) {
			event.preventDefault();
			$name.focus();
			scrollToElement('#quote-name');
		}
	});
});

function scrollToElement(selector) {
	var x = jQuery(selector).offset().top - 100;
	jQuery('html,body').animate({scrollTop: x}, 500);
}