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

function showinfo(id, wk) {
	var owdiv = wk + 'paketinfo' + id;
	var owdivicon = wk + 'paketinfoicon' + id;
	
	if ($('#'+owdiv).css('display') == "none") { 
		$('#'+owdiv).fadeIn('slow');
		$('#'+owdivicon).html("");
		$('#'+owdivicon).html('<a onclick="showinfo(\'' + id + '\', \'' + wk + '\')"><img src="/basics/images/info_grau.png" alt="Info" /></a>');
		var cookie = id + "=1;";
		document.cookie = cookie;
	} else {  
		$('#'+owdiv).fadeOut('slow');
		$('#'+owdivicon).html('<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, bereich) {



	var pid = "";
	var paketpreisfeld = "paketpreis" + id;
	pid = $('#'+paketpreisfeld).attr('value');
	// Info ausblenden falls eingeblendet
	var cookie = id + "=0;";
	document.cookie = cookie;
			
    $.getJSON("/content.php?action=addpaket&bereich="+bereich+"&id="+id+"&pid="+pid,
          function(json){ 
			$('#paketliste').html(json.paketliste);
			$('#wkliste').html(json.wkliste);
          }
    );
}

function delpaket(pid, id, bereich) {
	// Info ausblenden falls eingeblendet
	var cookie = id + "=0;";
	document.cookie = cookie;
	
	$.getJSON("/content.php?action=delpaket&bereich="+bereich+"&id="+id+"&pid="+pid, 
          function(json){ 
			$('#paketliste').html(json.paketliste);
			$('#wkliste').html(json.wkliste);
          }
    );
		    
}

function showzusatzinfo() {
    if ($('#zusatzinfoinput').css('display') == "none") { 
		$('#zusatzinfoinput').fadeIn('slow');;
		var cookie = "showzusatzinfo=1;";
		document.cookie = cookie;
	} else {
		$('#zusatzinfoinput').fadeOut('slow');;
		var cookie = "showzusatzinfo=0;";
		document.cookie = cookie;
	}
}

function showraten() {
	if ($('#rateninfoinput').css('display') == "none") { 	
	    $('#rateninfoinput').fadeIn('slow');
		var cookie = "rateninfoinput=1;";
		document.cookie = cookie;
	} else {
	    $('#rateninfoinput').fadeOut('slow');
		var cookie = "rateninfoinput=0;";
		document.cookie = cookie;
	}
}
function showfoerder() {
    if ($('#foerderinfo').css('display') == "none") { 
        $('#foerderinfo').fadeIn('slow');
		var cookie = "foerderinfo=1;";
		document.cookie = cookie;
	} else {
		$('#foerderinfo').fadeOut('slow');
		var cookie = "foerderinfo=0;";
		document.cookie = cookie;
	}
}

function rateaender(rate, bereich) {
		var cookie = "rate="+rate;
		document.cookie = cookie;
		
		$.getJSON("/content.php?action=wkerneuern&bereich="+bereich,  
          function(json){ 
			$('#wkliste').html(json.wkliste);
            }
        );
}

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

function kombipaket(kombiname, bereich) {
    $.getJSON("/content.php?action=kombipaket&bereich="+bereich+"&kombiname="+kombiname,  
          function(json){ 
			$('#paketliste').html(json.paketliste);
			$('#wkliste').html(json.wkliste);
          }
    );
}


function paketspeichern() {
    $.getJSON("/content.php?action=paketspeichern",  
          function(){ 
			alert('Ihr aktuelle Auswahl wurde gespeichert, mit dem 1. Paket in der linken Spalte wird Ihre Auswahl wieder geladen.');
			$('#eigenespaket').fadeIn('slow');
			document.cookie = "eigenespaket=1";
          }
    );
}

function paketauslesen(bereich) {
	$.getJSON("/content.php?action=paketauslesen&bereich="+bereich,  
          function(json){ 
			$('#paketliste').html(json.paketliste);
			$('#wkliste').html(json.wkliste);
          }
    );
}

function anfrageform() {
    $.getJSON("/content.php?action=anfrageform",  
          function(json){ 
			  $('#wkliste').html(json.anfrageform);
          }
    );
}

function kontaktformularPruefen(transport) {
	//var response = transport.responseText;
	//var kontakt = response.evalJSON();
	
	var meldung = "";
	
	
	$('telefon').css('backgroundColor', '#fff');
	$('kontakt').css('backgroundColor', '#fff');
	$('plz').css('backgroundColor', '#fff');
	$('ort').css('backgroundColor', '#fff');
	$('adresse').css('backgroundColor', '#fff');
	$('fax').css('backgroundColor', '#fff');
	$('email').css('backgroundColor', '#fff');
	$('nachname').css('backgroundColor', '#fff');
	
	if($('#kontakt').attr('value') == 'anruf' && $('#telefon').attr('value') == "") {
		meldung += "Bitte geben Sie eine Telefonnummer für unseren Rückruf an\n";
		$('#telefon').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}
	if($('#kontakt').attr('value') == 'email_info' && $('#email').attr('value') == "") {
		meldung += "Bitte geben Sie eine E-Mail-Adresse an\n";
		$('#email').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}	
	if($('#kontakt').attr('value') == 'email_angebot' && $('#email').attr('value') == "") {
		meldung += "Bitte geben Sie eine E-Mail-Adresse an\n";
		$('#email').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}	
	if($('#kontakt').attr('value') == 'post_info' && $('#plz').attr('value') == "") {
		meldung += "Bitte geben Sie eine Adresse an\n";
		$('#plz').css('backgroundColor', '#FDD0D1');
		$('#ort').css('backgroundColor', '#FDD0D1');
		$('#adresse').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}	
	if($('#kontakt').attr('value') == 'post_angebot' && $('#plz').attr('value') == "") {
		meldung += "Bitte geben Sie eine Adresse an\n";
		$('#plz').css('backgroundColor', '#FDD0D1');
		$('#ort').css('backgroundColor', '#FDD0D1');
		$('#adresse').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}
	if($('#kontakt').attr('value') == 'fax_info' && $('#email').attr('value') == "") {
		meldung += "Bitte geben Sie eineFax-Nummer an\n";
		$('#fax').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}	
	if($('#kontakt').attr('value') == 'fax_angebot' && $('#email').attr('value') == "") {
		meldung += "Bitte geben Sie eine Fax-Nummer an\n";
		$('#fax').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}	

	if($('#kontakt').attr('value') == 'anruf' && $('#telefon').attr('value') == "") {
		meldung += "Bitte geben Sie eine Telefonnummer für unseren Rückruf an\n";
		$('#telefon').css('backgroundColor', '#FDD0D1');
		$('#kontakt').css('backgroundColor', '#FDD0D1');
	}
	
	if ($('#anrede').attr('value') == '') {
		meldung += "Bitte wählen Sie eine Anrede aus\n";
		$('#anrede').css('backgroundColor', '#FDD0D1');
	} else {
		$('#anrede').css('backgroundColor', '#FFFFFF');
	}
	if ($('#nachname').attr('value') == '') {
		meldung += "Bitte geben Sie Ihren Nachnamen an\n";
		$('#nachname').css('backgroundColor', '#FDD0D1');
	} else {
		$('#nachname').css('backgroundColor', '#FFFFFF');
	}
	if ($('#email').attr('value') == '' && $('#telefon').attr('value') == '') {
		meldung += "Bitte geben Sie eine E-Mail-Adresse und / oder Telefonnummer an\n";
		$('#telefon').css('backgroundColor', '#fffddb'); 
		$('#email').css('backgroundColor', '#fffddb'); 
	} else if ($('#email').attr('value') != '') {
		var email = $('#email').attr('value');
		$('#telefon').css('backgroundColor', '#FFFFFF');
		erg = emailGueltigkeitPruefen(email);
		if (erg == false) {
			meldung += "Bitte geben Sie eine gültige E-Mail-Adresse an\n";
			$('#email').css('backgroundColor', '#FDD0D1');
		} else {
			$('#email').css('backgroundColor', '#FFFFFF');
		}
	}
	
	if (meldung == "") {
	
		$('#absendeninfo').html("Bitte warten, Ihre Nachricht wird versendet ...");
	
		vorname = $('#vorname').attr('value');
		nachname = $('#nachname').attr('value');
		anrede = $('#anrede').attr('value');
		firma = $('#firma').attr('value');
		adresse = $('#adresse').attr('value');
		plz = $('#plz').attr('value');
		ort = $('#ort').attr('value');
		email = $('#email').attr('value');
		telefon = $('#telefon').attr('value');
		telefax = $('#fax').attr('value');
		region = $('#xregion').attr('value');
		

		kontakt = $('#kontakt').attr('value');
		termin = $('#termin').val();
		terminwunsch = $('#terminwunsch').attr('value');
		
		installation = $('#installation').val();
		
		
		mitteilung = $('#mitteilung').attr('value');
		
		$.getJSON("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,  
          function(json){ 
			$('#wkliste').html('<div class="anfrageform"><h4>Unverbindliche Anfrage</h4><p>Vielen Dank für Ihre Anfrage, wir werden Ihnen umgehend antworten.</p></div>');
          }
        );
	} else {
		alert(meldung);
	}
}

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);
}
