$(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_fed").click(function() {
	$("input#txtemail").css('border', 'none');
	$("input#txtname").css('border', 'none');
	$("textarea#comments").css('border', 'none');
								
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
  var name = $("input#txtname").val();
	if (name == "" || name=="Name") {
      $("name_error").show();
      $("input#txtname").focus();
	  $("input#txtname").css('border', 'solid');
	  $("input#txtname").css('border-color', '#ff0000');
	  $("input#txtname").css('border-width', '1px');
      return false;
    }
	var email = $("input#txtemail").val();
	if (email == "" || email=="Email address") {
      $("email_error").show();
      $("input#txtemail").focus();
	  $("input#txtemail").css('border', 'solid');
	  $("input#txtemail").css('border-color', '#ff0000');
	  $("input#txtemail").css('border-width', '1px');
      return false;
    }
	
	var experience = $("input[@name='chkfeedback']:checked").val();
	if (comments == "" ) {
      $("email_error").show();
      $("input#experience").focus();
      return false;
    }
	
	
	var comments = $("textarea#comments").val();
	if (comments == "" ) {
      $("email_error").show();
      $("textarea#comments").focus();
	  $("textarea#comments").css('border', 'solid');
	  $("textarea#comments").css('border-color', '#ff0000');
	  $("textarea#comments").css('border-width', '1px');

      return false;
    }
	 
		var dataString = 'name='+ name + '&email=' + email+ '&comments='+comments+'&experience='+experience;	
		var url = $("input#url").val();
		var image = $("input#image").val();
		
		
		$.ajax({
      type: "POST",
      url: url,
      data: dataString,
      success: function() {
        $('#feedback').html("<div id='message2'></div>");
		//$("#submit_btn").css{'display','none'};
        $('#message2').html("<br><br><br><br><h4>Your data is sent successfully!</h4>")
        .append("")
        .hide()
        .fadeIn(1500, function() {
          //$('#message').append("<img id='checkmark' "+image+" />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

