
if (window.location.host.indexOf('tomcat')>-1)
{
	var server = "http://tomcat/maschinen-handel/site/";
}
else
{
	var server = "http://"+window.location.host+"/";
}

// umfrage-formular ueberpruefen

function checkForm()
{
	if(
	   document.umfrage.frage1[0].checked == false && document.umfrage.frage1[1].checked == false && document.umfrage.frage1[2].checked == false &&
	   document.umfrage.frage2[0].checked == false && document.umfrage.frage2[1].checked == false && document.umfrage.frage2[2].checked == false && 
	   document.umfrage.frage3[0].checked == false && document.umfrage.frage3[1].checked == false &&
	   document.umfrage.frage4[0].checked == false && document.umfrage.frage4[1].checked == false && document.umfrage.frage4[2].checked == false
	   )
	{
		alert("Bitte beantworten Sie mindestens eine Frage!");		
		return false;
	}   
}
function valanlegen()
{
	var error = new Array()
	var email = new RegExp ("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}|museum|travel$");
	var vorwahl = new RegExp("^([+][0-9 ]{2,}|0)([(]0[)]|)[0-9 ]{2,}$");
	var telefon = new RegExp("^[0-9- ]{3,}$");
	
	for (x=0;x<document.anlegen.length;x++)
	{
		document.getElementById(document.anlegen[x].name+"Label") ? document.getElementById(document.anlegen[x].name+"Label").style.color="#111C31" : '';
	}
	
	if (document.anlegen.kanzlei.value == '')
	{
		error.push('kanzlei');
	}
	if (document.anlegen.strasse.value == '')
	{
		error.push('strasse');
	}
	if (document.anlegen.plz.value == '' || isNaN(document.anlegen.plz.value) || document.anlegen.plz.value.length != 5)
	{
		error.push('plz');
	}
	if (document.anlegen.ort.value == '')
	{
		error.push('plz');
	}
	if (document.anlegen.vorwahl.value == '' || vorwahl.test(document.anlegen.vorwahl.value) == false)
	{
		error.push('vorwahl');
	}
	if (document.anlegen.tel.value == '' || telefon.test(document.anlegen.tel.value) == false)
	{
		error.push('tel');
	}
	if (document.anlegen.fax.value && telefon.test(document.anlegen.fax.value) == false)
	{
		error.push('fax');
	}
	if (document.anlegen.email.value == '' || email.test(document.anlegen.email.value) == false)
	{
		error.push('email');
	}
	for (x=0;x<error.length;x++)
	{
		document.getElementById(error[x]+'Label').style.color="#ff0000";
	}
	if (error.length>0)
	{
		alert('Bitte füllen Sie alle Rot markierten Formularfelder aus.');
		return false;
	}
	return true;
}
function loeschen()
{
	var test = confirm('Wirklich loeschen?');
	return test;
}

function domPop(dbid, action, idname)
{
	var y;
	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}
	
	var iframe = document.createElement("iframe");
	var id = document.createAttribute("id");
	var source = document.createAttribute("src");
	var frameb = document.createAttribute("frameborder");
	id.nodeValue = idname;
	source.nodeValue = server+action+".php?dbid=" + dbid;
	frameb.nodeValue = 0;
	iframe.setAttributeNode(id);
	iframe.setAttributeNode(source);
	iframe.setAttributeNode(frameb);
	document.getElementById('content').appendChild(iframe);
	document.getElementById(idname).style.top=(y+80)+"px";
	return false;
}
function domPopAus(action)
{
	parent.document.getElementById('content').removeChild(parent.document.getElementById(action));
	return false;
}
// ---- fkt. für Routenplaner
//
function adresscheck()
{
		if (document.routeForm.sstreet.value == "Strasse und Nr.") 
		{
			document.routeForm.sstreet.value = '';
		}
		if (document.routeForm.scity.value == "-Ort-") 
		{
			document.routeForm.scity.value = "";
		}
		if (document.routeForm.szip.value == "" || document.routeForm.szip.value == "PLZ") 
		{
			alert ("Bitte geben Sie eine Start PLZ ein.");
			return false;
		}
		else 
		{
			return true;
		}
}
// ---- fkt. für Routenplaner ende
//
/* Email Check */
function emailcheck()
{
	var error = new Array()
	var email = new RegExp ("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}|museum|travel$");
	
	for (x=0;x<document.emailForm.length;x++)
	{
		if (document.getElementsByName(document.emailForm[x].name)[0])
		{
			document.getElementsByName(document.emailForm[x].name)[0].style.background="white"
			document.getElementsByName(document.emailForm[x].name)[0].style.color="#808080"
		}
	}
	
	if (document.emailForm.name.value=='' || document.emailForm.name.value=='Ihr Name')
	{
		error.push('name');
	}
	if (document.emailForm.email.value == '' || email.test(document.emailForm.email.value) == false)
	{
		error.push('email');
	}
	if (document.emailForm.text.value=='' || document.emailForm.text.value=='Ihr Text')
	{
		error.push('text');
	}
	for (x=0;x<error.length;x++)
	{
		document.getElementsByName(error[x])[0].style.background="#ff0000";
		document.getElementsByName(error[x])[0].style.color="#000000";
	}
	if (error.length>0)
	{
		alert('Bitte füllen Sie alle Rot markierten Formularfelder aus.');
		return false;
	}
	return true;
}


/************************************************************/
/********* Funktionen fuer die Ajax-Geschichten *************/
/************************************************************/
function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		ro = new XMLHttpRequest();
	}
	return ro;
}
	
function sndReq(act, art) {
	action = act;
	land = art;
	http = createRequestObject();

	if (action == 'land') {
		land = document.europasuche.land.options[document.europasuche.land.selectedIndex].value;
		/*alert('ajax_check.php?action='+action+'&land='+land);*/
		
	     http.open('get', 'ajax_check.php?action='+action+'&land='+land);
		document.body.className = "curWait";
		http.onreadystatechange = handleResponse;
		http.send(null);
		
	}
		
	//alert('ortSelected: '+ortSelected);
	//alert('plzSelected: '+plzSelected);
}

function handleResponse() {
	// Auswahl Marke -> Update von Kategorie
	if (action == 'land') {
		if (http.readyState == 4) {
			document.body.className = "curNormal";
			var response = http.responseText;
			
			//alert(response);
			var werte = new Array();
			werte = response.split('###');
			
			//return false;
			document.getElementById('ort').options.length = 1;
			
			for (x=0; x<werte.length; x++) {
				var new_opt = document.createElement("option");
				new_opt.value = werte[x];
				new_opt.text = werte[x];
				document.getElementById('ort').options.add(new_opt);
			}
			document.getElementById('ort').disabled = false;
		}
	}
}