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 preloadImages() {
	MM_preloadImages('/img/ico_home_sel.gif','/img/ico_magazine_sel.gif','/img/ico_contatti_sel.gif')
}

// --- Funzioni utilita aggiunte by ale

loadUrl = function(url, target, options)
{
	
	// var urlIcona = "/img/funweek_loading.gif";
	var urlIcona = "/img/loader.gif";
	var backgroundColor = "#0a0a0a";

	// Setta i valori di defaults
	if(options != undefined){
    	if(options.urlIcona != undefined)
    		urlIcona = options.urlIcona;
    		
    	if(options.backgroundColor != undefined)
    		backgroundColor = options.backgroundColor;	
	}
	
	
	var container = document.getElementById(target);
	if(!container)
	{
		alert("Target: " + target + " non trovato!");
		return;
	}
	marginTop = (Math.round(container.clientHeight / 2) - 30) + "px";
	marginLeft = (Math.round(container.clientWidth / 2)- 30) + "px";
	var icoLoading = document.createElement('img');
	icoLoading.src= urlIcona;
	icoLoading.style.marginTop = marginTop;
	icoLoading.style.marginLeft = marginLeft;
	
	var backgroundDiv = document.createElement('div');
    backgroundDiv.style.position = 'absolute'; 
    backgroundDiv.style.backgroundColor = backgroundColor;
    backgroundDiv.style.width = "100%";
    backgroundDiv.style.height = "100%";
    
    backgroundDiv.style.top = '0px';
    backgroundDiv.style.left = '0px';
    backgroundDiv.style.zIndex = '100';
    backgroundDiv.style.opacity = '.80';
    backgroundDiv.style.filter = 'alpha(opacity=80)';
    
    backgroundDiv.appendChild(icoLoading);
    container.appendChild(backgroundDiv);
    
	ahah(url, target, undefined, undefined, undefined, true);
}


rolloverBannerPartner = function(id, url_swap)
{
	el = document.getElementById(id);
	if(el)
		el.src = url_swap;
	
}


// ---------- test modal dialog -----------
var modalDialogOldScrollFunction = null;


alertModalDialog = function(label, testo, width, height, colori, options)
{
	
	if(colori['colorBackgroundOk']===undefined)
		colorBackgroundOk = 'white';
	else
		colorBackgroundOk = colori['background'];	
	if(colori['colorBorderOk']===undefined)
		colorBorderOk = '#0A0A0A';
	else 
		colorBorderOk = colori['border'];
	
	var bttOk = "<input type='button' name='buttonOk' value='OK' onclick='closeModalDialog()' style='background:"+colorBackgroundOk+"; border:1px solid "+colorBorderOk+";color:"+colorBorderOk+"; font-size:11px'>";
	
	var divBttOk ="<div style='text-align:center;margin:10px'>"+bttOk+"</div>";
	
	if(options == undefined)
		options = new Array();
	options["testo"] = testo + divBttOk;
	modalDialog (label, undefined, width, height, colori, options);
}


modalDialog = function(label, url, width, height, colori, options)
{
	// Setta i valori di defaults
	if(width===undefined || width==='')
		var width = '300';
	if(colori===undefined)
		var colori = new Array();
	if(colori['background']===undefined)
		colori['background'] = '#0A0A0A';
	if(colori['border']===undefined)
		colori['border'] = '#f26522';
	if(options == undefined){
    	options = {backgroundClick:false};	
	}
		
    var body = document.getElementsByTagName('body').item(0); 
    
    var old_msg_background = document.getElementById('msg_background');  
    if(old_msg_background) body.removeChild(old_msg_background);  
     
    var msg_background = document.createElement('div');
    msg_background.id = 'msg_background';
    msg_background.style.position = 'absolute';
    msg_background.style.width = '100%';
    msg_background.style.height = '100%';
    msg_background.style.top = '0px';
    msg_background.style.left = '0px';
    msg_background.style.zIndex = '100';
    
	body.appendChild(msg_background);  
    
	var backgroundDiv = document.createElement('div');
    backgroundDiv.style.position = 'absolute';
    backgroundDiv.style.backgroundColor = colori['background'];
    backgroundDiv.style.width = '100%';
    backgroundDiv.style.height = '100%';
    backgroundDiv.style.top = '0px';
    backgroundDiv.style.left = '0px';
    backgroundDiv.style.zIndex = '30';
    backgroundDiv.style.opacity = '.80';
    backgroundDiv.style.filter = 'alpha(opacity=80)';
    
    
    if(options["backgroundClick"])
    {
    	backgroundDiv.onclick = function () {
    		display('msg_background');
    	}
    }
	
	msg_background.appendChild(backgroundDiv);
	
    var msgBox = document.createElement('div');
    msgBox.id = 'msgBox';
    msgBox.style.backgroundColor = '#fff';  
    msgBox.style.border = '2px solid '+colori['border'];  
    msgBox.style.width = width+'px';  
    msgBox.style.position = 'absolute'; 
    msgBox.style.zIndex = '150';    
    msgBox.style.overflow = 'auto';
    
	msg_background.appendChild(msgBox);
	
	if(label != undefined && label != '')
	{
	    var labelDiv = document.createElement('div');
	    labelDiv.style.lineHeight = '20px';
	    labelDiv.style.fontWeight = 'bold';
	    labelDiv.style.color = 'white';
	    labelDiv.style.backgroundColor = colori['border'];
	    labelDiv.style.paddingLeft = '5px';
	    labelDiv.style.textAlign = 'left';
	    labelDiv.innerHTML = label;
		
	    msgBox.appendChild(labelDiv);
	}
	
    var messageDiv = document.createElement('div');
    messageDiv.id= "targetDialog";
    messageDiv.style.textAlign = 'left';
    messageDiv.style.padding = '10px';
	
    if(options["testo"]){
    	messageDiv.innerHTML = options["testo"];
    }

    msgBox.appendChild(messageDiv);
    disableVideo();
   
    try {
   	
		var size = getPageSize();
		var scroll = getFullPageScroll();
		
		if(height == undefined)	
			height = msgBox.clientHeight;
		
		msgBox.style.left = (Math.round((size[0] - width )/2))+'px';
		msgBox.style.top = (Math.round((size[3] - height)/2))+'px';
		
		scrollEvent = function(){
			
			var scroll = getFullPageScroll();
			var size = getPageSize();
			var msgBox = document.getElementById('msgBox');
			var msg_background = document.getElementById('msg_background');
			
			var body = document.getElementsByTagName('body').item(0); 
			
			msg_background.style.width = (body.clientWidth + scroll[0]) + 'px';
			msg_background.style.height = (body.clientHeight + scroll[1]) + 'px';
		}
		
		resizeEvent = function(){
			
			var scroll = getFullPageScroll();
			var size = getPageSize();
			var msgBox = document.getElementById('msgBox');
			var msg_background = document.getElementById('msg_background');
			
			msgBox.style.left = (Math.round((size[2]-width)/2)+scroll[0])+'px';
			msgBox.style.top = (Math.round((size[3]-height)/2)+scroll[1])+'px';
			var body = document.getElementsByTagName('body').item(0); 
			
			msg_background.style.width = (body.clientWidth + scroll[0]) + 'px';
			msg_background.style.height = (body.clientHeight + scroll[1]) + 'px';
		}
		
		modalDialogOldScrollFunction = window.onscroll;
		window.onscroll = scrollEvent;
		
		window.onresize = resizeEvent;
		
		resizeEvent();
		//addEvent(window, 'scroll', scrollEvent)
	}
	catch(e)
	{
		alert(e + "\nIncludersi window.js");
	}	
	if(url!=undefined)
		window.setTimeout('ahah("' + url + '", "targetDialog");', 1000);
}

closeModalDialog= function()
{
	var el = document.getElementById("msg_background");
	if(el)
	{
		var p = el.parentNode;
		if(p.removeChild(el));
		enableVideo();
	}
	window.onscroll = modalDialogOldScrollFunction;
}

disableVideo = function()
{
	var elements = document.getElementsByTagName("object");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			// alert(elements[i].id);
			elements[i].style.visibility = "hidden";
	}
	
	var elements = document.getElementsByTagName("embed");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			//alert(elements[i].id);
			elements[i].style.visibility = "hidden";
	}
	
	var elements = document.getElementsByTagName("iframe");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			//alert(elements[i].id);
			elements[i].style.visibility = "hidden";
	}
}

enableVideo = function()
{
	var elements = document.getElementsByTagName("object");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			// alert(elements[i].id);
			elements[i].style.visibility = "visible";
	}
	
	var elements = document.getElementsByTagName("embed");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			//alert(elements[i].id);
			elements[i].style.visibility = "visible";
	}
	
	var elements = document.getElementsByTagName("iframe");
	for(i=0; i < elements.length; i++)
	{
		//if(elements[i].style != undefined)
			//alert(elements[i].id);
			elements[i].style.visibility = "visible";
	}
}

redirectComboMagazine = function()
{
	var comboMagazine = document.getElementById("comboMagazine");
	if(comboMagazine.value != '')
		document.location.href=comboMagazine.value;
}

selezionaElemento = function(idContenitore, tagElementi, prefisso, id, classe, classeSel, functionSel, functionDesel)
{
	var contenitore = document.getElementById(idContenitore);	
	var elementi =  contenitore.getElementsByTagName(tagElementi);	
	for(i=0; i < elementi.length; i ++)
	{
		if(elementi[i].id == id)
		{
			elementi[i].className = classeSel;
			if(functionSel != undefined)
				eval(functionSel + "('" + elementi[i].id + "')" );
		}else if(elementi[i].id.indexOf(prefisso) >= 0) {
			elementi[i].className = classe;
			if(functionDesel != undefined)
				eval(functionDesel + "('" + elementi[i].id + "')" );
		}
	}
}

emailVerificata = function (emailId)
{
	el = document.getElementById(emailId);
	el.style.color = "green";
	
	el_checked = document.getElementById(emailId + "_checked");
	if(el_checked)
		el_checked.value = 1;
}
 
emailNonVerificata = function (emailId)
{
	el = document.getElementById(emailId);
	el.style.color = "red";
	
	el_checked = document.getElementById(emailId + "_checked");
	if(el_checked)
		el_checked.value = 0;
}




/*test*/
function initFileUploads(options) {
	var urlImage = "/img/button.gif";
	var parentClassName = "fileinputs";
	var fileClassName = "file hidden";
	var containerFakeFileClassName = "fakefile";
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	
	if(options != undefined)
	{
		if(options.urlImage != undefined)
			urlImage = options.urlImage;
			
		if(options.parentClassName != undefined)
			parentClassName = options.parentClassName;	
			
		if(options.fileClassName != undefined)
			fileClassName = options.fileClassName;		
		
		if(options.fakeFileClassName != undefined)
			fakeFileClassName = options.fakeFileClassName;			
	}
	
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = containerFakeFileClassName;
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src= urlImage;
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != parentClassName) continue;
		
		x[i].className = fileClassName;
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}


controllaInformativeRedattore = function()
{
	info = document.getElementById("accettazione_informativa");
	noteLegali = document.getElementById("note_legali");
	
	if(info.checked && noteLegali.checked)
		return true;
	else if( !(noteLegali.checked) && !(info.checked) ) {
		alert("Per inviare il form occorre accettare sia l'informativa che le note legali");
	} else if( !(info.checked))
	{
		alert("Per inviare il form occorre accettare l'informativa");
	} else if( !(noteLegali.checked)){
		alert("Per inviare il form occorre accettare anche le note legali");
	}
	return false;
}


controllaInformativa = function()
{
	info = document.getElementById("accettazione_informativa");
	
	if(info && info.checked)
		return true;
	else {
		alert("Per inviare il form occorre accettare l'informativa");
		return false;
	}
}

selezionaSettimana = function(id, url)
{
	var oldSettimanaSel;
	var linkSettimanaSelAttuale;
	var linkSettimanaSel;
	var settimanaSel = document.getElementById("settimanaSel");
	
	if(settimanaSel.value)
	{
		oldSettimanaSel = settimanaSel.value;
		linkSettimanaSelAttuale = document.getElementById('settimana_' + settimanaSel.value); 
	}
	if(linkSettimanaSelAttuale){
		linkSettimanaSelAttuale.style.textDecoration = "none";
		linkSettimanaSelAttuale.style.color = "#9d9d9d";
	}
	linkSettimanaSel = document.getElementById('settimana_' + id); 
	if(linkSettimanaSel){
		linkSettimanaSel.style.textDecoration = "underline";
		linkSettimanaSel.style.color = "#6F6F6F";
	}
	settimanaSel.value = id;

	document.getElementById('frame_mockup').src=url;
	
}