var idSensSel = new String;
idSensSel = ""

function ChangeStazioni(lstSrc, lstDst, strArray) 
{
  var alen  = eval(strArray + ".length");
  var listLen = 1;
  var strKey  = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].value");

  eval("document.forms[0]." + lstDst + ".options.length = 0");  
  eval("document.forms[0]." + lstDst + ".disabled = false");
  
  posSel=0;
  for (var i = 0; i < alen; i++) 
  {
   if (eval(strArray + "[i][2].toString() == '" + strKey + "'")) {
      eval("document.forms[0]." + lstDst + ".options[listLen] = new Option(" + strArray + "[i][1], " + strArray + "[i][0].toString())");
      listLen = listLen + 1;
    }
  }
  if (listLen > 1) {
    eval("document.forms[0]." + lstDst + ".options[0] = new Option('                                                            ', '')");
    eval("document.forms[0]." + lstDst + ".options[" + posSel + "].selected = true");
  }
  else {
		eval("document.forms[0]." + lstDst + ".disabled = true"); 
	} 
}

function CheckStazione(lstSrc, strArray)
{
	var aLen  = eval(strArray + ".length");
	var IdElem = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].value");

	if (IdElem != '') {
		for (var i = 0; i < aLen; i++) {
			if (eval(strArray + "[i][0].toString() == '" + IdElem + "'")) {
				document.forms[0].localita.value = eval(strArray + "[i][3].toString()");
				if (document.forms[0].localita.value == '') {
					document.forms[0].localita.value = '--';
				}
			}
		}
	}
}



function ChangeSensori(lstSrc1, lstSrc2, lstSrc3, lstDst, strArray) 
{
	var alen  = eval(strArray + ".length");
	var listLen = 1;

	var strKey1 = eval("document.forms[0]." + lstSrc1 + ".options[document.forms[0]." + lstSrc1 + ".selectedIndex].value");
	var strKey2='';
	if ( eval("document.forms[0]." + lstSrc2 + ".disabled == false") ) {
		strKey2 = eval("document.forms[0]." + lstSrc2 + ".options[document.forms[0]." + lstSrc2 + ".selectedIndex].value");
	}
	var strKey3 = eval("document.forms[0]." + lstSrc3 + ".options[document.forms[0]." + lstSrc3 + ".selectedIndex].value");

	eval("document.forms[0]." + lstDst + ".options.length = 0");
	eval("document.forms[0]." + lstDst + ".disabled = false");

	posSel=0;
	//alert(strKey1 + " | " + strKey2 + " | " + strKey3 + "   | " + eval(strArray + "[0][1]"));

	if ( (strKey1 != '') || (strKey2 != '') || (strKey3 != ''))  {
		for (var i = 0; i < alen; i++)
		{
			if (
				( (( strKey1 != '') && (eval(strArray + "[i][2].toString() == '" + strKey1 + "'"))) || ( strKey1 == '') ) &&
				( (( strKey2 != '') && (eval(strArray + "[i][3].toString() == '" + strKey2 + "'"))) || ( strKey2 == '') ) &&
				( (( strKey3 != '') && (eval(strArray + "[i][4].toString() == '" + strKey3 + "'"))) || ( strKey3 == '') )
			) {
				eval("document.forms[0]." + lstDst + ".options[listLen] = new Option(" + strArray + "[i][1], " + strArray + "[i][0].toString())");
				listLen = listLen + 1;
			}
		} //chiuso for
	}

	if (listLen > 1) {
		eval("document.forms[0]." + lstDst + ".options[0] = new Option('                                                            ', '')");
		eval("document.forms[0]." + lstDst + ".options[" + posSel + "].selected = true");
	}
//	else {
//		eval("document.forms[0]." + lstDst + ".disabled = true");
//	}
}


function CheckSensore(lstSrc, lstSens, strArray)
{
	var alen  = eval(strArray + ".length");
	var IdSens = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].value");

	if (IdSens != '') {
		for (var i = 0; i < alen; i++) {
			if (eval(strArray + "[i][0].toString() == '" + IdSens + "'")) {
				document.forms[0].dataminvis.value = eval(strArray + "[i][5].toString()");
				document.forms[0].datamaxvis.value = eval(strArray + "[i][6].toString()");

				if (eval(strArray + "[i][6].toString()") == '') {
					document.forms[0].datamaxvis.value = '--';
				}
			}
		}
	}
}


function AddSensore(lstSrc, lstDst, lstSens)
{
	var nSens = eval("document.forms[0]." + lstDst + ".length");
	//alert(nSens);

	if (nSens < 5) {
	  var IdSens = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].value");
	  var NomeSens = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].text");

		if (IdSens!='') {	
			var posSens = eval(lstSens + ".indexOf('[" + IdSens + "]')");
			if (posSens == -1) {
				if (NomeSens.indexOf('Direzione Vento') != -1) {
					alert("ATTENZIONE" + "\n" + "Per i sensori di Direzione Vento sono disponibili i soli dati orari!")
				}
				eval(lstSens + " = " + lstSens + " + '[" + IdSens + "]'");								
				eval("document.forms[0]." + lstDst + ".options[" + nSens + "] = new Option('[" + IdSens + "] " + NomeSens + "', '" + IdSens + "')");
			}
			else {
				alert("Sensore già selezionato!")
			}
		} 		
	}
	else {
		alert("Possono essere selezionati al massimo 5 sensori.")
	}
}


function DelSensore(lstSrc, lstSens)
{
	var nSens = eval("document.forms[0]." + lstSrc + ".length");

	if (nSens > 0) {
	  var IdSens = eval("document.forms[0]." + lstSrc + ".options[document.forms[0]." + lstSrc + ".selectedIndex].value");
		eval(lstSens + "=" + lstSens + ".replace('[" + IdSens + "]', '')");

		eval("document.forms[0]." + lstSrc + ".remove(document.forms[0]." + lstSrc + ".selectedIndex)");
	}
}