// JavaScript Document

startList = function() {
	
	var heightContent = 0;
	var heightContenitore = 0;
	
	
				///////////////// POSIZIONO IL FOOTER SOTTO IL CONTENITORE //////////////////////////

		
				heightContenitore = document.getElementById('contenitore').offsetHeight;
				 
			if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0){

					document.getElementById('footer').style.setAttribute('top', (heightContenitore+20) + 'px');
					document.getElementById('footer').style.setAttribute('visibility', 'visible');
					
				} else {


					document.getElementById('footer').style.setProperty('top', (heightContenitore+20) + 'px', null);
					document.getElementById('footer').style.setProperty('visibility', 'visible', null);
				}
				
				
			///////////////////// PER GIUSTICARE IN ALTEZZA LE COLONNE CENTRALE E DESTRA //////////////
			
			
			if(document.getElementById('content')){

            heightContent = document.getElementById('content').offsetHeight;
        	heightPromo = document.getElementById('box_promo_destro').offsetHeight;
		
			if (heightPromo > heightContent){
				
				if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0){
					
					document.getElementById('content').style.setAttribute('height', heightPromo + 'px');	
					
				} else {
					
					document.getElementById('content').style.setProperty('height', heightPromo + 'px', null);
				}
			}
			
			}

	
	
	if (document.all&&document.getElementById) {
		
		//////////////////// PER IL MENU ///////////////////
		
		navRoot = document.getElementById("nav");
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}

		
		
	}
}



///////////////////////////////////// funzione che va ad aurl dal box news in flash /////////////////////

function vai_da_short_news(url){
	//alert(URLDecode(url));
	window.location.replace(URLDecode(url));
}


function URLDecode(encoded)
{

   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

///// CONTROLLO CHE ESISTA E SIA VALIDO UN VALORE PER I CAMPI OBBLIGATORI ////////////////////

function Controllo_campi(formname, campi, valori, input, lang) {
	
	if((!lang) || (lang=="")) lang="ita";
	
	var localform = document.getElementById(formname);
	if((campi.length>0) && (document.getElementById)){
	for(var i=0; i<campi.length; i++){
        //// CONTROLLO SE RADIO BUTTON
		if(input[i]=="radiobutton"){
			   var radio = false;
			   if((localform[campi[i]].length) && (localform[campi[i]].length>1)){
			   for (counter = 0; counter < localform[campi[i]].length; counter++){
				   if (localform[campi[i]][counter].checked){
				   radio = true;
				   }
			   }
			   if(radio==false){
			   if((lang=="") || (lang=="ita")){
			   alert("Assegnare un valore per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   alert("Please fill the field '" + valori[i] + "'.");     
			   }
			   return (false);
			   }
			   }else{
			   if (!localform[campi[i]].checked){
				   if((lang=="") || (lang=="ita")){
				   alert("E' necessario selezionare il campo '" + valori[i] + "' ai fini della richiesta.");
				   }else if(lang=="eng"){
				   alert("It is required to select the field '" + valori[i] + "' to complete the request.");     
				   }

				   return(false);
			       }
			   
			   }
			   
	   } else if(input[i]=="checkbox"){
		////// CONTROLLO SE DI TIPO CHECKBOX ///////////
			   var check = false;
			   for (counter = 0; counter < localform[campi[i]].length; counter++){
				   if (localform[campi[i]][counter].checked){
				   check = true;
				   }
			   }
			   if(check==false){
			   if((lang=="") || (lang=="ita")){
			   alert("Assegnare un valore per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   alert("Please fill the field '" + valori[i] + "'.");     
			   }
			   return (false);
			   }
		} else if(input[i]=="text"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if (localform[campi[i]].value==""){
			   if((lang=="") || (lang=="ita")){
			   alert("Assegnare un valore per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   alert("Please insert a value into the field '" + valori[i] + "'.");     
			   }
				localform[campi[i]].focus();
				return (false); 
			}
		} else if(input[i]=="number"){
		////// CONTROLLO SE DI TIPO NUMBER ///////////
		if (isNaN(localform[campi[i]].value)) {
			   if((lang=="") || (lang=="ita")){
		       alert("Inserire un valore di tipo numerico per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   alert("Please insert a numeric value into the field '" + valori[i] + "'.");     
			   }

		return false;
		}
			
		} else if(input[i]=="email"){
		////// CONTROLLO SE DI TIPO EMAIL ///////////
			  var goodEmail = localform[campi[i]].value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.biz)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
			  if (!goodEmail || localform[campi[i]].value==""){
				   if((lang=="") || (lang=="ita")){
				   alert("Inserire un indirizzo esatto per il campo '" + valori[i] + "'.");
				   }else if(lang=="eng"){
				   alert("Please insert a valid address into the field '" + valori[i] + "'.");     
				   }
				
				localform[campi[i]].focus();
				return (false);
			  }
  
		} else if(input[i]=="select-one"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if (localform[campi[i]].value==""){
				
				   if((lang=="") || (lang=="ita")){
				   alert("Selezionare un valore per il campo '" + valori[i] + "'.");
				   }else if(lang=="eng"){
				   alert("Please select an option from the list '" + valori[i] + "'.");     
				   }
				
				localform[campi[i]].focus();
				return (false); 
			}
		}

	}
	}

return (true); 
}

////////////////////////////////////////////////////////////////////////////////////////////


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


//////////////////////////////////// FUNZIONE MENU SELECT //////////////////////////

function go_to_url(sel){
   var sel = document.getElementById(sel);
   if(sel){
   var index = sel.selectedIndex;
   if(index>0) window.location.href=sel.options[index].value;
   }
	
}

/////////////////////////////////////////// POP UP CENTRO PAGINA CHE SI RIDIMENSIONA


	function getUrl(dato) {
	   var tmp = (location.search.substring(1));  // catturo i dati dopo il ?
	   blocco = tmp.split("&");   // divido le sezioni con &
	   for (i=0;i<blocco.length;i++) {
		  briciola=blocco[i].split("=");  // divido la variabile dal valore con =
		  if (briciola[0]==dato) return briciola[1];
	   }
	}
	
	

	function PopupPic(page, picURL, name, descURL) { 
	    if(picURL && (picURL!='')){
		 window.open( page + "?picURL=" + picURL + "&descURL=" + descURL, name, "resizable=1,HEIGHT=200,WIDTH=200"); 
		}
	} 
   

function adjust_popup()
{
        var w, h, fixedW, fixedH, diffW, diffH, marcoW, marcoH;

        if (document.all) {
                fixedW = document.body.clientWidth;
                fixedH = document.body.clientHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - document.body.clientWidth;
                diffH = fixedH - document.body.clientHeight;
				
        } else {
                fixedW = window.innerWidth;
                fixedH = window.innerHeight;
                window.resizeTo(fixedW, fixedH);
                diffW = fixedW - window.innerWidth;
                diffH = fixedH - window.innerHeight;
        }
        w = fixedW + diffW;
        h = fixedH + diffH;
        if (h >= screen.availHeight) w += 10;
        if (w >= screen.availWidth)  h += 10;
        w = Math.min(w,screen.availWidth);
        h = Math.min(h,screen.availHeight);
        window.resizeTo(w,h);
        window.moveTo((screen.availWidth-w)/2, (screen.availHeight-h)/2);
}



 <!--
 function ApriPopupCentrata(file,w,h) {
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open(file,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",status=no, menubar=no, toolbar=no scrollbar=no");
 }
 //-->



/////////////////////////////////// FUNZIONE PER POSIZIONARE IL FOOTER E LE COLONNE


    function positiondiv(){
         var heightContent = 0;
		 var heightContenitore = 0;


        if (document.getElementById){
			
			heightContenitore = document.getElementById('contenitore').offsetHeight;
			
			if(document.getElementById('content')){

            heightContent = document.getElementById('content').offsetHeight;
        	heightPromo = document.getElementById('box_promo_destro').offsetHeight;
		
			if (heightPromo > heightContent){
				
				if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0){
					
					document.getElementById('content').style.setAttribute('height', heightPromo + 'px');	
					
				} else {
					
					document.getElementById('content').style.setProperty('height', heightPromo + 'px', null);
				}
			}
			
			}
			///////////////// POSIZIONO IL FOOTER SOTTO IL CONTENITORE //////////////////////////
			
			if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0){
     
					document.getElementById('footer').style.setAttribute('top', (heightContenitore+20) + 'px');
					document.getElementById('footer').style.setAttribute('visibility', 'visible');
					
				} else {

					document.getElementById('footer').style.setProperty('top', (heightContenitore+20) + 'px', null);
					document.getElementById('footer').style.setProperty('visibility', 'visible', null);
				}
			
		
        }

    }



