$(document).ready(function() {
 $("#fbName").focus(function() {
  if(this.value == this.title)
   this.value = "";
 }).blur(function() {
  if(!this.value)
   this.value = this.title;
 });
 $("#fbEmail").focus(function() {
  if(this.value == this.title)
   this.value = "";
 }).blur(function() {
  if(!this.value)
   this.value = this.title;
 });
 $("#fbMsg").focus(function() {
  if(this.value == this.title)
   this.value = "";
 }).blur(function() {
  if(!this.value)
   this.value = this.title;
 });
 $("#fbForm").submit(function() {
  if(!is_string(this.name.value) || (this.name.value == this.name.title)) {
   alert("Укажите Ваше имя и компанию");
   this.name.focus();
   return false;
  }
  if(!is_email(this.email.value)) {
   alert("Укажите Ваш e-mail");
   this.email.focus();
   return false;
  }
  if(!is_string(this.msg.value) || (this.msg.value == this.msg.title)) {
   alert("Укажите Сообщение");
   this.msg.focus();
   return false;
  }
  $(this).ajaxSubmit({success:showR, url:'/feedsend.php', dataType:'json'});
  return false;
 });
});

function showR(data) {
 if(data[0] == 'OK') {
  $("#fbMsgDiv").empty().html("Сообщение отправлено");
  $("#fbFormDiv").hide();
 }
 else {
  var str = "К сожалению, невозможно оптравить сообщение:";
  for(var i = 0; i < data.length; i++) {
   str += '<br/>' + (i + 1) + '. ' + data[i];
  }
  $("#fbMsgDiv").empty().html(str);
 }
}

