// 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,autohide) {
  if(!type) {
    type = 'error';
  }
  var dialog;
  var dialogheader;
  var dialogclose;
  var dialogtitle;
  var dialogcontent;
  var dialogmask;
//    if(!document.getElementById('dialog')) {
  if(1) {
    dialog = document.createElement('div');
    dialog.id = 'dialog';
    dialogheader = document.createElement('div');
    dialogheader.id = 'dialog-header';
    dialogtitle = document.createElement('div');
    dialogtitle.id = 'dialog-title';
    dialogclose = document.createElement('div');
    dialogclose.id = 'dialog-close'
    dialogcontent = document.createElement('div');
    dialogcontent.id = 'dialog-content';
    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);;
    dialogclose.setAttribute('onclick','hideDialog()');
    dialogclose.onclick = hideDialog;
  } else {
    dialog = document.getElementById('dialog');
    dialogheader = document.getElementById('dialog-header');
    dialogtitle = document.getElementById('dialog-title');
    dialogclose = document.getElementById('dialog-close');
    dialogcontent = document.getElementById('dialog-content');
    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';
  dialog.timer = setInterval("fadeDialog(1)", TIMER);
  if(autohide) {
    dialogclose.style.visibility = "hidden";
    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);
}

// fade-in the dialog box //
function fadeDialog(flag) {
  if(flag == null) {
    flag = 1;
  }
  var dialog = document.getElementById('dialog');
  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");
}

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");
}

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");
}

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:580px;border:0px;padding:0px;margin:0px;\" scrolling=\"no\" frameborder=\"0\"></iframe>";
    WebContent += "</div>";
    showDialog("Museo Nazionale del Cinema - " + title, WebContent, "prompt");
}

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");
}

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");
}

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");
}

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");
}

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");
}

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");
}

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");
}

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");
}

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");
}

function showRivista(codice,title){
    var WebContent="<div style=\"width:100%;text-align:center;\">";
    WebContent += "<iframe src=\"http://www.katalogando.it\/catalogs\/C5-100001\/\" 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");
}

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();
        }   
	}
	
