
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=stat2&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 dagsMarkeringarTidUTC = new Array();
	dagsMarkeringarTidUTC['mo']='06:00:00';
	dagsMarkeringarTidUTC['em']='12:00:00';
	dagsMarkeringarTidUTC['kv']='18:00:00';
	dagsMarkeringarTidUTC['na']='00:00:00';
	dagsMarkeringarTidUTC['da']='12:00:00';
	
	var sunUp = new Array();
	var sunDown = new Array();
	for (var suncnt=0; suncnt<soltidArray.length; suncnt++)
	{
		sunUp[soltidArray[suncnt][0]]=soltidArray[suncnt][2];
		sunDown[soltidArray[suncnt][0]]=soltidArray[suncnt][3];
	}

		
		
	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);
	
	var placeName = nodeArray[selectedNodeNum].nodeName;

	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>"+ placeName +"</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']+".png\"><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('</TD>');
	document.write('</TR>');
	document.write('<TR>');
	document.write('<td class="ntv_legend_padding2_question"><a href="javascript:void(0);" onclick="window.open(\'beskrivning_local_world.html\', \'\', \'location=no, menubar=no, Height=200, width=200, status=no, resizable=no, scrollbar=no \')"><img src="img/question.gif" border=0></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); }
	}
	
	var placeName = nodeArray[selectedNodeNum].nodeName;
      document.write("<a name='vtabell'><table bgcolor=white cellspacing=0 cellpadding=2 width=360 border=0>");
	document.write('<TR>');
		document.write("<td colspan='8' class='ntv_rubrik_bottom'>"+ placeName +"</b> "+phraseArray[26]+" "+nuvaderArr[2].substr(0,2)+" "+phraseArray[20]+":<b>"+nuvaderArr[0]+"</b>&deg;C, "+phraseArray[44]+":<b>"+nuvaderArr[5]+"</b>mm</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>');
	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>');
	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>");
	for (var aktTidsteg=0;aktTidsteg<7;aktTidsteg++) {
		if (aktTidsteg>2) { aktbg=col2; } else { aktbg=col1; }
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			document.write("<td bgcolor='"+ aktbg +"' align=\"middle\">"+dagsMarkeringar[valuesArray[aktTidsteg+'-tidsteg']]+"</td>");
			if (aktTidsteg  != 6)
			{
				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>');

//Tidszon
var placeId = nodeArray[selectedNodeNum].placeId;
var tz=0;
if (String(placeId).substring(0, 4) == '1001' || String(placeId).substring(0, 4) == '1002'){tz=1;}
else if (String(placeId).substring(0, 4) == '1003'){tz=2;}

	// Symb rad 1
	document.write('<TR>');
	document.write("<td bgcolor="+colnodata+" valign=\"bottom\">&nbsp;</td>");
	document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
	for (var aktTidsteg=0;aktTidsteg<7;aktTidsteg++) {
		if (valuesArray[aktTidsteg+'-active'] == 1) {
			currLocalTime = getDateTimeUTCConvert('H:i', valuesArray[aktTidsteg+'-datum']+' '+dagsMarkeringarTidUTC[valuesArray[aktTidsteg+'-tidsteg']], tz)
					
			if (sunDown[valuesArray[aktTidsteg+'-datum']]<'01:00') sunDown[valuesArray[aktTidsteg+'-datum']]='23.59';
			var directory;
		
			if (sunUp[valuesArray[aktTidsteg+'-datum']]=='none') directory = "dag/";
			else if (sunUp[valuesArray[aktTidsteg+'-datum']] <= currLocalTime && sunDown[valuesArray[aktTidsteg+'-datum']] >= currLocalTime) directory = "dag/";
			else directory = "natt/";

			document.write("<td bgcolor=#FFFFFF valign=\"center\" align=\"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']+".png\"><img src=\"img/trans.gif\" width=2 height=1><br>");
			document.write(Math.round(valuesArray[aktTidsteg+'-temp'])+"&deg;<br>");
			document.write("<font class='ntv_vrikt'>"+vindriktningar[valuesArray[aktTidsteg+'-vrikt']]+"<br>"+Math.round(valuesArray[aktTidsteg+'-vhast'])+" m/s</font></td>");
			if (aktTidsteg  != 6)
			{
				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>');

	// 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(7) +"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		document.write("<td colspan='3' bgcolor='"+col2+"'>"+ printDateFromForecast(11) +"</td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
		document.write("<td colspan='3' bgcolor='"+col1+"'>"+ printDateFromForecast(15) +"</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=7;aktTidsteg<11;aktTidsteg++) {
		document.write("<td bgcolor='"+col1+"' align=\"middle\">"+dagsMarkeringar[valuesArray[(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 (valuesArray[(11+(aktTidsteg*2))+'-tidsteg'] == 'em') { valuesArray[(11+(aktTidsteg*2))+'-tidsteg'] = 'da'; }
		document.write("<td bgcolor='"+ aktbg +"' align=\"middle\">"+dagsMarkeringar[valuesArray[(11+(aktTidsteg*2))+'-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>');	
	//rad 2
	document.write('<TR>');
	for (var aktTidsteg=7;aktTidsteg<11;aktTidsteg++) {
		var directory;
		currLocalTime = getDateTimeUTCConvert('H:i', valuesArray[(aktTidsteg)+'-datum']+' '+dagsMarkeringarTidUTC[valuesArray[(aktTidsteg)+'-tidsteg']], tz);
		if (sunDown[valuesArray[(aktTidsteg)+'-datum']]<'01:00') sunDown[valuesArray[(aktTidsteg)+'-datum']]='23.59';
		var directory;
		if (sunUp[valuesArray[aktTidsteg+'-datum']]=='none') directory = "dag/";
		else if (sunUp[valuesArray[(aktTidsteg)+'-datum']] <= currLocalTime && sunDown[valuesArray[(aktTidsteg)+'-datum']] >= currLocalTime) directory = "dag/";
		else directory = "natt/";
		document.write("<td bgcolor='#FFFFFF' valign=\"bottom\" align=\"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']+".png\"><img src=\"img/trans.gif\" width=2 height=2 align=top><br>");
		document.write(Math.round(valuesArray[(aktTidsteg)+'-temp'])+"&deg;<br>");
		document.write("<font class='ntv_vrikt'>"+vindriktningar[valuesArray[(aktTidsteg)+'-vrikt']]+"<br>"+Math.round(valuesArray[(aktTidsteg)+'-vhast'])+" m/s</font></td>");
		document.write("<td><img src=\"img/trans.gif\" width=1 height=1></td>");
	}
	for (var aktTidsteg=0;aktTidsteg<4;aktTidsteg++) {
		var directory;
		currLocalTime = getDateTimeUTCConvert('H:i', valuesArray[(11+(aktTidsteg*2))+'-datum']+' '+dagsMarkeringarTidUTC[valuesArray[(11+(aktTidsteg*2))+'-tidsteg']], tz);
		if (sunDown[valuesArray[(11+(aktTidsteg*2))+'-datum']]<'01:00') sunDown[valuesArray[(11+(aktTidsteg*2))+'-datum']]='23.59';
		var directory;
		if (sunUp[valuesArray[aktTidsteg+'-datum']]=='none') directory = "dag/";
		else if (sunUp[valuesArray[(11+(aktTidsteg*2))+'-datum']] <= currLocalTime && sunDown[valuesArray[(11+(aktTidsteg*2))+'-datum']] >= currLocalTime) directory = "dag/";
		else directory = "natt/";

		document.write("<td bgcolor='#FFFFFF' valign=\"bottom\" align=\"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[(11+(aktTidsteg*2))+'-symbol']+".png\"><img src=\"img/trans.gif\" width=2 height=2 align=top><br>");
		document.write(Math.round(valuesArray[(11+(aktTidsteg*2))+'-temp'])+"&deg;<br>");
		document.write("<font bgcolor='#FFFFFF' class='ntv_vrikt'>"+vindriktningar[valuesArray[(11+(aktTidsteg*2))+'-vrikt']]+"<br>"+valuesArray[(11+(aktTidsteg*2))+'-vhast']+" m/s</font></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('</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 class="ntv_legend_padding2_question"><a href="javascript:void(0);" onclick="window.open(\'beskrivning_local.html\', \'\', \'location=no, menubar=no, Height=300, width=300, status=no, resizable=no, scrollbar=no \')"><img src="img/question.gif" border=0></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")) && selectArea == "1002") {
      		document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=citystat&kommunId=" + placeId + "'><\/script>");
      	}
      	if (placeId == selectArea)
      	{
      		document.write("<script language=javascript src='http://natvader.smhi.se/natvader/gateway/getmodule.php?user_id="+ mainUserId +"&module_request=stat2&komId=" + placeId + "'><\/script>");
      	}

	}

	function printMapAndStat() {
				var mapSize;
				var doPrintStat = doPrintStatTable();
				var doPrintStatNor = doPrintStatNorway();
				if (placeId == selectArea || doPrintStat || doPrintStatNor){mapSize=240;}
				else {mapSize=360;}
				
					document.write('<tr height=16><td bgcolor="#FFFFFF" class="ntv_rubrik_maptime"><input type="text" name="forcasttime" value="" class="ntv_timearea" size="10" readonly></td></tr>');
					document.write('<tr>');
						document.write('<td valign="top" bgcolor="#FFFFFF"><img src="img/loading.gif" name=main border=0 width='+mapSize+'"></td>');
					document.write('</tr>');
					document.write('</table><!-- /left content --></td>');
		
					if (placeId == selectArea || 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>');
					}
	}
	
	
