﻿
var _activeDivNews;
var _activeLink;
function showNews(DivContainer, Tab) {
    var _nTab = document.getElementById(Tab);
    var _nDiv = document.getElementById(DivContainer);

    //si mettono a posto i vecchi
    _activeLink.className = _activeLink.className + "Bis";


    _activeDivNews.style.display = 'none';

    //si fanno i nuovi
    _nTab.className = _nTab.className.replace('Bis', '');
    _nDiv.style.display = '';

    _activeDivNews = _nDiv;
    _activeLink = _nTab;

}


function searchInQualigeo() {

    var _cat = document.getElementById("ctl00_tipologia").value;
    var _naz = document.getElementById("ctl00_nazione").value;
    var _nome = document.getElementById("prod_nome").value;
    var m = window.open("http://www.qualigeo.eu/SearchIt.aspx?CATEGORIA=" + _cat + "&NAZIONE=" + _naz + "&NOME=" + _nome, "QUALIGEO", "");
    m.focus();
}

function searchInQualigeoHome() {

    var _cat = document.getElementById("tipologia").value;
    var _naz = document.getElementById("nazione").value;
    var _nome = document.getElementById("prod_nome").value;
    var m = window.open("http://www.qualigeo.eu/SearchIt.aspx?CATEGORIA=" + _cat + "&NAZIONE=" + _naz + "&NOME=" + _nome, "QUALIGEO", "");
    m.focus();
}

function searchInQualigeo2(Contest) {

    switch (Contest) {

        case "PRODOTTO":
            var _cat = document.getElementById("ctl00_cphAreaMain_tipologia").value;
            var _prot = document.getElementById("ctl00_cphAreaMain_protezione").value;
            var _naz = document.getElementById("ctl00_cphAreaMain_nazione").value;
            var _nome = document.getElementById("prod_nome").value;
            var m = window.open("http://www.qualigeo.eu/SearchIt.aspx?VAL=" + _prot + "&CATEGORIA=" + _cat + "&NAZIONE=" + _naz + "&NOME=" + _nome, "QUALIGEO", "");
            m.focus();
            break;
        case "AZIENDA":
            var _azienda = document.getElementById("ctl00_cphAreaMain_aziende").value;
            var _nome = document.getElementById("nome_azienda").value;
            var m = window.open("http://www.qualigeo.eu/SearchIt.aspx?SEARCHCONTEST=AZIENDA&CATEGORIA=" + _azienda + "&NOME=" + _nome, "QUALIGEO", "");
            m.focus();
            break;
        case "TERRITORIO":
            var _nome = document.getElementById("nome_territorio").value;
            var m = window.open("http://www.qualigeo.eu/SearchIt.aspx?SEARCHCONTEST=TERRITORIO&txtricerca=" + _nome, "QUALIGEO", "");
            m.focus();
            break;
    }

}

function setHeight() {

    var _sx = document.getElementById('DIV_TESTO').clientHeight;
    var _dx = document.getElementById("box_dx").clientHeight;
    //alert(_dx + "-"+ _sx);
    if (_dx < _sx)
        document.getElementById("box_dx").style.height = _sx;
    //alert(document.getElementById('box_dx').clientHeight);
}

function showMyDiv(divElement) {

    var _m = document.getElementById(divElement);
    if (_m != null) {

        _m.style.display = (_m.style.display == 'none') ? '' : 'none';
    }
}


function sendPage(ev) {

    if (!ev) var ev = window.event;
    showMyDiv("INVIAMAIL");
    var left = (ev.pageX != null) ? ev.pageX - 700 : ev.clientX - 700;
    var top = (ev.pageY != null) ? ev.pageY - 200 : ev.clientY + document.documentElement.scrollTop - 200;
    placeIt("INVIAMAIL", left, top)
}


// posiziona (left - top)  un oggetto html di id = obj
function placeIt(obj, left, top) {
    obj = document.getElementById(obj);
    obj.style.left = left + 'px';
    obj.style.top = top + 'px';
    //alert(obj.style.left + "-" + obj.style.top);
    //alert(xMousePosMax + "-" + yMousePosMax);

}


function QualikeyDown(e) {
    if (checkEnter(e)) {
        search();
        return false;
    }
}

function search() {

    var _searchString = document.getElementById("TxtCerca");
    location.href = "/site/_page/search.aspx?SEARCH=" + _searchString.value;
}

function checkEnter(e) { //e is event object passed from function invocation
    var characterCode //literal character code will be stored in this variable

    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which //character code is contained in NN4's which property
    }
    else {
        e = event
        characterCode = e.keyCode //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
        return true;
    }
    else {
        return false;
    }
}

function openTab(Naz) {

    var _cont = document.getElementById("RISULTATIMAPPA");
    _cont.style.display = '';
    _cont.innerHTML = 'loading...';
    var _rslt = Prodotti.getNazCert(Naz).value;


    _cont.style.display = '';
    _cont.innerHTML = _rslt;
}

function closeDiv(Container) {
    var _cont = document.getElementById(Container);
    _cont.style.display = 'none';
}



function showAlbum(Naz) {

    var _elem = document.getElementById("gallery2");
    _elem.attributes["href"].value = "album/rssGenerator.ashx?N=" + Naz;
    PicLensLite.start();
}

function showProd(Cat) {

    var _elem = document.getElementById("ctl00_gallery2");
    _elem.attributes["href"].value = "/album/rssGeneratorCat.ashx?C=" + Cat;
    PicLensLite.start();
}

function showProdCountry(Cat, Naz) {

    var _elem = document.getElementById("ctl00_gallery2");
    _elem.attributes["href"].value = "/album/rssGeneratorCatCountry.ashx?C=" + Cat + "&N=" + Naz;
    PicLensLite.start();
}

function sendCV() {
    var _pref = "ctl00_cphAreaMain_LavoraConNoi1_";
    var _nome = document.getElementById(_pref + "txt_nome").value;
    var _cognome = document.getElementById(_pref + "txt_cognome").value;
    var _data = document.getElementById(_pref + "txt_data").value;
    var _email = document.getElementById(_pref + "txt_email").value;
    var _tel = document.getElementById(_pref + "txt_telefono").value;
    var _msg = document.getElementById(_pref + "txt_messaggio").value;

    if (_nome == "" || _nome == null) {
        alert("Nome Obbligatorio / Name Required!");
        return;
    }
    if (_cognome == "" || _cognome == null) {
        alert("Cognome Obbligatorio / Surame Required!");
        return;
    }
    if (_email == "" || _email == null) {
        alert("Email Obbligatoria/ Email Required!");
        return;
    }
    if (_msg == "" || _msg == null) {
        alert("Messaggio Obbligatorio / Mesasge Required!");
        return;
    }

    var _body = "Nome: " + _nome + "<br>";
    _body += "Cognome: " + _cognome + "<br>";
    _body += "Data: " + _data + "<br>";
    _body += "Telefono: " + _tel + "<br>";
    _body += "Email : " + _email + "<br>";
    _body += "Messaggio: " + _msg + "<br>";

    Mail.SendMessageAjax(_email, "info@qualivita.it", _body, "Invio Curriculum dal sito Qualivita");
    document.getElementById(_pref + "lbl_err").innerHTML = "Mail inviata con successo / Mail sended with success";
}

function sendAlert(Tipo) {

    var _pref = "ctl00_cphAreaMain_" + Tipo + "_";
    var _nome = document.getElementById(_pref + "txt_nome").value;
    var _cognome = document.getElementById(_pref + "txt_cognome").value;
    var _email = document.getElementById(_pref + "txt_email").value;
    var _tel = document.getElementById(_pref + "txt_telefono").value;
    var _msg = document.getElementById(_pref + "txt_messaggio").value;

    if (_nome == "" || _nome == null) {
        alert("Nome Obbligatorio / Name Required!");
        return;
    }
    if (_cognome == "" || _cognome == null) {
        alert("Cognome Obbligatorio / Surame Required!");
        return;
    }
    if (_email == "" || _email == null) {
        alert("Email Obbligatoria/ Email Required!");
        return;
    }
    if (_msg == "" || _msg == null) {
        alert("Messaggio Obbligatorio / Mesasge Required!");
        return;
    }

    var _body = "Nome: " + _nome + "<br>";
    _body += "Cognome: " + _cognome + "<br>";

    _body += "Telefono: " + _tel + "<br>";
    _body += "Email : " + _email + "<br>";
    _body += "Messaggio: " + _msg + "<br>";


    var _sub = "";
    switch (Tipo) {
        case "sitoFondazione":
            _sub = "Mail sul sito della Fondazione";
            break;
        case "segnalaAnomalia":
            _sub = "Mail per seganalare un'anomalia sul sito della Fondazione";
            break;
        case "lavoroFondazione":
            _sub = "Mail sul lavoro della Fondazione";
            break;
    }

    Mail.SendMessageAjax(_email, "info@qualivita.it", _body, _sub);
    document.getElementById(_pref + "lbl_err").innerHTML = "Mail inviata con successo / Mail sended with success";

}


function segnalaAzienda() {
    var _pref = "ctl00_cphAreaMain_SegnalaAzienda1_";
    var _settore = document.getElementById(_pref + "list_settore").value;
    var _ragione = document.getElementById(_pref + "txt_ragione").value;
    var _indirizzo = document.getElementById(_pref + "txt_indirizzo").value;
    var _citta = document.getElementById(_pref + "txt_citta").value;
    var _cap = document.getElementById(_pref + "txt_cap").value;
    var _nazione = document.getElementById(_pref + "txt_nazione").value;
    var _telefono = document.getElementById(_pref + "txt_telefono").value;
    var _fax = document.getElementById(_pref + "txt_fax").value;
    var _email = document.getElementById(_pref + "txt_mail").value;
    var _url = document.getElementById(_pref + "txt_url").value;
    var _prodotti = document.getElementById(_pref + "txt_prodotti").value;
    var _vendita = document.getElementById(_pref + "chk_vendita").value;

    if (_ragione == "" || _ragione == null) {
        alert("Nome Obbligatorio / Name Required!");
        return;
    }

    if (_email == "" || _email == null) {
        alert("Email Obbligatoria/ Email Required!");
        return;
    }

    var _body = "Settore: " + _settore + "<br>";
    _body += "Ragione Sociale: " + _ragione + "<br>";
    _body += "Indirizzo: " + _indirizzo + "<br>";
    _body += "Città: " + _citta + "<br>";
    _body += "Cap: " + _cap + "<br>";
    _body += "Nazione: " + _nazione + "<br>";
    _body += "Telefono: " + _telefono + "<br>";
    _body += "Fax: " + _fax + "<br>";
    _body += "Email : " + _email + "<br>";
    _body += "Url: " + _url + "<br>";
    _body += "Prodotti : " + _prodotti + "<br>";
    _body += "Vendita Diretta: " + _vendita + "<br>";

    Mail.SendMessageAjax(_email, "info@qualivita.it", _body, "Segnalazione Azienda da Sito Fondazione Qualivita");
    document.getElementById(_pref + "lbl_err").innerHTML = "Mail inviata con successo / Mail sended with success";
}

function sendPageAjax() {
    var _pref = "ctl00_";
    var _url = document.getElementById(_pref + "MAILPAG").value + "?MAILSEND=1";
    var _from = document.getElementById(_pref + "txt_mail").value;
    var _to = document.getElementById(_pref + "txt_mail2").value;
    var _sub = document.getElementById(_pref + "txt_subject").value;

    Mail.SendPageAjax(_from, _to, _url, _sub);
    alert('Mail inviata con successo / Mail sended with success');

    document.getElementById(_pref + "txt_mail").value = "";
    document.getElementById(_pref + "txt_mail2").value = "";
    document.getElementById(_pref + "txt_subject").value = "";

    showMyDiv("INVIA_MAIL");
}


var _startImg;
function change() {
    var _img = document.getElementById("IMG_BANNER");
    if (_startImg == null) {
        _startImg = document.getElementById("START_IMG").value;
    }
    _img.src = "/immagini/banner/" + _startImg + ".jpg";

    _startImg = eval(_startImg) + 1;
    if (_startImg == 8) _startImg = 1;

    window.setTimeout(change, 3000);
}

function openMap() {
    var m = window.open("/site/_page/elenco_europa.aspx", "ELENCO", "width=1300,height=750");
    m.focus();

}