﻿AjaxPro.onLoading = function(b) 
{
    positionLoadingLabel (b);
}

function oncmbchange(ctrl) {
    if (ctrl.id == "alert_level") {
        if (ctrl.selectedIndex <= 1)
            $('alert_grade').disabled = true;
        else
            $('alert_grade').disabled = false;
    }

    if (ctrl.id == "plevel") {
        if (ctrl.selectedIndex <= 1)
            $('pgrade').disabled = true;
        else
            $('pgrade').disabled = false;
    }
    return true;

}

function processAjax(url) {


    if (window.XMLHttpRequest) { // Non-IE browsers
        req = new XMLHttpRequest();
        req.onreadystatechange = targetDiv;
        try {
            req.open("GET", url, true);
        } catch (e) {
            alert(e);
        }
        req.send(null);
    } else if (window.ActiveXObject) { // IE
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = targetDiv;
            req.open("GET", url, true);
            req.send();

        }
    }
}

function targetDiv() {
    if (req.readyState == 4) { // Complete
        if (req.status == 200) { // OK response
            document.getElementById("viewdiv").innerHTML = req.responseText;
        } else {
            alert("Problem: " + req.statusText);
        }
    }
}

function open_sitiutili() {

    var sitiutili = AjaxExamples.GetSitiUtili();
    document.getElementById("viewdiv").innerHTML = sitiutili.value;
    $("ul.tabs").tabs("div.panes > div"); 
}

function open_news() {

    var news = AjaxExamples.GetNews();
    document.getElementById("viewdiv").innerHTML = news.value;
   
}

function opennewsact(ctrl) {
    var fname = AjaxExamples.GetStringSession(document.getElementById("sessionState").value, "curidnews");
 
    window.open("../upload/" + fname.value);
}

function hideNetMap() {
    $('mapdiv').innerHTML = "";
}

function getNetMapData(ctrl) {
    var regione = $('regione').value;
    var prov = $('prov').value;
    var usert = $('usert').value;

    var sql = " where ";
    if (regione != "ALL")
        sql += " operatori.region = '" + regione + "' and ";
    if (usert != -1)
        sql += " usertype = " + usert + " and ";

    if (prov != "ALL")
        sql += " city in (select descrizione from tab_comuni where substring(codistat,1,3) = '" + prov + "') and ";

    AjaxExamples.SetSessionString(document.getElementById("sessionState").value, "netmapfilter", sql);
    return true;
}

function showNetMap(ctrl) {
    var f = AjaxExamples.GetStringSession(document.getElementById("sessionState").value, "netmapfilter");

    if (f.value != "") {
        $('mapdiv').style['display'] = "block";
        $('div_grd_network').style['display'] = "none";

        window.open('../mapout.aspx?maptype=1&mapfilter=' + f.value, "mapout");

    }
    else {

        $('mapdiv').style['display'] = "none";
        $('div_grd_network').style['display'] = "block";
    }
}
function menuUtCustomClick(menu) {
 
    var menuItem = GetAttribute(menu, "lastMenuId");
    var opcode = AjaxExamples.GetStringSession(document.getElementById("sessionState").value, "cursession");
    var viewdiv = document.getElementById("viewdiv");

    if (menuItem == "idSiti") {
        open_sitiutili();
        return false;
    }
    else if (menuItem == "idNews") {
        open_news();
        return false;
    }

    return true;
}

function loginmenuItemClicked (menu)
{
    var menuItem = GetAttribute(menu, "lastMenuId");

    try {
        AjaxExamples.SetLastMenuId(document.getElementById("sessionState").value, menuItem);
    }
    catch (e) {
        alert("attendere il caricamento della pagina... riprovare l'operazione");
        return false;
    }

    if (menuItem == "idNetwork") {
        return true;

    }
    if (menuItem == "idDb") {
        return true;

    }
    if (menuItem == "idCaseReport") {
        return true;

    }
    if (menuItem == "idNewsAct") {
        return true;
    
    }
    if (menuItem == "idUtilities") {
        AjaxExamples.SetSessionString(document.getElementById("sessionState").value, "utilitiesFrom", "unlogged");
        return true;

    }
    try {
            window.location.href("Login2.aspx?menuid=" + menuItem);
    }
    catch (e) {
            document.location.href = "Login2.aspx?menuid=" + menuItem;
    }
    return false;
}

function hi_link(ctrl) {
}

function un_link(ctrl) {
}

function open_leg_aero(ctrl) {
    window.open("leg_areoporti.aspx", 'legenda', 'width=480px; height=650px; scrollbars=1', true);
}

function open_leg_porti(ctrl) {
    window.open("leg_porti.aspx", 'legenda', 'width=480px; height=650px; scrollbars=1', true);
}

function open_leg_valichi(ctrl) {
    window.open("leg_valichi.aspx", 'legenda', 'width=480px; height=650px; scrollbars=1', true);
}

function hilitelink (ctrl)
{
    ctrl.style.backgroundColor = "#99ccff";
    ctrl.bgColor = "#99ccff";
}

function loginFailed (btn, errorMessage)
{
    document.getElementById("errorLabel").style.visibility = "visible";
    document.getElementById("errorLabel").style.color = "#F00";
    document.getElementById("errorLabel").innerHTML = "nome utente e/o password non corretti.";
}

function loginSuccess (btn)
{
    document.getElementById("errorLabel").style.visibility = "visible";
    document.getElementById("errorLabel").style.color = "#0F0";
    document.getElementById("errorLabel").innerHTML = "login effettuato con successo.<br>caricamento pagina richiesta in corso...";
    location.replace("../default.aspx");
    // window.location = "../default.aspx";
}

function validate (form)
{
    return false;
}

function onpwdkeydown (btn, event)
{
    var btnLogin = document.getElementById("btnLogin");
    if (event.keyCode.toString () == "13")
        onGlButtonEx_click (btnLogin);       
}

function showRegister (ctrl) {
    alert("Per partecipare al network del Sistema di Allerta è necessario contattare il Gruppo di Coordinamento Operativo del Sistema al numero telefoni 045/8076278 o via mail agli indirizzi allerta@dronet.org e allerta@alertadroga.it");

    //document.getElementById('register').style['display'] = "block";
}
function hideRegister (ctrl)
{
    document.getElementById('register').style['display'] = "none";
}
function hideOkRegister (ctrl)
{
    alert ("Richiesta di registrazione inviata con successo");
    document.getElementById('register').style['display'] = "none";

}