$(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() {
	////clickthis();
   /// return false;
	//});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

function clickthis()
{
		// validate and process form
		// first hide any error messages
    //alert('clickths');
	$('.error').hide();

	  var name = $("input#cname").val();
		if (name == "") {
      $("label#cname_error").show();
      $("input#cname").focus();
      return false;
    }
		var email = $("input#cemail").val();
		if (email == "") {
      $("label#cemail_error").show();
      $("input#cemail").focus();
      return false;
    }
		var theid = $("input#theid").val();
		var phone = $("input#cemailto").val();
		if (phone == "") {
      $("label#cemailto_error").show();
      $("input#cemailto").focus();
      return false;
    }
		//alert ( theid );

		var dataString = 'cname='+ name + '&cemail=' + email + '&cemailto=' + phone + '&theid=' + theid + '&';
		//alert (dataString);return false;
	// $("#contactForm").hide();
	 $('#contact_form').html("<div id='message' style='margin-left:10px'> &nbsp;&nbsp; please wait... contacting server</div>");
		/*$.ajax({
		  type: "POST",
		  url: "http://www.workingthree.com/3wm/script/process.php",
		  data: dataString,
		  success: function() 
		  {
			$('#contact_form').html("<div id='message'></div>");
			$('#message').html("<h2>Nice, we've sent it on.</h2>")
				.append("<p>Good on you for sharing.</p>")
				.hide()
				.fadeIn(1500, function()
				{
				  $('#message').append("<img id='checkmark' src='images/check.png' />");
				}
				);
		  },
		  error: function() 
		  {
			$('#contact_form').html("<div id='message'></div>");
			$('#message').html("<h2>Sorry there has been a problem sending your message</h2>");
		   
		  }
       
	  });*/
	  //alert(phone+'-'+$("input#cemailto").val());
	  $.post("http://boredroom.3wisemen.com.au/script/process.php",
   { cname: name, cemail: email, cemailto: phone, theid: theid},
   	function(data){
		//$('#contact_form').html("<div id='message' style='margin-left:10px'></div>");
			//alert( $('#hiddendivo').html() );
			$('#message').html("<h2>Nice, we've sent it on.</h2>")
				.append("<p>Good on you for sharing.</p>")
				.hide()
				.fadeIn(3000, function()
				{
				  //$('#message').append("<a href=''>click here to share again</a>");)
				  setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow");', 2000);
				   setTimeout(' $("#contact_form").html($("#hiddendivo").html());', 3000);
				}
				);
	}
);
     //});	
}
