$(document).ready(function(){
  $("#form_info").hide();
  $("#submit_contact_request").bind("click", function(e) { process_contact(); return false; });
}); 

$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};

function process_contact() {
  $.ajax({
    type: "POST",
    url: "createContactRequest.php5",
    data: $("#kontaktform").serialize(),
    success: function(txt){
      if (txt == "ok") {
        $("#kontaktform").clearForm().hide();
	$("#form_info").html("Nachricht erfolgreich gesendet!");
	$("#form_info").fadeIn(1000, function() {
	  $("#container").mousemove(function() {
	    $("#form_info").fadeOut(500, function() {
	      $("#kontaktform").fadeIn(500);
	    });
	  });
	});
      } else {
        alert(txt);
      }	
    },
    error: function(msg){
      alert("Back. Error. :-( " + msg);
    }
  });
}

