function Trim(str) { 
return str.replace(/\s+$|^\s+/g,""); 
} 

// ------------ FUNZIONE APRIPOPUP -----------
function ApriPopup(w,h,s,pagina)
{ 
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   appo = window.open(pagina,"appo","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l+",status=yes, dependent=yes ,scrollbars="+(s));
} 
function ApriPopup2(w,h,s,pagina)
{ 
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   appoggio = window.open(pagina,"appoggio","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l+",status=yes, dependent=yes ,scrollbars="+(s));
} 

function Anteprima(w,h,s,pagina)
{ 
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   appo = window.open(pagina,"appo","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l+",status=no, dependent=yes ,scrollbars="+(s));
} 
// ----------- FINE APRIPOPUP -----------------

// ------------ FUNZIONE TIPODIALOG -----------
function ApriDialog(w,h,s,pagina)
{
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   appo = window.open(pagina,"appo","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l+",  scrollbars="+(s));
 
	if(appo.window.focus){appo.window.focus();}
}
// ----------- FINE TIPODIALOG -----------------
// ----- INIZIO LINGUA -----//
function Instr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
                  if (charSearchFor == strSearch.substr(i, 1))
                  {    
                        return i;
						
                  }
            }
            return -1;
}
function settaLingua(idLng)
{   nodoid = String(window.location);
  	tipoPag = nodoid.substr(nodoid.lastIndexOf("tipoPag="));

	pidgr = Instr(String(nodoid) , "id_gr")
	pidport = Instr(String(nodoid) , "id_port")
	pnome = Instr(String(nodoid) , "nome")	
	if (pidgr > 0){
	  	id_gr ="&"+nodoid.substr(nodoid.lastIndexOf("id_gr="));		
		}
	else{
	  	id_gr ="";
		}	
	if (pidport > 0){
	  	id_port ="&"+nodoid.substr(nodoid.lastIndexOf("id_port="));		
		}
	else{
	  	id_port ="";
		}	
	if (pnome > 0){
	  	nome ="&"+nodoid.substr(nodoid.lastIndexOf("nome="));		
		}
	else{
	  	nome ="";
		}	

	
	//nodoid = nodoid.substr(nodoid.lastIndexOf("nodeId="));
	window.location.href = "settaLingua.asp?idLng="+idLng+"&"+tipoPag+id_gr+id_port+nome;
}

// ------ FINE LINGUA ------//

// ---------- INIZIO FUNZIONE COLORE ------------
function colore(oggetto,colore)
{
	oggetto.style.backgroundColor=colore;
}
// ---------- FINE FUNZIONE COLORE ------------
// ---------- MENU ---

navHover = function() {
	try{
		var lis = document.getElementById("navmenu").getElementsByTagName("LI");

			for (var i=0; i<lis.length; i++) {
				lis[i].onmouseover=function() {
					this.className+=" iehover";
				}
				lis[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" iehover\\b"), "");
				}
			}
	}catch (e){}
}
if (window.attachEvent) window.attachEvent("onload", navHover);



isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";

if (whichDog=isIE ){
	whichDog= document.all.contMenu;
}
else{
	whichDog= document.getElementById("contMenu");
}
//  whichDog=isIE ? document.all.contMenu : document.getElementById("contMenu");  
if(hotDog=isIE){
	hotDog = event.srcElement;
}
else{
	hotDog = e.target;
}

//  hotDog=isIE ? event.srcElement : e.target;  
try {
	while (hotDog.id!="contMenu"&&(hotDog.tagName!="HTML" || hotDog.tagName!="BODY")){//hotDog.tagName!=topDog){
		hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
	}  
  if (hotDog.id=="contMenu"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}
catch (e){
}
  
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");

// ---------- FINE MENU -----------------

// ---------- FUNZIONE CONTROLLO INVIO MAIL --------
messMail = new Array();
messMail[0] = new Array("Attention!\nInsert correct name.", "Attenzione!\nInserire un nome valido.");
messMail[1] = new Array("Attention!\nInsert correct surname.", "Attention!\nInserire un cognome valido.");
messMail[2] = new Array("Attention!\nInsert correct mail.", "Attenzione!\nInserire una mail valida.");
messMail[3] = new Array("Attention!\nInsert correct phone number.", "Attenzione!\nInserire un numero di telefono valido.");
messMail[4] = new Array("Attention!\nInsert correct message.", "Attenzione!\nInserire un messaggio valido.");

/*
messMail[0][0] = "Attention!\nInsert correct name.";
messMail[0][1] = "Attenzione!\nInserire una nome valido.";
messMail[1][0] = "Attention!\nInsert correct surname.";
messMail[1][1] = "Attention!\nInserire un cognome valido."
messMail[2][0] = "Attention!\nInsert correct mail.";
messMail[2][1] = "Attenzione!\nInserire una mail valida.";
messMail[3][0] = "Attention!\nInsert correct message.";
messMail[3][1] = "Attenzione!\nInserire un messaggio valido.";
*/
function valida_mail(x)
   {      
      email = Trim(document.frm_email.email.value);
	 
	    if (email != "" )
         {
		   var re = /^([a-z0-9\._-]+)(@[a-z0-9\.-_]+)(\.{1}[a-z]{2,6})$/;
		   if(re.test(email))
		   		   
		     {return true;}
		  else 
		  
		     {
	  		   alert(messMail[2][x] );
			   document.frm_email.email.value = "";
			   document.frm_email.email.focus();
			   return false;
			 }
		 }
	  else
	     {
		   alert(messMail[2][x] );
		 }
   }

function valida_nome(x)
   { 
		if(Trim(document.frm_email.nome.value) != "" )	
		   {
			 if (isNaN(document.frm_email.nome.value))
				{
				 if (document.frm_email.nome.value.length < 3)
					 {
					   alert(messMail[0][x]);
					   document.frm_email.nome.focus();
					   return false; 
					 }
				  else		 
					 {return true;}
				}
			 else
				{
				 alert(messMail[0][x]);	 
				 document.frm_email.nome.value = "" ;
				 document.frm_email.nome.focus();
				 return false;
				}	 
			}
		 else
			 {
				 alert(messMail[0][x]);	 
				 return false;
			  }
   }

function valida_cognome(x)
   {
		if( Trim(document.frm_email.cognome.value) != "" )	
		   {
			 if (isNaN(document.frm_email.cognome.value))
				{
				 if (document.frm_email.cognome.value.length < 3)
					 {
					   alert(messMail[1][x]);
					   document.frm_email.cognome.focus();
					   return false; 
					 }
				  else		 
					 {return true;}
				}
			 else
				{
				 alert(messMail[1][x]);		 
				 document.frm_email.cognome.value = "" ;
				 document.frm_email.cognome.focus();
				 return false;		 
				}	 
			 }
		else
			{
				 alert(messMail[1][x]);
				 return false;
			}

   }

function valida_telefono(x)
   {
		if( Trim(document.frm_email.phone.value) != "" )	
		   {
				 if (document.frm_email.phone.value.length < 4)
					 {
					   alert(messMail[3][x]);
					   document.frm_email.phone.focus();
					   return false; 
					 }
				  else if (isNaN(document.frm_email.phone.value))
				  		{	alert(messMail[3][x]);
					   		document.frm_email.phone.focus();
					   		return false; }
						else				
					 		{return true;}
			 }
		else
			{
				 return true;
			}

   }   

function valida_messaggio(x)
   {
		if( Trim(document.frm_email.messaggio.value) != "" )	
		   {
				 if (document.frm_email.messaggio.value.length < 4)
					 {
					   alert(messMail[4][x])
					   document.frm_email.messaggio.focus();
					   return false; 
					 }
				  else		 
					 {return true;}
			 }
		else
			{
				alert(messMail[4][x])
				 return false;
			}

   }   

function controlliMail(xx)
{
    if (!valida_nome(xx)){
		return;
		}
    if (!valida_cognome(xx)){
		return;
		}	
    if (!valida_mail(xx)){
		return;
		}		
    if (!valida_telefono(xx)){
		return;
		}				
    if (!valida_messaggio(xx)){
		return;
		}			
	appoL = document.location;
	
	j = Instr(appoL,"&");
	
	while (j>0)
	{
		appoL=appoL.replace("&","X");
		j = Instr(appoL,"&");
	} 
	document.frm_email.appoL.value=appoL;
	document.frm_email.submit(); 
 } 

function resetMail()
{
	document.frm_email.reset(); 
}
// -------- FINE CONTROLLO INVIO MAIL -------------

//--------- INIZIO FUNZIONI HOME ------
defaultStep=1
step=defaultStep
function scrollMenuDown(id){
document.getElementById(id).scrollTop+=step
timerDown=setTimeout("scrollMenuDown('"+id+"')",10)
}

function scrollMenuUp(id){
document.getElementById(id).scrollTop-=step
timerUp=setTimeout("scrollMenuUp('"+id+"')",10)
}
function _verScroll(){
if (document.getElementById("menu").scrollHeight > 118 )
	{document.getElementById("menuUp").style.display = "block";
	 document.getElementById("menuDown").style.display = "block";		
	}
else
	{document.getElementById("menuUp").style.display = "none";
	 document.getElementById("menuDown").style.display = "none";	
	}
}

function controlli()
  {
    appo_user = true;
	appo_password = true;
	contapsw = Instr( document.frmLogin.password.value,"=");
	contauser = Instr(document.frmLogin.username.value,"=");	

    if (document.frmLogin.username.value == "" || document.frmLogin.username.value == " " || contauser > 0)
	   {appo_user = false;}
	if (appo_user){
		if (document.frmLogin.password.value == "" || document.frmLogin.password.value == " "  || contapsw > 0)
		   {appo_password = false;}	
	}
	if ((appo_user)&& (appo_password))
		{document.frmLogin.action="cms/index.asp?cmd=LOGIN"
	     document.frmLogin.submit();}

    if(!appo_user)
      {alert("La UserName è obbligatoria!");
	   document.frmLogin.username.focus();}
	else if(!appo_password)
	 {alert("La Password è obbligatoria!");
	   document.frmLogin.password.focus();}
  } 
  

/*
	function HideDiv(ID){

			document.getElementById(ID).style.display='none';
			document.getElementById("corpo").style.height = '336px';
			document.getElementById("sfdorpo").style.height = '336px';
			//sfdorpo216pxcorpo204px;
		}
		
		function ShowDiv(ID){
			document.getElementById(ID).style.display='';
			document.getElementById("corpo").style.height = '212px';			
			document.getElementById("sfdorpo").style.height = '212px';			
		}
*/
//----- FINE FUNZIONI HOME ----------//