function using(jsFile) {
    document.write('<script type="text/javascript" src="'
    + jsFile + '"></script>');
}
using('/js/BrowserDetect.js');


var conttab0 = 1;
var conttab1 = 1;
var conttab2 = 1;

/*
//precaricamento dei bottoni rollover
if (navigator.appVersion.substring(0, 1) >= 3) {


    var i1 = new Image;
    i1.src = '/img/bt_prec_novita_over.png';
    var i2 = new Image;
    i2.src = '/img/bt_succ_novita_over.png';
    var i3 = new Image;
    i3.src = '/img/bt_prec_pross_over.png';
    var i4 = new Image;
    i4.src = '/img/bt_succ_pross_over.png';
    var i5 = new Image;
    i5.src = '/img/bt_prec_viste_over.png';
    var i6 = new Image;
    i6.src = '/img/bt_succ_viste_over.png';
}
*/



function sfoglia(pag, tab, ntab) {
    var cont = this['cont' + tab];
    document.getElementById(tab + cont).style.display = 'none';
	document.getElementById("pag_" + tab + cont).src = '/img/pallino_grigio.gif';

    this['cont' + tab] = this['cont' + tab] + pag;
    if (this['cont' + tab] > ntab) {
        this['cont' + tab] = 1;
    } else if (this['cont' + tab] < 1) {
        this['cont' + tab] = ntab;
    }

    document.getElementById(tab + this['cont' + tab]).style.display = 'block';
	document.getElementById("pag_" + tab + this['cont' + tab]).src = '/img/pallino_rosso.gif';
}

function pag_numpagine(pag) {
	var ret="";
	for(var i = 1; i<pag +1; i++ ){
		if(i==pag)
			ret += '<img width="15" height="11" border="0" src="/img/pallino_grigio.gif">';
		else
			ret += '<img width="15" height="11" border="0" src="/img/pallino_rosso.gif">';
	}
	return ret ;
}

function cambiaImmagine(quale, evento) {
	try{
		document.images[quale].src = '/img/' + quale + '_' + evento + '.png'	
	}catch(e){}
}


// funzione per visualizzare flash senza bordo su ie
function includeSwf(movie, qs, width, height, wmode, imgSost, elementWrite) {
    var elementDiv = null;
    var strSost = "";

    var nRandom = Math.floor(Math.random() * 1000)

    if (imgSost != undefined)
        strSost = '<img src="' + imgSost + '" width="' + width + '" height="' + height + '" />';

    if (elementWrite != undefined && elementWrite != null && elementWrite != "")

        elementDiv = document.getElementById(elementWrite);

    var objStr = '<object type="application/x-shockwave-flash" data="' + movie + '" width="' + width + '" height="' + height + '" title=""  id="idFlash' + nRandom + '">\n' +
	'<param name="allowScriptAccess" value="always" />\n' +
	'<param name="allowFullScreen" value="true" />\n' +
	'<param name="movie" value="' + movie + '" />\n' +
	'<param name="quality" value="high" />\n' +
	'<param name="scale" value="exactfit" />\n' +
	'<param name="FlashVars" value="' + qs + '" />\n' +
	'<param name="wmode" value="transparent" />\n' +
	strSost + '\n' +
	'</object>';

    if (elementDiv == null)
        document.write(objStr);
    else
        elementDiv.innerHTML = objStr;  

}


/*  VEDI SOTTO LA NUOVA IMPLEMENTAZIONE*/
/*
function includeSwfHp(movie,qs,width,height)
{
var objStr=	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="videoPlayer" align="middle" >\n'+
'<param name="allowScriptAccess" value="sameDomain" />\n'+
'<param name="allowFullScreen" value="false" />\n'+
'<param name="FlashVars" value="'+qs+'" />\n'+
'<param name="movie" value="'+movie+'" />\n'+
'<param name="quality" value="high" />\n'+
'<param name="bgcolor" value="#ffffff" />\n'+	
'<embed src="'+movie+'" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="videoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+qs+'" />\n'+
'</object>';
	
document.write(objStr);
}
*/

function includeSwfHp(movie, qs, width, height) {
    if (movie == "/videoPlayerMulti.swf") {
        if (BrowserDetect.OS == "Windows")
            includeSwfHpAdv(qs, width, height); //vedi scriptAdv.js
        else
            includeSwfHpNoAdv(movie, qs, width, height);
    }
    else
        includeSwfHpNoAdv(movie, qs, width, height);
}

function includeSwfHpNoAdv(movie, qs, width, height) {
    var objStr = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="videoPlayer" align="middle" >\n' +
	'<param name="allowScriptAccess" value="sameDomain" />\n' +
	'<param name="allowFullScreen" value="false" />\n' +
	'<param name="FlashVars" value="' + qs + '" />\n' +
	'<param name="movie" value="' + movie + '" />\n' +
	'<param name="quality" value="high" />\n' +
	'<param name="bgcolor" value="#ffffff" />\n' +
	'<embed src="' + movie + '" quality="high" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="videoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="' + qs + '" />\n' +
	'</object>';

    document.write(objStr);
}


function BI(pmk) {
    var url = "http://" + window.location.hostname + "/biTrack.pippo?pmk=" + pmk + "&rndNumber=";
    var rndNumber = Math.floor(Math.random() * 100000);
    url = url + rndNumber;
    //alert(url) 
    if (document.getElementById("biPmk") != null)
        document.getElementById("biPmk").src = url;
    else {
        var externalImg = document.createElement("img");
        externalImg.id = "biPmk";
        externalImg.src = url;
        externalImg.style.display = "none";
        document.body.appendChild(externalImg);
    }
    return false;

}

function BI_OFFERTA(link) {
    var url = "http://" + window.location.hostname + link + "?pmk=" + PMK_OFFERTA;
    document.location.href = url;
}


/*Cookie*/
function read_querystring() {
    var a_out = new Object();
    var s_loc = String(location.href);

    if (s_loc.indexOf('?') > 0) {
        var p;
        var s_query = s_loc.substr(s_loc.indexOf('?') + 1);
        var a_query = s_query ? s_query.split('&') : new Array();

        for (var i = 0; i < a_query.length; i++) {
            p = a_query[i].split('=');
            a_out[p[0]] = p[1].replace(/\+/g, ' ');
        }
    }
    return a_out;
}

function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function SetRawCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + value +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function setACEVCookie() {
    dominio = "alice.it";
    var scade = new Date();

    timestamp = ('0' + scade.getDate()).substr((('0' + scade.getDate()).length) - 2, 2) + '/' + ('0' + (scade.getMonth() + 1)).substr((('0' + (scade.getMonth() + 1)).length) - 2, 2) + '/' + scade.getFullYear();
    ora = ('0' + scade.getHours()).substr((('0' + scade.getHours()).length) - 2, 2) + ':' + ('0' + scade.getMinutes()).substr((('0' + scade.getMinutes()).length) - 2, 2) + ':' + ('0' + scade.getSeconds()).substr((('0' + scade.getSeconds()).length) - 2, 2);
    timestamp = timestamp + '-' + ora;

    scade.setTime(scade.getTime() + 30 * 24 * 60 * 60 * 1000);
    trovato = false;

    var oldValue;
    var query_vars = read_querystring();
    var value = query_vars['AC_EV'];

    //se esiste in QS il parametro AC_EV
    if (value != null && value != '') {
        //recupero il valore dell'azione e il timestamp
        nuovoValoreCookie = value + '#' + timestamp + ';';

        //se non esiste il cookie lo creo e lo inizializzo con il valore del parametro in QS e il TS
        oldValue = GetCookie("MXACEV");
        //alert(oldValue);
        if (oldValue == null || oldValue == '') {
            SetCookie("MXACEV", nuovoValoreCookie, scade, "/", document.location.hostname, null);
            SetCookie("MXACEV", nuovoValoreCookie, scade, "/", dominio, null);
        }
        else {
            //altrimenti verifico se ho già quel valore e in caso affermativo aggiorno il TimeStamp

            trovato = GetCookie("MXACEV").match(value + '#');
            if (trovato != null) {
                inizio = oldValue.indexOf(trovato);
                fine = oldValue.indexOf(';', inizio);
                oldValueButta = oldValue.slice(inizio, fine + 1);
                nuovoValoreCookie = oldValue.replace(oldValueButta, nuovoValoreCookie);
                SetCookie("MXACEV", nuovoValoreCookie, scade, "/", document.location.hostname, null);
                SetCookie("MXACEV", nuovoValoreCookie, scade, "/", dominio, null);
            }
            else
            //altrimenti aggiungo il nuovo valore
            {

                nuovoValoreCookie = oldValue + nuovoValoreCookie;
                SetCookie("MXACEV", nuovoValoreCookie, scade, "/", document.location.hostname, null);
                SetCookie("MXACEV", nuovoValoreCookie, scade, "/", dominio, null);
            }
        }
    }

}

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

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 setACEVCookie() {
//    
//	var scade = new Date();
//	scade.setTime(scade.getTime() + 30*24*60*60*1000);
//	var query_vars = read_querystring(); 
//	var value = query_vars['AC_EV']; 
//	
//	//se esiste in QS il parametro AC_EV
//	if(value != null && value!='')
//	{
//		//setto il cookie
//	    SetCookie("MXACEV", value, scade, "/", document.location.hostname, null);
//	}	
//}


function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(NameOfCookie, value, expiredays) {
    var ExpireDate = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
    document.cookie = NameOfCookie + "=" + escape(value) + ";path=/" + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function change(prog) {
    var containerTab = document.getElementById("tab_top");
    var lnk = containerTab.getElementsByTagName("li");
    for (var i = 0; i < lnk.length; i++) {
        lnk[i].className = '';
    }
    var containerCnt = document.getElementById("cnttab");
    var elm = containerCnt.getElementsByTagName("div");
    for (var i = 0; i < elm.length; i++) {
        elm[i].style.display = 'none';
    }
    document.getElementById('tab' + prog).className = 'evidenza';
    document.getElementById('cnt' + prog).style.display = 'block';
}
function ApriChiudiBox(DomNode) {
    var BoxPrincipale = DomNode.parentNode.parentNode;
    var BoxContainer = BoxPrincipale.parentNode;
    if (BoxPrincipale.className == "off") {
        //chiude tutti i box
        var ArrayDiv = BoxContainer.getElementsByTagName('div');
        for (i = 0; i < ArrayDiv.length; i++) {
            if (ArrayDiv[i].className == "on") {
                ArrayDiv[i].className = "off"
            }
        }
        //apre
        BoxPrincipale.className = "on";
    } else {
        // chiude 
        BoxPrincipale.className = "off";
    }
}

function isArray(obj) {
    try {
        obj.sort();
        return true;
    } catch (e) {
        return false;
    }
}
 
function CreateBookmarkLink() {
	title = "tv.telecomitalia.it"; 
	url = "http://tv.telecomitalia.it";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
} 




