// JavaScript Document

function decodifica_data(str)
{
	var giorno = str.substring(6,8)
	var mese = str.substring(4,6);
	var anno = str.substring(0,4);
	
	return giorno + "-" + mese + "-" + anno;
}

function ShowHide(checkboxName, id) {
//document.writeln(document.getElementById(checkboxName).checked == true);
//document.writeln(id);
//document.writeln(document.getElementsByTagName(checkboxName).checked == true)
	if (document.getElementById(checkboxName).checked == true) {
		document.getElementById(id).style.display = "block"
	} else {
		document.getElementById(id).style.display = "none"
	}
}

function AntispamEmail(email) {
	tokens = email.split('@');

	return tokens;
}

function addToSottosezioni(optionIndex, optionIndex2, idsottosezione, nomesottosezione)
{
	sottosezioni[optionIndex][optionIndex2] = new Object();
	sottosezioni[optionIndex][optionIndex2].value= idsottosezione;
	sottosezioni[optionIndex][optionIndex2].text= nomesottosezione;
}

function caricaSottosezioni(chooser) {
    var newElem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var cityChooser = chooser.form.elements["sottosezionepadre"];
    while (cityChooser.options.length) {
        cityChooser.remove(0);
    }
    var choice = chooser.selectedIndex;
    var db = sottosezioni[choice];
//document.write("Prova: " + sottosezioni[choice].text);
    newElem = document.createElement("option");
    newElem.text = "";
    newElem.value = 0;
    cityChooser.add(newElem, where);
	
//	document.write("Prova: " + choice);
    if (choice != null) {
//		document.write("Ciao")
        for (var i = 0; i < sottosezioni[choice].length; i++) {
            newElem = document.createElement("option");
            newElem.text = sottosezioni[choice][i].text;
            newElem.value = sottosezioni[choice][i].value;
            cityChooser.add(newElem, where);
        }
    }
	
//	cityChooser.selectedIndex = 0;
}

function stampaSottosezioni()
{
	document.write(sottosezioni[0][0].value);
	document.write(sottosezioni[0][0].text);
}

function accodaValore(campo, campoValore)
{
  var valore = document.getElementById(campoValore).value;
  var imgDim, width, height;
  var larghezzaImmagine = 100;
  var altezzaImmagine;
  
  if (valore.length > 0)
  {
    imgDim = getImageDimension(valore);
    width = imgDim[0];
    height = imgDim[1];
    altezzaImmagine = getHeightOnWidth(width, height, larghezzaImmagine);
    document.getElementById(campo).innerHTML = document.getElementById(campo).innerHTML + getFilename(valore) + "<br><img src='"+ valore +"' width='100'> [<a onClick='removeFile("+ valore +")'>rimuovi</a>]<br><br>";
  }
}

function getFilename(s)
{
  var sArray = s.split('/');
  return sArray[sArray.length-1];
}

function getImageDimension(imgSrc)
{
  var oImg = new Image();
  oImg.src = imgSrc;
  return [oImg.width,oImg.height];
}

function getHeightOnWidth(width, height, newWidth)
{
  var newHeight = height * newWidth / width;
  return newHeight;
}

/*
</script></head>


<body>
<h1>Esempio - Select dinamiche</h1>
<hr> 
<form name="form">
Invia la richiesta a: 
<select name="continente" onchange="caricaSottosezioni(this)">
<option value="" selected="selected">Seleziona un continente:</option>
<option value="africa">Africa</option>
<option value="asia">Asia</option>
<option value="australia">Australia/Oceania</option>
<option value="europa">Europa</option>
<option value="noamer">Nord America</option>
<option value="suamer">Sud America</option>
</select> 
<select name="cittą">
<option value="" selected="selected">Seleziona una cittą:</option>
</select>
</form>
*/

