﻿//system send //

function printNewsInit(idArticolo)
{
    location.href = "./articoli/ArticoloNews.aspx?idArticolo=" + idArticolo;   
}

function dettagliOnPage(idArticolo){
    window.scrollTo(0,0);
    vediArticoloNews(idArticolo);
}
function vediArticoloNews(valoreVariabile){
    _Default.getArticoloNews(valoreVariabile, sendDescrizioneArticoloNews);
}

function sendDescrizioneArticoloNews(oResponse) {
    if (!oResponse.error) {
        document.getElementById('descrizione').innerHTML = oResponse.value;
    } else {
        alert(oResponse.value);
    }
}

function nascondiDettaglioSearch(inizialize) {
		        document.getElementById('idConfirmConnection').style.display = 'none';
	if (inizialize)
    {
        document.getElementById('idDivDettaglioSearch').style.position = 'absolute'
        //document.getElementById('idDivDettaglioSearch').style.backgroundColor = '#f6dbdb';
        document.getElementById('idDivDettaglioSearch').style.backgroundColor = '#f9f9d2';
		document.getElementById('idDivDettaglioSearch').style.borderStyle= 'ridge'; 
	    document.getElementById('idDivDettaglioSearch').style.borderColor= 'Red';
	}
	if (!inizialize) {
	    nascondiDivSearch('225', '1', '340', '1')
	} else {
	    document.getElementById('idDivDettaglioSearch').style.display = 'none';
	}
    document.getElementById('reldiv2').style.display = '';
}

//esegue la ricerca di un esercizio
//dal menu' avanzate
//mi serve per impostare i contatori
function trovaDettaglioEsercizioInit(){
    try {
	    openLoader();
	    closeNewsNoAnimazione();
	} catch (e){
	}
	//inizio da pagina 1
	document.getElementById('idLimitValue').value = "0";
	document.getElementById('idSearchHtmlResult').innerHTML = '';
	//questa impostazione mi servono per il navigatore della ricerca semplice
    //altrimenti andava in conflitto con la ricerca dettagliata
	document.getElementById('idInputLocalitaSearchTesto').value = "";
	var localita = '';
	var nomeAzienda = '';
	var idTipoAttivita = '';
	var idProvincia = '';
	if (document.getElementById('idInputLocalitaSearch')!=null)
	    localita = document.getElementById('idInputLocalitaSearch').value;
	if (document.getElementById('idInputAziendaSearch')!=null)
	    nomeAzienda = document.getElementById('idInputAziendaSearch').value;
	if (document.getElementById('idTipoAttivitaDettSearch')!=null)
	    idTipoAttivita = document.getElementById('idTipoAttivitaDettSearch').value;
	if (document.getElementById('idProvinciaSearch')!=null)
	    idProvincia = document.getElementById('idProvinciaSearch').value;	    
	var idLimitValue = '0';
	//si trova su SearchAvanzato.js
	if (idTipoAttivita == '' && idProvincia == '' && nomeAzienda == '' && localita=='')
	{
	    alert("Attenzione: per effettuare una ricerca è necessario inserire almeno un campo");
	    closeLoader();
	}
	else
	    eseguiSearchDettaglioInit(idTipoAttivita, idProvincia, nomeAzienda, localita, idLimitValue.toString());
}

//esegue la ricerca di un esercizio
//dal menu' avanzate
function trovaDettaglioEsercizio(newLimit){
    try {
	    openLoader();
	    closeNewsNoAnimazione();
	} catch (e){
	}	
	document.getElementById('idSearchHtmlResult').innerHTML = '';
	var localita = '';
	var nomeAzienda = '';
	var idTipoAttivita = '';
	var idProvincia = '';
	//else if mi serve per il navigatore della ricerca semplice
    //altrimenti andava in conflitto con la ricerca dettagliata
	if (document.getElementById('idInputLocalitaSearch')!=null && document.getElementById('idInputLocalitaSearch').value != '')
	    localita = document.getElementById('idInputLocalitaSearch').value;
	else if (document.getElementById('idInputLocalitaSearchTesto')!= '')
	    localita = document.getElementById('idInputLocalitaSearchTesto').value;
	if (document.getElementById('idInputAziendaSearch')!=null)
	    nomeAzienda = document.getElementById('idInputAziendaSearch').value;
	if (document.getElementById('idInputLocalitaSearch')!=null)
	    idTipoAttivita = document.getElementById('idTipoAttivitaDettSearch').value;
	if (document.getElementById('idProvinciaSearch')!=null)
	    idProvincia = document.getElementById('idProvinciaSearch').value;
	    
	var idLimitValue = document.getElementById('idLimitValue').value;
	if (newLimit){
		idLimitValue = parseInt(idLimitValue) + parseInt(newLimit);
		document.getElementById('idLimitValue').value = idLimitValue.toString();
	}
	if (idTipoAttivita == '' && idProvincia == '' && nomeAzienda == '' && localita=='')
	{
	    alert("Attenzione: per effettuare una ricerca è necessario inserire almeno un campo");
	    closeLoader();
	}
	else
	    eseguiSearchDettaglio(idTipoAttivita, idProvincia, nomeAzienda, localita, idLimitValue.toString());
}

function sendDescrizione(oResponse) {
    if (!oResponse.error) {
        displayDescrizione(oResponse.value);
    } else {
        alert("An error occurred: " + oResponse.value);
    }
}

function sendTitolo(oResponse) {
    if (!oResponse.error) {
        displayTitle(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkHotels(oResponse) {
    if (!oResponse.error) {
        displayLinkHotels(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkHotelsRegistra(oResponse) {
    if (!oResponse.error) {
        displayLinkHotelsRegistra(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkA(oResponse) {
    if (!oResponse.error) {
        displayLinkA(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkB(oResponse) {
    if (!oResponse.error) {
        displayLinkB(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkC(oResponse) {
    if (!oResponse.error) {
        displayLinkC(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

function sendLinkD(oResponse) {
    if (!oResponse.error) {
        displayLinkD(oResponse.value);
    } else {
        alert("An error occurred.");
    }
}

//end system send //




//inzio funzioni di visualizzazione//
function displayDescrizione(sText) {
    var dispayID = document.getElementById("descrizione");
    dispayID.innerHTML = sText;
}

function displayTitle(sText) {
    var dispayID = document.getElementById("titolo");
    dispayID.innerHTML = sText;
}

function displayLinkA(sText) {
    var dispayID = document.getElementById("linkA");
    document.getElementById("linkA").style.display = 'inline';
    dispayID.innerText = sText;
}

function displayLinkB(sText) {
    var dispayID = document.getElementById("linkB");
    dispayID.innerHTML = sText;
}

function displayLinkC(sText) {
    var dispayID = document.getElementById("linkC");
    dispayID.innerHTML = sText;
}

function displayLinkD(sText) {
    var dispayID = document.getElementById("linkD");
    dispayID.innerHTML = sText;
}

function displayLinkHotels(sText) {
    var dispayID = document.getElementById("linkHotels");
    dispayID.innerHTML = sText;
}

function displayLinkHotelsRegistra(sText) {
    var dispayID = document.getElementById("linkInserisci");
    dispayID.innerHTML = sText;
    document.getElementById("linkInserisci").style.display = "none";
}

//fine funzioni di visualizzazione//

//dati personali//
function requestCustomerInfo() {
    Wrox.AjaxFunction.GetCustomerInfo(sendDescrizione);
}
//fine dati personali//


function getAreeProtette() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();    
    Wrox.AjaxFunction.getDescrizioneAreeProtette(sendDescrizione);
    Wrox.AjaxFunction.getTitoloAreeProtette(sendTitolo);
}
function getCentriTuristici() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();    
    Wrox.AjaxFunction.getDescrizioneCentriTuristici(sendDescrizione);
    Wrox.AjaxFunction.getTitoloCentriTuristici(sendTitolo);
}

function getItinerari() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneItinerari(sendDescrizione);
    Wrox.AjaxFunction.getTitoloItinerari(sendTitolo);
}

function getServiziHotels(){
    window.scrollTo(0,0);
    //nascondiAutenticazione();
    document.getElementById("linkHotels").style.display = 'inline';
    document.getElementById("linkInserisci").style.display = 'inline';
    Wrox.AjaxFunction.getDescrizioneServiziHotels(sendDescrizione);
    Wrox.AjaxFunction.getTitoloServiziHotels(sendTitolo);
    Wrox.AjaxFunction.getServiziLinkA(sendLinkHotels);
    Wrox.AjaxFunction.getServiziLinkRegistra(sendLinkHotelsRegistra);
}

function getUtenti() {
    window.scrollTo(0,0);
    nascondiLink();
    Wrox.AjaxFunction.getDescrizioneUtenti(sendDescrizione);
    Wrox.AjaxFunction.getTitoloUtenti(sendTitolo);
}

function sendResult(oResponse) {
    if (!oResponse.error) {
        //do nothing
    } else {
        alert("An error occurred: " + oResponse.value);
    }
}

function writeDatiNavigatori(ip, browser, lingua){
    Wrox.AjaxFunction.writeIp(ip, browser, lingua, sendResult);
}

function getAmbiente() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneAmbiente(sendDescrizione);
    Wrox.AjaxFunction.getTitoloAmbiente(sendTitolo);
}

function getNovita() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneNovita(sendDescrizione);
    Wrox.AjaxFunction.getTitoloNovita(sendTitolo);
}

function getSoggiorni() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneSoggiorni(sendDescrizione);
    Wrox.AjaxFunction.getTitoloSoggiorni(sendTitolo);
}

function getLocalita() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneLocalita(sendDescrizione);
    Wrox.AjaxFunction.getTitoloLocalita(sendTitolo);
}

function getManifestazioni() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneManifestazioni(sendDescrizione);
    Wrox.AjaxFunction.getTitoloManifestazioni(sendTitolo);
}

function getProdottiTipici() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneProdottiTipici(sendDescrizione);
    Wrox.AjaxFunction.getTitoloProdottiTipici(sendTitolo);
}

function getComeArrivare() {
    window.scrollTo(0,0);
    nascondiLink();
    //nascondiAutenticazione();
    Wrox.AjaxFunction.getDescrizioneComeArrivare(sendDescrizione);
    Wrox.AjaxFunction.getTitoloComeArrivare(sendTitolo);
}


function sendSearchIntestazione(oResponse) {
    if (!oResponse.error) {
        document.getElementById('idSearchIntestazioneTable').innerHTML = oResponse.value;
        try 
        {
            closeLoader();
        } catch (e){
        }
    } else {
        alert("An error occurred: " + oResponse.value);
    }
}

function sendSearch(oResponse) {
    if (!oResponse.error) {
        document.getElementById('searchDivChiudi').style.display = '';
        document.getElementById('searchDivSx').style.display = '';
        document.getElementById('searchDivPippo').style.display = '';
        document.getElementById('searchDivIntestazione').style.display = '';
        document.getElementById('searchDivPulsantiera').style.display = '';
        var paginaCorrente = parseInt(parseInt(document.getElementById('idLimitValue').value) / 10) + 1;
        var pagineTotali = parseInt(parseInt(document.getElementById('idTotPage').value) / 10) + 1;
        var finePagine = (pagineTotali - paginaCorrente) * 10;
        var paginaIniziale = -(paginaCorrente-1)*10;
        if (pagineTotali > 1)
        {
            if (document.getElementById('idLimitValue').value == '0')
                document.getElementById('idHtmlButton').innerHTML = "<center><table><tr><td width=\"23\"></td><td width=\"23\"></td><td width=\"120\"><font class=\"InputBlackCenter\">Pagina " + paginaCorrente.toString() + " di " + pagineTotali.toString() + "</font></td><td width=\"23\"><input type=\"button\" class=\"Button\" onclick=\"trovaDettaglioEsercizio('10');\" value=\">\" /></td><td width=\"23\"><input type=\"button\" onclick=\"trovaDettaglioEsercizio('"+ finePagine +"');\" class=\"Button\" value=\">|\" /></td></tr></table></center>";
            else if (paginaCorrente == pagineTotali)
                document.getElementById('idHtmlButton').innerHTML = "<center><table><tr><td width=\"23\"><input type=\"button\" onclick=\"trovaDettaglioEsercizio('" + paginaIniziale +"');\" class=\"Button\" value=\"|<\" /></td><td width=\"23\"><input type=\"button\" onclick=\"trovaDettaglioEsercizio('-10');\" class=\"Button\" value=\"<\" /></td><td width=\"120\"><font class=\"InputBlackCenter\">Pagina " + paginaCorrente.toString() + " di " + pagineTotali.toString() + "</font></td><td width=\"23\"></td><td width=\"23\"></td></tr></table></center>";
            else
                document.getElementById('idHtmlButton').innerHTML = "<center><table><tr><td width=\"23\"><input type=\"button\"  onclick=\"trovaDettaglioEsercizio('" + paginaIniziale +"');\" class=\"Button\" value=\"|<\" /></td><td width=\"23\"><input type=\"button\" onclick=\"trovaDettaglioEsercizio('-10');\" class=\"Button\" value=\"<\" /></td><td width=\"120\"><font class=\"InputBlackCenter\">Pagina " + paginaCorrente.toString() + " di " + pagineTotali.toString() + "</font></td><td width=\"23\"><input type=\"button\" class=\"Button\" onclick=\"trovaDettaglioEsercizio('10');\" value=\">\" /></td><td width=\"23\"><input type=\"button\" onclick=\"trovaDettaglioEsercizio('"+ finePagine +"');\" class=\"Button\" value=\">|\" /></td></tr></table></center>";
        } else {
             document.getElementById('idHtmlButton').innerHTML = "<center><font class=\"InputBlackCenter\">Pagina " + paginaCorrente.toString() + " di " + pagineTotali.toString() + "</font></center>";
        }
        document.getElementById('idSearchHtmlResult').innerHTML = oResponse.value;
        try {
            closeLoader();
        } catch (e){
        }
    } else {
        alert("An error occurred: " + oResponse.value);
    }
}

function search(testo) {
    window.scrollTo(0,0);
    Wrox.AjaxFunction.searchIntestazione(sendSearchIntestazione);
    //sendPage si trova su SearchAvanzato
    Wrox.AjaxFunction.getNumPageSimpleSearch(testo, sendPage);
    //queste impostazioni mi servono per il navigatore della ricerca semplice
    //altrimenti andava in conflitto con la ricerca dettagliata
    if (document.getElementById('idInputLocalitaSearch'))
        document.getElementById('idInputLocalitaSearch').value = '';
    document.getElementById('idLimitValue').value = "0";
    document.getElementById('idInputLocalitaSearchTesto').value = testo;
    Wrox.AjaxFunction.search(testo, sendSearch);    
}

//non utilizzata: nasconde i campi di input di username e password
function nascondiAutenticazione(){
    if (document.getElementById("textUsername"))
    {
        document.getElementById("textUsername").style.display='none';
    }
    if (document.getElementById("textPassword"))
    {
        document.getElementById("textPassword").style.display='none';
    }
    if (document.getElementById("username"))
    {
        document.getElementById("username").style.display='none';
    }
    if (document.getElementById("password"))
    {
        document.getElementById("password").style.display='none';
    }
    if (document.getElementById("login"))
    {
        document.getElementById("login").style.display='none';
    }
}




function nascondiLink(){
    if (document.getElementById("linkA")){
        document.getElementById("linkA").style.display='none';
    }
    if (document.getElementById("linkB")){
        document.getElementById("linkB").style.display='none';
    }
    if (document.getElementById("linkC")){
        document.getElementById("linkC").style.display='none';
    }
    if (document.getElementById("linkD")){
        document.getElementById("linkD").style.display='none';
    }
    if (document.getElementById("linkHotels")){
        document.getElementById("linkHotels").style.display='none';
    }
    if (document.getElementById("linkInserisci")){
        document.getElementById("linkInserisci").style.display='none';
    }
        //document.getElementById("linkD").style.display = 'inline';
        /*document.getElementById("linkB").setAttribute('style','visibility:hidden;');
        document.getElementById("linkC").setAttribute('style','visibility:hidden;');*/
        //document.getElementById("linkD").setAttribute('style','visibility:hidden;');
       
}