function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function cngPag(a,b) {
  document.forms.chgeprod.pagina.value=b;
  cambiascheda(a);
}

function filterDownload(a){
  document.forms.chgedownload.categorie.value=a;
  document.forms.chgedownload.submit();
}

function filterCorrelati(a){
  document.forms.chgecorrelati.tipologie.value=a;
  document.forms.chgecorrelati.submit();
}

function startsearch(frase){
	if(document.forms.formcerca.cerca.value!=""){document.forms.formcerca.submit();}
	else{alert(frase);}
	}

function changelang(x){
	document.forms.lang.cambialingua.value=x;
	document.forms.lang.submit();
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  newwin=window.open(theURL,winName,features);
  newwin.focus();
}

function vediutente(val){
  MM_openBrWindow('vediutente.php?sel='+val,'utente','scrollbars=no,width=200,height=400')
}

function vediutente_adm(val){
  MM_openBrWindow('vediutente_adm.php?sel='+val,'utente','scrollbars=yes,width=200,height=400')
}

function openimage(image,dimw,dimh,resizew,resizeh){
	if((resizew=='')&&(resizeh=='')){
		dimw=dimw+20;
		dimh=dimh+20;
		MM_openBrWindow(image,'image','width='+dimw+',height='+dimh);
		}
	else{
		dimw=resizew+20;
		dimh=resizeh+30;
		MM_openBrWindow('include_file/viewlist_image.php?image='+image,'image','width='+dimw+',height='+dimh);
		}
	}
	

function controllaserie(lista,trueval){
	serie=0;
	if(lista.length>0){
		for(q=0;q<lista.length;q++){
			//alert(q+'........'+lista[q]);
			if(lista.charAt(q)==lista.charAt(q+1)){
				serie++;
				if(serie>=3){
					//alert(lista+' : valore non permesso');
					trueval++;
					}
				}
			else{
				serie=0;
				}
			}
		}
	return trueval;
	}


function controlla_register(x,y){
	notype=Array('.','-','_','#',' ','@',';',':','"','!','$','&','%','/','?');
	myform=document.forms.utente;
	trueform=0;
	if(myform.sms.checked==true){
		if(myform.tipologia.options[myform.tipologia.selectedIndex].value=='11'){
			MM_validateForm_lingua('nome','','R','cognome','','R','indirizzo','','R','citta','','R','cap','','RisNum','telefono','','RisNum','cellulare','','RisNum','email','','RisEmail','password','','R','repassword','','R');	
			}
		else{
			MM_validateForm_lingua('nome','','R','cognome','','R','ragsoc','','R','piva','','RisNum','indirizzo','','R','citta','','R','cap','','RisNum','telefono','','RisNum','cellulare','','RisNum','email','','RisEmail','password','','R','repassword','','R');	
			}
		sect=1;
		}
	else{
		if(myform.tipologia.options[myform.tipologia.selectedIndex].value=='11'){
			MM_validateForm_lingua('nome','','R','cognome','','R','indirizzo','','R','citta','','R','cap','','RisNum','telefono','','RisNum','email','','RisEmail','password','','R','repassword','','R');	
			}
		else{
			MM_validateForm_lingua('nome','','R','cognome','','R','ragsoc','','R','piva','','RisNum','indirizzo','','R','citta','','R','cap','','RisNum','telefono','','RisNum','email','','RisEmail','password','','R','repassword','','R');	
			}
		sect=2;
		}
	if(document.MM_returnValue==true){
		if(myform.tipologia.options[myform.tipologia.selectedIndex].value!=""){
			if(myform.password.value==myform.repassword.value){
				for(a=0;a<notype.length;a++){
					//alert(a)
					multi=notype[a]+notype[a];
					if((myform.nome.value==notype[a])||(myform.nome.value==multi)){trueform++;}
					if((myform.cognome.value==notype[a])||(myform.cognome.value==multi)){trueform++;}
					if((myform.ragsoc.value==notype[a])||(myform.ragsoc.value==multi)){trueform++;}
					if((myform.piva.value==notype[a])||(myform.piva.value==multi)){trueform++;}
					if((myform.indirizzo.value==notype[a])||(myform.indirizzo.value==multi)){trueform++;}
					if((myform.citta.value==notype[a])||(myform.citta.value==multi)){trueform++;}
					if((myform.cap.value==notype[a])||(myform.cap.value==multi)){trueform++;}
					if((myform.telefono.value==notype[a])||(myform.telefono.value==multi)){trueform++;}
					if(myform.email.value==multi){trueform++;}
					if((myform.password.value==notype[a])||(myform.password.value==multi)){trueform++;}
					if((myform.repassword.value==notype[a])||(myform.repassword.value==multi)){trueform++;}
					if(sect==2){
						if((myform.cellulare.value==notype[a])||(myform.cellulare.value==multi)){trueform++;}
						}
					}
				
				trueform=controllaserie(myform.nome.value,trueform);
				trueform=controllaserie(myform.cognome.value,trueform);
				trueform=controllaserie(myform.ragsoc.value,trueform);
				trueform=controllaserie(myform.piva.value,trueform);
				trueform=controllaserie(myform.indirizzo.value,trueform);
				trueform=controllaserie(myform.citta.value,trueform);
				trueform=controllaserie(myform.cap.value,trueform);
				trueform=controllaserie(myform.telefono.value,trueform);
				trueform=controllaserie(myform.email.value,trueform);
				trueform=controllaserie(myform.password.value,trueform);
				trueform=controllaserie(myform.repassword.value,trueform);
				if(sect==2){
					trueform=controllaserie(myform.cellulare.value,trueform);
					}
				
				if(trueform==0){
					myform.submit();
					}
				else{
					alert('Error: set of characters not permitted');
					}
				}
			else{
				alert(y);
				}
			}
		else{
			alert(x);
			}
		}
	}
	
function cellulare_scritta(valore){
	if(document.forms.utente.sms.checked==true){document.forms.utente.nomecel.value='*'+valore;}
	else{document.forms.utente.nomecel.value=valore;}
	}
	
function piva_scritta(valore){
	if(document.forms.utente.ragsoc.value!=""){document.forms.utente.nomepiva.value='*'+valore;}
	else{document.forms.utente.nomepiva.value=valore;}
	}
	
function controlla_contattaci(valore){
	if(document.forms.utente.destinatario.options[document.forms.utente.destinatario.selectedIndex].value==""){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('nome','','R','cognome','','R','email','','RisEmail','info','','R');	
		if(document.MM_returnValue==true){
			document.forms.utente.submit();
			}
		}
	}
	
function controlla_admcontattaci(valore){
	if(document.forms.data.destinatario.options[document.forms.data.destinatario.selectedIndex].value==""){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('info','','R');	
		if(document.MM_returnValue==true){
			document.forms.data.submit();
			}
		}
	}
	
function controlla_curriculum(){
	MM_validateForm_lingua('nome','','R','cognome','','R','cap','','NisNum','telefono','','NisNum','cellulare','','NisNum','email','','RisEmail');	
	if(document.MM_returnValue==true){
		document.forms.jobsearch.submit();
		}
	}
	
function controlla_comunic(valore){
	frm=document.forms.data;
	if((frm.titolo.value=="")||((frm.tipologia.options[frm.tipologia.options.selectedIndex].value=="")&&(frm.newtipologia.value==""))){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('titolo','','R','desc','','R');	
		if(document.MM_returnValue==true){
			document.forms.data.submit();
			}
		}
	}
	
function controlla_mailing(valore,x){
	if(x==0){document.forms.data.submit();}
	else{
		frm=document.forms.data;
		if(frm.titolo.value==""){
			printmessage(valore);
			}
		else{
			MM_validateForm_lingua('titolo','','R');	
			if(document.MM_returnValue==true){
				document.forms.data.insertmail.value=1;
				document.forms.data.submit();
				}
			}
		}
	}
	
function controlla_comunic1(valore){
	frm=document.forms.data;
	if((frm.titolo.value=="")||(frm.desc.value=="")){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('titolo','','R','desc','','R');	
		if(document.MM_returnValue==true){
			document.forms.data.submit();
			}
		}
	}

function controlla_media(valore){
	frm=document.forms.data;
	if((frm.titolo.value=="")||((frm.tipologia.options[frm.tipologia.options.selectedIndex].value=="")&&(frm.newtipologia.value==""))){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('titolo','','R','desc','','R');	
		if(document.MM_returnValue==true){
			document.forms.data.submit();
			}
		}
	}
	
function controlla_team(valore){
	frm=document.forms.data;
	if((frm.titolo.value=="")||((frm.tipologia.options[frm.tipologia.options.selectedIndex].value=="")&&(frm.newtipologia.value==""))){
		printmessage(valore);
		}
	else{
		MM_validateForm_lingua('nome','','R','cognome','','R');	
		if(document.MM_returnValue==true){
			document.forms.data.submit();
			}
		}
	}
	
	
function setProvince(sel) {
	if (sel =="ITA"){
		document.forms.utente.provinciaa.style.display='none';
		document.forms.utente.provinciaa.value='';
		document.forms.utente.provinciab.style.display='inline';
		}
	else{
		document.forms.utente.provinciaa.style.display='inline';
		document.forms.utente.provinciab.style.display='none';
		document.forms.utente.provinciab.options[document.forms.utente.provinciab.selectedIndex].value='';
		} 
	}
	
function posizione(x,y){
	document.forms.posizione.tipologia.value=y;
	document.forms.posizione.regione.value=x;
	document.forms.posizione.provincia.value='';
	document.forms.posizione.submit();
	}
	
function modificaprovincia(x,y){
	document.forms.posizione.tipologia.value=y;
	document.forms.posizione.regione.value=x;
	document.forms.posizione.submit();
	}
	
function changemap(x,a){
	if(x==1){
		if(document.forms.mapform.situation.value<3){
			document.forms.mapform.situation.value++;
			document.mymap.src='img/map_0'+document.forms.mapform.situation.value;
			}
		else{alert(a);}
		}
	else{
		if(document.forms.mapform.situation.value>1){
			document.forms.mapform.situation.value--;
			document.mymap.src='img/map_0'+document.forms.mapform.situation.value;
			}
		else{alert(a);}
		}
	}

function printmessage(x){
	alert(x);
	}
	
function exitlog(){
	document.forms.riconosci.submit()
	}
	
function changepag_adm(valore){
	document.forms.menuadm_val.admmenu.value=valore;
	document.forms.menuadm_val.submit();
	}
	
function adm_inviadati(azione,id){
	if(azione=='elimina'){document.forms.data.sezione.value=azione;document.forms.data.submit();}
	if(azione=='aggiungi'){document.forms.data.sezione.value=azione;document.forms.data.submit();}
	if(azione=='modifica'){document.forms.data.sezione.value=azione;document.forms.data.action='areariservata.php?mod='+id;document.forms.data.submit();}
	}
	
function adm_inviadati1(azione,pagina){
	if(azione=='elimina'){document.forms.data.submit();}
	if(azione=='aggiungi'){document.location.href=pagina;}
	}
	
function open_doimg(percorso,id,qta,sizew,sizeh){
	indirizzo='include_file/areariservata/doimg.php?percorso='+percorso+'&id='+id+'&qta='+qta;
	MM_openBrWindow(indirizzo,'image','scrollbars=yes,width='+sizew+',height='+sizeh);
	}
	
function open_doimg1(percorso,id,qta,sizew,sizeh){
	indirizzo='include_file/areariservata/doimg.php?percorso='+percorso+'&id='+id+'&qta='+qta;
	showModalDialog(indirizzo,window, "resizable: no; help: no; status: no; scroll: yes; height: "+sizew+"; height="+sizeh);
	}
	
function open_doimg2(percorso,id,qta,indice,sizew,sizeh){
	indirizzo='include_file/areariservata/doimg.php?percorso='+percorso+'&id='+id+'&qta='+qta+'&indice='+indice;
	MM_openBrWindow(indirizzo,'image','scrollbars=yes,width='+sizew+',height='+sizeh);
	}

function open_dodoc(percorso,id,qta,sizew,sizeh){
	indirizzo='include_file/areariservata/dodoc.php?percorso='+percorso+'&id='+id+'&qta='+qta;
	MM_openBrWindow(indirizzo,'image','scrollbar=yes,width='+sizew+',height='+sizeh);
	}
	
function open_dodoc1(percorso,id,qta,sizew,sizeh){
	indirizzo='dodoc.php?percorso='+percorso+'&id='+id+'&qta='+qta;
	MM_openBrWindow(indirizzo,'image','scrollbar=yes,width='+sizew+',height='+sizeh);
	}
	
function open_dodoc2(percorso,id,qta,sizew,sizeh){
	indirizzo='dodoc_user.php?percorso='+percorso+'&id='+id+'&qta='+qta;
	MM_openBrWindow(indirizzo,'image','scrollbar=yes,width='+sizew+',height='+sizeh);
	}
	
function aggiornaopener(){
	window.opener.location.reload();
	}
	
function gotosection(){
	/*x1=document.forms.searchmode.sezionecerca.options[document.forms.searchmode.sezionecerca.selectedIndex].value;
	document.location.href='#sect'+x1;*/
	document.forms.searchmode.submit();
	}

function gotosectionMore(a,b){
	document.forms.searchmode.sezionecerca.value=a;
	document.forms.searchmode.pag.value=b;
	document.forms.searchmode.submit();
}
	
function selectdownload(x){
	if(x==1){
		if(document.forms.chgeprod.newver.value!=""){
			document.forms.chgeprod.prodotti.options[document.forms.chgeprod.prodotti.selectedIndex].value="";
			document.forms.chgeprod.versioni.options[document.forms.chgeprod.versioni.selectedIndex].value="";
			}
		else{
			if(document.forms.chgeprod.newprod.value!=""){
				document.forms.chgeprod.prodotti.options[document.forms.chgeprod.prodotti.selectedIndex].value="";
				}
			}
		}
	if(x==2){
		if(document.forms.chgeprod.newver.value!=""){
			document.forms.chgeprod.versioni.options[document.forms.chgeprod.versioni.selectedIndex].value="";
			}
		}
	document.forms.chgeprod.submit();
	}

function selectmedia(){
	document.forms.chgemedia.submit();
	}
	
function selectdownload(){
	//document.location.href='#'+document.forms.chgedownload.categorie.options[document.forms.chgedownload.categorie.selectedIndex].value
	document.forms.chgedownload.submit();
	}

function admpage(valore1,valore2){
	//window.document.calendario.forms.calend.privatearea=valore1;
	document.forms.menuprivatearea.privatearea.value=valore1;
	document.forms.menuprivatearea.permessoarea.value=valore2;
	document.forms.menuprivatearea.submit();
	}
	
function trovaid(){
	for(i=0;i<=1000;i++){
		if(document.forms.data.elements[i].name=='categorie[]'){alert(i);}
		}
	}
	
function add_comunic(val){
	if(val==2){
		if(document.forms.data.allcat.checked==true){
				document.forms.data.elements[0].disabled=true;
				document.forms.data.elements[2].disabled=true;
				document.forms.data.elements[3].disabled=true;
				}
		else{
			document.forms.data.elements[0].disabled=false;
			document.forms.data.elements[2].disabled=false;
			document.forms.data.elements[3].disabled=false;
			}
		}
	if(val==5){
		if(document.forms.data.tipologia.options[document.forms.data.tipologia.options.selectedIndex].value==''){
			document.forms.data.newtipologia.disabled=false;
			}
		else{document.forms.data.newtipologia.disabled=true;}
		}
	if(val==6){
		if(document.forms.data.newtipologia.value==''){
			document.forms.data.tipologia.disabled=false;
			}
		else{document.forms.data.tipologia.disabled=true;}
		}
	}
	
function reload_add(val){ 
   document.forms.data.action='add_'+val+'.php';
   document.forms.data.submit();
   }
   
function reload_page(x){ 
   if(x==0){document.forms.data.submit();}
   else{
	   document.forms.data.insertsms.value=1;
	   document.forms.data.submit();
   		}
   }
   
function reload_mod(val,sel){ 
   document.forms.data.action='mod_'+val+'.php?sel='+sel;
   document.forms.data.submit();
   }

function cuenta() {
		textoIntroducido(document.formsms)
		if (!teclas) setTimeout("cuenta()",500)
		}

function textoIntroducido(f) {
		actualizado = false
		maxcaratteri=159
		maxLength = maxcaratteri;
		maxLength1 = maxcaratteri - f.TITLE_SMS.value.length
		
		lung=f.MSG_SMS.value.length+f.TITLE_SMS.value.length

        if (lung > maxLength) { 
	        f.MSG_SMS.value = f.MSG_SMS.value.substring(0,maxLength1)
			f.TITLE_SMS.value = f.TITLE_SMS.value.substring(0,maxLength)
		    CaracteresRestantes = 0
		    actualizado = true
        } else {
			CaracteresRestantes = maxLength - f.MSG_SMS.value.length - f.TITLE_SMS.value.length
		}

        f.restantes.value = CaracteresRestantes


		
        return actualizado
}

function compruebaTexto(f) {
	teclas = true
	textoIntroducido(f)
}

function delutenti(){
		document.forms.data.deluser.value=1;
		document.forms.data.submit();
}

function reloadpage(x,indirizzo,tomod){
		if(tomod==0){
			document.forms.data.action=indirizzo+'.php';
			}
		else{
			document.forms.data.action=indirizzo+'.php?sel='+tomod;
			}
		
		document.forms.data.deluser.value=x;
		
		if(indirizzo!='sms'){
			document.forms.data.desc.value=editor_getHTML('testodinamico');
		}
		
		document.forms.data.submit();
}

function SubmitOnEnter(e) {
	var keycode;
	if (window.event) {
		keycode = window.event.keyCode;
		}
	else if (e) {
			keycode = e.which;
			}
		else{return true;}
	if (keycode == 13) {
		document.forms.riconosci.submit();
		return false;
		}
	else{return true;}
	}


