﻿$(document).ready(function(){

$("#feedback-send").click(function(){$("#feedback_info").submit();});


//------reg form

var options = {
	beforeSubmit:  function() {
		if (!$("#feedback_info").valid()) return false;

		show_popup("popup_update");
		$("#popup_update .ttl").html("Daten werden gesendet.");
		$("#popup_update .txt").html("Bitte warten...");

		return true;
	},
	success:  feedback_ok,
	error:      function(XMLHttpRequest, textStatus, errorThrown) {
		$("#popup_update .ttl").html("Error processing the request");
		$("#popup_update .txt").html("Invalid response");
	},

	url: '/contacts/?mode=json_feedback',
	type:      "post",
	dataType:  "json"
};


$("#feedback_info").ajaxForm(options).validate({
	errorPlacement: function(error, element) {

	},

	rules: {
		Email : {required: true,  email: true},
		Vorname : {required: true},
		Phone : {required: true},
		Text : {required: true}

	}
});



});



function feedback_ok(data)
{

	if(data["error"])
	{

		$("#popup_update .ttl").html("Fehler!");
		$("#popup_update .txt").html(data["error"]);

		return;
	}

	$("#popup_update .ttl").html("Mitteilung.");
	$("#popup_update .txt").html("Ihre Nachricht wurde an uns übermittelt.");


	setTimeout (function(){hide_popup("popup_update", true);}, 2000);

}

