/* 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(unselectother == 1) {
    uncheckAll3(crit, key);
  } 
  
  var field = crit +'_'+ key;
  if(document.getElementById(field).value == '0') {
    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();
}