$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var comment = $("#comment").val();
		
		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comment=' + comment;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.html",
      data: dataString,
	  beforeSend: function() {
		  $('#loader').html("<img id='checkmark' src='i/ajax-loader.gif' style='margin-top:20' />");
		  },
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='i/check.png' />");
        });
      }
     });
    return false;
	});
});
//runOnLoad(function(){
  //$("input#name").select().focus();
//});


function submitenter(e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   return quote();
   return false;
   }
else
   return true;
}

function quote()
{
	var url;
	var qt = document.getElementById('formtype').value;
	if (qt != '')
	{
		var affil = 100035;
		var theme_id = 1669;
		var z = document.getElementById('formzip').value;
		var affil_name = 'illinoisinsurance-com';
		url = '/quotes.html?type='+ qt+ '&a='+ affil+ '&t='+ theme_id +'&c='+ affil_name;
		if (/^\d{5}$/.test(z))
		{
			url += '&zip='+ z;
		}
		document.location.href = url;
		return false;
	}
	return false;
}


