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

  $("input#submit_btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $('#txtname').attr('value');
	  if (name == "") {
		  $("label#txtname_error").show();
		  $("input#txtname").focus();
		  return false;
       }
		var phone = $("#txtphone").attr('value');
		if (phone == "") {
      $("label#txtphone_error").show();
      $("input#txtphone").focus();
      return false;
    }
		var debt = $("#txtdebt").attr('value');
		if (debt == "") {
      $("label#txtdebt_error").show();
      $("input#txtdebt").focus();
      return false;
    }
	   var state = $("#cmbstate").val();
	   var besttime = $("#cmbbesttime").val();
		
	   var dataString = 'name='+ name + '&phone=' + phone + '&debt=' + debt + '&state=' + state + '&besttime=' + besttime;
		//alert (dataString);return false;
		
		$.ajax({
			  type: "GET",
			  url: "php/email.php",
			  dataType: "html",
			  data: dataString,
			  success: function(response){
				$(':input')
 					.not(':button, :submit, :reset, :hidden')
 					.val('')
			 		.removeAttr('checked')
 					.removeAttr('selected');
			   // if sucessful; response will contain some stuff echo-ed from .php
			   // quick tect: alert("Here is your response: " + response);
			   // Append this response to some <div> => let's append it to div with id "serverMsg"
			  },
			  error: function(){
			   alert("Could not communicate with server please try again later");
			  }
			 });
    return false;
	});
});

runOnLoad(function(){
  $("input#txtname").select().focus();
});
