﻿function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Ottiene informazioni sulla finestra, lo scroll, ecc...
function ViewPort() {
    this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; 
    this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; 
    this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; 
    this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; 
    this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; 
    this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}

// Trova oggetti nella pagina
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

// Apre una nuova finestra
function OpenWindow(url, winName, width, height)
{
    if(winName == null) 
    { 
        winName = "NewWindow"; 
    }
    if(width == null) 
    { 
        ViewPort();
        width = windowX / 2; 
    }
    if(height == null)
    { 
        ViewPort();
        height = windowY / 2; 
    }
	width = screen.width * 0.7;
	height = screen.height * 0.7;
	window.open(url,winName,'scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',scrollbars=yes');			
}

// Seleziona una voce di menu a tendina
function SelectItem(targetMenu, value)
{
    var menu = MM_findObj(targetMenu);
    for(x=0; x<menu.options.length; x++)
    {
        if(menu.options[x].value==value)
        {
            menu.selectedIndex=x;
            break;
        }
    }   
}

// Seleziona una voce di menu a tendina a partire da un altro menu a tendina
function SelectItemFromMenu(sourceMenu, targetMenu)
{
    var menu = MM_findObj(sourceMenu);
    SelectItem(targetMenu, menu.options[menu.selectedIndex].value);
}

// Assegna un valore ad un campo textfield
function SetValue(field, value)
{
    // Trovo l'oggetto
    var obj = MM_findObj(field);
    // Creo una stringa 
    var str = new String(value);
    // Ripristino gli apici
    str = str.replace("&acute;", "\'");
    // Ripristino le virgolette
    str = str.replace("&quot;", "\"");
    // Imposto il valore dell'oggetto
    obj.value = str;
}

// Cambia lo stile di un controllo
function SetStyle(control, cssClass)
{
    // Trova l'oggetto
    var obj = MM_findObj(control);
    // Assegna lo stile al controllo
    if(obj != null)
    {
        obj.className = cssClass;
    }
}

// Apre il pannello specificato dal BehaviorID del controllo CollapsiblePanelExtender
function OpenAjaxPanel(panel)
{
    var colPanel = $find(panel);
    if(colPanel != null)
    {
        colPanel._doOpen();
    }
}

// Chiude il pannello specificato dal BehaviorID del controllo CollapsiblePanelExtender
function CloseAjaxPanel(panel)
{
    var colPanel = $find(panel);
    if(colPanel != null)
    {
        colPanel._doClose();
    }
}

// Mostra il controllo Ajax ModalPopupExtender 
function ShowAjaxModalPopup(control)
{
    var mpe = $find(control);
    //mpe.add_showing( calledWhenShown );
    mpe.show();
}

// Nasconde il controllo Ajax ModalPopupExtender
function HideAjaxModalPopup(control)
{
    var mpe = $find(control);
    mpe.hide();       
}

// Apre un pannello generico
function ShowPanel(panel)
{
    // Trova il pannello
    var obj = MM_findObj(panel);
    // Mostra il pannello
    obj.style.display = "block";
}

// Chiude un pannello generico
function HidePanel(panel)
{
    // Trova il pannello
    var obj = MM_findObj(panel);
    // Mostra il pannello
    obj.style.display = "none";
}
