﻿function SetImgTransparency () {
    /*if ($.browser.msie) {
        $.each($("img"), function (i, n) {
            var src = n.src;
            if (n.src.indexOf(".png") > -1) {
                n.style.visibility = "hidden";
                var div = document.createElement("img");
                div.src = "Images/void.gif";
                div.height = n.height;
                div.width = n.width;
                div.style.height = n.height;
                div.style.width = n.width;
                div.border = 0;
                div.alt = n.alt;
                div.title = n.title;
                div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
                n.replaceNode(div);
            }
        });
    }*/
}

jQuery.extend (
    jQuery.expr[ ":" ], {
        popup : (
            "jQuery(a).attr('rel') == 'popup'"
        )
    }
);
function logInfos(sSessionId) {
    $.post('LogInfos.aspx?sSession=' + sSessionId + '&sX=' + screen.width + '&sY=' + screen.height, {});
}
    
function SetPopup() {
    $("a:popup").click(function() {
        var sUrl = this.href;
        
        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else
            setTimeout(sUrl, 0);
        return false;
    });
    $("a:popup").bind("onkeydown", function() {
        if (sUrl.indexOf("javascript") < 0)
            window.open(sUrl);
        else
            setTimeout(sUrl, 0);
        return false;
    });
    
    $("a:popup").each(function() {
        if ($(this).attr("title") == null) {
            $(this).attr("title", "Questo link si apre in una nuova finestra.");
            $(this).children("img").attr("title", "Questo link si apre in una nuova finestra.");
        } else {
            $(this).attr("title", $(this).attr("title") + " Questo link si apre in una nuova finestra.");
            $(this).children("img").attr("title", $(this).children("img").attr("alt") + " Questo link si apre in una nuova finestra.");
        }
    });
    

        
    $("select").bind("onkeypress", function (e) {
        var key = window.event ? event.keyCode : e.which; 
        alert(key);
    });

    // Previene l'autopostback con la tastiera
    var elms = document.getElementsByTagName("select");
    for(i=0; i < elms.length; i++) {
        elms[i].onkeydown = function (e) {
            var key = window.event ? event.keyCode : e.which; 
            
            if (key == 40 || key == 38)
                this.onchange = null;
        }
    }
}

//function blinkLink(){
//    if ($(".Novita").is(".Novita_1"))
//        $(".Novita").removeClass("Novita_1");
//    else
//        $(".Novita").addClass("Novita_1");
//    
//    setTimeout("blinkLink()", 600);     
//}


$(document).ready(function() {
    SetImgTransparency();
    SetPopup();
    //$(".Novita").queue(blinkLink);
});

function NascondiSottoMenu() {
    $("div#Menu ul").each(function () {
        if (($(this).attr("className") != "none") && ($(this).attr("className") != "MenuDiretto"))
            $(this).hide();
    });

    $("div#MenuLeftMinistero ul").each(function() {
        if (($(this).attr("className") != "none") && ($(this).attr("className") != "MenuDiretto"))
            $(this).hide();
    });
    
    $("div#Menu h3").each(function () {
        if ($(this).attr("className") != "none") {            
            $(this).bind("click", function () {
                  VisualizzaSottoMenu($(this).attr("className"));
            });
        }
    });

    $("div#MenuLeftMinistero h3").each(function() {
        if ($(this).attr("className") != "none") {
            $(this).bind("click", function() {
                VisualizzaSottoMenu($(this).attr("className"));
            });
        }
    });
}

function VisualizzaSottoMenu(id) {
    $("div#Menu ul[@class=" + id + "]").toggle(300);
    $("div#MenuLeftMinistero ul[@class=" + id + "]").toggle(300);
}

function NascondiBlocchiHomepage() {
    $("div.boxHomepage100 ul").each(function () {
        if (($(this).attr("className") != null) && ($(this).attr("className") != "none"))
            $(this).hide();
     });

     $("div.boxHomepage100 p").each(function () {
            if (($(this).attr("className") != null) && ($(this).attr("className") != "none"))
                $(this).hide();
      });

    $("div.boxHomepage100 h2").each(function () {
        if ($(this).attr("className") != "none") {            
            $(this).bind("click", function () {
                  VisualizzaBlocchiHomepage($(this).attr("className"));
            });
        }
    });
}

function VisualizzaBlocchiHomepage(id) {
    $("div.boxHomepage100 ul[@class=" + id + "]").toggle(300);
    $("div.boxHomepage100 p[@class=" + id + "]").toggle(300);
}

function GoogleMap(Pagina){
    window.open(Pagina,'Cartina','scrollbars=no,resizable=yes,width=750,height=550, top=100, left=40');
}

function SetProcessSubmit() {
    theForm.onsubmit = function() {
        ProcessSubmit();
        theForm.onsubmit;
    }
}

function ProcessSubmit() {
    var x = 0;
    var y = 0;
    
    try {
        x = pageXOffset;
        y = pageYOffset;
    } catch (e) {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    
    var inputScrollX = document.createElement("input");
    inputScrollX.setAttribute("type", "hidden");
    inputScrollX.setAttribute("name", "scrollX");
    inputScrollX.setAttribute("id", "scrollX");
    inputScrollX.setAttribute("value", x);
    
    theForm.appendChild(inputScrollX);
    
    var inputScrollY = document.createElement("input");
    inputScrollY.setAttribute("type", "hidden");
    inputScrollY.setAttribute("name", "scrollY");
    inputScrollY.setAttribute("id", "scrollY");
    inputScrollY.setAttribute("value", y);
    
    theForm.appendChild(inputScrollY);
    
    return true;
}
