$(document).ready(function(){
	$('#quote_form').validate({
    wrapper: 'span style="color: red; font-style: italic;"',
		rules: {
			quote_name: {
        requiredWithValue: 'Your Name'
      },  	
			quote_email: {
        requiredWithValue: 'Your Email',
				email: true
			},
      quote_phone: {
        requiredWithValue: 'Your Phone Number',
        phoneUS: true
      }
		},
		messages: {
			quote_name: {
				requiredWithValue: "Enter your full name",
        equalTo: "Not = name"				
			},
			quote_company: {
				requiredWithValue: "Enter your company name"				
			},      
			quote_email: {
				requiredWithValue: "Enter your email address.",
				email: "Invalid email address."
			},
			quote_phone: {
				requiredWithValue: "Enter your telephone number.",
				phoneUS: "Invalid telephone number."
			}      								
		},
    submitHandler: function(form) {
      $.ajax({
  			type: 'POST',
  			url: 'bin/quote.php',
  			dataType: 'json',
  			data: {
  				name: $('#quote_name').val(),				
  				email: $('#quote_email').val(),
  				phone: $('#quote_phone').val(),								
  				message: $('#quote_message').val()										
  			},
        success: function(data){
          $("#quote_form").hide("slow");          	
        	//$('#quote_name').val('');
        	//$('#quote_company').val('');
        	//$('#quote_email').val('');
        	//$('#quote_phone').val('');
        	//$('#quote_message').val('');                           					          
          $('#quote_error span').html(data.msg);
          $("#quote_error").show("slow");            
        }
      });
    }      
	});
  
	$('#coupon_form').validate({
    wrapper: 'span style="color: red; font-style: italic;"',
		rules: { 	
			coupon_email: {
//        requiredWithValue: 'Your Email',
				email: true
			}
		},
		messages: {     
			coupon_email: {
//				requiredWithValue: "Enter your email address.",
				email: "Invalid email address."
			}      								
		},
    submitHandler: function(form) {
      $.ajax({
  			type: 'POST',
  			url: 'bin/coupon.php',
  			dataType: 'json',
  			data: {		
  				email: $('#coupon_email').val()								
  			},
        success: function(data){
          $("#coupon_request").hide("slow");          	
        	//$('#quote_name').val('');
        	//$('#quote_company').val('');
        	//$('#quote_email').val('');
        	//$('#quote_phone').val('');
        	//$('#quote_message').val('');                           					          
          $('#coupon_message span').html(data.msg);
          $("#coupon_message").show("slow");            
        }
      });
    }      
	});
  
  // set the initial values for the quote form in the footer
	$('#quote_name').val('Your Name');
	$('#quote_company').val('Your Company');
	$('#quote_email').val('Your Email');
	$('#quote_phone').val('Your Phone Number');
	$('#quote_message').val('Your Message');				
	   
	// set the inline labels on the quote form when user leaves entry field
	$('#quote_form #quote_name').blur(function() 
	{
		if ($.trim($(this).val()) == '') 
		{
			$(this).val('Your Name');
		}		
	});

	$('#quote_form #quote_company').blur(function() 
	{
		if ($.trim($(this).val()) == '') 
		{
			$(this).val('Your Company');
		}		
	});
	
	$('#quote_form #quote_email').blur(function() 
	{
		if ($.trim($(this).val()) == '') 
		{
			$(this).val('Your Email');
		}		
	});  
	
	$('#quote_form #quote_phone').blur(function() 
	{
		if ($.trim($(this).val()) == '') 
		{
			$(this).val('Your Phone Number');
		}		
	}); 
	
	$('#quote_form #quote_message').blur(function() 
	{
		if ($.trim($(this).val()) == '') 
		{
			$(this).val('Your Message');
		}		
	}); 	
		
	// clear the inline labels on the quote form when user clicks entry field
	$('#quote_form #quote_name').focus( function() 
	{ 
		if ($(this).val() == 'Your Name') 
		{
			$(this).val('');
		}
	});

	$('#quote_form #quote_company').focus( function() 
	{ 
		if ($(this).val() == 'Your Company') 
		{
			$(this).val('');
		}
	});

	$('#quote_form #quote_email').focus( function() 
	{ 
		if ($(this).val() == 'Your Email') 
		{
			$(this).val('');
		}
	});

	$('#quote_form #quote_phone').focus( function() 
	{ 
		if ($(this).val() == 'Your Phone Number') 
		{
			$(this).val('');
		}
	});	
	
	$('#quote_form #quote_message').focus( function() 
	{ 
		if ($(this).val() == 'Your Message') 
		{
			$(this).val('');
		}
	});			
});
