$(document).ready(function(){

 
	$('.box_two_entrie a').click(function() {
		var hrefAttr = $(this).attr('href');
		
		$.ajax({
			url: ''+hrefAttr,
			 dataType: 'html',
			 success: function(result) {
				$('.box_tree_entrie').html(result);
				// funktion zum Prüfen, ob checkboxen gesetzt sind
				kantonShowHide();
			 },
			 error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert('ERROR:'+errorThrown);
			 }
		});
		
		return false;
	});



		
var options = {   
    'maxCharacterSize': 250,   
    'originalStyle': 'originalDisplayInfo',   
    'warningStyle': 'warningDisplayInfo',   
    'warningNumber': 40,   
    'displayFormat': ' #left free'  
};   
$('#mytextarea').textareaCount(options);





	//Ziel: Wenn 'alle' gewählt wurde
$("input[name='check_all']").click(function(){
		if ($('#check_all:checked').is(':checked'))  {  // Insert code here.}
        $(this).parents("table")
               .find("input:checkbox")
               .attr("checked","checked");
				kantonShowHide();
		}else{
        $(this).parents("table")
               .find("input:checkbox")
               .attr("checked","");
				kantonShowHide();
		}
    }); 




	//Ziel: Die angekreutzten Kantone sollen nicht im Endresultat erscheinen

$("input[name='kanton[]']").click( function(){
	// funktion zum Prüfen, ob checkboxen gesetzt sind
	kantonShowHide();
});



});










function kantonShowHide(){
	
	// alle box_entrie anzeigen
	$('.box_tree_entrie .entries').hide();
	
	var formArray = $('#kantons').serializeArray();
	  	
	$.each(formArray,function(index,value) {
		if(value.name=='kanton[]'){
			$("div."+value.value).show();
		}
	});
}


function DivEinAusblenden(divName){
    $("div.box_two_entrie").css({'display' : 'none'});
	$("div."+divName).css({'display' : 'block'});
	$('.box_tree_entrie').html('');
}


function DivEinAusblendenForm(divName){

      if ($("div."+divName).css("display")!= "block")  {
			 $("div."+divName).css({'display' : 'block'});
      } else {
			 $("div."+divName).css({'display' : 'none'});       
      }
}
