﻿// Script per il funzionamento del modulo news ticker

function scrollmarquee(){
        if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
            cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px";
        else
            cross_marquee.style.top=parseInt(marqueeheight)+8+"px";
    }

function initializemarquee(){
    cross_marquee=document.getElementById("vmarquee");
    cross_marquee.style.top=0;
    marqueeheight=document.getElementById("marqueecontainer").offsetHeight;
    actualheight=cross_marquee.offsetHeight;
    if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
        cross_marquee.style.height=marqueeheight+"px";
        cross_marquee.style.overflow="scroll";
        return;
    }
    setTimeout('lefttime=setInterval("scrollmarquee()",60)', delayb4scroll);
}

function chiudiLayer(){
	var NewsHidden = document.getElementById("NewsHidden");
	NewsHidden.style.display = 'none';
}	
function apriLayer(Id){
 	var NewsHidden = document.getElementById("NewsHidden");
	NewsHidden.style.display = 'block';
	GetNewsList(Id);
}

function GetNewsList(Id){
    //Settaggio Richiesta Server
    var xmlHttp = GetXMLHttpRequest();

    xmlHttp.onreadystatechange = function (){
        if(xmlHttp.readyState == 4){
            if(xmlHttp.status == 200){
                var risposta = xmlHttp.responseText;
                if(risposta != ""){
                    NEWSBOX.innerHTML = risposta;
                }
                return
            }
            else{
                alert('Errore nel salvataggio dei dati.');
                return
            }
        }
    }

    xmlHttp.open("GET", "Module/OpenNews.aspx?I0=" + Id, true);
    xmlHttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(null);
}

function OpenNews(Id){
    //Settaggio Richiesta Server
    var xmlHttp = GetXMLHttpRequest();

    xmlHttp.onreadystatechange = function (){
        if(xmlHttp.readyState == 4){
            if(xmlHttp.status == 200){
                var risposta = xmlHttp.responseText;
                if(risposta != ""){
                    ReplaceBody.innerHTML = risposta;
                }
                return
            }
            else{
                alert('Errore nel salvataggio dei dati.');
                return
            }
        }
    }
    
    var parametri = "Btn=Open&Id=" + Id;
    
    xmlHttp.open("POST", "Module/OpenNewsDetail.aspx", true);
    xmlHttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    xmlHttp.send(parametri);
}

//Utilities AJAX Request
function GetXMLHttpRequest(){
        var XHR = null,
        browserUtente = navigator.userAgent.toUpperCase();

        // browser standard con supporto nativo
        // non importa il tipo di browser
        if(typeof(XMLHttpRequest) == "function" || typeof(XMLHttpRequest) == "object")
            XHR = new XMLHttpRequest();

        // browser Internet Explorer
        // è necessario filtrare la versione 4
        else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0){
        // la versione 6 di IE ha un nome differente
        // per il tipo di oggetto ActiveX
            if(browserUtente.indexOf("MSIE 5") < 0)
                XHR = new ActiveXObject("Msxml2.XMLHTTP");
            // le versioni 5 e 5.5 invece sfruttano lo stesso nome
            else
                XHR = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        return XHR;
    }
