	var curFileName = "";
	var curRegione="toscana";
	
	function doLoad()	
	{
	  //curRegione="toscana";
	  document.fComuni.regName.value="toscana";
		document.fComuni.regID.value="1";
    GetCampi("1");
	}
	
	function loadForecast(fileName)
	{
		if (curFileName!="")
		{
			document.getElementById(curFileName).className="";
			document.getElementById("a_"+curFileName).className="";
		}
		document.getElementById(fileName).className="selected";
		document.getElementById("a_"+fileName).className="selected";
		
		var fName=fileName.replace(curRegione.toLowerCase()+"_","").replace(".xml","");
		
		curFileName=fileName;
		tipoRis="forecastGolf";
		document.fComuni.curFile.value = fileName;
		regID = document.fComuni.regID.value;
		campoID = document.fComuni.campoID.value;
		setHashGolf(regID,campoID,fName);
		
		fileName = fileName.replace(" ","").replace("'","");
		url = "../servlet/action?navigate=Comuni&usage=ajax&name=" + tipoRis + "&regid="+regID+"&campoid=" + campoID +"&fileName=" + fileName;
    AJAXCall(url, tipoRis,false,true);
	}
	
	function setHashGolf(regID,campoID,fName)
  {
  	var hs = "r="+regID+"|p="+campoID+"|c=|f="+fName;
 		location.hash=hs;
  	
  }
  
	function GetCampi(regID)
	{
		tipoRis="campigolf";
		url = "../servlet/action?navigate=Comuni&usage=ajax&name=" + tipoRis + "&regid=" + regID;
    AJAXCall(url, tipoRis,false,true);
	}
	
	function postProcessForecastGolf(responseXML)
	{
		
	  var tbody = document.getElementById("forecast").getElementsByTagName("TBODY")[0];
	  
	  tbody=addForecastHeader(tbody);
	  odd=false;

	  for (i=0;i<responseXML.getElementsByTagName("forecast").length;i++)
 		{
 			odd = !odd;
	  	addForecastRow(tbody, odd, responseXML.getElementsByTagName("forecast")[i])
	  }
	}
	
	function addForecastHeader(tbody)
	{
		if (tbody.hasChildNodes()) 
		{ 
			var nRows=tbody.childNodes.length;
	    for (var i = 0; i < nRows; i++) 
	    { 	        
	      tbody.removeChild(tbody.childNodes[0]); 
	    } 
		}
		var row = document.createElement("tr");
	  row.className="riga_top"; 
	  var td =  document.createElement("td");
	  td.innerHTML = "Ora";
	  row.appendChild(td);
	  td =  document.createElement("td");
	  td.innerHTML = "Tempo";
	  row.appendChild(td);
	  //td =  document.createElement("td");
	  //td.innerHTML = "&nbsp;";
	  //row.appendChild(td);
		td =  document.createElement("td");
	  td.innerHTML = "Pioggia mm";
	  row.appendChild(td);
		td =  document.createElement("td");
	  td.innerHTML = "Temp. &deg;C";
	  row.appendChild(td);
	  td =  document.createElement("td");
	  td.innerHTML = "Temp. percepita &deg;C";
	  row.appendChild(td);
	  td =  document.createElement("td");
	  td.innerHTML = "Vento";
	  row.appendChild(td);
	  td =  document.createElement("td");
	  td.innerHTML = "Raffica km/h";
	  row.appendChild(td);
	  
		tbody.appendChild(row);
		return tbody;
		
	}
	
	function addForecastRow(tbody, odd, node)
	{
    row = document.createElement("tr");
    if (odd)
	    row.className="riga1"; 
	  else
	    row.className="riga2"; 
    var td = document.createElement("td");
    td.className="td_ora";
    td.innerHTML = node.getAttribute("ora");
    row.appendChild(td);
    
    td = document.createElement("td");
    td.className="td_tempodescr";
    img = document.createElement("img");
    img.className="td_imgdescr";
    img.src = node.getAttribute("statoimg");
    td.appendChild(img);
    spn = document.createElement("div");
    spn.className="td_divdescr";
    spn.innerHTML = node.getAttribute("stato");
    td.appendChild(spn);
    
    row.appendChild(td);
    
    //td = document.createElement("td");
    //td.className="td_tempoimg";
    //img = document.createElement("img");
    //img.src = node.getAttribute("statoimg");
    //td.appendChild(img);
    //row.appendChild(td);
    
    td = document.createElement("td");
    td.className="td_temp";
    var pioggia=node.getAttribute("pioggia");
    td.innerHTML = (pioggia=="0" ? "-" : pioggia);
    row.appendChild(td);
    
    td = document.createElement("td");
    td.className="td_temp";
    td.innerHTML = node.getAttribute("temp");
    row.appendChild(td);
		
   	td = document.createElement("td");
   	td.className="td_tempperc";
    td.innerHTML = node.getAttribute("tempperc");
    row.appendChild(td);
    
    td = document.createElement("td");
    td.className="td_ventodescr";
    img = document.createElement("img");
    img.className="td_imgdescr";
    img.src = node.getAttribute("ventoimg");
    td.appendChild(img);
    spn = document.createElement("div");
    spn.className="td_divdescr";
    spn.innerHTML = GetVentoDescr(node.getAttribute("vento"));
    td.appendChild(spn);
    row.appendChild(td);
    
    td = document.createElement("td");
    td.className="td_tempmare";
    td.innerHTML = node.getAttribute("raffica");
    row.appendChild(td);
        
    tbody.appendChild(row);
  }
	
	function	postProcessCampiGolf(responseXML)
	{
		var	selProv = document.getElementById("selcampo");
		var idxSel = 0;
		var innerHtml = "";
		var className ="";
		for (var i=0;i<responseXML.getElementsByTagName("campog").length;i++)
 		{
	 		id=responseXML.getElementsByTagName("campog")[i].getAttribute("id");
	 		descr=responseXML.getElementsByTagName("campog")[i].getAttribute("descr");
	 		if (innerHtml!="") innerHtml += "<br/>";
	 		
	 		if (i==0)
	 		{
	 			document.getElementById("campoID").value = id;
	 			className =" class=\"listSelec\" ";
	 		}
 			else
 				className =" class=\"list\" ";
 			innerHtml += "<a id=\"G_"+id+"\" "+className+" href=\"javascript:;\" onclick=\"javascript:changeCampoG('"+id+"');\"><span>"+descr+"</span><a/>";
	 	}
	 	selProv.innerHTML=innerHtml;
		
	 	
	 	LoadCurrDayForecast();
	}	
	
  function changeCampoG(campoID)
  {
	  var prevId = document.getElementById("campoID").value;
  	if (prevId!="" && document.getElementById("G_"+prevId))
  		document.getElementById("G_"+prevId).className = "list";
  	document.getElementById("G_"+campoID).className = "listSelec";
	  document.getElementById("campoID").value = campoID;
  	LoadCurrDayForecast();
  }
  
  

