$(document).ready(function(){
   window.onload = function () {
   var re = new RegExp('\\b' + 'Please' + '\\b');
    $("dd").each(function (i){
          var $match = $("dt").eq(i);
          $(this).children('input').focus( function () {
                $match.children('strong').hide();
                if ($(this).val().match(re)) {
                    $(this).css('color','#333333');
                    $(this).val('');
                }
          });
          $(this).children('input').blur( function () {
              if ($(this).attr('class') == 'error' && $(this).val() == "") {
                       $(this).val('Please fill in required field.');
                       $(this).css('color','#cc0000');

              }
          });
    });
  }

    $("form#contact_us").submit( function () {
     var error_messages = 0;
      /** text fields **/
     var fields_required = {'contact_name':'ContactName','contact_email':'ContactEmail'};

     var error_fields = [];

     error_fields['ContactName'] = 'Please fill in required field.';
     error_fields['ContactEmail'] = 'Please fill in required field.';
      
     $.each(fields_required,function(key,val) {
              $("dt").each( function (i) {
              var $match = $("dd").eq(i);
              var temp_var = $(this).children('label').text().replace(/ /g,'');
              var temp_var = temp_var.replace(/:/g,'');
              var temp_var = temp_var.replace(/\*/g,'');

              if ($("input#"+key).val() == "") {
                            if (temp_var == val) {
                                  error_messages++;
                                  var existing_class = $("input#"+key).attr('class');
                                  $("input#"+key).addClass('error');
                                  $("input#"+key).val(error_fields[val]);
                            }
             }

             if ($("input#"+key).val() != "") {
                  if (temp_var == val) {
                    if ($("input#"+key).val() == "Please fill in required field.") {
                        error_messages++;
                    }
                  }
             }

             if ($("input#"+key).val() != "" && ($("input#"+key).val() != 'Please fill in required field.')) {
                      if(key == 'Email') {
                      }
             } 
         });
      });
        if (error_messages > 0 ) {
          return false;    
        }

   });
});
