// JavaScript Document
var XMLHTTP;
var XMLHTTP2;
var XMLHTTP3;
var XMLHTTP4;
var XMLHTTP5;

function utenti(Stringa)
{
	
    if (Stringa.length > 2)
    {
		document.getElementById("div_utenti").innerHTML = "<p align=\"center\"valign=\"center\"><img src=\"http://www.mykugi.com/web_im/index.gif\"> Loading...</p>";
        var url = "http://www.mykugi.com/v2/ajax.php?t=u&nome=" + Stringa.toUpperCase();
        XMLHTTP = RicavaBrowser(CambioStato);
        XMLHTTP.open("GET", url, true);
        XMLHTTP.send(null);
    }
    else
    {
        document.getElementById("div_utenti").innerHTML = "";
    } 
}

function CambioStato()
{
    if (XMLHTTP.readyState == 4)
    {
        var R = document.getElementById("div_utenti");
        R.innerHTML = XMLHTTP.responseText;
    }
}

function contenuti(StringaR)
{
	
    if (StringaR.length > 2)
    {
		document.getElementById("risultati").innerHTML = "<p align=\"center\" valign=\"center\"><img src=\"http://www.mykugi.com/web_im/index.gif\"> Loading...</p>";
        var url = "http://www.mykugi.com/v2/ajax.php?t=c&nome=" + StringaR.toUpperCase();
        XMLHTTP2 = RicavaBrowser(CambioStato2);
        XMLHTTP2.open("GET", url, true);
        XMLHTTP2.send(null);
    }
    else
    {
        document.getElementById("risultati").innerHTML = "";
    } 
}
function CambioStato2()
{
    if (XMLHTTP2.readyState == 4)
    {
        var R2 = document.getElementById("risultati");
        R2.innerHTML = XMLHTTP2.responseText;
    }
}


function vicini(StringaLat,StringaLon)
{
	
    if (StringaLat > "")
    {
		document.getElementById("div_vicini").innerHTML = "<p align=\"center\" valign=\"center\"><img src=\"http://www.mykugi.com/web_im/index.gif\"> Loading...</p>";
        var url = "http://www.mykugi.com/v2/ajax.php?t=v&lat=" + StringaLat + "&lon=" + StringaLon;
        XMLHTTP3 = RicavaBrowser(CambioStato3);
        XMLHTTP3.open("GET", url, true);
        XMLHTTP3.send(null);
    }
    else
    {
        document.getElementById("div_vicini").innerHTML = "";
    } 
}
function CambioStato3()
{
    if (XMLHTTP3.readyState == 4)
    {
        var R3 = document.getElementById("div_vicini");
        R3.innerHTML = XMLHTTP3.responseText;
    }
}

function top()
{
		document.getElementById("risultati").innerHTML = "<p align=\"center\" valign=\"center\"><img src=\"http://www.mykugi.com/web_im/index.gif\"> Loading...</p>";
        var url = "http://www.mykugi.com/v2/ajax.php?t=t";
        XMLHTTP4 = RicavaBrowser(CambioStato4);
        XMLHTTP4.open("GET", url, true);
        XMLHTTP4.send(null);
}
function CambioStato4()
{
    if (XMLHTTP4.readyState == 4)
    {
        var R4 = document.getElementById("risultati");
        R4.innerHTML = XMLHTTP4.responseText;
    }
}

function ultimi()
{
		document.getElementById("risultati").innerHTML = "<p align=\"center\" valign=\"center\"><img src=\"http://www.mykugi.com/web_im/index.gif\"> Loading...</p>";
        var url = "http://www.mykugi.com/v2/ajax.php?t=ul";
        XMLHTTP5 = RicavaBrowser(CambioStato5);
        XMLHTTP5.open("GET", url, true);
        XMLHTTP5.send(null);
}
function CambioStato5()
{
    if (XMLHTTP5.readyState == 4)
    {
        var R5 = document.getElementById("risultati");
        R5.innerHTML = XMLHTTP5.responseText;
    }
}


function RicavaBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Microsoft.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrą eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else if (navigator.userAgent.indexOf("Opera") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
	else if (!OggettoXMLHTTP && typeof XMLHttpRequest != 'undefined')
	{
		OggettoXMLHTTP = new XMLHttpRequest();        //For Mozilla, Opera Browsers
		OggettoXMLHTTP.onload = QualeBrowser;
		OggettoXMLHTTP.onerror = QualeBrowser;
		return OggettoXMLHTTP;
	}
    else
    {
        alert("Qualcosa potrebbe non funzionare con il tuo browser!");
    }
}

function thisMovie(movieName) {
 if (navigator.appName.indexOf("Microsoft") != -1) {
	 return window[movieName];
 } else {
	 return document[movieName+"F"];
 }
}
function thisPage(){
 if (navigator.appName.indexOf("Microsoft") != -1) {
	 return window;
 } else {
	 return document;
 }		
}
function gotojs(lat,lon,azi,alt) {
	var objflash = thisMovie("moviemkg");
	//var nome = objflash.id;
	objflash.go_to(lat,lon,azi,0);
}
function gettojs() {
	var objflash = thisMovie("moviemkg");
	//var nome = objflash.id;
	//if (nome == undefined) nome = objflash.name;
	return objflash.get_to();
}
//index_2.php
function thisMovie2(movieName) {
 if (navigator.appName.indexOf("Microsoft") != -1) {
	 return window[movieName];
 } else {
	 return document[movieName]; //+"F"
 }
}
function gotojs2(lat,lon,azi,alt) {
	var objflash2 = thisMovie2("visore");
	objflash2.go_to(lat,lon,azi,0);
}
function gettojs2() {
	var objflash2 = thisMovie2("visore");
	return objflash2.get_to();
}
//fine index_2.php




var dimlimite = 98000/screen.availWidth;
var dimlimite2 = 400;
var tipo_visore = "kgc";


function opn(cosa){	
	var divcontainer = document.getElementById("container");
	var divflash = document.getElementById("vnav_dinamico");
	var divmenuvisore = document.getElementById("menu_visore");
	//var flash = thisMovie("moviemkg");
	if (cosa == 1){
		popup = window.open("http://www.mykugi.it/ticket/eticket/","assistenza","width=800,height=750,scrollable=yes");
	}
	if (cosa == 2){
		dimlimite = 98000/screen.availWidth;
		dimlimite2 = 400;
		var zetaind = divflash.style.zIndex;

		if (zetaind != "99"){
			
		    var w = window.screen.width;
		    var h = window.screen.height;
			
			//alert("Larghezza:"+w+"\r\nAltezza:"+h);
			altezza = screen.availHeight*70/100 - 100;
			//altezza = document.height - 140;
			//alert(altezza);
			//divflash.style.padding="11px";
			divcontainer.style.height="1520px";
			divflash.style.zIndex="99";
			//divmenuvisore.style.paddingLeft= "0px";
			//divmenuvisore.style.paddingRight= "0px";

			up = setInterval("piu(90,"+altezza+")",20);
			
			//flash.width = "100%";
			//flash.height = "100%";

		} else {

			//divflash.style.padding= "0px";
			divflash.style.zIndex="4";
			//divmenuvisore.style.paddingLeft= "0px";
			//divmenuvisore.style.paddingRight= "0px";
			
			divcontainer.style.width="980px";
			divcontainer.style.height="1300px";
			divflash.style.height = "400px";		
			
			//flash.width = "980px";
			//flash.height = "400px";	

		}
	}
}

function piu(limite,limite2){
	var divcontainer = document.getElementById("container");
	var divflash = document.getElementById("vnav_dinamico");
	//var divmenuvisore = document.getElementById("menu_visore");
	//var flash = thisMovie("moviemkg");

	
	
	if (dimlimite < limite) {
		dimlimite += 1;
		divcontainer.style.width = dimlimite + "%";
	}
	if (dimlimite2 < limite2) {
		dimlimite2 += 8;
		divflash.style.height = dimlimite2 + "px";
	}
	if (dimlimite >= limite && dimlimite2 >= limite2) { 
		clearInterval(up);
		//alert("fino a:"+limite2+". Arrivato a:"+dimlimite2);
	}
}

function apri_strumenti(){
	//var divcontainer = document.getElementById("container");
	var divflash = document.getElementById("vnav_dinamico");
	//var divmenuvisore = document.getElementById("menu_visore");

	if (tipo_visore == "kgc") {

		tipo_visore = "mkg";
	} else {

		tipo_visore = "kgc";
	}
}

function apriaiuti(){
	var divaiuti = thisMovie("aiuti");
	divaiuti.setAttribute("visibility","visible");
}
function up_testo(stringa){
	var div_testo = document.getElementById("aiuti");
	div_testo.innerHTML = stringa.toString();
	div_testo.setAttribute("visibility","visible");
}

var sopra = false;
function soprasotto(valore){
	sopra = valore;
}
/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) {
        if (delta < 0){
			if (sopra == false) {
				//alert("su");
				window.scrollBy (0,50);
			}
		} else {
			if (sopra == false){
				//alert("giu");
				window.scrollBy (0,-50);
			}
		}
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener) {
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
		/** IE/Opera. */
		window.onmousewheel = document.onmousewheel = wheel;
}
