﻿ // Ripulisce il JSON in un formato leggibile
function clearJSONInput(JSONText)
{
    var cleanJson = JSONText.replace(/\\u003c/g,'<');
    cleanJson = cleanJson.replace(/\\u0027/g,'\'');
    cleanJson = cleanJson.replace(/\\u003e/g,'>');
    cleanJson = cleanJson.replace(/\\/g,'');
    cleanJson = cleanJson.substr(1,cleanJson.length-2);
    var jsonObject = eval("(" + cleanJson + ")" );
    return jsonObject;
}

 
 $(function () {
    $(".panelHeader").addClass("ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all trigger");
    
    $(".panelHeaderLogin").addClass("ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all trigger");
    
    if ($("#btnSaveLogin")[0])
    {
        $("#btnSaveLogin").button(
            {
                icons: {
                    primary: 'ui-icon-triangle-1-e'
                }
            }
        );
        
        $("#btnSaveLogin").click(function ()
            {
                window.open($("#btnSaveLogin").attr('rel'),'_self');
            }
        );
        
        if (!(navigator.userAgent.match(/iPad/i) != null))
        {
            $('#btnSaveLogin').tooltip({ 
                track: true, 
                delay: 0, 
                showURL: false,
                opacity: 1, 
                fixPNG: true, 
                showBody: " - ", 
                bodyHandler: function() {
                    return wdgShowFavoritesTooltipText;
                },
                top: -40, 
                left: 5 
            });
        }
    }
    
    $(".panelHeader").next().hide();
    
    $(".panelHeader").click(function() {
        $(this).toggleClass("active")
        $(this).next().toggle();
        return false;
    });

    $(".panelHeader").hover(function () {
        $(this).addClass("hover");
      },
      function () {
        $(this).removeClass("hover");
      }
    );

    $("#btnSendComment").button({
        icons: {
            primary: 'ui-icon-comment'
        }
    });
    
    $("#btnPrint").button({
        icons: {
            primary: 'ui-icon-print'
        }
    });
    
    if (!(navigator.userAgent.match(/iPad/i) != null))
    {
        $('#btnPrint').tooltip({ 
                track: true, 
                delay: 0, 
                showURL: false,
                opacity: 1, 
                fixPNG: true, 
                showBody: " - ", 
                bodyHandler: function() {
                    return wdgPrintTooltipText;
                },
                top: -40, 
                left: 5 
            });
    }
        
    $("#btnPrint").click(function (){
        window.open($("#btnPrint").attr('rel'),'printMedia','resizable=no,scrollbars=no,width=800,height=900,left=10,top=10');
    });
 
    $("#panelShowSendMail").hide();

    $("#btnShare").button(
        {
            icons: {
                primary: 'ui-icon-triangle-1-e'
            }
        }
    );

    $("#btnShare").click(function ()
        {
            $("#panelShowSendMail").toggle('slow');
            if ($("#btnShare").button('option','icons').primary == 'ui-icon-triangle-1-e')
                    $("#btnShare").button('option','icons',{primary: 'ui-icon-triangle-1-s'});
            else
                    $("#btnShare").button('option','icons',{primary: 'ui-icon-triangle-1-e'});
        }
        
    );
    
    if (!(navigator.userAgent.match(/iPad/i) != null))
    {
        $('#btnShare').tooltip({ 
                track: true, 
                delay: 0, 
                showURL: false,
                opacity: 1, 
                fixPNG: true, 
                showBody: " - ", 
                bodyHandler: function() {
                    return wdgShareTooltipText;
                },
                top: -40, 
                left: 5 
            });
    }

    var params = "{idMedia:'" + mediaObject.idmedia + "'}";

    jQuery.ajax({
           url: "/services/mediaservice/mediaservice.asmx/GetBasicPressCommentForMedia",
           type: "POST",
           data: params,
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           complete: function(response,stat){
              if(stat=="success") {
                 if (response.responseText != '""')
                 { 
                     var commentsData = clearJSONInput(response.responseText);
                     $('#basicPressComment').empty();
                     $('#basicPressComment').append('<span >' + commentsData[0].comment + '</span>');
                     $('#basicPressComment').height('80px');
                     return true;
                 }
                 else
                 {
                    $('#basicPressComment').height('10px');
                 }
              }
           }
        });
});



function showInfo ()
  {
    var newWindow = window.open("popUpInfo.asp","InfoMediaCorrelati","resizable=no,scrollbars=no,width=300,height=200,left=100,top=100");
    return;
  
    var posx = 20;
    var posy = 20;
    
    var infoPanel = window.document.getElementById("relatedInfoPanel");
    var infoLink = window.document.getElementById("relatedInfoLink");
    if (infoPanel)
    {
        if (infoLink)
        {
            posx = findPosX(infoLink);
            posy = findPosY(infoLink) + 20;
        }
        if (infoPanel.style.visibility == "hidden")
        {
            infoPanel.style.visibility = "visible";
            infoPanel.style.display = "block";
            infoPanel.style.left = String(posx)+"px"
            infoPanel.style.top = String(posy)+"px"
        }
    }
  }
  
  function DownloadFile (url)
  {
    var iMyWidth;
    var iMyHeight;
    //half the screen width minus half the new window width (plus 5 pixel borders).
    iMyWidth = (window.screen.width/2) - (5 + 60);
    //half the screen height minus half the new window height (plus title and status bars).
    iMyHeight = (window.screen.height/2) - (5 + 50);
    window.open(url,'_new','toolbars=no,scrollbars=yes,resizable=yes,width=800,height=900,left=20,top=20,screenX=20,screenY=20');
    //window.open(url,'_new','toolbars=no,scrollbars=yes,resizable=yes,width=10,height=10,left=' + iMyWidth + ',top=' + iMyHeight + ',screenX=' + iMyWidth + ',screenY=' + iMyHeight);
  }
  
  function DownloadImage (url)
  {
    window.open(url,'_new','toolbars=no,scrollbars=yes,resizable=yes,width=800,height=900,left=20,top=20,screenX=20,screenY=20');
}
