var loading = 'bitte warten';

function setError(what,nummer){
	if(nummer==1){
		document.getElementById(what).style.color = '#800000';
		fehler++;
	}else
		document.getElementById(what).style.color = '#424A4E';
}

function warten(){
	loading += '.';
	if(loading == 'bitte warten....')
		loading = 'bitte warten';
	document.getElementById('fobu').value = loading;
	window.setTimeout("warten()",250);
}

function getRequestSend() {
	if (httpSend.readyState == 4) {
		if (httpSend.status == 200) {
			ergebnis 	= httpSend.responseText;	
			document.getElementById('k2').style.display = 'none';
			document.getElementById('k1').innerHTML = ergebnis;
			
			return true;							
		} else {
			alert('There was a problem with the request.');
		}
	}
}

function kontaktform(){
	
	erg = parseInt(document.kform.s1.value) + parseInt(document.kform.s2.value);
	
	fehler = '';
	if(document.kform.vorname.value=="" || document.kform.vorname.value.length <= 2) setError('e_vorname',1); else setError('e_vorname',0);
	if(document.kform.nachname.value=="" || document.kform.nachname.value.length <= 2) setError('e_nachname',1); else setError('e_nachname',0);
	if(document.kform.email.value=="" || document.kform.email.value.length < 8 || document.kform.email.value.indexOf('@')==-1 || document.kform.email.value.indexOf('.')==-1 ) setError('e_email',1); else setError('e_email',0);
	if(document.kform.nachricht.value=="" || document.kform.nachricht.value.length <= 2) setError('e_nachricht',1); else setError('e_nachricht',0);			
	if(erg != document.kform.spamschutz.value) setError('e_spam',1); else setError('e_spam',0);
	if(fehler==0){
		document.getElementById('fobu').style.disabled = true;
		warten();
		document.getElementById('hinweis').style.color 	= '#424A4E';
		document.getElementById('hinweis').innerHTML 	= 'Bitte füllen Sie alle Felder aus.';			
		
		
		if (window.XMLHttpRequest) { 
			httpSend = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
			httpSend = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		
		httpSend.onreadystatechange = getRequestSend;
		parameter = 'anrede='+escape(document.kform.anrede.value)+'&vorname='+escape(document.kform.vorname.value)+'&nachname='+escape(document.kform.nachname.value)+'&email='+escape(document.kform.email.value)+'&nachricht='+escape(document.kform.nachricht.value);
		//alert(ptr+'ajaxSend.php?'+parameter);
		httpSend.open('GET', ptr+'ajaxSend.php?'+parameter, true);
		httpSend.send(null);
		
	}else{
		document.getElementById('hinweis').style.color 	= '#800000';
		document.getElementById('hinweis').innerHTML 	= 'Bitte füllen Sie alle markierten Felder aus.';	
	}
}


