// JavaScript Document

//JQuery Code

$(function() {

  $('.error').hide();
/*  $('input.text').css({backgroundColor:"#FFFFFF"});
  $('input.text').focus(function(){
    $(this).css({backgroundColor:"#EEEEEE"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
*/
  $(".submit").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "" || name == "name") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		
		var email = $("input#email").val();
		if (email == "" || email == "email") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var comments = $("textarea#comments").val();
		if (comments == "" || comments == "message") {
      $("label#comments_error").show();
      $("input#comments").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email + '&comments=' + comments;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "scripts/_process.php",
      data: dataString,
      success: function() {
        $('#signup').html("<div id='message'></div>");
        $('#message').html("<h2 class='white'>Thank You "+name+".</h2>")
        .append("<p>Thanks for using my contact form to get in touch with me. If you\'re reading this, then your message is already in my inbox. I'll respond as soon as I check my email.<br /><br />While you\'re waiting for that, be sure and browse through my <b><a href=\'http://drewhorine.com\'>portfolio</a></b> and don\'t forget to download my <b><a href=\'http://drewhorine.com/drewhorine_resume.pdf\' target=\'_blank\'>resume</a></b> (in a handy printable PDF format).")
		
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});







//Idle Field Changers


	//Form Fields
		$(document).ready(function() {
			$('#name').addClass("idleField");
			$('#email').addClass("idleField");
			$('#comments').addClass("idleField");
       		
			$('#name').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('#name').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
       		
       		
			$('#email').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('#email').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
       		
       		
			$('#comments').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('#comments').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		});			
