// JavaScript Document

function CallbackForm() {
	var f = document.callback;
	var msg = '';
	var bol = true;
	
	if(f.cb_telefon.value == '') {
		msg = 'Bitte geben Sie Ihre Telefonnummer für den Rückruf ein!';
		f.cb_telefon.focus();
		bol = false;
	}
	
	if(f.cb_name.value == '') {
		msg = 'Das Feld Name (Ansprecherson / Firma) bitte ausfüllen!';
		f.cb_name.focus();
		bol = false;
	}
	
	if(bol) {
		// Ajax
		var myAjax = new Ajax();
		myAjax.url = "eigene_scripts/mail.php";
		myAjax.method = "POST";
		myAjax.params = "cb_name=" + encodeURIComponent(f.cb_name.value);
		myAjax.params += "&cb_telefon=" + encodeURIComponent(f.cb_telefon.value);
		myAjax.params += "&cb_anmerkung=" + encodeURIComponent(f.cb_anmerkung.value);
		myAjax.params += "&cb_rueckruf=" + encodeURIComponent(f.cb_rueckruf.value);
		myAjax.params += "&ajax=true";
		
		// Response war erfolgreich
		myAjax.onSuccess = function(txt, xml) {
			//alert(txt); // Rückgabewert aus PHP
			var callbackform = document.callback;
			callbackform.innerHTML = "<h6>Callback - Rückrufservice </h6>\
<p>Danke für Ihre Nachricht.</p>\
<div><input type=\"button\" name=\"new_callback\" id=\"new_callback\" value=\"Callback Formular aufrufen !\" onclick=\"location.href=document.URL\" /></div>";
		}
		
		// Fehler bei Kommunikation zwischen Client und Server
		myAjax.onError = function(msg) {
			alert("Fehler bei Kommunikation zwischen Client und Server: " + msg);
		}
		
		// ausführen
		myAjax.doRequest();		
	}
	else {
		alert(msg);
	}
	
	return false; // immer abbrechen
}
