// JavaScript Document
	function ControllaDatiForm(lingua) {
		var testo;
		if(lingua=="IT")
			testo = "Campo mancante. Tutti i campi sono obbligatori";
		else
			testo = "Missing field. All fields are compulsory";

		if(jisNullString(Trim(document.getElementById('email').value))){
			alert(testo);
			document.getElementById('email').focus();
			return false;
		}
		if(jisNullString(Trim(document.getElementById('Pwd').value))){
			alert(testo);
			document.getElementById('Pwd').focus();
			return false;
		}
		
		document.getElementById('mail').value = hex_md5(document.getElementById('email').value);
		document.getElementById('wordpass').value= hex_md5(document.getElementById('Pwd').value);
		document.getElementById('email').value = '';
		document.getElementById('Pwd').value = '';
		document.getElementById('Form_login').action = 'include/verifica_login.php';
		
		return true;
		
	}

	function VerificaLogin(valore){
		if(valore=="OK"){
			document.getElementById('InputForm').action="/index.php";
			document.getElementById('InputForm').submit();
		}else{
			document.getElementById('errore_login').innerHTML = "<strong>"+valore+"</strong>";
			document.getElementById('errore_login').style.visibility = 'visible';
			document.getElementById('email').focus();
		}
	
	}
	
	function Nascondi_div(){
		document.getElementById('errore_login').style.visibility = 'hidden';
	}

	function ControllaDatiFormRichiediPass(lingua) {
		var testo;
		if(lingua=="IT")
			testo = "Campo mancante. Tutti i campi sono obbligatori";
		else
			testo = "Missing field. All fields are compulsory";

		if(jisNullString(Trim(document.getElementById('email').value))){
			alert(testo);
			document.getElementById('email').focus();
			return false;
		}
		
		document.getElementById('mail').value = hex_md5(document.getElementById('email').value);
		document.getElementById('email').value = '';
		document.getElementById('Form_Richiedi').action = 'include/invia_password.php';
		
		return true;
		
	}


	function ControllaDatiFormNEWDOC(lingua) {
		var testo;
		var testo_file;
		if(lingua=="IT"){
			testo = "Campo mancante. Tutti i campi sono obbligatori";
			testo_file = "Il file selezionato non e' valido. E' consentito l'inserimento dei seguenti tipi di file:\r\nWord, Excel, Pdf, Zip";
		}else{
			testo = "Missing field. All fields are compulsory";
			testo_file = "The file you selected is invalid. You can upload only the following types of files:\r\nWord, Excel, Pdf, Zip";
		}
		
		if(jisNullString(Trim(document.getElementById('titolo').value))){
			alert(testo);
			document.getElementById('titolo').focus();
			return false;
		}

		if(jisNullString(Trim(document.getElementById('descrizione').value))){
			alert(testo);
			document.getElementById('descrizione').focus();
			return false;
		}
		
		if(jisNullString(document.getElementById('nuovodoc').value) || !VerificaFile(document.getElementById('nuovodoc').value)){
			alert(testo_file);
			document.getElementById('nuovodoc').focus();
			return false;
		}

		var i=1;
		for(; i<=5; i++){
			var appo_radio = "sezione_"+i;
			if(document.getElementById(appo_radio).checked){
				break;
			}
		}
		if(i>5){
			document.getElementById('sezione_1').focus();
			alert(testo);
			return false;
		}

		/*if(!document.getElementById('area').checked && !document.getElementById('area_p').checked){
			document.getElementById('area').focus();
			return false;
		}
		
		if((i==1 && document.getElementById('area').checked) || (i>1 && document.getElementById('area_p').checked)){
			document.getElementById('area').focus();
			return false;
		}*/
		
		
		document.getElementById('Form_Nuovo_DOC').action = 'include/area_riservata/salva_documento.php';
		document.getElementById('invia').disabled=true;
		document.getElementById('f1_upload_process').style.visibility = 'visible';		
		document.getElementById('f1_upload_form').style.visibility = 'hidden';

	    return true;

	}
	
	function stopUpload(success){
		alert(success);
		document.getElementById('Form_Lingua').submit();

	    document.getElementById('f1_upload_process').style.visibility = 'hidden';
		document.getElementById('f1_upload_form').style.visibility = 'visible';

		document.getElementById('titolo').value="";
		document.getElementById('descrizione').value="";
		document.getElementById('nuovodoc').value=false;

		for(i=1; i<=5; i++){
			var appo_radio = "sezione_"+i;
			document.getElementById(appo_radio).checked=false;
		}

		//document.getElementById('area').checked=false;
		//document.getElementById('area_p').checked=false;

		
/*document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
		  document.getElementById('f1_upload_form').style.visibility = 'visible';      */
  		document.getElementById('divfile').innerHTML = "<input type='file' width='200px' id='nuovodoc' name='nuovodoc' value='' onkeydown='javascript:displaylimit(this.name,this.id,0,0,0);' />";
		document.getElementById('invia').disabled=false;
		document.getElementById('titolo').focus();
		return true; 
		
	}
	
	function ModificaArea(valore){
		document.getElementById('area').value = valore;
	}
	
	

	function VerificaFile(file){
		extArray = new Array(".doc", ".pdf", ".xls", ".zip");
		okfile = false;
		
		while (file.indexOf("\\") != -1)
			file = file.slice(file.indexOf("\\") + 1);
		
		ext = file.slice(file.indexOf(".")).toLowerCase();
		
		for (var i = 0; i < extArray.length; i++){
			if(extArray[i] == ext){ 
				okfile = true; 
				break; 
			}
		}
		return okfile;
	}
	
	function ModificaDoc(iddoc,tipomod,val,testoatt,immatt,testomod,immmod){
		var nomediv = "";
		if(tipomod=="A")
			nomediv = "div_"+iddoc+"_area";
		else if(tipomod=="V")
			nomediv = "div_"+iddoc+"_visibile";
		else
			nomediv = "div_"+iddoc+"_sezione";
			
		document.getElementById('id_doc').value = iddoc;
		document.getElementById('tipo_mod').value = tipomod;
		document.getElementById('valore').value = val;
		document.getElementById('testo_attivo').value = testoatt;
		document.getElementById('immagine_attiva').value = immatt;
		document.getElementById('testo_modifica').value = testomod;
		document.getElementById('immagine_modifica').value = immmod;
		xmlhttpPost('include/area_riservata/modifica_documento.php','Form_Modifica_Doc',nomediv,val);
		
	
	}
