function switchpreise(gruppenid) {
	var cookie = 'mwst='+$F('mwst');
	document.cookie = cookie;
	window.location = "/baukasten.php?gruppenid="+ gruppenid;
}

function showinfo(id, wk) {
	var owdiv = wk + 'paketinfo' + id;
	var owdivicon = wk + 'paketinfoicon' + id;
	if ($(owdiv).style.display == "none") {
		$(owdiv).style.display = "block";
		$(owdivicon).innerHTML = "";
		$(owdivicon).innerHTML = '<a onclick="showinfo(\'' + id + '\', \'' + wk + '\')"><img src="/basics/images/info_grau.png" alt="Info" /></a>';
		var cookie = id + "=1;";
		document.cookie = cookie;
	} else {
		$(owdiv).style.display = "none";
		$(owdivicon).innerHTML = '<a onclick="showinfo(\'' + id + '\', \'' + wk + '\')"><img src="/basics/images/info_weiss.png" alt="Info" /></a>';
		var cookie = id + "=0;";
		document.cookie = cookie;
	}
}
function addpaket(id, gruppenid, anzeige) {
	var pid = "";
	var paketpreisfeld = "paketpreis" + id;
	pid = $(paketpreisfeld).value;
	// Info ausblenden falls eingeblendet
	var cookie = id + "=0;";
	document.cookie = cookie;
	new Ajax.Request("/content.php?action=addpaket&gruppenid="+gruppenid+"&id="+id+"&pid="+pid+"&anzeige="+anzeige,
			{
				method: 'get',
				onComplete: paketeerneuern,
				onFailure: function() { alert('Something went wrong...') }
			} );  
		    
}

function delpaket(pid, id, gruppenid, anzeige) {
	// Info ausblenden falls eingeblendet
	var cookie = id + "=0;";
	document.cookie = cookie;
	new Ajax.Request("/content.php?action=delpaket&gruppenid="+gruppenid+"&id="+id+"&pid="+pid+"&anzeige="+anzeige,
			{
				method: 'get',
				onComplete: paketeerneuern,
				onFailure: function() { alert('Something went wrong...') }
			} );  
		    
}
function paketeerneuern(transport) {
	var response = transport.responseText;
	var pakete = response.evalJSON();
	$('paketliste').innerHTML = pakete.paketliste;
	$('wkliste').innerHTML = pakete.wkliste;
	
}

function showzusatzinfo() {
	if ($('zusatzinfoinput').style.display == "none") {
		$('zusatzinfoinput').style.display = "block";
		var cookie = "showzusatzinfo=1;";
		document.cookie = cookie;
	} else {
		$('zusatzinfoinput').style.display = "none";
		var cookie = "showzusatzinfo=0;";
		document.cookie = cookie;
	}
}

function showraten() {
	if ($('rateninfoinput').style.display == "none") {
		$('rateninfoinput').style.display = "block";
		var cookie = "rateninfoinput=1;";
		document.cookie = cookie;
	} else {
		$('rateninfoinput').style.display = "none";
		var cookie = "rateninfoinput=0;";
		document.cookie = cookie;
	}
}
function showfoerder() {
	if ($('foerderinfo').style.display == "none") {
		$('foerderinfo').style.display = "block";
		var cookie = "foerderinfo=1;";
		document.cookie = cookie;
	} else {
		$('foerderinfo').style.display = "none";
		var cookie = "foerderinfo=0;";
		document.cookie = cookie;
	}
}

function rateaender(rate, bereich) {
		var cookie = "rate="+rate;
		document.cookie = cookie;
		new Ajax.Request("/content.php?action=wkerneuern&bereich="+bereich, 
			{
				method: 'get',
				onComplete: wkerneuern,
				onFailure: function() { alert('Something went wrong...') }
			} ); 
	
}

function wkerneuern(transport) {
	var response = transport.responseText;
	var pakete = response.evalJSON();
	$('wkliste').innerHTML = pakete.wkliste;
}

function mitteilungspeichern() {
	//var mitteilung = $('mitteilung').value;
	//var cookie = "mitteilung=" + mitteilung;
	//document.cookie = cookie;
}

function kombipaket(kombiname, bereich) {
	new Ajax.Request("/content.php?action=kombipaket&bereich="+bereich+"&kombiname="+kombiname, 
			{
				method: 'get',
				onComplete: paketeerneuern,
				onFailure: function() { alert('Something went wrong...') }
			} ); 
}


function paketspeichern() {
	new Ajax.Request("/content.php?action=paketspeichern", 
			{
				method: 'get',
				onComplete: paketspeichernok(),
				onFailure: function() { alert('Something went wrong...') }
			} ); 
}

function paketspeichernok() {
	alert('Ihr aktuelle Auswahl wurde gespeichert, mit dem 1. Paket in der linken Spalte wird Ihre Auswahl wieder geladen.');
	$('eigenespaket').style.display = "block";
	document.cookie = "eigenespaket=1";
	
}

function paketauslesen(bereich) {
	new Ajax.Request("/content.php?action=paketauslesen&bereich="+bereich, 
			{
				method: 'get',
				onComplete: paketeerneuern,
				onFailure: function() { alert('Something went wrong...') }
			} ); 
}
function anfrageform() {
	new Ajax.Request("/content.php?action=anfrageform", 
			{
				method: 'get',
				onComplete: anfrageformausgeben,
				onFailure: function() { alert('Something went wrong...') }
			} ); 
}
function anfrageformausgeben(transport) {
	var response = transport.responseText;
	var output = response.evalJSON();
	$('wkliste').innerHTML = output.anfrageform;
}




function kontaktformularPruefen(transport) {
	//var response = transport.responseText;
	//var kontakt = response.evalJSON();
	
	var meldung = "";
	
	
	$('telefon').style.backgroundColor = "#fff";
	$('kontakt').style.backgroundColor = "#fff";
	$('plz').style.backgroundColor = "#fff";
	$('ort').style.backgroundColor = "#fff";
	$('adresse').style.backgroundColor = "#fff";
	$('fax').style.backgroundColor = "#fff";
	$('email').style.backgroundColor = "#fff";
	$('nachname').style.backgroundColor = "#fff";
	
	if($('kontakt').value == 'anruf' && $('telefon').value == "") {
		meldung += "Bitte geben Sie eine Telefonnummer für unseren Rückruf an\n";
		$('telefon').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}
	if($('kontakt').value == 'email_info' && $('email').value == "") {
		meldung += "Bitte geben Sie eine E-Mail-Adresse an\n";
		$('email').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}	
	if($('kontakt').value == 'email_angebot' && $('email').value == "") {
		meldung += "Bitte geben Sie eine E-Mail-Adresse an\n";
		$('email').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}	
	if($('kontakt').value == 'post_info' && $('plz').value == "") {
		meldung += "Bitte geben Sie eine Adresse an\n";
		$('plz').style.backgroundColor = "#FDD0D1";
		$('ort').style.backgroundColor = "#FDD0D1";
		$('adresse').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}	
	if($('kontakt').value == 'post_angebot' && $('plz').value == "") {
		meldung += "Bitte geben Sie eine Adresse an\n";
		$('plz').style.backgroundColor = "#FDD0D1";
		$('ort').style.backgroundColor = "#FDD0D1";
		$('adresse').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}
	if($('kontakt').value == 'fax_info' && $('email').value == "") {
		meldung += "Bitte geben Sie eineFax-Nummer an\n";
		$('fax').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}	
	if($('kontakt').value == 'fax_angebot' && $('email').value == "") {
		meldung += "Bitte geben Sie eine Fax-Nummer an\n";
		$('fax').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}	
	
	
	if($('kontakt').value == 'anruf' && $('telefon').value == "") {
		meldung += "Bitte geben Sie eine Telefonnummer für unseren Rückruf an\n";
		$('telefon').style.backgroundColor = "#FDD0D1";
		$('kontakt').style.backgroundColor = "#FDD0D1";
	}
	
	if ($('anrede').value == '') {
		meldung += "Bitte wählen Sie eine Anrede aus\n";
		$('anrede').style.backgroundColor = "#FDD0D1";
	} else {
		$('anrede').style.backgroundColor = "#FFFFFF";
	}
	if ($('nachname').value == '') {
		meldung += "Bitte geben Sie Ihren Nachnamen an\n";
		$('nachname').style.backgroundColor = "#FDD0D1";
	} else {
		$('nachname').style.backgroundColor = "#FFFFFF";
	}
	if ($('email').value == '' && $('telefon').value == '') {
		meldung += "Bitte geben Sie eine E-Mail-Adresse und / oder Telefonnummer an\n";
		$('telefon').style.backgroundColor = "#fffddb";
		$('email').style.backgroundColor = "#fffddb";
	} else if ($('email').value != '') {
		var email = $('email').value;
		$('telefon').style.backgroundColor = "#FFFFFF";
		erg = emailGueltigkeitPruefen(email);
		if (erg == false) {
			meldung += "Bitte geben Sie eine gültige E-Mail-Adresse an\n";
			$('email').style.backgroundColor = "#FDD0D1";
		} else {
			$('email').style.backgroundColor = "#FFFFFF";
		}
	}
	
	if (meldung == "") {
	
		$('absendeninfo').innerHTML = "Bitte warten, Ihre Nachricht wird versendet ...";
	
		vorname = $('vorname').value;
		nachname = $('nachname').value;
		anrede = $('anrede').value;
		firma = $('firma').value;
		adresse = $('adresse').value;
		plz = $('plz').value;
		ort = $('ort').value;
		email = $('email').value;
		telefon = $('telefon').value;
		telefax = $('fax').value;
		region = $('xregion').value;
		

		kontakt = $('kontakt').value;
		termin = $F('termin');
		terminwunsch = $('terminwunsch').value;
		
		installation = $F('installation');
		
		
		mitteilung = $('mitteilung').value;
		new Ajax.Request("anfrage.php?action=formular_senden&xregion="+region+"&installation="+installation+"&kontakt="+kontakt+"&termin="+termin+"&terminwunsch="+terminwunsch+"&vorname="+vorname+"&nachname="+nachname+"&anrede="+anrede+"&firma="+firma+"&adresse="+adresse+"&plz="+plz+"&ort="+ort+"&email="+email+"&telefon="+telefon+"&telefax="+telefax+"&mitteilung="+mitteilung, 
		{
			method: 'get',
			onSuccess: getKontaktBestaetigung,
			onFailure: function() { alert('Something went wrong...') }
		} );
	} else {
		alert(meldung);
	}
}

function getKontaktBestaetigung() {
	$('wkliste').innerHTML = '<div class="anfrageform"><h4>Unverbindliche Anfrage</h4><p>Vielen Dank für Ihre Anfrage, wir werden Ihnen umgehend antworten.</p></div>';

}
function emailGueltigkeitPruefen(s) {
	 var a = false;
	 var res = false;
	 if(typeof(RegExp) == 'function')
	 {
		  var b = new RegExp('abc');
		  if(b.test('abc') == true){a = true;}
	 }
	
	 if(a == true)
	 {
	  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
	                   '(\\@)([a-zA-Z0-9\\-\\.]+)'+
	                   '(\\.)([a-zA-Z]{2,4})$');
	  res = (reg.test(s));
	 } else {
	  res = (s.search('@') >= 1 &&
	         s.lastIndexOf('.') > s.search('@') &&
	         s.lastIndexOf('.') >= s.length-5)
	 }
	 return(res);
}
