YAHOO.util.Event.addListener(window, 'load', prepareCalculator);

function prepareCalculator(){
	// elements that show results and errors
	errorText = document.createElement("div");
	errorText.id = "errorText";
	errorText.className = "is24-hint-error";
	errorText.innerHTML = "<h3>Achtung:</h3><p>Bitte geben Sie einen Ort an.</p>";
	errorText.style.display = "none";
	YAHOO.util.Dom.insertBefore(errorText, document.searchEntranceSenioren.parentNode);
	
}

function searchSeniorEntrance(event){

	if(!document.all) { 
					event.preventDefault(); }
			else { 	var oEvent = window.event; oEvent.returnValue = false;}

	var form = document.searchEntranceSenioren;
	var plz = document.getElementById("sUS_plz").value;
	var ort = document.getElementById("sUS_ort").value;
	var umkreis = document.getElementById("sUS_dropdown").value;
	var host = window.location.protocol + "//" + window.location.host;
	
	
	if(!ort){
		showError();		
	}
	
	else if(form.radio_default_3.checked){
	
		var betreutesWohnen = host + "/servlet/requestDispatcher?portalAction=go&attr0=6&attr2=20&attr4=" + ort + "&attr5=&attr6=&attr7=" + plz + "&attr8=" + umkreis + "&attr65=true"									
		window.location.href = betreutesWohnen;
		hideError();
	}
	else if(form.radio_default_2.checked){
	
		var altenpflege =  host + "/servlet/requestDispatcher?portalAction=go&attr0=6&attr2=21&attr4=" + ort + "&attr5=&attr6=&attr7=" + plz + "&attr8=" + umkreis + "&attr65=true"
		window.location.href = altenpflege;	
		hideError();	
	}
}

function showError(){
	var ort = document.getElementById("sUS_ort");
	errorText.style.display = "block";
	YAHOO.util.Dom.addClass(ort.parentNode, "is24-invalid");
}

function hideError(){
	var ort = document.getElementById("sUS_ort");
	errorText.style.display = "none";
	YAHOO.util.Dom.addClass(ort.parentNode, "is24-required");
}