function set_table_view(newview) {
  $('#table_view').attr('value', newview);
  $('#form2').submit();
}

function checkSeries2(series, cssclass, callerid, sub) {
  weight = $('#'+callerid).css('font-weight');
  
  if(weight == 'bold' || weight == '700') {
    $('#'+callerid).css('font-weight', 'normal');
    $('.'+sub).attr('value', 0);
  } else {
    $('#'+callerid).css('font-weight', 'bold');
    $('.'+sub).attr('value', 1);
  }
  hfs = $('input.'+ cssclass);
  for(x = 0; x < hfs.length; x++) {  
    cur = hfs[x];
    if(weight == 'bold' || weight == '700') {
      cur.value = '0';
      document.getElementById('a_'+series+'_'+cur.id.replace(series+'_', '')).style.fontWeight = 'normal';
    } else {
      cur.value = cur.id.replace(series+'_', '');      
      document.getElementById('a_'+series+'_'+cur.id.replace(series+'_', '')).style.fontWeight = 'bold';  
      $('#a_'+series+'_'+cur.id.replace(series+'_', '')).css('font-weight', 'bold');
    } 
  }
}

/* Aktiviert alle links mit dem Namen NAME */        
function checkAll3(name) {
 hiddenfields = document.getElementsByName(name+'[]');
 for(x = 0; x < hiddenfields.length; x++) {        
   newval = hiddenfields[x].id.substring(name.length+1);  
   document.getElementById(name +'_'+newval).value=newval;
   document.getElementById('a_'+name +'_'+newval).style.fontWeight='bold';
 }
}

/* Deaktiviert alle links mit dem Namen NAME */    
function uncheckAll3(crit, key) {
 hiddenfields = document.getElementsByName(crit+'[]');
 for(x = 0; x < hiddenfields.length; x++) {        
   newval = hiddenfields[x].id.substring(crit.length+1);
   if(newval != key) {  
     document.getElementById(crit +'_'+newval).value='0';
     document.getElementById('a_'+crit +'_'+newval).style.fontWeight='normal';
   }
 }
}

function switchview(id) {
	document.form3.view.value=id;
	if (id!="1")
	{
		document.form3.map_year.value=document.form3.map_year.value;
	}else{
		document.form3.map_year.value="";
	}
	document.form3.viewlevel.value=document.form3.viewlevel.value;
	document.form3.farbstufen.value="6";
	document.form3.show_crit.value="";
	$("#form3").submit();
}

function switchlevel(id,sid) {
	
	document.form3.viewlevel.value=id;
	if (sid!=0)
	{
		document.form3.sid.value=sid;
		if (id==1) document.form3.topnav_region.value="3";
		if (id==2) document.form3.topnav_region.value="2";
		if (id==3) document.form3.topnav_region.value="1";
	}
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
}


function switch_farben(anz) {
  document.form3.farbstufen.value=anz;
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
	// $("#chartmapdiv").load("chartmap_xml.php",{"completeform":completeform});
}

function switch_crits(anz) {
    document.form3.show_crit.value=anz;
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
	// $("#chartmapdiv").load("chartmap_xml.php",{"completeform":completeform});
}

function switch_crit_chart(anz) {
    if(document.form3.show_crit_chart.value == "") {
    	document.form3.show_crit_chart.value=anz;
    } else {
    	document.form3.show_crit_chart.value=document.form3.show_crit_chart.value+"#sep#"+anz;
    }
    
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
}

function switch_crit_chart_off(anz) {
    var arr = document.form3.show_crit_chart.value.split("#sep#");
    var fin = new Array();
    for(i = 0; i<arr.length; i++) {
    	if(arr[i] != anz)
    		fin.push(arr[i]);
    }
    document.form3.show_crit_chart.value = fin.join("#sep#");
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
}

function switch_crit_chart_reset() {
   document.form3.show_crit_chart.value = "";
}

function switch_verlauf(anz) {
  document.form3.verlauf.value=anz;
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
}

 function switch_year(doy) {
  document.form3.map_year.value=doy;
	completeform=$("#form3").serialize();
	document.form3.completeform.value=completeform;
	document.form3.submit();
}

function select_critera(crit, key, unselectother) {
  if(crit == 'crits') {
    $("input[name='auspr[]']").attr('value', 0);
    $("input[name='auspr_sub_do']").attr('value', 0);
    $("a[name='auspr_link']").css('font-weight', 'normal'); 
    $("tr.auspr_hide").css('display', 'none');
  }
  
  if(unselectother == 1) {
    uncheckAll3(crit, key);
    $('#ws_auspr').css('font-weight', 'normal');
  } 
  
  var field = crit +'_'+ key;
  if(document.getElementById(field).value == '0' || document.getElementById(field).value == '') {
    document.getElementById(field).value = key; 
    document.getElementById('a_'+field).style.fontWeight = 'bold';  
  } else {
    document.getElementById(field).value = '0';  
    document.getElementById('a_'+field).style.fontWeight = 'normal';
  }
         
}

function xls_export() {
  actionbackup = document.form3.action;
  document.form3.action = 'xls.php';
  document.form3.submit();   
  document.form3.action = actionbackup;
}


function saveMap(){
  //Get map from its ID
  var mapObject = getMapFromId('firstMap');
  // alert (mapObject);
  mapObject.saveAsImage();
}

function saveChart(){
  //Get map from its ID
  var chartObject = getChartFromId('Chart1');
  // alert (mapObject);
  chartObject.saveAsImage();
}

function saveMap2(val){
  document.printmap.submit();
}

function ausklappen(c) {
  $('.' + c).css('overflow', 'visible');
  $('.BlendeRechts').css('visibility', 'hidden');
  $('.ausklappen').css('display', 'none');
  $('.einklappen').css('display', 'inline');
  
  $('.tablecontainer').css('width', $('#datatable').width());
}

function einklappen(c) {
  $('.' + c).css('overflow', 'hidden');
  $('.BlendeRechts').css('visibility', 'visible');
  $('.einklappen').css('display', 'none');
  $('.ausklappen').css('display', 'inline');
  $('.tablecontainer').css('width', 'auto');
}


