function Init(){};

function ReloadResolution()
{
	var availWidth = window.screen.availWidth;
	if (IsEmpty(availWidth))
		availWidth = window.screen.width;
	if (IsEmpty(availWidth))
		availWidth = 800;

	var screenWidth = CookieGet("ScreenWidth");
	if (IsEmpty(screenWidth))
	{
		// Cookie not supported?
		return false;
	}
	CookieSet("ScreenWidth", availWidth)
	if ( availWidth != screenWidth )
		return true;
	else
		return false;
}

var PreloadImage = [];
function DoPreloadImages()
{
	var d=document;
	if(d.images)
	{
		if(!d.MM_p)
			d.MM_p=new Array();
	    var i, j=d.MM_p.length, a=PreloadImage;
	    for(i=0; i<a.length; i++)
	    {
  			d.MM_p[j]=new Image;
   			d.MM_p[j++].src=a[i];
    	}
    }
}

function SwapOut(img){ try { img.src = img.src.replace(/-over/, "-out"); } catch(e){} }
function SwapOver(img){ try { img.src = img.src.replace(/-out/, "-over"); } catch(e){} }

window.onload = function ()
{
	if (ReloadResolution())
		return document.location.reload();
	DoPreloadImages();
	Init();
}

// Apertura della pagina di ViaMichelin
function OpenDoveSiamo(language, idPoint)
{
	if (IsEmpty(language)) language = Lingua;
	if (IsEmpty(idPoint)) idPoint = "1";

	switch(language)
	{
		case "IT":
			language = "ita";
			break;
		case "DE":
			language = "deu";
			break;
		case "GB":
		default:
			language = "gbr";
			break;
	}

	// Url di test.
	//var url = "http://test.bs.viamichelin.com/b2b2c/" + language + "/dyn/controller/dlPoiAccess?from=1234&id=" + idPoint + "&clientID=ITALCOM&productId=50313";

	// Url definitivo
	var url = "http://www.viamichelin.com/b2b2c/" + language + "/dyn/controller/dlPoiAccess?from=1234&id=" + idPoint + "&productId=50313";

	window.open(url);
}

function OpenArticoloApiu(idObject)
{
    if (idObject == null)
        return;

    var lingua = "<%= Lingua %>" != "IT" && "<%= Lingua %>" != "GB" ? "GB" : "<%= Lingua %>";
    window.open("ArticoloApiu.asp?Lingua=" + lingua + "&IdObject=" + idObject);
}

function OpenArticoloAlessia(idObject)
{
    if (idObject == null)
        return;

    window.open("EventiPage.asp?IdObject=" + idObject);
}

function OpenOperatore(idOperatore, idClass)
{
	window.open("Operatore.asp?IdOperatore=" + idOperatore +"&IdClass=" + idClass, "Operatore", "resizable=yes,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function OpenPercorso(idObject)
{
	var features = "width=700,height=550,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
	window.open("PercorsiPage.asp?IdObject="+ idObject, "PercorsoPage_"+idObject, features);
}

function OpenNews(idObject)
{
	var features = "width=700,height=550,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
	window.open("NewsPage.asp?IdObject="+ idObject, "NewsPage_"+idObject, features);
}

function OpenPacchetto(idObject)
{
	var features = "width=700,height=550,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
	window.open("PacchettoPage.asp?IdObject="+ idObject, "PacchettoPage_"+idObject, features);
}

function OpenFlashPlayer(swf, width, height)
{
	window.open("FlashPlayer.asp?swf=" + swf +"&width=" + width + "&height=" + height, "FlashPlayer", "width=" + width + ",height=" + height + ",resizable=no,status=no,toolbar=no,menubar=no,location=no");
}

// Indice della prima posizione in cui viene trovato item. Se non trovato restituisce -1.
Array.prototype.indexOf = function(item)
{
    for (var i = 0; i < this.length; i++)
    {
        if (this[i] == item)
            return i;
    }
    
    return -1;
}

// Rimuove dall'array tutte le occorrenze di item.
Array.prototype.removeAll = function(item)
{
    var i;
    while ((i = this.indexOf(item)) >= 0)
        this.splice(i, 1);
}

function XMLGetAttributeList(document, elementName, attributeName)
{
    if (document == null || elementName == null || attributeName == null)
        return [];
    
    var result = [];
    var list = document.selectNodes("//" + elementName);
    for (var i = 0; i < list.length; i++)
        result[result.length] = list.item(i).attributes.getNamedItem(attributeName).nodeValue;
    
    return result;
}

function DoTerritorio()
{
    document.location = "Territorio.asp?map=<%= AspIdZona %>";
}

function Init()
{
	window.focus();
}

function DoChiudi()
{
	try
	{
		window.close();
		window.opener.focus();
	}
	catch(e)
	{}
}