$(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 fmessage=$("textarea#f_message").val();
		//alert(fmessage);
		if (fmessage == "" || fmessage=="Your Message" ) {
      $("label#f_message_error").show();
      $("textarea#f_message").focus();
      return false;
    }
	
	var email = $("input#f_email").val();
	var apos=email.indexOf("@");
  		var dotpos=email.lastIndexOf(".");	
		if (email == "" || email == "Email Address") {
      		 $("label#f_email_error").show();
     		 $("input#f_email").focus();
     	 return false; 
    }
	
	if ( apos<1 || dotpos-apos<2) {
     		 $("label#f_email_typeerror").show();
     		 $("input#f_email").focus();
      return false; 
    }
	
  
	//alert(emailCorrect);
		//if (email == "" || email == "Email Address" ) {
//      $("label#f_email_error").show();
//      $("input#f_email").focus();
//      return false;
//    }
		
		var dataString = 'f_email=' + email + '&f_message=' + fmessage;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/scripts/process.php",
      data: dataString,
	  
	  beforeSend: function() {
		 $("#footerContactWrapper").fadeOut(); 
		 setTimeout(function(){$("#contactSending").fadeIn();}, 1000); 
                },
            success: function() {
				setTimeout(function(){$("#contactSending").fadeOut();}, 2000);
				setTimeout(function(){$("#contactSent").fadeIn();}, 3500);
				;
                }
	
     });
    return false;
	});
});

runOnLoad(function(){
  $("input#f_message").select().focus();
});




function hideDeafult(obj)
{
	if(obj.value==obj.defaultValue)
	{
	obj.value="";
	}
	
}
function showDefault(obj)
{
	if(obj.value=="")
	{
	obj.value=obj.defaultValue;
	}
}

function hideDeafultText(obj)
{
	if(obj.value==obj.defaultValue)
	{
	obj.value="";
	}
	
}
function showDefaultText(obj)
{
	if(obj.value=="")
	{
	obj.value=obj.defaultValue;
	}
}


function validate_email(field)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return false;}
  else {return true;}
  }
}

