var win = null;
function popup(pagina,nomewindow,w,h,scroll,tool)
	{		
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings = 'height='+h+', width='+w+', top='+TopPosition+', left='+LeftPosition+', scrollbars='+scroll+', resizable=no, status=no, toolbar='+tool
		win = window.open(pagina,nomewindow,settings)		
	}		

function FinestraAssociata(pagina,nomewindow,w,h,scroll,tool)
	{	
		var win = null;	
		LeftPosition = (screen.width) ? (screen.width-w-20) : 0;
		TopPosition = -500	
		settings = 'height='+h+', width='+w+', top=10, left='+LeftPosition+', scrollbars='+scroll+', resizable=yes, status=no, toolbar='+tool
		win = window.open(pagina,nomewindow,settings)				
		/*
		for(i=TopPosition;i<=10;i++) {
			win.moveTo(LeftPosition,i);
		}*/
	}	
	
    function setSelectedIndex(obj)
 		{
	    if(window.event.keyCode == 27)
	    {
	      obj.selectedString = '';
	      obj.selectedIndex = -1;
	    }
	    else if(window.event.keyCode == 9 || window.event.keyCode == 38 || window.event.keyCode == 40  || window.event.ctrlKey || window.event.altKey || window.event.type.toLowerCase() == 'blur') // tab, arrow-up, arrow-down, ctrl, or alt keys
	    {
	      obj.selectedString = '';
	      return true;
	    }
	    else
	    {
	      if(typeof obj.selectedString == 'undefined') obj.selectedString = '';
	      if(window.event.keyCode == 8) // backspace
	        obj.selectedString = (obj.selectedString.length != 0) ? obj.selectedString.substring(0, obj.selectedString.length - 1) : '';
	      else
	        obj.selectedString = obj.selectedString + String.fromCharCode(window.event.keyCode);
	      var newSelectedIndex = -1;
	      for(var i = 0; i < obj.options.length; i++)
	      {
	        if(obj.options[i].text.toLowerCase().indexOf(obj.selectedString.toLowerCase()) == 0)
	        {
	          newSelectedIndex = i;
	          break;
	        }
	      }
	      if(newSelectedIndex != -1)
	        obj.selectedIndex = newSelectedIndex;
	      else
	      {
	        obj.selectedString = String.fromCharCode(window.event.keyCode);
	        return true;
	      }
	    }
	    return false;
 	 	}
 	 	
function ReverseDisplay() {
	for (var i=0; i<arguments.length; i++) {
    if(document.getElementById(arguments[i]).style.display == "none") {
        document.getElementById(arguments[i]).style.display = "block";
    } else {
        document.getElementById(arguments[i]).style.display = "none";
    }
	}
}
 	 	

function RefreshImage(valImageId) {
  var objImage = document.images[valImageId];
  if (objImage == undefined) {
    return;
  }
  var now = new Date();
  objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function refresh() {
	//var sURL = unescape(window.location.pathname);
  //window.location.href = sURL;
  window.location.reload(true);
}

function AdvancedSearch() {
	parent.location.href='index.asp?action=formricerca';
}

function Report() {
	parent.location.href="index.asp?action=formreport";
}

function AudioVisivi() {
	//window.open('../AudioVisivi/index.asp?action=elenco','AudioVisivi','left=10,top=10,width=850,height=575')
	top.centerFrame.Inizializza('Audiovisual Archive','Audiovisual Archive','../../AudioVisivi/index.asp?action=elenco&','PopUp_AudioVisivi',9,970,550,'no');
}


function CampoEuro(form, stringa) {
  var Lunghezza = document.all[stringa].value.length;
  var Carattere = document.all[stringa].value.substring(Lunghezza,Lunghezza-1);
  var TipoStringa = "0123456789,";
  var s = TipoStringa.indexOf(Carattere);
  cont = 0;
  for(i=0;i<Lunghezza;i++) {
    Testo = document.all[stringa].value;
    Testo = Testo.split("");
    if (TipoStringa.indexOf(Testo[i]) == -1)
    	document.all[stringa].value = document.all[stringa].value.substring(0,i)
    if (Testo[i] == ',') cont++;                 
    if (cont>1) {
	    document.all[stringa].value = document.all[stringa].value.substring(0,i)
	    break;
    }
  }
}

function CampoNumerico(form, stringa) {
  var Lunghezza = document.all[stringa].value.length;
  var Carattere = document.all[stringa].value.substring(Lunghezza,Lunghezza-1);
  var TipoStringa = "0123456789";
  var s = TipoStringa.indexOf(Carattere);
  cont = 0;
  for(i=0;i<Lunghezza;i++) {
    Testo = document.all[stringa].value;
    Testo = Testo.split("");
    if (TipoStringa.indexOf(Testo[i]) == -1)
    	document.all[stringa].value = document.all[stringa].value.substring(0,i)
    if (Testo[i] == ',') cont++;                 
    if (cont>1) {
	    document.all[stringa].value = document.all[stringa].value.substring(0,i)
	    break;
    }
  }
}

  function CampoNumericoDecimale(form, stringa)
    {    
	    var Lunghezza = document.all[stringa].value.length;
	    var Carattere = document.all[stringa].value.substring(Lunghezza,Lunghezza-1);
	    var TipoStringa = "0123456789,";
	    var s = TipoStringa.indexOf(Carattere);
	    cont = 0;
	    for(i=0;i<Lunghezza;i++)
	      {
	        Testo = document.all[stringa].value;
	        Testo = Testo.split("");
	        if (TipoStringa.indexOf(Testo[i]) == -1)
	          {
	            document.all[stringa].value = document.all[stringa].value.substring(0,i)
	          }
	        if (Testo[i] == ',') cont++;                 
	        if (cont>1)
	          {
	            document.all[stringa].value = document.all[stringa].value.substring(0,i)
	            break;
	          }
	      }
	  }

function CampoTestoNumerico(form, stringa) {
  var Lunghezza = document.all[stringa].value.length;
  var Carattere = document.all[stringa].value.substring(Lunghezza,Lunghezza-1);
  var TipoStringa = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var s = TipoStringa.indexOf(Carattere);
  cont = 0;
  for(i=0;i<Lunghezza;i++) {
    Testo = document.all[stringa].value;
    Testo = Testo.split("");
    if (TipoStringa.indexOf(Testo[i]) == -1)
    	document.all[stringa].value = document.all[stringa].value.substring(0,i)
    if (Testo[i] == ',') cont++;                 
    if (cont>1) {
	    document.all[stringa].value = document.all[stringa].value.substring(0,i)
	    break;
    }
  }
}


function CampoTestoNumericoWebmail(form, stringa) {
  var Lunghezza = document.all[stringa].value.length;
  var Carattere = document.all[stringa].value.substring(Lunghezza,Lunghezza-1);
  var TipoStringa = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@.";
  var s = TipoStringa.indexOf(Carattere);
  cont = 0;
  for(i=0;i<Lunghezza;i++) {
    Testo = document.all[stringa].value;
    Testo = Testo.split("");
    if (TipoStringa.indexOf(Testo[i]) == -1)
    	document.all[stringa].value = document.all[stringa].value.substring(0,i)
    if (Testo[i] == ',' || Testo[i] == '@') cont++;                 
    if (cont>1) {
	    document.all[stringa].value = document.all[stringa].value.substring(0,i)
	    break;
    }
  }
}


	function BarraOn(src,colore) {
		   	src.bgColor = colore;			   	
	    	src.style.cursor = 'pointer';		
		/*	    	
		if (!src.contains(event.fromElement)) {			
		   	src.bgColor = colore;			   	
	    	src.style.cursor = 'pointer';		
	  } else {
	  	alert("FireFox")
	  }
	  */
	}	

 function BarraOff(src,colore){
		src.style.cursor = 'default';
		src.bgColor = colore;
	/*
	if (!src.contains(event.toElement)){
		src.style.cursor = 'default';
		src.bgColor = colore;
	}
	*/
 }

function xin(src,colore) {	
	if (!src.contains(event.fromElement)) {			
			src.className = "cssTabellaMenuOVER";	
	   	src.bgColor = colore;	
    	src.style.cursor = 'hand';			    	
    }
}
 
 function xout(src,cancella){
	if (!src.contains(event.toElement)){
		src.className = "cssTabellaMenuOVER";
		src.style.cursor = 'default';
		src.bgColor = cancella;
	}
 }
 
 function xclk(src){ 
	if (!src.contains(event.toElement)){
		src.className = "cssTabellaMenuCLICK";
		src.style.cursor = 'default';		
	}
	//if(event.srcElement.tagName=='TD'){
	//	src.children.tags('A')[0].click();
	//}
 }

function IconaOn(src) {
	if (!src.contains(event.fromElement)) {		
			src.className = "cssIconaOn";	
    	src.style.cursor = 'hand';			    	
    }
}
function IconaOff(src){
	if (!src.contains(event.toElement)){
		src.className = "cssTesto";
		src.style.cursor = 'default';
	}
}

 function IconaClick(src){ 
	if (!src.contains(event.toElement)){
		src.className = "cssIconaClick";
		src.style.cursor = 'default';		
	}
 }

function PulsanteOn(src) {
	if (!src.contains(event.fromElement)) {		
			src.className = "cssPulsanteOn";	
    	src.style.cursor = 'hand';			    	
    }
}
function PulsanteOff(src){
	if (!src.contains(event.toElement)){
		src.className = "cssTesto";
		src.style.cursor = 'default';
	}
}

function PulsanteMenuOn(src) {
	if (!src.contains(event.fromElement)) {		
			src.className = "cssPulsanteMenuOn";	
    	src.style.cursor = 'hand';			    	
    }
}
function PulsanteMenuOff(src){
	if (!src.contains(event.toElement)){
		src.className = "cssTestoMenu";
		src.style.cursor = 'default';
	}
}

 
 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_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_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;
}

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 runClock() {		
    theTime = window.setTimeout("runClock()", 1000);
    var today = new Date();
    var display = today.toLocaleString();
    status = ":: TURBO PRINT MULTIMEDIA :: " + display;
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos+',scrollbars=no, status=no';}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}
