
//
// Air quality now -functions...
//

function showStationBox(label,label2,label3,label4,region,name,param,value,index){

	
	var div=document.getElementById('divId');
//	alert(param);

	var html;
	var t11='style=\"font-family: Arial, Helvetica, sans-serif; font-size: 11px;\"';

	html='<table style=\"background: transparent; \"><tr><td colspan=\"2\" class=\"teksti11\"><b>'+label+':&nbsp;</b>'+index+'</td></tr>';

	var codes=param.split(":");
	

	if(value.length==0){
	
			html=html+'<tr><td class=\"teksti11bold\">'+label2+':</td><td '+t11+'>'+codes[1];
		for(i=2;i<codes.length;i++){
	
			html=html+', '+codes[i];
	
		}
		html=html+'</td></tr>';
		html=html+
		'<tr><td class=\"teksti11bold\">'+label3+':</td><td '+t11+'>'+codes[1]+'</td></tr>';

	}else{
		
		if(value=="NaN")
			value="";
		html=html+'<tr><td class=\"teksti11bold\">'+label2+':</td><td '+t11+'>'+codes[0]+'</td></tr>';
		
		html=html+'<tr><td class=\"teksti11bold\">'+label3+':</td><td '+t11+'>'+value+'</td></tr>';

	}
	html=html+'<tr><td class=\"teksti11bold\">'+label4+':</td><td '+t11+'>'+region+'</td></tr>';
	html=html+'</table>';
	div.innerHTML=html;
	
	
	
	if(div.style.visibility=='visible')
		div.style.visibility='hidden';
	else
		div.style.visibility='visible';
	

}

// Checks if given text is numeric or not...
function IsNumeric(sText){
  
  
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         	IsNumber = false;
         }
      }
   return IsNumber;
   
}
   
// Function is used when for example station is changed because selected station causes the viemode to change
// to graph...
function changeViewMode(mode){
	
	
	if(mode=="map"){
		
	}
	else if(mode=="graph"){
		
		var element=document.getElementById('stationselectId');
		var element2=document.getElementById('etk');
		
		if(IsNumeric(element.options[element.selectedIndex].value) && element2.checked){
		
			document.getElementById('etg').disabled=false;
			document.getElementById('etk').checked=false;
			document.getElementById('etg').checked=true;
			document.getElementById('ett').checked=false;
			//alert(document.getElementById('etg').checked);
		}
	}
	else{
		
	}
	
	
	
}



//Increases the handled hour by 1
function moveValueForward(value){

	
	var selectElement=document.getElementById(value);

	selectElement.selectedIndex=selectElement.selectedIndex+1;
	document.getElementById("form1").submit();
	
}

//Decreases the handled hour by 1
function moveValueBack(value){

	
	var selectElement=document.getElementById(value);

	if(selectElement.selectedIndex!=0){

		selectElement.selectedIndex=selectElement.selectedIndex-1;
		
		document.getElementById("form1").submit();
		//updateMap();
	}
	
}

//Increase or decrease date by given amount...
function changeDay(dayChange){

	var today=new Date();

	var hiddenTime=document.getElementById('karttaaika').value;

	var year=hiddenTime.substring(0,4);

	var month=hiddenTime.substring(4,6);

	month=month-1;
	var day=hiddenTime.substring(6,8);

	var oldpvm=new Date(year, month, day);
	var pvm=new Date(year, month, day);

	pvm.setDate(pvm.getDate()+dayChange);


	var newMonth=pvm.getMonth()+1+'';
	var newDay=pvm.getDate()+'';



	if(newMonth.length==1){

		newMonth='0'+newMonth;
	}
	if(newDay.length==1){
		newDay='0'+newDay;
	}




	var pvmString=pvm.getFullYear()+''+newMonth+''+newDay;

	document.getElementById('karttaaika').value=pvmString;
	document.getElementById('pvm1').value=newDay+'.'+newMonth+'.'+pvm.getFullYear();



	//if((today.getFullYear()+''+today.getMonth()+today.getDate()==pvm.getFullYear()+''+pvm.getMonth()+pvm.getDate()) || (today.getFullYear()+''+today.getMonth()+today.getDate()==oldpvm.getFullYear()+''+oldpvm.getMonth()+oldpvm.getDate()))
		document.getElementById('form1').submit();


}



//Gets the text of the selected area, region or station...
function getListText(id, secondaryId, lastId){

	
	//alert(parseFloat(document.getElementById(id).options[document.getElementById(id).selectedIndex].value));

	tmp=parseFloat(document.getElementById(id).options[document.getElementById(id).selectedIndex].value);

	//alert(tmp);

	if(!isNaN(tmp))
		document.write(document.getElementById(id).options[document.getElementById(id).selectedIndex].text);
	else{

		tmp=parseFloat(document.getElementById(secondaryId).options[document.getElementById(secondaryId).selectedIndex].value);

		if(!isNaN(tmp))
			document.write(document.getElementById(secondaryId).options[document.getElementById(secondaryId).selectedIndex].text);
		else
			document.write(document.getElementById(lastId).options[document.getElementById(lastId).selectedIndex].text);
	}
}


//Function used in graph-mode

// Unchecks all the plots on the graph
function uncheckPlots(count){

	//alert(count);

	parent.document.getElementById('deleteplot').value='0,'+count;



	//document.getElementById('plot0').checked=true;

	//updatePlots('plot0','0');
	//updatePlots('plot1','1');



}

// Checks or unchecks certain plot on the graph
function updatePlots(id, index){


	var check=document.getElementById(id);

	
	//alert(index);

	if(check.checked){

		parent.document.getElementById('addplot').value=index+',1';
		parent.document.getElementById('deleteplot').value='';
	}else{
		parent.document.getElementById('deleteplot').value=index+',1';
		parent.document.getElementById('addplot').value='';
	}

	//alert('toimiko? '+check+' '+id+' '+index);


}

//Changes some elements value
function changeElementValue(element, value){


	
	parent.document.getElementById(element).value=value;

	


}

function showPlot(id,force){


	var plot=document.getElementById(id);
	

	if(force.length>0)
		plot.style.visibility=force;
	else{
		if(plot.style.visibility!='hidden')
			plot.style.visibility='hidden';
		else
			plot.style.visibility='visible';
	}
}

function showAllPlots(){

	var mainBox=document.getElementById('plot-1');
	var check=false;
	
	check=mainBox.checked;
	
	var force="hidden";
	if(check)
		force="visible";
		
	var boxes=document.getElementsByName('plotBox');

	for(i=0;i<boxes.length;i++){
	
		boxes[i].checked=check;
		showPlot('plot'+(i+1),force);
	}
}



