
var totTidsteg;

  /*
   * Write an script tag into the document that will make the forecast table for the current place available.
   */
   
  function writeForecastTableImporter() {
    if (isLeafNode(selectedNodeNum)) {
      var placeId = nodeArray[selectedNodeNum].placeId;
      document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=landvader&komId=" + placeId + "'><\/script>");
      document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=stat&komId=" + placeId + "'><\/script>");
    }
  }

  /*
   * Write the imported forecast data table into the document.
   */

  function printForecastDataTable() {
    // Sverigeväder
	var dagsMarkeringar = new Array();
	dagsMarkeringar['mo']=phraseArray[21];
	dagsMarkeringar['em']=phraseArray[22];
	dagsMarkeringar['kv']=phraseArray[23];
	dagsMarkeringar['na']=phraseArray[24];
	dagsMarkeringar['da']=phraseArray[25];
	

	
	var vindriktningar = new Array('',phraseArray[46],phraseArray[47],phraseArray[48],phraseArray[49],phraseArray[50],phraseArray[51],phraseArray[52],phraseArray[53]);
if (totTidsteg == 0) {
	document.write('No data available...');
} else if (totTidsteg == 6) {
    // Utlandstabell
	
	var aktbgArr = new Array(col1,col2,col1,col2,col1);
	var aktbgArrSel = new Array(col1,col2,col1,col2,col1);
	


	

	
	document.write("<a name='vtabell'><table bgcolor=white cellspacing=0 cellpadding=0 width=360>");
	document.write('<TR>');
		document.write("<td colspan='8' class='ntv_rubrik_bottom'><b>***"+ ortsNamn +"***</b></td>");
	document.write('</TR>');
	document.write('<TR>');
	document.write('<TD align=center>');
	document.write('<img src=\"img/trans.gif\" width=1 height=5>');
	document.write('<table border=0 cellspacing=0 cellpadding=0 bgcolor=#000000>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=1 cellpadding=0>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=0 cellpadding=0 border=0>');
	document.write('<TR>');
	
	
	for (var aktTidsteg=0;aktTidsteg<5;aktTidsteg++) {
		document.write("<td bgcolor='"+ aktbgArr[aktTidsteg] +"' width=40 align=center>"+ printDateFromForecast(aktTidsteg) +"</td>");
		if (aktTidsteg  != 4)
		{
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
		
	document.write('<TR>');
	document.write('<TD>');
	document.write('<img src=\"img/trans.gif\" width=1 height=1>');
	document.write('</TD>');
	document.write('</TR>');	

	// Symb rad 1
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<5;aktTidsteg++) {
		document.write("<td bgcolor=#FFFFFF valign=\"center\"><img src=\"img/trans.gif\" width=4 height=2 align=top><br><img src=\"img/trans.gif\" width=2 height=2 align=top><img src=\""+symbolLib16+"/dag/ntvms16_"+valuesArray[aktTidsteg+'-symbol']+".gif\"><img src=\"img/trans.gif\" width=2 height=1></td>");
		if (aktTidsteg  != 4)
		{
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<5;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' align=\"middle\">"+Math.round(valuesArray[aktTidsteg+'-tmax'])+"&deg;</td>");
		if (aktTidsteg  != 4)
		{
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<5;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' class='ntv_vrikt'>"+vindriktningar[valuesArray[aktTidsteg+'-vrikt']]+"<br>"+valuesArray[aktTidsteg+'-vhast']+" m/s</td>");
		if (aktTidsteg  != 4)
		{
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
	document.write('</TABLE>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('</TABLE>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('</TABLE>');
	document.write('<img src=\"img/trans.gif\" width=1 height=5>');
	document.write('</TD>');
	document.write('</TR>');
	document.write("</table></a>");

	// document.location='#vtabell';

    } else if (totTidsteg > 10) {
	var aktbg;
	for (var x=0;x<23;x++) {
		if (valuesArray[x+'-datum']=="") { alert ('saknar '+x); }
	}
      document.write("<a name='vtabell'><table bgcolor=white cellspacing=0 cellpadding=2 width=360 border=0>");
	document.write('<TR>');
		document.write("<td colspan='8' bgcolor='#666666'><table><tr><td rowspan='2' valign='top'><b><font color=#FFFFFF>"+ ortsNamn +"</b><font color=#FFFFFF> kl "+nuvaderArr[2].substr(0,5)+"</td><td><font color=#FFFFFF> Temp:<b>"+nuvaderArr[0]+"</b>&deg;C, Nederbörd/timme:<b>"+nuvaderArr[5]+"mm</b>,</td></tr><tr><td><font color=#FFFFFF> Luftfuktighet:<b>"+nuvaderArr[6]+"</b>%</td></tr></table></td>");
	document.write('</TR>');

	// var aktbgArr = new Array('#9DB7D6','#D49D9C','#9DB7D6','#D49D9C','#9DB7D6');
	// var aktbgArrSel = new Array('#AEC8E7','#E5AEAD','#AEC8E7','#E5AEAD','#AEC8E7');
	document.write('<TR>');
	document.write('<TD align=center>');
	document.write('<img src=\"img/trans.gif\" width=1 height=5>');
	document.write('<table border=0 cellspacing=0 cellpadding=0 bgcolor=#000000>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=1 cellpadding=0>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=0 cellpadding=0>');
	document.write('<TR>');
		document.write("<td colspan='7' bgcolor='"+col1+"'>"+ printDateFromForecast(0) +"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		document.write("<td colspan='8' bgcolor='"+col2+"'>"+ printDateFromForecast(4) +"</td>");
	document.write('</TR>');
	
	document.write('<TR>');
	document.write('<TD>');
	document.write('<img src=\"img/trans.gif\" width=1 height=1>');
	document.write('</TD>');
	document.write('</TR>');	
	
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4*2;aktTidsteg++) {
		if (aktTidsteg>3) { aktbg=col2; } else { aktbg=col1; }
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			document.write("<td bgcolor='"+ aktbg +"' align=\"middle\">"+dagsMarkeringar[valuesArray[aktTidsteg+'-tidsteg']]+"</td>");
			if (aktTidsteg  != 7)
			{
				document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
			}
		} else {
			document.write("<td bgcolor="+colnodata+" align=\"middle\"><img src=\"img/trans.gif\" width=37 height=1></td>");
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<img src=\"img/trans.gif\" width=1 height=1>');
	document.write('</TD>');
	document.write('</TR>');

	// Symb rad 1
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4*2;aktTidsteg++) {
		
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			var directory;
			if (aktTidsteg==0 || aktTidsteg==1 || aktTidsteg==4 || aktTidsteg==5) directory = "dag/";
			else directory = "natt/";
			document.write("<td bgcolor=#FFFFFF valign=\"center\"><img src=\"img/trans.gif\" width=4 height=2 align=top><br><img src=\"img/trans.gif\" width=2 height=2 align=top><img src=\""+symbolLib15+"/"+directory+"ntvms15_"+valuesArray[aktTidsteg+'-symbol']+".gif\"><img src=\"img/trans.gif\" width=2 height=1></td>");
			if (aktTidsteg  != 7)
			{
				document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
			}
		} else {
			document.write("<td bgcolor="+colnodata+" valign=\"bottom\">&nbsp;</td>");
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4*2;aktTidsteg++) {
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			//document.write("<td bgcolor='"+ aktbg +"' align=\"middle\">"+Math.round(valuesArray[aktTidsteg+'-temp'])+"&deg;</td>");
			document.write("<td bgcolor=#FFFFFF align=\"middle\">"+Math.round(valuesArray[aktTidsteg+'-temp'])+"&deg;</td>");
			if (aktTidsteg  != 7)
			{
				document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
			}
		} else {
			document.write("<td bgcolor='"+colnodata+"' align=\"middle\">&nbsp;</td>");
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4*2;aktTidsteg++) {
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			//document.write("<td bgcolor='"+ aktbg +"' class='ntv_vrikt'>"+vindriktningar[valuesArray[aktTidsteg+'-vrikt']]+"<br>"+Math.round(valuesArray[aktTidsteg+'-vhast'])+" m/s</td>");
			document.write("<td bgcolor=#FFFFFF class='ntv_vrikt'>"+vindriktningar[valuesArray[aktTidsteg+'-vrikt']]+"<br>"+Math.round(valuesArray[aktTidsteg+'-vhast'])+" m/s</td>");
			if (aktTidsteg  != 7)
			{
				document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
			}
		} else {
			document.write("<td bgcolor='"+colnodata+"' align=\"middle\">&nbsp;</td>");
			document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	// RAD 1 SLUTAR //
	document.write('</table>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('</table>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('</table>');
	document.write('</TD>');
	document.write('</TR>');
	document.write('<TR>');
	document.write('<TD align=center>');
	document.write('<img src=\"img/trans.gif\" width=1 height=5>');
	document.write('<table border=0 cellspacing=0 cellpadding=0 bgcolor=#000000>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=1 cellpadding=0>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<table border=0 cellspacing=0 cellpadding=0>');
	// RAD 2 BÖRJAR //

	document.write('<TR>');
		document.write("<td colspan='7' bgcolor='"+col1+"'>"+ printDateFromForecast(8) +"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		document.write("<td colspan='3' bgcolor='"+col2+"'>"+ printDateFromForecast(12) +"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		document.write("<td colspan='3' bgcolor='"+col1+"'>"+ printDateFromForecast(16) +"</td>");
	document.write('</TR>');

	document.write('<TR>');
	document.write('<TD>');
	document.write('<img src=\"img/trans.gif\" width=1 height=1>');
	document.write('</TD>');
	document.write('</TR>');	

	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		document.write("<td bgcolor='"+col1+"' align=\"middle\">"+dagsMarkeringar[valuesArray[(8+aktTidsteg)+'-tidsteg']]+"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
			
	}
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		if (aktTidsteg>1) { aktbg=col1; } else { aktbg=col2; }
		//if (aktTidsteg>1) { aktbg='#AEC8E7'; } else { aktbg='#E5AEAD'; }
		if (valuesArray[(12+(aktTidsteg*2))+1+'-tidsteg'] == 'em') { valuesArray[(12+(aktTidsteg*2))+1+'-tidsteg'] = 'da'; }
		document.write("<td bgcolor='"+ aktbg +"' align=\"middle\">"+dagsMarkeringar[valuesArray[(12+(aktTidsteg*2))+1+'-tidsteg']]+"</td>");
		if (aktTidsteg != 3){
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
	document.write('<TR>');
	document.write('<TD>');
	document.write('<img src=\"img/trans.gif\" width=1 height=1>');
	document.write('</TD>');
	document.write('</TR>');	
	// Symb rad 2
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		var directory;
		if (aktTidsteg==0 || aktTidsteg==1) directory = "dag/";
		else directory = "natt/";
		document.write("<td bgcolor='#FFFFFF' valign=\"bottom\" align=\"middle\"><img src=\"img/trans.gif\" width=4 height=2 align=top><br><img src=\"img/trans.gif\" width=2 height=2 align=top><img src=\""+symbolLib15+"/"+directory+"ntvms15_"+valuesArray[(8+aktTidsteg)+'-symbol']+".gif\"><img src=\"img/trans.gif\" width=2 height=2 align=top></td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
	}
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		var directory;
		if (aktTidsteg==0 || aktTidsteg==2) directory = "dag/";
		else directory = "natt/";
		document.write("<td bgcolor='#FFFFFF' valign=\"bottom\" align=\"middle\"><img src=\"img/trans.gif\" width=4 height=2 align=top><br><img src=\"img/trans.gif\" width=2 height=2 align=top><img src=\""+symbolLib15+"/"+directory+"ntvms15_"+valuesArray[(12+(aktTidsteg*2))+1+'-symbol']+".gif\"><img src=\"img/trans.gif\" width=2 height=2 align=top></td>");
		if (aktTidsteg != 3){
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	// Temp rad 2
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' align=\"middle\">"+Math.round(valuesArray[(8+aktTidsteg)+'-temp'])+"&deg;</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
	}
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' align=\"middle\">"+Math.round(valuesArray[(12+(aktTidsteg*2))+1+'-temp'])+"&deg;</td>");
		if (aktTidsteg != 3){
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');

	// Vind rad 2
	document.write('<TR>');
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' class='ntv_vrikt'>"+vindriktningar[valuesArray[(8+aktTidsteg)+'-vrikt']]+"<br>"+Math.round(valuesArray[(8+aktTidsteg)+'-vhast'])+" m/s</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
	}
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		document.write("<td bgcolor='#FFFFFF' class='ntv_vrikt'>"+vindriktningar[valuesArray[(12+(aktTidsteg*2))+1+'-vrikt']]+"<br>"+valuesArray[(12+(aktTidsteg*2))+1+'-vhast']+" m/s</td>");
		if (aktTidsteg != 3){
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		}
	}
	document.write('</TR>');
	document.write('</table>');
	document.write('</TD>');
	document.write('</TR>');
	document.write("</table>");
	document.write('</TD>');
	document.write('</TR>');
	document.write("</table>");
	document.write('<img src=\"img/trans.gif\" width=1 height=5>');
	document.write('</TD>');
	document.write('</TR>');
	document.write("</table>");


	} else {
		document.write("<table bgcolor=white cellspacing=0 cellpadding=2 width=360 border=0><tr><td></td></tr></table>");
	}
	
  }

  function printDateFromForecast(qTidsteg) {
	return Math.round(valuesArray[qTidsteg+'-datum'].substring(8,10))+"/"+Math.round(valuesArray[qTidsteg+'-datum'].substring(5,7))+" "+vDagArr[(valuesArray[qTidsteg+'-vdag'])];
  }

	function loadMapAndStat(){
			var placeId = nodeArray[selectedNodeNum].placeId;
			if ((String(placeId).length>10) && ((String(placeId).substring(0, 4) == "1001") || (String(placeId).substring(0, 4) == "1003"))) {
      		document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=vstatdiagram&komId=" + placeId + "'><\/script>");
      	}
  
			if ((String(placeId).length>10) && ((String(placeId).substring(0, 4) == "1002"))) {
      		document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=citystat&kommunId=" + placeId + "'><\/script>");
      	}
      	document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=stat&komId=" + placeId + "&selectArea="+selectArea+"'><\/script>");      	
	}

	function printMapAndStat() {
				var mapSize;
				var doPrintStat = doPrintStatTable();
				var doPrintStatNor = doPrintStatNorway();
				if (sweStatArr['kommun0']!='no data' || doPrintStat || doPrintStatNor){mapSize=240;}
			
				else {mapSize=360;}
				
					document.write('<tr>');
						document.write('<td valign="top" bgcolor="#FFFFFF"><img rc="" name=main border=0 width='+mapSize+' usemap="#worldmap"></td>');
					document.write('</tr>');
					document.write('</table><!-- /left content --></td>');
		
					if (sweStatArr['kommun0']!='no data' || doPrintStat || doPrintStatNor)
					{ 
					
						document.write('<td colspan="1" width="118" valign="top" bgcolor="#000000"><!-- right content --><table border="0" cellpadding="0" cellspacing="0" width="100%">');
						document.write('<tr>');
							document.write('<td valign="top" class="ntv_rubrik_right">');
	  						document.write(phraseArray[7]);
							document.write('</td>');
						document.write('</tr>');
						
						if (doPrintStat)
						{
							printStatTable();
							printSunTimesTable();
						}
						else if(doPrintStatNor)
						{
							printStatNorway();
							printSunTimesTable();
						}
						else
						{
							printDayRecord();
						}
						
						document.write('</table><!-- /right content --></td>');
					}
	}
	
	
