// BEGIN toolbar utility
var d='.tiscali.it';
var hOne=Array(['internet gratis','www'+d+'/abbonamenti'],['internet e minori','social'+d+'/interneteminori'],['business'],['telefonia','abbonati'+d+'/telefonia']);
var hTwo=Array(['internet gratis','www'+d+'/abbonamenti'],['come abbonarsi','abbonati'+d+'/comeabbonarsi'],['business','abbonati'+d+'/business/adsl'],['assistenza'],['telefonia','abbonati'+d+'/telefonia']);
var hThree=Array(['plus','abbonati'+d+'/plus'],['supermail','abbonati'+d+'/sicurezza/extramail'],['securePC','sicurezza'+d+'/prodotti/security.html'],['securefamily','abbonati'+d+'/sicurezza/securefamily'],['mailbyphone','byphone'+d],['fax'],['communicator'],['netphone'],['newsletter'],['cartoline']);
var hFour=Array(['animali'],['arte'],['donna'],['europa'],['finanza'],['lavoro'],['local'],['motori'],['musica'],['shopping'],['social'],['spettacoli'],['sport'],['tecnologia'],['viaggi']);
var hFive=Array(['annunci'],['blog'],['chat'],['download'],['foto','photo'+d],['gamesurf'],['giochi'],['incontri'],['mail'],['mobile'],['newsgroup'],['webspace']);
var hSix=Array(['adsl','assistenza'+d+'/adsl'],['area clienti','assistenza'+d+'/areaclienti'],['avvisi','assistenza'+d+'/avvisi'],['connessione','assistenza'+d+'/connessione'],['domini','assistenza'+d+'/domini'],['faq','assistenza'+d+'/faq'],['mail','assistenza'+d+'/plus'],['parametri','assistenza'+d+'/parametri'],['posta','assistenza'+d+'/posta'],['sicurezza','assistenza'+d+'/sicurezza'],['spazio web','assistenza'+d+'/spazioweb'],['voce','assistenza'+d+'/adsl/voce']);

function make_tool(id,content,x){
	var html='',y=1;
	for (i in content){
		html+=("<a href=\""+click_code(x,y)+((content[i][1]!=null)?content[i][1]:content[i][0]+d)+"/\" target=\"_top\">."+content[i][0]+"</a>");
		y++;
	}
	document.getElementById(id).innerHTML=html;
}
function click_code(x,y){
	var clickS=(clickSrvArea!='')?'http://go.tiscali.it/'+clickSrvArea+'.01/TROW'+x+'\.'+((y<10)?'0'+y:y)+'/T/KEY.001/http://':'http://';
	return clickS;
}
// END toolbar utility

function GetCookie(name){
	var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;
	while(i<clen){
		var j=i+alen;
		if(document.cookie.substring(i,j)==arg)
			return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if(i==0)
			break;
		}
	return null;
}

function SetCookie(name,value,expires,path,domain,secure){
	var today = new Date();
	var expires_date = new Date();
	if (isFinite(expires)){
		expires_date.setTime(today.getTime() + 3600000*24*expires);
	}else{
		expires_date=expires;
		}
        document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires_date.toGMTString():"")+((path)?"; path="+path:"")+((domain)?";domain="+domain:"")+((secure)?"; secure":"");
}

function DeleteCookie(name,path,domain){
	if(GetCookie(name)){
document.cookie=name+"="+((path)?"; path="+path:"")+((domain)?"; domain="+domain:"")+"; expires=Tue, 01-Jan-2002 00:00:01 GMT";
	}
}

function getCookieVal(offset){
	var endstr=document.cookie.indexOf(";",offset);
	if(endstr==-1)endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}

document.write("<sc"+"ript src=\"http:/"+"/www.tiscali.it/js/v1.8/lib.html\"></sc"+"ript>");

var CLASS = GetCookie("CLASS");
sz        = 2000; 
sImg      = new Image;

function spCK(){
if(CLASS == null){
    s1 = new Date();
    sImg.src="http://img.tiscali.it/etc/pxw2k.bmp?"+Math.random(); 
    if(navigator.userAgent.indexOf("Fire")==-1){
      setTimeout("getSp()",1);         
    }else{
      sImg.onload = getSp;
    }
 }
}

function getSp(){
   if(sImg.complete){
     s2 = new Date();
     CLASS = s2.getTime()-s1.getTime();    
     if (CLASS!=0){
       CLASS=Math.floor(8*sz/CLASS);
       CLASS=(CLASS<=36?1:2);
     }
WH:     while(1){
if(TIP.search("^(195.130|213.205|217.133|62.1|82.(82|84|85|222))")!=-1){TIP="1";break WH;}
if(TIP.search("^(151|193|212|213.140|217)")!=-1){TIP="A";break WH;}
if(TIP.search("^(80|81|82|83|84|85|213.45)")!=-1){TIP="B";break WH;}
TIP = "Z"; break WH;}
SetCookie("CLASS",TIP+CLASS,2,"/","tiscali.it","");
}else{
  setTimeout("getSp()",1);
  }
}

var oldonload = window.onload;
if (typeof window.onload != 'function') {
  window.onload = spCK;
}else {
  window.onload = function() {
   oldonload();
   spCK();
 }
}

function gatway(col,typ){
	document.forms[0].collection.value=col;
	document.forms[0].tiscalitype.value=typ;
	document.forms[0].maxCount.value=(typ=="image")?'4':'';
}

function ts_gourl(url){
	top.location.href=url;
}

function LabelAbbonatiToolbar(label_adsl,url_adsl,label_others,url_others){
		var cookie_val=GetCookie('CLASS');
		var output_html=(cookie_val!=12)?'<a href="'+url_adsl+'" target="_top"  onmouseover="klick(\'two\');">'+label_adsl+'</a>':'<a href="'+url_others+'" target="_top"  onmouseover="klick(\'two\');">'+label_others+'</a>';
		document.write(output_html);
}

// box vol too_sx
function make_box(site,page,area,element,key){
var click_code='http://go.tiscali.it/'+site+'.'+page+'/'+area;
var id=1;
var cookie_val=GetCookie('CLASS');
if (cookie_val!=12){
var content="<div class=\"w298 barAcc brdAcc\"><a href="+click_code+".0"+id+"/B/"+key+"http://abbonati.tiscali.it/adsl/sa/4flat_tc/><img src=\"http://img.tiscali.it/v001/accesso/b2c.jpg\" class=\"fL\" alt=\"\" /></a></div><div class=\"bgAcc bg wMax mB12\">&nbsp;</div>";
}
/*
else{
var content="<div class=\"w298 barAcc brdAcc\"><a href="+click_code+".06/B/"+key+"http://abbonati.tiscali.it/promozioni/adsl/mgm01/><img src=\"http://img.tiscali.it/v001/accesso/mgm.gif\" class=\"fL\" alt=\"\" /></a></div><div class=\"bgAcc bg wMax mB24 brd2WT\">&nbsp;</div>";
}
*/
else{
	var flashurl=click_code+".06/F/"+key+"http://procedure.tiscali.it/mgm/?id=3";
	var content="<div class=\"w300\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"300\" height=\"68\" id=\"intro\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"http://img.tiscali.it/v001/accesso/mgm.swf?flashurl="+flashurl+"\" /><param name=\"quality\" value=\"high\" /><embed src=\"http://img.tiscali.it/v001/accesso/mgm.swf?flashurl="+flashurl+"\" quality=\"high\" wmode=\"transparent\" width=\"300\" height=\"68\" name=\"intro\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object></div><div class=\"bgAcc bg wMax mB12\">&nbsp;</div>";
}
document.write(content);
}


if(navigator.platform.indexOf('Mac') != -1){
	document.write('<style>.toolbar .tab b{font:bold 10px Arial;}</style>');
}
var last=null;
var verspringen=null;
var verspringob=null;
var terugspringob=null;
var verspringen=null;
var terugspringen=null;
var timeoutID='';

function klick(thiso) {
  if(terugspringob == null) {
    terugspringob = thiso;
  }
  noklick();
  verspringob = thiso;
  verspringen = setTimeout("TisKlick()",400);
}

function leavemenu() {
  noklick();
  terugspringen = setTimeout("TisUnKlick()",1000)
}

function noklick() {
  if (verspringen) {
    clearTimeout(verspringen)
  }
  if (terugspringen) {
    clearTimeout(terugspringen)
  }
}

function TisKlick() {
  var color_sel=verspringob.style.backgroundColor;
  if(last){
    last.getElementsByTagName('b').item(0).style.borderBottom='1px solid #FFF';
  }
  verspringob.getElementsByTagName('b').item(0).style.borderBottom='1px solid '+color_sel;
  document.getElementById('lowbar').style.backgroundColor=color_sel;
  last=verspringob;
  var label='H-'+verspringob.id;
  document.getElementById('menu').innerHTML=document.getElementById(label).innerHTML;
}


function Unklick_body(num){
	var thiso=document.getElementById(num);
	var color_sel=thiso.style.backgroundColor;
	if(last){
		last.getElementsByTagName('b').item(0).style.borderBottom='1px solid #FFF';
	}
	thiso.getElementsByTagName('b').item(0).style.borderBottom='1px solid '+color_sel;
	document.getElementById('lowbar').style.backgroundColor=color_sel;
	last=thiso;
	var label='H-'+thiso.id;
	document.getElementById('menu').innerHTML=document.getElementById(label).innerHTML;
}

function TisUnKlick() {
  var color_sel=terugspringob.style.backgroundColor;
  if(last){
    last.getElementsByTagName('b').item(0).style.borderBottom='1px solid #FFF';
  }
  terugspringob.getElementsByTagName('b').item(0).style.borderBottom='1px solid '+color_sel;
  document.getElementById('lowbar').style.backgroundColor=color_sel;
  last=terugspringob;
  var label='H-'+terugspringob.id;
  document.getElementById('menu').innerHTML=document.getElementById(label).innerHTML;
}

function getUrlValue(what,iframe){
	if(iframe==false){
		if(what=='image'){
			if(tsLogo){
				return tsLogo;
			}
			else{
				return('img/logo.gif');
			}
		}
		if(what=='selected'){
			if(tsSelected){
				return tsSelected;
			}
			else{
				return('one');
			}
		}
		if(what=='area_HP_link'){
			if(tsLogoLink){
				return tsLogoLink;
			}
			else{
				return('');
			}
		}
	}
	else{
		var url=document.location.href;
		if(url.indexOf(what)==-1){
			return;
		}
		url=url.substring(url.indexOf(what)+what.length+1);
		var end=(url.indexOf('&')!=-1)?url.indexOf('&'):url.length;
		url=url.substring(0,end);
		return (url);
	}
	return null;
}

function w3cLinks(){
	var anchors = document.getElementsByTagName("a"); 
	for(i=0;i<anchors.length;i++){
		anchors[i].target = "_top"; 
	}
}

function setup(iframe){
	w3cLinks();
	klick_body('one');
}

function select(thiso){
	var rows=document.getElementById('versions').getElementsByTagName('div');
	for(i=0;i<rows.length;i++){
		rows[i].style.backgroundColor='#EEE';
	}
	thiso.style.backgroundColor='yellow';
}

function getParam(PARAM, DEF){
	var str = top.location.search;
	var reg = new RegExp(PARAM+"=([^&]+)");
	var result = str.match(reg);
	if(result != null){
		return result[1];
	}	
	return DEF;	
}
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function urlencode(KEY){
	return escape(trim(KEY)).replace(/%20/g, '+');
}
function urldecode(KEY){
	if(KEY != "")
		return unescape(trim(KEY)).replace(/\+/g, ' ');
	return "";
}
function changeView(T){
	if(T == ""){
		T = document.formTiscali.tiscalitype.value;
	}else{
		document.formTiscali.tiscalitype.value = T;
	}
	document.getElementById('s_form').style.backgroundColor = "#E5E5E5";
	var arrInputs = new Array('search_simple','search_pg','search_mp3','search_mappe','s_google');
	for(var i=0;i<arrInputs.length;i++){
		document.getElementById(arrInputs[i]).style.display = "none";
	}		
	//var arrLabels = new Array('web','image','video','mappe','mp3','directory','pg');
	var arrLabels = new Array('web','image','video','mappe','mp3','directory');	
	for(var i=0;i<arrLabels.length;i++){			
		document.getElementById('t_'+arrLabels[i]).style.color = "#0750d9";	
	}
	document.getElementById('t_'+T).style.color = "#626262";	
	document.getElementById('box_radio_tiscali').style.display = "none";	
	document.getElementById('box_radio_web').style.display = "none";	
	document.getElementById('box_radio_it').style.display = "none";	
	var where = "";
	for(var i=0;i<document.formTiscali.selectsearch.length;i++){
		if(document.formTiscali.selectsearch[i].checked)
			where = document.formTiscali.selectsearch[i].value;
	}
	if(T == "pg"){
		document.getElementById('s_form').style.backgroundColor = "#FEDE19";		
		document.getElementById('search_pg').style.display = "block";			
		return;
	}
	if(T == "mp3"){
		document.getElementById('search_mp3').style.display = "block";			
		return;
	}
	if(T == "mappe"){
		document.getElementById('search_mappe').style.display = "block";			
		return;
	}
	if(T == "web" || T == "image" || T == "video" || T == "directory"){
		document.getElementById('search_simple').style.display = "block";	
		document.getElementById('box_radio_tiscali').style.display = "block";	
		document.getElementById('box_radio_web').style.display = "block";	
		document.getElementById('box_radio_it').style.display = "block";	
		if(T != "video" && (where == "web" || where == "it")){
			document.getElementById('collection').value = where;
			document.getElementById('s_google').style.display = "block";	
		}	
		if(T == "directory"){
			document.getElementById('radio_web').checked = true;
			document.getElementById('box_radio_tiscali').style.display = "none";	
			document.getElementById('box_radio_web').style.display = "none";	
			document.getElementById('box_radio_it').style.display = "none";	
			document.getElementById('s_google').style.display = "block";
		}	
		if(T == "video"){
			document.getElementById('radio_tiscali').checked = true;	
			document.getElementById('box_radio_web').style.display = "none";	
			document.getElementById('box_radio_it').style.display = "none";	
		}	
		if(T == "image" ){
			if(!document.getElementById('radio_tiscali').checked)
				document.getElementById('radio_web').checked = true;
			document.getElementById('box_radio_it').style.display = "none";	
		}
		return;
	}	
}
function submitSearch(){
	var obj = document.formTiscali;
	var where = obj.tiscalitype.value;
	var selectsearch = "";
	for(var i=0;i<document.formTiscali.selectsearch.length;i++){
		if(document.formTiscali.selectsearch[i].checked)
			selectsearch = document.formTiscali.selectsearch[i].value;
	}
	switch(where){
		case "pg":
			var url = "tiscalitype=pg&key="+urlencode(obj.cosa.value)+"&d="+urlencode(obj.dove.value);	
			top.location.href = "http://search.tiscali.it/?"+url;	
		break;
		case "mp3":
			var url = "shop=11&associd=2";
			if(obj.artistsearch.value == "" && obj.titlesearch.value != ""){
				url += "&redirect=searchtitle&titlesearch="+obj.titlesearch.value;
			}else if(obj.artistsearch.value != "" && obj.titlesearch.value == ""){
				url += "&redirect=searchartist&artistsearch="+obj.artistsearch.value;
			}else if(obj.artistsearch.value != "" && obj.titlesearch.value != ""){
				url += "&redirect=searchartisttitle&artistsearch="+obj.artistsearch.value+"&titlesearch="+obj.titlesearch.value;
			}			
			top.location.href = "http://sib1.od2.com/common/config.asp?"+url;			
		break;
		case "mappe":
			var url = "txtIndirizzo="+urlencode(obj.txtIndirizzo.value)+"&txtCivico="+urlencode(obj.txtCivico.value)+"&txtComune="+urlencode(obj.txtComune.value)+"&Nation=ITALIA&cerca.x=18&ContextName="+(new Date()).getTime();
			top.location.href = "http://mappe.tiscali.it/mappe/cercaindirizzo.asp?"+url;	
		break;
		case "video":
			var url = "tiscalitype=video&key="+urlencode(obj.key.value);	
			top.location.href = "http://search.tiscali.it/?"+url;		
		break;
		default:
			if(selectsearch == "web" || selectsearch == "it"){
				var url = "collapse=on&pg=1&offset=0&tiscalitype="+obj.tiscalitype.value+"&collection="+obj.collection.value;
				if(where == "image"){
					url += "&hits=9";
				}else{
					url += "&hits=10";
				}
				if(selectsearch == "it"){
					url += "&language=it";
				}else{
					url += "&hl=it";
				}
				url += "&key="+urlencode(obj.key.value.replace("site:directory.tiscali.it",""));				
				if(obj.tiscalitype.value == "directory"){
					url += "+site:directory.tiscali.it";
					url += "&hl=it";
				}
				top.location.href = "http://search-dyn.tiscali.it/search.php?"+url;		
			}else{
				var url = "tiscalitype="+where+"&key="+urlencode(obj.key.value)+"&collection=tiscali";	
				top.location.href = "http://search.tiscali.it/?"+url;	
			}			
		break;
	}
}
