// JavaScript Document
jQuery.noConflict();
jQuery(document).ready(function(){	
	jQuery('#instantestimate').validate({
		rules: {
			roomname: {required: true},
			email: {required: true,	email: true},
			walla: {number: true},
			wallb: {number: true},
			wallc: {number: true},
			walld: {number: true},
			Holesandcracks: {required: true},
			height: {required: true}
		}, 
		messages: {
			roomname: 'Please enter a name for your room.',
			email: 'Please enter a valid email address',
			walla: 'Please enter the length of this wall.',
			wallb: 'Please enter the length of this wall.',
			wallc: 'Please enter the length of this wall.',
			walld: 'Please enter the length of this wall.'
		},
		submitHandler: 	function(){
			var options = {
				target: 		'.output',
				type:			'post',
				success:		showResponse,
				url: 			submiturl
			};
			jQuery('#instantestimate').ajaxSubmit(options);	
			return false;
		}
	});
});


function showResponse(responseText, statusText){
	jQuery('#instantestimate').fadeOut('slow', function(){
		jQuery('.output').slideDown('slow');												  
	});
}

function toggle(id){
	jQuery('#' + id).slideToggle();
}

/* Validation */
function validateRequest(){

}

jQuery.validator.setDefaults({});
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");