﻿// JScript File

function espandiContrai(nomeTagDisplay, nomeTagHide) 
{ 
    odiv = document.getElementById(nomeTagDisplay); 
    odiv.style.display='block'; 
    odiv.style.visibility='visible'; 
    
    odiv = document.getElementById(nomeTagHide); 
    odiv.style.display='none'; 
    odiv.style.visibility='hidden'; 
}

function espandiContrai(nomeTagDisplay, nomeTagHide, nomeLinkDisplay, nomeLinkHide) 
{ 
    odiv = document.getElementById(nomeTagDisplay); 
    odiv.style.display='block'; 
    odiv.style.visibility='visible'; 
    
    if(nomeLinkDisplay!="")
    {
        odiv = document.getElementById(nomeLinkDisplay); 
        //odiv.style.display='block'; 
        odiv.style.visibility='visible'; 
    }
    
    odiv = document.getElementById(nomeTagHide); 
    odiv.style.display='none'; 
    odiv.style.visibility='hidden'; 
    
    if(nomeLinkHide!="")
    {
        odiv = document.getElementById(nomeLinkHide); 
        //odiv.style.display='none'; 
        odiv.style.visibility='hidden'; 
    }
}


function setUniquevalue(checkBox, nameContainer)
{

    var listItem = (document.getElementById(nameContainer)).getElementsByTagName('input');

    if(checkBox.checked == true)
    {
    
        var currentValue = checkBox.value;
                    
        
        for(i=0;i<listItem.length;i++)
        {
            listItem[i].checked = false;
        }	    
        
        for(i=0;i<listItem.length;i++)
        {
            if(listItem[i].value == currentValue)
                
               listItem[i].checked = true;
               
        }
    }
    
    else
    
    {
    
         for(i=0;i<listItem.length;i++)
        {
            listItem[i].checked = false;
        }
    
    }	    
    
}


            
            
function verificaCheckbox(arrayCheck)
{
    
    var listItem = arrayCheck.getElementsByTagName('input');
//    
   for(i=0;i<listItem.length;i++)
    {
        if(listItem[i].checked) return true;
    }	    
    return false;
}

function pulisciCheckbox(arrayCheck) {

    var listItem = arrayCheck.getElementsByTagName('input');
    //    
    for (i = 0; i < listItem.length; i++) {
        listItem[i].checked= false;
    }
}



function memorizzaCheckedFonti()
{
    var listItem =  (document.getElementById('tableFonti')).getElementsByTagName('input');
      
    for(i=0;i<listItem.length;i++)
    {
        
        if(listItem[i].checked)
        {
            document.getElementById('fontiScelte').value  += listItem[i].value + ',';
        }
    }
    return true;
}

function memorizzaThumbDefault()
{
    document.getElementById('thumbScelto').value = '';
    
    var listItem =  (document.getElementById('tableThumb')).getElementsByTagName('input');
    
    for(i=0;i<listItem.length;i++)
    {
        
        if(listItem[i].checked)
        {
            document.getElementById('thumbScelto').value = listItem[i].value;
        }
    }
    return true;
}

function pulisciCampiHidden()
{
    document.getElementById('argomentiScelti').value  = '';
    document.getElementById('canaliScelti').value     = '';
    document.getElementById('fontiScelte').value      = '';

}

function memorizzaCheckedItems()
{
    
    var listItem =  (document.getElementById('tableArgomenti')).getElementsByTagName('input');
    
    for(i=0;i<listItem.length;i++)
    {
        
        if(listItem[i].checked)
        {
            document.getElementById('argomentiScelti').value  += listItem[i].value + ',';
        }
    }
    
    var secondlistItem =  (document.getElementById('tableCanali')).getElementsByTagName('input');
    
    for(i=0;i<secondlistItem.length;i++)
    {
        
        if(secondlistItem[i].id.indexOf("chk_Channel")!=-1)
        
        {    
        
                if(secondlistItem[i].checked)
                {
                    document.getElementById('canaliScelti').value  += secondlistItem [i].value  + ',';
                }
        
        }
        
        
        if(secondlistItem[i].id.indexOf("chk_inEvidenza")!=-1)
         
 
        {
          
            if(secondlistItem[i].checked)
            {
            document.getElementById('inEvidenza').value  += secondlistItem [i].value  + ',';
            }  
                    
        }
               
         
    }
       
    return true;
}

/* region DIV */

function hideDiv()
{ 
    tag = document.getElementsByTagName("div"); 
    for(x=0;x<tag.length; x++)
    { 
        _id= tag[x].getAttribute('id');
        if(_id!=null && _id.indexOf("choose_") != -1)
        { 
            tag[x].style.display = "none"; 
        } 
    } 
} 

function view(id)
{ 
    hideDiv(); 
    ge = document.getElementById('choose_' + id.value); 
    ge.style.display = "block"; 
} 

function setRigaFilmato(radioButton)
{   

    switch (radioButton.value)
    {
    
        case 'I':
              document.getElementById('internoRiga').style.visibility = "visible";
              document.getElementById('esternoRiga').style.visibility = "hidden";
              document.getElementById('internoRiga').style.display = "block";
              document.getElementById('esternoRiga').style.display = "none";
            break;
            
        case 'E':
            document.getElementById('internoRiga').style.visibility = "hidden";
            document.getElementById('esternoRiga').style.visibility = "visible";
            document.getElementById('internoRiga').style.display = "none";
            document.getElementById('esternoRiga').style.display = "block";
            
            div = document.getElementById('divUploadThumbEsterno'); 
            div.style.display = "block"; 
                        
            break;
        
        default:
            break;
            
    }   
    
}


function startScrollNewsAll(lDiv)
{
    startScrollNews(lDiv);
    startScrollNewsBottom(lDiv)
}

   /////////    ///////////////////////////////////////////////////////
  //// TICKER ORIZZONTALE SCORREVOLE                          ////
 ////    by Grassi Claudio                                   ////
////////////////////////////////////////////////////////////////

var _timerID;
var lunghezzaItemContainer;

//impostazioni dello scorrimento
var lunghezzaDiv = "750px"; //lunghezza del contenitore
var speed = 2; //numero di pixel di decremento
var freq = 25; //millisecondi che intercorrono tra le chiamate alla muoviDiv()
var waitStart = 300; //millisecondi di attesa della prima partenza dello scroll;
var waitRestart = 120; //millisecondi di attesa della ripartenza dello scroll;


function startScrollNews(_lunghezzaDiv) {

    if (_lunghezzaDiv != -1) lunghezzaDiv = _lunghezzaDiv;
    odiv = document.getElementById("itemContainer"); 
    if (odiv == null) return;
    odiv.style.marginLeft = lunghezzaDiv;
    olabel = document.getElementById("labelItemCont");
    if (odiv.offsetParent.offsetWidth == odiv.offsetWidth)
        lunghezzaItemContainer = olabel.offsetWidth;
    else
        lunghezzaItemContainer = odiv.offsetWidth;
    _timerID = window.setTimeout('muoviDiv()', waitStart);
}

function muoviDiv() {
    odiv = document.getElementById("itemContainer");
    var margine = odiv.style.marginLeft;
    /*var numero = parseInt(margine.replace("px",""),10);
    numero -= speed;
    if (numero>=0)
        odiv.style.marginLeft = "" + numero + "px";
    
    if (numero < -(parseInt(lunghezzaItemContainer, 10)*2 + 30) ) {
        odiv.style.marginLeft = lunghezzaDiv;
        _timerID = window.setTimeout('muoviDiv()', waitRestart);
    }
    else 
    {
        _timerID = window.setTimeout('muoviDiv()', freq);
    }*/
    var numero = margine.substring(0, margine.indexOf("px"));
    numero -= speed;
    odiv.style.marginLeft = "" + numero + "px";

    if (numero < -(parseInt(lunghezzaItemContainer, 10) * 2 + 30)) {
        odiv.style.marginLeft = lunghezzaDiv;
        _timerID = window.setTimeout('muoviDiv()', waitRestart);
    }
    else
        _timerID = window.setTimeout('muoviDiv()', freq);
} 

function stopScroll()
{
    window.clearTimeout(_timerID);
}

function restartScroll()
{
    _timerID = window.setTimeout('muoviDiv()', freq);
}

   ////////////////////////////////////////////////////////////////
  //// TICKER ORIZZONTALE SCORREVOLE                          ////
 ////    by Grassi Claudio      -FINE-                       ////
////////////////////////////////////////////////////////////////

var _timerIDBottom;
var lunghezzaItemContainerBottom;

//impostazioni dello scorrimento
var lunghezzaDivBottom = "750px"; //lunghezza del contenitore
var speedBottom = 2; //numero di pixel di decremento
var freqBottom = 25; //millisecondi che intercorrono tra le chiamate alla muoviDiv()
var waitStartBottom = 500; //millisecondi di attesa della prima partenza dello scroll;
var waitRestartBottom = 100; //millisecondi di attesa della ripartenza dello scroll;

function startScrollNewsBottom(_lunghezzaDivBottom) {
    if (_lunghezzaDivBottom != -1) lunghezzaDivBottom = _lunghezzaDivBottom;
    odiv = document.getElementById("itemContainerBottom");
    if (odiv == null) return;
    odiv.style.marginLeft = lunghezzaDivBottom;
    olabel = document.getElementById("labelItemContBottom");
    if (odiv.offsetParent.offsetWidth == odiv.offsetWidth)
        lunghezzaItemContainerBottom = olabel.offsetWidth;
    else
        lunghezzaItemContainerBottom = odiv.offsetWidth;

    _timerIDBottom = window.setTimeout('muoviDivBottom()', waitStartBottom);
}

function muoviDivBottom() {
    odiv = document.getElementById("itemContainerBottom");
    var margine = odiv.style.marginLeft;
    var numero = margine.substring(0, margine.indexOf("px"));
    numero -= speedBottom;
    odiv.style.marginLeft = "" + numero + "px";

    if (numero < -(parseInt(lunghezzaItemContainerBottom, 10) * 2 + 30) ) {
        odiv.style.marginLeft = lunghezzaDivBottom;
        _timerIDBottom = window.setTimeout('muoviDivBottom()', waitRestartBottom);
    }
    else
        _timerIDBottom = window.setTimeout('muoviDivBottom()', freqBottom);
}

function stopScrollBottom() {
    window.clearTimeout(_timerIDBottom);
}

function restartScrollBottom() {
    _timerIDBottom = window.setTimeout('muoviDivBottom()', freqBottom);
}
