﻿// JScript File

function setPage(idCont,canale)
{
    setSessionVariable("scope","");
    
    setPageCounter(idCont);
    
    getCombo(document.getElementById("cboCanali"),"GetCanali",null);
    
    getListaArticoli("tdUltimi","getArticoliUltimiPubblicati",canale,"");
    
    getListaArticoli("tdLetti","getArticoliPiuLetti",canale,"");
}

function setPageCounter(idCont)
{
    var xmlDoc = getXmlDoc();
    var objNode = xmlDoc.createElement("form");
    var objParams = xmlDoc.createElement("params");
    objNode.setAttribute("request","setPageCounter");
    objParams.appendChild(addNode("param","idCont","",idCont));
    objNode.appendChild(objParams);
    xmlDoc.appendChild(objNode);
    var xmlHttp = getXmlHttpObject();
    xmlHttp.open("POST", "/Service/dataInterfaceHub.aspx", false);
    xmlHttp.send(xmlDoc);
    return xmlHttp.responseText;
}

function getListaArticoli(objTD,Kind,Sezione)
{
    if (document.getElementById(objTD) != null)
    {
        document.getElementById(objTD).style.visibility = "hidden";
        var xmlDoc = getXmlDoc();
        var objNode = xmlDoc.createElement("form");
        var objParams = xmlDoc.createElement("params");
        objNode.setAttribute("request",Kind);
        objParams.appendChild(addNode("param","sezione","",Sezione));
        objNode.appendChild(objParams);
        xmlDoc.appendChild(objNode);
        var xmlHttp = getXmlHttpObject();
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState==4)
            {
                if (xmlHttp.responseText != "")
                {
                    xmlDoc = loadXmlString(xmlHttp.responseText);
                    tb = document.createElement("table");
                    tb.style.vAlign = "top";
                    ListaArticoli = xmlDoc.childNodes[0].childNodes;
                    for (i=0;i<ListaArticoli.length;i++)
                    {
                        tr = tb.insertRow(i);
                        td = tr.insertCell(0);
                        td.setAttribute("class","testo_bianco10");
                        td.innerHTML = "&nbsp;&nbsp;<a class='testo_bianco10' href='" + getNodeText(ListaArticoli[i].childNodes[2]) + "'>" + getNodeText(ListaArticoli[i].childNodes[0]) + "</a><br>"
                    }
                    //alert(tb.innerHTML);
                    document.getElementById(objTD).innerHTML = tb.innerHTML;
                    document.getElementById(objTD).style.visibility = "visible";
                }
            }
        }
        xmlHttp.open("POST", "/Service/dataInterfaceHub.aspx", true);
        xmlHttp.send(xmlDoc);
    }  
}

function doSearch()
{
    if (document.getElementById("txtFullSearch") != null)
    {
        if (document.getElementById("txtFullSearch").value != "")
        {
            setSessionVariable("txtsearch",document.getElementById("txtFullSearch").value);
            setSessionVariable("query","fulltext");
            document.location = "/Service/Ricerca.aspx";
        }
        else
        {
            alert("Inserisci una parola o frase da ricercare");
        }
    }
}

function doSearchMagazine()
{
    if (document.getElementById("txtSearch") != null)
    {
        if (document.getElementById("txtSearch").value != "") 
            setSessionVariable("query","SearchCanale");
        else
            setSessionVariable("query","SearchCanaleAll");
        obj = document.getElementById("cboCanali");
        setSessionVariable("scope",obj.options[obj.selectedIndex].value + "/");
        setSessionVariable("txtsearch",document.getElementById("txtSearch").value);
        document.location = "/Service/Ricerca.aspx";
    }
}

function doSearchPremi()
{
    if (document.getElementById("txtPunti") != null)
    {
        if (document.getElementById("txtPunti").value != "")
        {
            setSessionVariable("punti",document.getElementById("txtPunti").value);
            document.location = "/Service/CercaPremi.aspx";
        }
        else
        {
            alert("Inserisci un valore");
        }
    }
}

function setScopeMagazine(objCombo)
{
    if (objCombo != null) setSessionVariable("scope",objCombo.options[objCombo.selectedIndex].value);
}


