var http = null;
if (window.XMLHttpRequest) {
   http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
   http = new ActiveXObject("Microsoft.XMLHTTP");
}

function getInfoAbout(){
	infoAboutArray = document.getElementsByName("infoAbout");
	infoAbout="";
	spacer="";
	for(var i=0; i<infoAboutArray.length; i++){
		if(infoAboutArray[i].checked){
			infoAbout+=spacer+infoAboutArray[i].value;
			spacer="-";
		}
		
	}
	return infoAbout;
}

function checkMail(mail){
	if (http != null) {
		http.open("GET", "kontakt.php?action=checkMail?mail="+mail, true);
		http.onreadystatechange = responseCheckMail;
		http.send(null);
	}
}

function nl2br_10(s) {
	s+="";
	r=""; c="";
	while(s.length) {
		if(s.substr(0,1)=="\n") if(c!="\r") r+="<BR>";
		else if(s.substr(0,1)=="\r") if(c!="\n") r+="&ltBR>";
	 else r+=s.substr(0,1);
	 c=s.substr(0,1);
	 s=s.substr(1,s.length-1);
	}
	return r;
}

function sendMail(){
	infoAbout = getInfoAbout();
	mail = document.getElementById('email').value;
	company1 = document.getElementById('company1').value;
	company2 = document.getElementById('company2').value;
	company=company1+"\n"+company2;
	street = document.getElementById('street').value;
	plz = document.getElementById('plz').value;
	city = document.getElementById('city').value;
	cP = document.getElementById('cP').value;
	position = document.getElementById('position').value;
	tel = document.getElementById('tel').value;
	fax = document.getElementById('fax').value;
	messageText = "";
	messageText = document.getElementById("messageText").value;
	message = nl2br_10(messageText);
	if(http != null){
		http.open("get", "kontakt.php?infoAbout="+infoAbout+"&company="+company+"&mail="+mail+"&street="+street+"&plz="+plz+"&city="+city+"&cP="+cP+"&position="+position+"&tel="+tel+"&fax="+fax+"&messageText="+message, true);
		http.onreadystatechange = responseSendMail;
		http.send(null);
	}
}



function responseSendMail(){
	if(http.readyState==4){
		if(http.responseText>0){
			document.getElementById("message").innerHTML="Fehler!.";
		}
		else{
			document.getElementById("message").innerHTML="Ihre Nachricht wurde erfolgreich verschickt.";
			document.getElementById("kontaktForm").reset();
		}
	}
}

function countryChoose(select){
	countryCode = select.options[select.options.selectedIndex].value;
	switch(countryCode){
		case "1" : document.location.href="http://www.oranka.at"; break;
		case "2" : document.location.href="http://www.oranka.nl/FR/fr2005.php"; break;
		case "3" : document.location.href="http://www.oranka.nl/FR/fr2005.php"; break;
		case "4" : document.location.href="http://www.oranka.de"; break;
		case "5" : document.location.href="http://www.oranka.de"; break;
		case "6" : document.location.href="http://www.oranka.nl/NL/nl2005.php"; break;
		case "7" : document.location.href="http://www.oranka.nl/UK/uk2005.php"; break;
		default : false; break;
	}
}
