﻿ /* Show new window telerik */
  function ShowNewWindow(filePage, title, width, height)
  {
    
    //Close all windows
    GetRadWindowManager().CloseAll(); 
     
    //Show new window
    //not providing a name as a second parameter will create a new window
    var oWindow = window.radopen (filePage, null);
    
    
    //Using the reference to the window its clientside methods can be called
    oWindow.SetSize (width + 10, height + 50);
    oWindow.SetTitle (title);
    
  }
  
  
  //Apro la pagina di stampa per le occasioni
  function openPrintProdotti(strIdProdotto) {
    window.open('tools/stampa/StampaProdotto.aspx?prod=' + strIdProdotto, 'print', 'width=630,height=600,status=no,menubar=no,resizable=no,scrollbars=yes,left=200,top=150');
  }
  
  //Apro la pagina di stampa per le news
  function openPrintNews(strIdNews) {
    window.open('tools/stampa/StampaNews.aspx?news=' + strIdNews, 'print', 'width=630,height=600,status=no,menubar=no,resizable=no,scrollbars=yes,left=200,top=150');
  }
  
  
  //Funzione per la visualizzazione e non dei layer.
  //In principio viene fatto un controllo del browser
  //utilizzato dall'utente.
  
  var browserType;

  if (document.layers) {browserType = "nn4"}
  if (document.all) {browserType = "ie"}
  if (window.navigator.userAgent.toLowerCase().match("gecko")) {
     browserType= "gecko"
  }

  function ShowHideDiv(divName) {

  if (browserType == "gecko" )
     document.poppedLayer = 
         eval('document.getElementById(divName)');
  else if (browserType == "ie")
     document.poppedLayer = 
        eval('document.getElementById(divName)');
  else
     document.poppedLayer =   
        eval('document.layers[divName]');

  if (document.poppedLayer.style.display == "none")      
     document.poppedLayer.style.display = "inline";
  else
     document.poppedLayer.style.display = "none";
  }

   
  //Refresh della parent page 
  function RefreshParentPage()
  {
    document.forms[0].submit();
  }
  
  
  function addLoadEvent(func, param) {
	  /**
    
        Prog: Simon Willison
        http://simonwillison.net/2004/May/26/addLoadEvent/
        
        Modif: Nahuel Scotti
        n.scotti@studioleonardo.com
   
        Richiama una funzione all'onload cioè, una volta
        che la pagina è caricata.
        
        --> Esempio:
        
        addLoadEvent(contoAllaRovescia, 10);
        
        --> BUG:
        
        Solo è permesso un parametro per la funzione richiamata.
    
    **/

	var oldonload = window.onload;

	if (typeof window.onload != 'function') 
	{
		window.onload = function (){func(param)};
	}
	else
	{
		window.onload = function() {
	        if (oldonload)
	        {
		        oldonload();
	        }
	        func(param);
        }
	}
}

function onLoadNormalizeAltezze(param1, param2) {
	var oldonload = window.onload;

	if (typeof window.onload != 'function') 
	{
		window.onload = function (){normalizeAltezza(param1, param2)};
	}
	else
	{
		window.onload = function() {
	        if (oldonload)
	        {
		        oldonload();
	        }
	        normalizeAltezza(param1, param2);
        }
	}
}

var myBrowser = findBrowser();

function normalizeAltezza(idElemento1, idElemento2, param3)
{

    /**
    ------------------------------------------------------------
    
        2007 05 04 / ver 1.0
        Prog: Nahuel Scotti. n.scotti@studioleonardo.com
    
    ------------------------------------------------------------
    
        Faccio diventare l'altezza del'elemento "A" == a quella
        dell'elemento "B" o viceversa, prendo come riferimento
        l'altezza del elemento più alto.
        
        Il terzo parametro se è settato in "true" indica che se
        l'elemento "idElemento2" fosse più alto dell' "idElemento1"
        quest'ultimo deve quell'altezza dell' "idElemento2".
        
    ------------------------------------------------------------

        La funzione deve essere chiamata cosi:
        
        <!-- code -->
            <a href="javascript:setStessaAltezza('idElemento1', 'idElemento2');">Stessa Altezza</a>
            <div id="idElemento1" style="height:200px;">Contenuto</div>
            <div id="idElemento2" style="height:100px;">Contenuto</div>
        <!-- code -->
        
        L'elemento "idElemento2" diventerà alto == "200px";
    
    -----------------------------------------------------------
        //////////////////////////////////////////
            BUG
        //////////////////////////////////////////
        Gli elementi perdono qualsiasi propieta definita dentro
        l'attributo "style", quindi, queste devono essere definite
        dentro una class CSS.
    */

    var elem1;
    var elem2;
    
    //Verifico se esiste l'oggetto "elem1"
    try
    {
        elem1 = document.getElementById(idElemento1);
        if(elem1 == null) throw "l'oggetto con l'id = " + idElemento1 + " non esiste.";
    }
    catch(e)
    {
            alert(e);
            return;
    }

    //Verifico se esiste l'oggetto "elem2"
    try
    {
        elem2 = document.getElementById(idElemento2);
        if(elem2 == null) throw "l'oggetto con l'id = " + idElemento2 + " non esiste.";
    }
    catch(e)
    {
            alert(e);
            return;
    }
    
    //ALTEZZA
    var altezzaOrigine = elem1.scrollHeight;
    var altezzaDestino = elem2.scrollHeight;

    if(altezzaDestino == altezzaOrigine) return;
    if(altezzaOrigine > altezzaDestino)
    {
        setAltezza(altezzaOrigine, elem2)
    }
    if(altezzaDestino > altezzaOrigine && param3)
    {
        setAltezza(altezzaDestino, elem1)
    }
}

function setAltezza(altezza, elemento)
{
    switch(myBrowser)
    {
       case "IE":
                elemento.style.height = altezza-10;
       break;
       case "Mozilla":
                elemento.setAttribute("style", "height:" + (altezza-10) + "px");
       break;
    }
}

function findBrowser()
{
    /*
        findBrowser();
        Ristituisce il nome del browser
    */
    if(document.getElementById && document.all)
    {
        return "IE";
    }
    else
    {
        return "Mozilla";
    }
}

function changeMiniImage(divObject)
{
    //il div con l'immagine grande
    var imgGrande = document.getElementById('imgPhotogalleryGrande'); 
    var imgZoom = divObject.style.backgroundImage;
        
    imgGrande.style.backgroundImage = divObject.style.backgroundImage;
        
    //tolgo i primi 4 caratteri a "url(laMiaImmagine_zoom.jpg)",
    //quindi diventa "laMiaImmagine_zoom.jpg"
    //document.getElementById('imgGrandeLink').href = imgZoom.substr(4, imgZoom.length-5);
}


function changeMiniImageNews(divObject)
{
    //il div con l'immagine grande
    var imgGrande = document.getElementById('divImmagine'); 
    var imgZoom = divObject.style.backgroundImage.replace("_Icon", "_Zoom");
        
    imgGrande.style.backgroundImage = divObject.style.backgroundImage.replace("_Icon", "_Int");
    
    document.getElementById('imgZoomLink').href = imgZoom.substr(4, imgZoom.length-5);    
}
