$(document).ready(function(){
  
  //setting up our value checks
  validate();
  
});


function validate()
{   

     formTarget = "checkIt";
     
     //can we submit it? this will tell us
     $("#submitBtn").click( submitHandler );

      //add classes to form in order to value check
     $("#formContain input").addClass(""+ formTarget +"");
     $("#formContain textarea").addClass(""+ formTarget +"");
      
      
      // on blur... check this value
     $("."+ formTarget +"").blur(function(){
          if( this.value == '' ){
              this.value=this.defaultValue;
              $(this).removeClass('hasValue').addClass('invalid');
          }
          else{
              $(this).addClass('hasValue');
          }
     });
     
     // on focus.. check this value
     $("."+ formTarget +"").focus(function(){
          if( this.value == this.defaultValue || this.val() == this.defaultValue ){
              this.value='';
          }
          // if focused, and was declared invalid, lets remove the invalid class
          if ( $(this).is(".invalid") ){
            $(this).removeClass("invalid");
          }
          $(this).removeClass('hasValue');
      });
}


function submitHandler( event )
{
  if ( $(".invalid").length || $(""+ formTarget +"").length )
  {
    event.preventDefault();
  }
}
