// JavaScript Document
function finestraConferma(_link, testo){
	var value = confirm(testo);
		if(value){
			window.location=_link
		}
	}
function popUp(url,nomeFinestra,attributi){
		var finestra=window.open(url,nomeFinestra,attributi);
		finestra.focus();
		//questo la utilizzo per creare la finestra sottomenu che nn doveva aggiornare la finestrapadre
		if(nomeFinestra=="finestraMenu"){
			return false;
		}
	}
function chiudiFinestra(){
			window.close();
	}
function aggionraFinestraPadre(){
		window.opener.location.reload();
	}

function controlloModulo(form,n){
	if(!controlla_privacy()){
		return false;	
	} else {
	for(var i=0;i<n;i++){
		if(form.elements[i].value == "" ){
			window.alert("Spiacente il campo " + form.elements[i].name + " é obbligatorio.");
				return false;
			} 
			if(form.elements[i].name == "c7"){
					return controlloEmail(form.elements[i].value)
					}
			}
		}
	}
		
function controlloNumero(valore){
	if(isNaN(valore)){
		alert("Spiacente il campo " + form.elements[i].name + " deve essere un numero.");
		return false;
		}
	}
function controlloEmail(valore){
	if(valore.indexOf("@")==-1 || valore.indexOf(".")==-1){
		window.alert("Spiacente il campo email deve contentere una email.");
		return false;
	}
}
function controlla_privacy() {
 if (eval(document.camere.accetto[1].checked)) {
   	   alert("Al fine dell'effettuazione della richiesta di supporto bisogna accettare l'autorizzazione al trattamento dei dati personali.");
	   return false;
  	} else {
		return true;
	}
}
function controlloPassword(form){
	if(form.password.value.length<6){
		window.alert("Spiacente la password deve contenere almeno 4 caratteri.");
		return false;
		} else {
				if(form.password.value != form.password2.value){
					window.alert("Spiacente i campi password non coincidono.");
					return false;
				} else {
			return true;
		}
	}
}

function contolloCheck(nomeForm,nomeChekbox,nomeCampo,urlPagina,nomePagina,parametri){
		if(document.forms[nomeForm].elements[nomeChekbox].checked){
			document.forms[nomeForm].elements[nomeCampo].value = 'null';
			return popUp(urlPagina,nomePagina,parametri);		
		} else {
			document.forms[nomeForm].elements[nomeCampo].value = 'N';
			document.forms[nomeForm].profondita.value = ''
			}
}

function ritornaValore(nomeForm,nomeSelect,nomeFormGen,nomeCampoGenv){
	var lista = document.forms[nomeForm].elements[nomeSelect];
	window.opener.document.forms[nomeFormGen].elements[nomeCampoGenv].value = lista.options[lista.selectedIndex].value;
}

function  creaNodo(){
	//uso la casella di testo per far un contatore
	document.forms[1].elements['i'].value++;
	var k = document.forms[1].elements['i'].value;
		
	var newElementTdFile = document.createElement('td');
	newElementTdFile.id = 'tdfilenew';
	newElementTdFile.colspan = '2';
	
	var newElementTdDidascalia = document.createElement('td');
	newElementTdDidascalia.id = 'tddidascalianew';
	newElementTdDidascalia.colspan = '2';
	
	var newElementInputFile = document.createElement('input');
	newElementInputFile.type = 'file';
	newElementInputFile.id = 'textInput';
	newElementInputFile.name = 'file'+k;
	newElementInputFile.size ='48';
	
	var newElementLabelfile = document.createElement('label');
	var newTesto = document.createTextNode('File'+k);
	newElementLabelfile.appendChild(newTesto);
	newElementLabelfile.id = 'Labelfile';
	
	var newElementLabeldidascalia = document.createElement('label');
	var newTesto = document.createTextNode('Didascalia');
	newElementLabeldidascalia.appendChild(newTesto);
	newElementLabeldidascalia.id = 'Labeldidascalia';
	
	var newElementPcancella = document.createElement('div');
	newElementPcancella.id = 'label';
	var newTesto = document.createTextNode('CANCELLA');
	newElementPcancella.appendChild(newTesto);
	
	var newElementInputText = document.createElement('input');
	newElementInputText.type = 'text';
	newElementInputText.id = 'textInput';
	newElementInputText.name = 'didascalia'+k;
	newElementInputText.size = '48';
	
	newElementTdFile.appendChild(newElementInputFile);
	newElementTdDidascalia.appendChild(newElementInputText);
	
	document.getElementById("tabFile").appendChild(newElementLabelfile);
	document.getElementById("tabFile").appendChild(newElementTdFile);
	document.getElementById("tabFile").appendChild(newElementLabeldidascalia);
	//document.getElementById("tabFile").appendChild(newElementPcancella);
	document.getElementById("tabFile").appendChild(newElementTdDidascalia);
	
	
	
	
	//var url = document.forms[0].elements[nomeCampo].value;
	/*var did = document.forms[0].elements[_did].value;
	var newElementP = document.createElement('p');
	var newTesto = document.createTextNode(did);
	newElementP.id = 'dida';

	newElementP.appendChild(newTesto);

	newElementTd.appendChild(newElementImg);*/
	
	
	//document.body.appendChild(newElementP);


	//leggi(newElementImg);
	/*newElementPcancella.onclick=function() {
		cancella(this);
	};*/
}


function cancella(o){
	alert(children.o);
//	o.removeNode(true);
	}
	
function tipoStile(_tag,_class){
	var _testo = document.selection.createRange().text;
	var testo = "<"+_tag+" class=\'"+_class+"\'>"+_testo+"</" + _tag + ">";
	document.selection.createRange().text = testo;
	}

	/*
function leggiSrc(){
	var i = document.getElementsByTagName('img').length;
	var j=0;
	while(j<i){
				
		var _scr = new String();
		
		_scr = document.getElementsByTagName('img')[j].src;
		
		var x = _scr.lastIndexOf("/")+1;
		var y = _scr.length;
		var scrDefinitivo= _scr.substr(x,y);
		
		document.forms[0].elements['prova'].value+=scrDefinitivo+",";
		j++;
	}
}
function leggiDidascalia(){
	var i = document.getElementsByTagName('p').length;
	var j=0;
	while(j<i){
		document.getElementsByTagName('p')[j].value;
		j++;
	}	
}*/
function visualizzaDidascali(dida,indice){
		document.forms[1].elements['didascalia'].value = dida;
		document.forms[1].elements['k'].value = indice;
	}
function modificaDidascali(dida,indice){
		document.forms[1].elements['didascalia'].value = dida;
		document.forms[1].elements['j'].value = indice;
	}
function controllaCampoDidascalia(){
		if(document.forms[1].elements['k'].value==""){
			alert("Spiacente selezionare la didascalia da modificare");
		}
	}