// global variables //
var TIMER = 1;
var SPEED = 40;
var WRAPPER = 'content';

// calculate the current window width //
function pageWidth() {
  return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

// calculate the current window height //
function pageHeight() {
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// calculate the current window vertical offset //
function topPosition() {
  return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

// calculate the position starting at the left of the window //
function leftPosition() {
  return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

// build/show the dialog box, populate the data and call the fadeDialog function //
function showDialog(title,message,type,big,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
  var cssdialogcontent = 'dialog-content';
  if (big == 1) cssdialogcontent += "2";
  if (big == -1) cssdialogcontent += "3";
//    if(!document.getElementById('dialog')) {
  if(1) {
      dialog = document.createElement('div');
      if (big == -1) {
          dialog.id = 'dialog3';
      } else {
            dialog.id = 'dialog';
      }
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    if (big == -1) dialogheader.id = 'dialog-header3';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    //    dialogcontent.id = 'dialog-content';
    dialogcontent.id = cssdialogcontent;
    dialogmask = document.createElement('div');
    dialogmask.id = 'dialog-mask';
    document.body.appendChild(dialogmask);
    document.body.appendChild(dialog);
    dialog.appendChild(dialogheader);
    dialogheader.appendChild(dialogtitle);
    dialogheader.appendChild(dialogclose);
    dialog.appendChild(dialogcontent);
     if (big == -1) {
         dialogclose.setAttribute('onclick', "hideDialog3()");
         dialogclose.onclick = hideDialog3;
      } else {
      dialogclose.setAttribute('onclick', "hideDialog()");
    dialogclose.onclick = hideDialog;
      }
} else {
    if (big == -1) {
        dialog = document.getElementById('dialog3');
        dialogheader = document.getElementById('dialog-header3');
        dialogcontent = document.getElementById('dialog-content3');
    } else {
        dialog = document.getElementById('dialog');
        dialogheader = document.getElementById('dialog-header');
        dialogcontent = document.getElementById('dialog-content');
    }
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogmask = document.getElementById('dialog-mask');
    dialogmask.style.visibility = "visible";
    dialog.style.visibility = "visible";
  }
  dialog.style.opacity = .00;
  dialog.style.filter = 'alpha(opacity=0)';
  dialog.alpha = 0;
  var width = pageWidth();
  var height = pageHeight();
  var left = leftPosition();
  var top = topPosition();
  var dialogwidth = dialog.offsetWidth;
  var dialogheight = dialog.offsetHeight;
  var topposition = top + (height / 2) - (dialogheight / 2);
  var leftposition = left + (width / 2) - (dialogwidth / 2);
  if (topposition < 0) topposition = 0;
  if (height < dialogheight) {
      topposition = top;
  }
  dialog.style.top = topposition + "px";
  dialog.style.left = leftposition + "px";
  dialogheader.className = type + "header";
  dialogtitle.innerHTML = title;
  dialogcontent.className = type;
  dialogcontent.innerHTML = message;
  var content = document.getElementById(WRAPPER);
  dialogmask.style.height = content.offsetHeight + 'px';
  if (big == -1) {
      dialog.timer = setInterval("fadeDialog(1,'3')", TIMER);
  } else {
      dialog.timer = setInterval("fadeDialog(1,'')", TIMER);
  }  
  if(autohide) {
      dialogclose.style.visibility = "hidden";
      if (big == -1) {
          window.setTimeout("hideDialog3()", (autohide * 1000));
      } else {
          window.setTimeout("hideDialog()", (autohide * 1000));
      }
  } else {
    dialogclose.style.visibility = "visible";
    }
}

// hide the dialog box //
function hideDialog() {
    var dialog = document.getElementById('dialog');
  clearInterval(dialog.timer);
  dialog.timer = setInterval("fadeDialog(0,'')", TIMER);
}

function hideDialog3() {
    var dialog = document.getElementById('dialog3');
    clearInterval(dialog.timer);
    dialog.timer = setInterval("fadeDialog(0,'3')", TIMER);
}

// fade-in the dialog box //
function fadeDialog(flag, desinenza) {
  if(flag == null) {
    flag = 1;
}
if (desinenza == null) {
    desinenza = '';
}
  var dialog = document.getElementById('dialog' + desinenza);
  var value;
  if(flag == 1) {
    value = dialog.alpha + SPEED;
  } else {
    value = dialog.alpha - SPEED;
  }
  dialog.alpha = value;
  dialog.style.opacity = (value / 100);
  dialog.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(dialog.timer);
    dialog.timer = null;
  } else if(value <= 1) {
    dialog.style.visibility = "hidden";
    document.getElementById('dialog-mask').style.visibility = "hidden";
    clearInterval(dialog.timer);
    dialog.parentNode.removeChild(dialog);
    document.getElementById('dialog-mask').parentNode.removeChild(document.getElementById('dialog-mask'));
  }
}

function showIMG(file,title,code){
	var WebContent="<div style=\"width:100%;text-align:center;color:#FFFFFF;\"><img src=\"thumb.php?w=886&h=540&f=../"+file+"\" alt=\"\" /><br /><br />"+code+"</div>"
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showZF(file,title){
	var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Zoom.aspx?file="+file+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showPia(id, title) {
    var WebContent = "<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"ZoomPia.aspx?id=" + id + "\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
    showDialog("Museo Nazionale del Cinema - " + title, WebContent, "prompt",0);
}

function showLanterna(id, img, title) {
    var WebContent = "<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"ZoomLanterna.aspx?id=" + id + "&amp;img=" + img + "\" style=\"width:886px;height:680px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
    showDialog("Museo Nazionale del Cinema - " + title, WebContent, "prompt",1);
}

function showLanternaVideo(id, video, title) {
    var WebContent = "<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"VideoLanterna.aspx?id=" + id + "&amp;video=" + video + "\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
    showDialog("Museo Nazionale del Cinema - " + title, WebContent, "prompt",0);
}

function showBrochure(ID,Tipo,title){
	var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Brochure.aspx?S";
    if(Tipo=='0'){
        WebContent +="F";
    } else {
        WebContent +="N";
        }
    WebContent +="="+ID+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showManifesti(ID,Tipo,title){
	var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Manifesti.aspx?S";
    if(Tipo=='0'){
        WebContent +="F";
    } else {
        WebContent +="N";
        }
    WebContent +="="+ID+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showVideo(ID,Tipo,title){
	var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Video.aspx?SF=";
    if(Tipo=='0'){
        WebContent +=ID;
    } else WebContent +="0";
    WebContent += "&amp;SN=";
    if(Tipo=='1'){
        WebContent +=ID;
    } else WebContent +="0";
    WebContent +="\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showGallery(codice, title){
	var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Gallery.aspx?cf="+codice+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function EspandiComprimi(Elemento){
    var str=Elemento.innerHTML;
    var pos=str.indexOf("apri");
    if(pos>=0){
        Elemento.innerHTML='<img src="css/freccia_news1.gif" style="border:0;margin-right:5px;" alt="" />chiudi';
    } else {
        Elemento.innerHTML='<img src="css/freccia_down.gif" style="border:0;margin-right:5px;" alt="" />apri';
    }
}

function showPhotoGallery(ID,Tipo,title){
    var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Gallery"+Tipo+".aspx?S";
    if(Tipo=='0'){
        WebContent +="F";
    } else {
        WebContent +="N";
        }
    WebContent +="="+ID+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showMateriali(codice,title){
    var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Materiali.aspx?cm="+codice+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showArchivi(codice,title){
    var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Archivi.aspx?cai="+codice+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showArchivio(codice,title){
    var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"Archivi.aspx?ca="+codice+"\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function showRosi(codice, title) {
    var WebContent = "<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"RosiViewScheda.aspx?ca=" + codice + "\" style=\"width:486px;height:280px;border:0px;padding:0px;margin:0px;\" scrolling=\"auto\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
    showDialog("Museo Nazionale del Cinema - " + title, WebContent, "prompt3", -1);
}

function showRivista(catalogo,pagina,title){
    var WebContent = "<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"http://www.rivistecinema.it\/goto.asp?Page=" + pagina + "&amp;Catalog=C5-1" + catalogo + "\" style=\"width:886px;height:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
	showDialog("Museo Nazionale del Cinema - "+title,WebContent,"prompt",0);
}

function cntrl_over(nome) {
	max_i=6;
	if ($GET(nome).style.display=='block'){
			for (i=1; i<max_i; i++) {
				$GET("menu_col"+i).style.display='none';
			 }
		} else {
			 for (i=1; i<max_i; i++) {
				 if (nome=="menu_col"+i){
					$GET(nome).style.display='block';
		//			document.getElementById('txt_'+nome).focus();
				} else {
					$GET("menu_col"+i).style.display='none';
				}
			} 
		}
 
	}
	

function $GET(id_elemento) {
		var elemento;
		if(document.getElementById)
			elemento = document.getElementById(id_elemento);
		else
			elemento = document.all[id_elemento];
		return elemento;
};
	
	function Ricerca_Semplice() {
	    $GET('Semplice_Panel').style.display='block';
	    $GET('Avanzata_Panel').style.display='none';
	    $GET('HF1').value=0;
	    $GET('Img_Semplice').src='css/freccia_down.gif';
	    $GET('Img_Avanzata').src='css/freccia_news1.jpg';
	    return false;
	}
	
	function Ricerca_Avanzata() {
	    $GET('Semplice_Panel').style.display='none';
	    $GET('Avanzata_Panel').style.display='block';
	    $GET('Img_Semplice').src='css/freccia_news1.jpg';
	    $GET('Img_Avanzata').src='css/freccia_down.gif';
	    $GET('HF1').value=1;
	    return false;
	}
	
	function ReturnHandler(e,form){
	    var keynum;
        if(window.event){
            keynum = e.keyCode
        } else if(e.which){
            keynum = e.which
        }
        if(keynum==13){
            if($GET('Button1')!=null){
                $GET('Button1').click();
            } else if($GET('Ricerca1')!=null) $GET('Ricerca1').click();
           // form.submit();
        }
    }

    function ReturnHandlerLanterna(e, form) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        } else if (e.which) {
            keynum = e.which
        }
        if (keynum == 13) {alert('invio');
            if ($GET('BCercaSemplice') != null) {
                //$GET('BCercaSemplice').click();
                __doPostBack('BCercaSemplice');
            } else if ($GET('BCercaAvanzata') != null) {
                //$GET('BCercaAvanzata').click();
                __doPostBack('BCercaAvanzata');
            }
            // form.submit();
        }
    }

    function LanternaJSSemplice(e, form) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        } else if (e.which) {
            keynum = e.which
        }
        if (keynum == 13) {
            //__doPostBack('BCercaSemplice');
             if ($GET('BCercaSemplice') != null) $GET('BCercaSemplice').click();
        }
    }

    function LanternaJSAvanzata(e, form) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        } else if (e.which) {
            keynum = e.which
        }
        if (keynum == 13) {
            // __doPostBack('BCercaAvanzata');
            if ($GET('BCercaAvanzata') != null) $GET('BCercaAvanzata').click();
        }
    }

    function LanternaJS(e, form, buttonid) {
        var keynum;
        if (window.event) {
            keynum = e.keyCode
        } else if (e.which) {
            keynum = e.which
        }
        if (keynum == 13) {
             __doPostBack(buttonid);
            //if ($GET('BCercaAvanzata') != null) $GET('BCercaAvanzata').click();
        }
    }
	

