// Skripte: Kontakt-Formular Prüfen


// Ändert "Abschicken" in "Prüfen"
function setCheckButtonValue() {
	document.kontaktFormular.abschicken.value='Prüfen';
}


// Eine Eingabe allgemein prüfen; Fragezeichen setzen
function checkValue(o) {
	if (o.value=="" || o.value=="?") {
		o.value="?";
		return false;
	}
	return true; 
}

// Eine Eingabe allgemein prüfen; Warnung ausgeben setzen
function alertValue(o,msg) {
	if (o.value!="JA" || o.checked==false) {
		alert(msg);
		return false;
	}
	return true;

}

// Eingaben Prüfen
function checkValues() {
	var valuesOK=true;
	with (document.kontaktFormular) {
		valuesOK=valuesOK & checkValue(realname);
		if (!valuesOK) {
			alert("Es wurden nicht alle notwendigen Felder ausgefüllt");
		}
	}
	return valuesOK
}


// Ausgabe in Zeichenkette schreiben
function outString() {
	with (document.kontaktFormular) {
		ausgabe = "Kontakt:\n\n"
								   +"Name		: " + realname.value +"\n\n";
		if (anschrift.value!="") 	ausgabe +="Anschrift	: " + anschrift.value + "\n";
		if (telefon.value!="") 		ausgabe +="Telefon	: " + telefon.value	+"\n";
		if (email.value!="") 		ausgabe +="E-Mail		: " + email.value	+"\n\n";
		if (betreff.value!="") 		ausgabe +="Betreff	: " + betreff.value + "\n";
		if (message.value!="") 		ausgabe +="Nachricht 	: \n"+message.value	+"\n";
	}
	return ausgabe;
}

// Prüffenster
function openCheckAndSendWindow() {
	var checkAndSend = window.open("","_blank","width=650,height=600,menubar=no,scrollbars=yes,toolbar=no");
	checkAndSend.focus();
	with (checkAndSend.document) {
		writeln('<html><head>\n<title>Eingabeformular absenden</title>\n'+
			'<link rel="stylesheet" href="/css/ubDisplay.css" type="text/css">\n'+
			'</head><body>\n'+
			'<img src="/grafix/logo6ub.gif" style="float:none">\n'+
			'<h2 class="contentH2">Anmeldung</h2>\n'+
			'<pre style="width:600px; font-size:80%; border: 1px solid #2a2a2a; background-color: #e0e0e0; padding: 1em 1em 1em 1em">\n'+
			 outString()+'</pre>\n'+
			'<form method="POST" action="http://www.ulrichbuehrle.de/cgi/ubmail.cgi">\n'+
			'<input type="hidden" name="subject" value="'+document.kontaktFormular.subject.value+'">\n'+
			'<input type="hidden" name="realname" value="'+document.kontaktFormular.realname.value+'">\n'+
			'<input type="hidden" name="email" value="'+document.kontaktFormular.email.value+'">\n'+
			'<input type="hidden" name="redirect" value="'+document.kontaktFormular.redirect.value+'">\n'+
			'<input type="hidden" name="message" value="'+outString()+'">\n'+
		 	'<input type="submit" value="Abschicken" class="formButtonNL">\n'+
			'<input type="button" value="Zurück" class="formButtonNL" onClick="window.close()">\n'+
			'</form>\n'+
			'</body></html>');
	}

}


// Hauptfunktion
function checkForm() {
	if (checkValues()) {
		openCheckAndSendWindow();
	}
}