// JavaScript Document
// autore: Luigi Faragalli
// sito: www.windgroup.it
// sezione: intero sito
// framework: mootools
// note: script comuni


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();
}

function search_arianna(lan)
{
	q=encodeURIComponent(document.frmArianna.query.value);
	if (q == '') {
		return false;
	} else {
		document.frmArianna.method = 'GET';
		document.frmArianna.action = lan + "search.phtml";
		document.frmArianna.submit();
		return false;	
	}
}


/*FUNZIONI NON GENERICHE MA CONDIVISE DA DUE O PIU' PAGINE AVENTI SIMILE STRUTTURA*/

// 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+",directories=no,toolbar=no,scrollbars=yes,resizable=no");
    }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function aggiorna_tab(reqBarId, reqStart, reqTabOn) {
	obj_bar=document.getElementById(reqBarId);
	obj_bar.innerHTML='<div class="fright"><img height="26" border="0" width="6" class="phide" alt="" src="/img94/new/static/new_itab_right_curve_1024.gif"/></div>';		
	cnt=tabTxt.length-1; // ignora l'ultimo elemento dato che e' vuoto (virgola aggiuntiva)
	size=0;
	// alert(size);
	lastDivPos=0;
	if(reqStart>0) 
		{
		obj_bar.innerHTML+='<div class="new_itab_item_off" id="new_tab_prec" ><p><a href="#'+(reqStart-1)+'" onclick="aggiorna_tab(\''+reqBarId+'\','+(reqStart-1)+')">&#160; << &#160;</a></p></div>';
		size+=document.getElementById("new_tab_prec").offsetWidth+7;
		// alert(size);
		obj_bar.innerHTML+='<div class="new_itab_spacer">&#160;</div>';
		}
	for(i=reqStart;i<cnt;i++) 
		{
		if(i!=reqStart) 
			{
			obj_bar.innerHTML+='<div class="new_itab_spacer">&#160;</div>';
			size+=7;
			// alert(size);
			}
		if(i==tabOn) 
			{
			lastDivPos = obj_bar.innerHTML.length;
			obj_bar.innerHTML+='<div class="new_itab_item_on" id="tab_'+i+'" ><p><span>&#160; '+tabTxt[i]+' &#160;</span></p></div>';
			}
			else 
			{
			lastDivPos = obj_bar.innerHTML.length;
			obj_bar.innerHTML+='<div class="new_itab_item_off" id="tab_'+i+'" ><p><a href="'+tabUrl[i]+'">&#160; '+tabTxt[i]+' &#160;</a></p></div>';
			}
		size+=document.getElementById("tab_"+i).offsetWidth;
		//alert(size);
		if(size>sizeLimit || (typeof($$('#tab_'+i+' a')[0])!='undefined' && $$('#tab_'+i+' a')[0].offsetHeight>26))
			{
			obj_bar.innerHTML = obj_bar.innerHTML.substring(0,lastDivPos);
			if(i+1<=cnt) 
				{
				obj_bar.innerHTML+='<div class="new_itab_item_off" ><p><a href="#'+(reqStart+1)+'" onclick="aggiorna_tab(\''+reqBarId+'\','+(reqStart+1)+')">&#160; >> &#160;</a></p></div>';
				}
			if ((document.getElementById('tab_0') != null) && (document.getElementById('tab_0').className == 'new_itab_item_off'))
				{
				document.getElementById('tab_0').style.background ="transparent url(/img94/new/static/new_itab_off_left_tab0_1024.gif) no-repeat scroll left top" ;
				}
				else if ((document.getElementById('tab_0') != null) && (document.getElementById('tab_0').className == 'new_itab_item_on'))
				{
				document.getElementById('tab_0').style.background ="transparent url(/img94/new/static/new_itab_on_left_1024.gif) no-repeat scroll left top" ;
				}
	
			break;
			}
		}
	if ((document.getElementById('tab_0') != null) && (document.getElementById('tab_0').className == 'new_itab_item_off'))
		{
		document.getElementById('tab_0').style.background ="transparent url(/img94/new/static/new_itab_off_left_tab0_1024.gif) no-repeat scroll left top" ;
		}
		else if ((document.getElementById('tab_0') != null) && (document.getElementById('tab_0').className == 'new_itab_item_on'))
		{
		document.getElementById('tab_0').style.background ="transparent url(/img94/new/static/new_itab_on_left_tab_1024.gif) no-repeat scroll left top" ;
		}
}

//Text Box Clear function
function Tclear(el) {
if (el.defaultValue==el.value) el.value = "";
}

function startBoxScroller() {
	if($$('.focus_box').length > 1)
		{
		var elementTarget = $('focus_wrapper').getFirst().getNext();
		boxScroller.toElement(elementTarget);
		}
}


/* FUNZIONI COOKIE */

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;
}