var timeout         = 360;
var closetimer		= 0;
var ddmenuitem      = 0;

function mopen(id)
{	
	mcancelclosetime();
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';
}

function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

document.onclick = mclose; 

function DisableLinks(){
  objLinks = document.links;  
  for(i=0;i<objLinks.length;i++){
	appo=""+objLinks[i].rel;	
	if (appo.indexOf('ibox') != -1) {
		objLinks[i].rel='falso';		
		objLinks[i].disabled = true;
		objLinks[i].onclick = function(){return false;}		
	}    
  }
}

function EnableLinks(){
  objLinks = document.links;  
  for(i=0;i<objLinks.length;i++){
	appo=""+objLinks[i].rel;	
	if (appo.indexOf('falso') != -1) {	
		objLinks[i].rel='ibox&width=898';				
		objLinks[i].disabled = false;     
		objLinks[i].onclick = null;		
	}    
  }
}

String.prototype.getFuncBody = function(){ 
  var str=this.toString(); 
  str=str.replace(/[^{]+{/,"");
  str=str.substring(0,str.length-1);   
  str = str.replace(/\n/gi,"");
  if(!str.match(/\(.*\)/gi))str += ")";
  return str; 
} 

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

function trim( value ) {	
	return LTrim(RTrim(value));	
}

function checkValidEmail(stringa) {	 
	 if (stringa != "") {
	  if (stringa.indexOf(" ", 0) == -1) {	   
	   if (stringa.indexOf("@", 1) != -1) {
		startpoint = stringa.split("@");		
		if (startpoint.length>0 && startpoint[1].indexOf(".", 1) != -1) {
		 startpoint2 = startpoint[1].split(".");		 
		 if (startpoint2[1].length>1) {
		  return true;
		 }
		}
	   }
	  }
	 }
	}
	
function controlla_mail(azione) {				
	if (trim(document.mailing_list.email.value)!='') {				
		if (checkValidEmail(document.mailing_list.email.value)) {
			document.mailing_list.azione.value=azione;			
			//document.mailing_list.email.value='';	
			document.mailing_list.submit();	
		} else {	
			alert('La mail inserita non è valida!');			
		}
	} else {
		alert('Devi inserire un indirizzo Email!');
	}
}

function controlla_login() {				
	if (trim(document.form_login.username.value)!='' && trim(document.form_login.password.value)!='') {				
		document.form_login.submit();
	} else {
		alert('Devi inserire Username e Password!');
	}
}

function controlla_pwd() {
	if (trim(document.form_register.password.value)!='') {	
		if (trim(document.form_register.password.value).length>5) {	
			valore_username=trim(document.form_register.username.value);	
			valore_password=trim(document.form_register.password.value);	
			if (valore_username.indexOf(" ")==-1 && valore_password.indexOf(" ")==-1 )	 {
			
			} else {
				alert('Username e Password non possono contenere spazi!');
				return false;	
			}	
					
		} else {
			alert('La password deve essere composta da almeno 6 caratteri!');
			return false;	
		}
	}
	return true;		
}

function controlla_registrazione() {				
	if (trim(document.form_register.username.value)!='' && trim(document.form_register.password.value)!='' && trim(document.form_register.nome.value)!='' && trim(document.form_register.cognome.value)!='' && trim(document.form_register.indirizzo.value)!='' && trim(document.form_register.localita.value)!='' && trim(document.form_register.eta.value)!='' && trim(document.form_register.email.value)!='') {				
		if (checkValidEmail(document.form_register.email.value)) {
			if (controlla_pwd()) {		
				if (document.form_register.privacy.checked) {						
					document.form_register.nome.value=""+document.form_register.nome.value.replace(" ","_|spazio|_");
					document.form_register.cognome.value=""+document.form_register.cognome.value.replace(" ","_|spazio|_");
					document.form_register.indirizzo.value=""+document.form_register.indirizzo.value.replace(" ","_|spazio|_");
					document.form_register.localita.value=""+document.form_register.localita.value.replace(" ","_|spazio|_");
					document.form_register.eta.value=""+document.form_register.eta.value.replace(" ","_|spazio|_");
					document.form_register.telefono.value=""+document.form_register.telefono.value.replace(" ","_|spazio|_");
					document.form_register.sito.value=""+document.form_register.sito.value.replace(" ","_|spazio|_");					
					document.form_register.submit();						
				} else {
					alert('Devi acconsentire al Trattamento dei dati per procedere con la registrazione!');					
				}	
			}
		} else {	
			alert('La mail inserita non è valida!');			
		}		
	} else {
		alert('I campi asteriscati sono obbligatori!');
	}
}

function controlla_contatti() {				
	if (trim(document.form_contatti.nome.value)!='' && trim(document.form_contatti.cognome.value)!='' && trim(document.form_contatti.email.value)!='' && trim(document.form_contatti.oggetto.value)!='' && trim(document.form_contatti.testo.value)!='') {				
		if (checkValidEmail(document.form_contatti.email.value)) {			
			document.form_contatti.submit();				
		} else {	
			alert('La mail inserita non è valida!');			
		}		
	} else {
		alert('I campi asteriscati sono obbligatori!');
	}
}

function apri_tabs(quale) {
	if (quale=='tab1') {
		document.getElementById('tab1').style.display='block';
		document.getElementById('tab2').style.display='none';
		document.getElementById('tab3').style.display='none';
		document.getElementById('apri1').className='selectedtab';
		document.getElementById('apri2').className='tabs';
		document.getElementById('apri3').className='tabs';
	}
	if (quale=='tab2') {
		document.getElementById('tab1').style.display='none';
		document.getElementById('tab2').style.display='block';
		document.getElementById('tab3').style.display='none';
		document.getElementById('apri1').className='tabs';
		document.getElementById('apri2').className='selectedtab';
		document.getElementById('apri3').className='tabs';
	}
	if (quale=='tab3') {
		document.getElementById('tab1').style.display='none';
		document.getElementById('tab2').style.display='none';
		document.getElementById('tab3').style.display='block';
		document.getElementById('apri1').className='tabs';
		document.getElementById('apri2').className='tabs';
		document.getElementById('apri3').className='selectedtab';
	}
}