// globali
var ie = (document.all) ? 1 : 0;
var n4 = (document.layers) ? 1 : 0;
var n6 = ((!document.all)&&(document.getElementById)) ? 1 : 0;

// include CSS
function includeCSS(page){
if (n4) {
	document.write ("<link rel=stylesheet type=text/css href='/wb/base-n4.css'>")
	document.write ("<link rel=stylesheet type=text/css href='/wb/page-n4.css'>")
	}
else if (n6) {
	document.write ("<link rel=stylesheet type=text/css href='/wb/base-n6.css'>")
	document.write ("<link rel=stylesheet type=text/css href='/wb/page-n6.css'>")
	}
else {
	document.write ("<link rel=stylesheet type=text/css href='/wb/base-ie.css'>")
	document.write ("<link rel=stylesheet type=text/css href='/wb/page-ie.css'>")
	}
}


var progr = 0;
//popup generico
function newPop (tipo, area, lan) {
newWinName = 'newWin'+progr; progr++;
if (tipo=="negozio") {page = '/negoziPop.jhtml?area=' + area + '&lan=' +lan;}
if (tipo=="servizio") {page = '/serviziPop.jhtml?area=' + area + '&lan=' +lan;}
newWin = window.open (page,newWinName,'menubar=no,toolbar=no,scrollbars=yes,width=400,height=370,top=10,left=10');
newWin.focus();
}

//popup fidelity card
function fidelityPop (lan) {
page = '/elements/servizi/fidelityPop.jhtml?&lan=' +lan;
newWin = window.open (page,'FidelityCard','menubar=no,toolbar=no,scrollbars=no,width=300,height=270,top=10,left=10');
newWin.focus();
}

/*
//popup Galleria
function galleriaPop (url) {
gp = '/galleriaPop.jhtml?im=' + url;
evidenza = window.open ( gp, 'evidenza','menubar=no,resizable=yes,toolbar=no,scrollbars=yes,width=450,height=350,top=10,left=10');
evidenza.focus();
}
*/

//popup Negozio
function negoziPop (area, lan) {
page = '/negoziPop.jhtml?area=' + area + '&lan=' +lan;
negoziPopWin = window.open ( page, 'negoziPopWin','menubar=no,toolbar=no,scrollbars=yes,width=400,height=370,top=10,left=10');
negoziPopWin.focus();
}

//popup Servizi
function serviziPop (area, lan) {
page = '/serviziPop.jhtml?area=' + area + '&lan=' +lan;
serviziPopWin = window.open ( page, 'serviziPopWin','menubar=no,toolbar=no,scrollbars=yes,width=400,height=370,top=10,left=10');
serviziPopWin.focus();
}

//popup Help
function helpPop (helpSrc,lan) {
page = "/helpPop.jhtml?about=" + helpSrc + "&lan=" +lan;
helpPopWin = window.open ( page, 'helpPopWin','menubar=no,toolbar=no,scrollbars=yes,width=420,height=400,top=50,left=50');
helpPopWin.focus();
}

//popup Compagnie
function compagnieAereePop (id,lan) {
page = '/compagnieAereePop.jhtml?lan=' +lan+ '&id=' +id;
companiesPopWin = window.open ( page, 'companiesPopWin','menubar=no,toolbar=no,scrollbars=yes,width=400,height=370,top=10,left=10');
companiesPopWin.focus();
}

//popup VirtualTour
/*
function virtualTourPop (lan, regId) {
page = '/virtualTourPop.jhtml?regId='+regId;
virtualTourPopWin = window.open ( page, 'virtualTourPopWin','menubar=no,toolbar=no,scrollbars=no,width=760,height=520,top=0,left=0');
virtualTourPopWin.focus();
}
*/

//popup Login
function loginPop () {
page = '/loginPop.jhtml';
loginWin = window.open ( page, 'loginWin','menubar=no,toolbar=no,scrollbars=yes,width=200,height=300,top=10,left=10');
loginWin.focus();
}

//popup mappe
/*
function popUpMappe(lan,aeroporto,idPiano,idZona,idPuntocom,idMacro) {
	url='/pop_punti_commerciali_noflash.jhtml?lan='+lan+'&aeroporto='+aeroporto+'&idPiano='+idPiano+'&zona='+idZona+'&idPuntocom='+idPuntocom+'&suPopUp=S&singoloPuntoComm=S&idMacro='+idMacro;
	window.open(url,'popUpMappe','width=405,height=395,toolbar=no,menubar=none,scrollbars=yes,resizable=none');
}
*/

//popup registrazione
function registrazionePop (navi,lan) {
var page = '/registrazione.jhtml?lan=' +lan;
switch (navi) {
case "unsubscribe": page += "&navi=unregOne"; break;
case "profile": page += "&navi=profileEdit"; break;
case "phone": page += "&navi=changePhoneNo"; break;
case "password": page += "&navi=changePasswd"; break;
case "forgotten": page += "&navi=rememberPasswd"; break;
case "subscribe": page += "&navi=regOne"; break;

//case "subscribe": page += "&navi=stepSix&subscribe=y"; break;
default :  page += "&navi=default";
}
registrazionePopWin = window.open ( page, 'registrazionePopWin','dependent,menubar=no,toolbar=no,scrollbars=yes,width=550,height=450,top=50,left=50');
registrazionePopWin.focus();
}



//printNegozi
function Negozio(n, id, ref){
this.id = id;
this.ref = ref;
shop = "<b>" + n +  "</b> <" + "a href=# class=newsTxt onclick=\"" + "negoziPop('" + ref + "', '" + lang +"');\">" + id + "</a><br>"
document.write (shop);
}

//printServizi
function Servizio(n, id, ref){
this.id = id;
this.ref = ref;
service = "<b>" + n +  "</b> <" + "a href=# class=newsTxt onclick=\"" + "serviziPop('" + ref + "', '" + lang +"');\">" + id + "</a><br>"
document.write (service);
}

// apro un link del pop-up nella finestra madre
function openLinkInParentWnd (zaza){
opener.location = zaza;
}

// utils per GESTIONE SWITCH LINGUA
function setNewUrl (nl){
window.location = nl;
}

function langSwitch(lingua){
if (currentLang=="") {currentLang="it"}
oldLang = "lan="+currentLang;
oldLoka = window.location;
oldHash = window.location.hash;
newLoka = "";
hashStr = oldHash.toString();
locationStr = (window.location.toString());
hasHash = (locationStr.indexOf("#")!=-1) ? 1 : 0; //controllo se c'e' qualcosa in location.hash
hasQuery = (locationStr.indexOf("?")!=-1) ? 1 : 0; //controllo se c'e' qualcosa in location.search
pos = window.location.search.indexOf("lan="); //calcolo la posizione del parametro lan nell'url
newLang="lan="+lingua;
//se nella location non c'e' la query
if (hasQuery==0) { 	
	if (hasHash==0){//e neanche l'hash non faccio altro che aggiungere la lingua
	newLoka=oldLoka+"?"+newLang;
	}
else { //se c'e' l'hash invece
	oldLokaStr = oldLoka.toString();
	lokaHashSplit = oldLokaStr.split(hashStr);
	newLoka=lokaHashSplit[0]+"?"+newLang
	}
}
//altrimenti
else {
	if (pos==-1){//se non c'e' il parametro lan in location.search lo appendo dopo agli altri
		if (hasHash==0){// se non c'e' l'hash aggiungo la lingua
	newLoka=oldLoka+"&"+newLang;
	}
else { //se c'e' l'hash invece	
	oldLokaStr = oldLoka.toString();
	lokaHashSplit = oldLokaStr.split(hashStr);
	newLoka=lokaHashSplit[0]+"&"+newLang
	}
//		newLoka=oldLoka+"&"+newLang;
		}

	else { //se il parametro lan e' gia' settato...
		if (pos!=1) {prefix="&";} else if (pos==1) {prefix="?"} else {prefix="";}
		oldLokaStr = oldLoka.toString();
		splitter = prefix + oldLang;
		oldSplit = oldLokaStr.split(splitter);
		newLoka = oldSplit[0] + prefix + newLang + oldSplit[1];
		}
	}
setTimeout ('setNewUrl(newLoka)',10);
}

