/* FUNZIONI GENERICHE UTILIZZABILI DA QUALSIASI PAGINA */
/* ultima versione Luigi Faragalli - 22 giugno 2010 */

function sendNews(lan){
	if (!lan) {lan='it';}
	nWidth=490;
	nHeight=450;
	window.open("/dynnew/"+lan+"/popup/popSendNews.phtml?link="+escape(window.location.href),"WinPopUp","width="+nWidth+",height="+nHeight+",directories=no,toolbar=no,scrollbars=no,resizable=no,status=no");
}

function submitForm(button, form){
		button.disabled=true;
		form.submit();
}



/*FUNZIONI NON GENERICHE MA CONDIVISE DA DUE O PIU' PAGINE AVENTI SIMILE STRUTTURA*/
//Setta/resetta i flag dei consensi di MWOL
function pickConsensiMwol(bConsensoCondAcquisto, bConsensoDatiAcquisto, bConsensoDatiPubblicita) {
	// Abilitazione di iscrizione a MWOL
	  document.form_reg.tmpCOND_ACQUISTO[0].disabled=false;
	  document.form_reg.tmpCONSENSODIFFUSIONE[0].disabled=false;
	  document.form_reg.tmpMATERIALEINFORMATIVO[0].disabled=false;
	  document.form_reg.tmpCOND_ACQUISTO[1].disabled=false;
	  document.form_reg.tmpCONSENSODIFFUSIONE[1].disabled=false;
	  document.form_reg.tmpMATERIALEINFORMATIVO[1].disabled=false;	    							  
		//imposto i valori di default
	  document.form_reg.tmpCOND_ACQUISTO[0].checked=Boolean(bConsensoCondAcquisto);
	  document.form_reg.tmpCONSENSODIFFUSIONE[0].checked=Boolean(bConsensoDatiAcquisto);
	  document.form_reg.tmpMATERIALEINFORMATIVO[0].checked=Boolean(bConsensoDatiPubblicita);
	  document.form_reg.tmpCOND_ACQUISTO[1].checked=Boolean(!bConsensoCondAcquisto);
	  document.form_reg.tmpCONSENSODIFFUSIONE[1].checked=Boolean(!bConsensoDatiAcquisto);
	  document.form_reg.tmpMATERIALEINFORMATIVO[1].checked=Boolean(!bConsensoDatiPubblicita);
}

// Funzioni di apertura popup Emulatore i-mode
function popupEmu(filename){
	filepath = "/imode/it/emu/";
        if (filename=="popupEmuHome.phtml"){
	nWidth=732;
	nHeight=560;
      }else if (filename=="popupEmuTech.phtml"){
        nWidth=350;
        nHeight=632;
      }else{
        nWidth=800;
                nHeight=600;
      }
      var nXMax = screen.width;
        var nYMax = screen.height;
      var nXOffset = (nXMax - nWidth)/2;
        var nYOffset = (nYMax - nHeight)/2;
        window.open(filepath+filename,"emu","top="+nYOffset+",left="+nXOffset+", width="+nWidth+",height="+nHeight+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0");
    }


function GuidaConto() {
        win = window.open("guidaconto/guidaConto.html", "win", "height=600,width=700,top=50,left=50,toolbar=no,resizable=no,menubar=no,scrollbars=yes")
        if (win.window.focus) win.window.focus();
}

function flashGuidaConto()
{
        var flashmenu = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="660" height="1200" id="guidaConto_base" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="guidaConto_base.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="guidaConto_base.swf" quality="high" bgcolor="#ffffff" width="660" height="1200" name="guidaConto_base" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
        document.write(flashmenu);
}

function impostaCookie (nome, valore, scadenza, path) {
    valore = escape(valore);
	stringaCookie = nome +'='+ valore;
	if (typeof(scadenza) != 'undefined' && scadenza != '') { stringaCookie += ';expires='+ scadenza; };
	// esempio stringa scadenza -- Thu, 2 Aug 2001 20:47:11 UTC
	// alert (typeof(scadenza));
	// alert (stringaCookie);
	if (typeof(path) != 'undefined') { stringaCookie += ';path='+path; } else { stringaCookie += ';path=/'; };
    document.cookie= stringaCookie;
}

function valoreCookie (nome) {
   var valore=document.cookie; //ottiene la stringa di cookie
   var inizioCookie=valore.indexOf(" " + nome + "="); //trova il cookie desiderato
 
   //se non esiste, magari e' all'inizio della stringa
   if (inizioCookie == -1) { 
      inizioCookie = valore.indexOf(nome + "=");
   }
 
   if (inizioCookie == -1) { //il cookie non esiste proprio
      valore = null;
   }
 
   if (inizioCookie >= 0) { //il cookie esiste
      //qui inizia la stringa del valore
      inizioCookie = valore.indexOf("=", inizioCookie) + 1; 
      var fineCookie = valore.indexOf(";", inizioCookie); //qui finisce
      if (fineCookie == -1)  //se non viene trovato, allora e' l'ultimo cookie
         fineCookie = valore.length;
      //elimina i caratteri commutati
      valore = unescape(valore.substring(inizioCookie, fineCookie)); 
   }
 
   return valore;
}

function cookieAttivi () {
    ris = false; //imposta il risultato a falso
    impostaCookie("testCookie", "test"); //crea il cookie fittizio
    if (valoreCookie("testCookie") == "test") { //se esiste
        ris = true; //allora i cookie sono abilitati
    }
    return ris;
}

/* FUNZIONI PSEUDO MODALBOX PER LOYALTY */

function pseudoModalBox(messaggioTrasmesso, modoConfirm, funzionePerYes){
	var divMascheramento = new Element('div', {
		'id' : 'loyalty_modal_wrapper',
		'styles' : {
			'width' : document.body.clientWidth,
			'height' : $('header').clientHeight+$('middle_part').clientHeight+$('footer').clientHeight
			}
		});
	var divContenitore = new Element('div', {
		'id' : 'loyalty_modal_box',
		'styles' : {
			'left' : (document.body.clientWidth-370)/2,
			'top' : (document.body.clientHeight-100)/2
			}
		});
	var divContenitoreSub1 = new Element('div', {
		'class': 'loyalty_modal_box_top'
		});
		divContenitoreSub1.innerHTML = '&nbsp;';
	var divContenitoreSub2 = new Element('div', {
		'class': 'loyalty_modal_box_content'
		})
		divContenitoreSub2.innerHTML = messaggioTrasmesso;
	var divContenitoreSub3 = new Element('div', {
		'class': 'loyalty_modal_box_bottom'
		});
		divContenitoreSub3.innerHTML = '&nbsp;';
	
	if(modoConfirm == true)
		{
			// alert('creazione tasti');
			var divSeparatore = new Element('div', {
			'class': 'clear f0'
			});
			divSeparatore.innerHTML = '&nbsp;';
			divSeparatore.inject(divContenitoreSub2, 'bottom');
			var divContenitoreTasti = new Element('div', {
				'class': 'loyalty_modal_box_content_confirm'
				});
			divContenitoreTasti.innerHTML = '<a onclick=' + funzionePerYes + 'href="#" class="loyalty_btn">S&igrave;</a><a onclick="$(\'loyalty_modal_wrapper\').remove(); return false" href="#" class="loyalty_btn">No</a>';
			divContenitoreTasti.setStyle('padding-left' , '90px');
			divContenitoreTasti.inject(divContenitoreSub2, 'bottom');
		}
		else if(modoConfirm == false)
		{
			var divSeparatore = new Element('div', {
			'class': 'clear f0'
			});
			divSeparatore.innerHTML = '&nbsp;';
			divSeparatore.inject(divContenitoreSub2, 'bottom');
			var divContenitoreTasti = new Element('div', {
				'class': 'loyalty_modal_box_content_confirm'
				});
			if(window.location.pathname == '/shop/carrello.phtml')
				{
				divContenitoreTasti.innerHTML = '<a onclick="$(\'loyalty_modal_wrapper\').destroy(); return false" href="#" class="loyalty_btn">Chiudi</a>';
				}
				else
				{
				divContenitoreTasti.innerHTML = '<a onclick="$(\'loyalty_modal_wrapper\').remove(); return false" href="#" class="loyalty_btn">Chiudi</a>';
				}
			divContenitoreTasti.setStyle('padding-left' , '132px');
			divContenitoreTasti.inject(divContenitoreSub2, 'bottom');
		}
	
	divContenitoreSub1.inject(divContenitore, 'top');
	divContenitoreSub2.inject(divContenitore, 'bottom');
	divContenitoreSub3.inject(divContenitore, 'bottom');
	divContenitore.inject(divMascheramento, 'top');
	divMascheramento.inject($('inner_content'), 'after');
}

function aggiornaDomande(valorePassato){
	// attivo seconda select
	$('loyalty_faq_select_domande').removeProperty('disabled');
	// azzero domande precedenti se presenti
	$$('#loyalty_faq_select_domande option').each(function(item, index){
				if(index != 0)
					{
						item.remove();
					}
				});
	// ciclo ricerca domande per argomento passato
	$$('.loyalty_faq_domanda').each(function(item, index){
		// selezioni domanda solo se relativa all'argomento scelto
		if(item.getNext('div').getNext('div').innerHTML == arrayArgomenti[valorePassato])
			{
			// alert(item.getNext('div').getNext('div').innerHTML);
			var optionDaAggiungere = new Element('option', {
				'value' : index
				});
			optionDaAggiungere.innerHTML = item.innerHTML;
			optionDaAggiungere.inject($('loyalty_faq_select_domande'), 'bottom');
			}
		});
	// alert(arrayArgomenti[valorePassato]);
}

function mostraRisposta(valorePassato){
	// alert(valorePassato);	
	if(valorePassato != 'null')
		{
		$('loyalty_domanda_prescelta').innerHTML = $$('.loyalty_faq_domanda')[valorePassato].innerHTML;
		$('loyalty_risposta_prescelta').innerHTML = $$('.loyalty_faq_risposta')[valorePassato].innerHTML;
		}
		else
		{
		$('loyalty_domanda_prescelta').innerHTML = '&nbsp;';
		$('loyalty_risposta_prescelta').innerHTML = '&nbsp;';
		}
}

function WinPopUp(strPath,nWidth,nHeight){
	if(isNaN(nWidth)){nWidth=490;}
	if(isNaN(nHeight)){nHeight=340;}
	var nXMax = screen.width;
	var nYMax = screen.height;
	var nXOffset = (nXMax - nWidth)/2;
	var nYOffset = (nYMax - nHeight)/2;
	window.open(strPath,"win"+nWidth,"top="+nYOffset+",left="+nXOffset+",width="+nWidth+",height="+nHeight
+",directories=no,toolbar=no,scrollbars=yes,resizable=no");
}



function get_url_param(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec( window.location.href ); 
	if( results == null ) return ""; 
	else return results[1];
}


// Popup video verso Libero Video
function videoPopup(theID, dimX, dimY, player) {
	vPopup = window.open("about:Blank","videopopupid","width="+(dimX+20)+",height="+(dimY+20)+",status=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no");
	vPopup.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	vPopup.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	vPopup.document.write('<head>');
	vPopup.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	vPopup.document.write('<title>Wind.it</title>');
	vPopup.document.write('</head>');
	vPopup.document.write('<body>');

	if (player == "youtube") {
		vPopup.document.write('<object width="'+dimX+'" height="'+dimY+'"><param name="movie" value="http://www.youtube.com/v/'+ theID +'?hl=it&fs=1" /></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ theID +'?hl=it&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+dimX+'" height="'+dimY+'"></embed></object>');
	} else if (player == "libero") {
		vPopup.document.write('<object width="'+dimX+'" height="'+dimY+'"><param name="movie" value="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" /><embed src="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" width="'+dimX+'" height="'+dimY+'" type="application/x-shockwave-flash"></embed></object>');
	} else {
		vPopup.document.write('<object width="'+dimX+'" height="'+dimY+'"><param name="movie" value="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" /><embed src="http://video.libero.it/static/swf/eltvplayer.swf?id='+ theID +'&ap=1" width="'+dimX+'" height="'+dimY+'" type="application/x-shockwave-flash"></embed></object>');
	}

	vPopup.document.write('</body>');
	vPopup.document.write('</html>');
}

// Popup video verso Libero Video
// Si apre solo se chiamato con un url che abbia un parametro openvideo==OpenVideoValue
function videoPopupIf(theID, OpenVideoValue, dimX, dimY, player) {
	ovvalue = get_url_param("openvideo");
	if (ovvalue == OpenVideoValue) {
		videoPopup(theID, dimX, dimY, player);
	}
}

