function Release()
{
 var sTitle="NTG JS LIBRARY - WEB PAGES BASE SCRIPTS";
 return "030629";
}

// Global Vars
var NT_Debug=0;
var NT_DebugProc="";

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_validateForm() { //v4.0
// Example: <input type="submit" name="Submit2" value="Invia Annuncio" class="tasti">
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve contenere un indirizzo e-mail valido.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' deve contenere un valore numerico.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' è obbligatorio.\n'; }
  } if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function NF_CheckOS()
{
 if(navigator.userAgent.indexOf('Linux') != -1)
 { var OpSys = "Linux"; }
 else if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1))
 { var OpSys = "Windows95"; }
 else if(navigator.userAgent.indexOf('Win') != -1)
 { var OpSys = "Windows3.1 or NT"; }
 else if(navigator.userAgent.indexOf('Mac') != -1)
 { var OpSys = "Macintosh"; }
 else
 { var OpSys = "other"; }

 return OpSys;
}

function MM_swapImage() { //v2.0
 var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;
 for (i=0; i < (MM_swapImage.arguments.length-2); i+=3)
 {
  objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];
  if ((objStr.indexOf('document.layers[')==0 && document.layers==null) || (objStr.indexOf('document.all[')==0 && document.all==null))
  objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);
  obj = eval(objStr);
  if (obj != null)
  {
   swapArray[j++] = obj;
   swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];
   obj.src = MM_swapImage.arguments[i+2];
  }
 }
 document.MM_swapImgData = swapArray; //used for restore
}

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) { //v3.0
 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);
 return x;
}

function NF_LoadImage(sURL) // PRE-Load Images in memory
{ var img = new Image(); img.src=sURL; return img; }

function Approfondimento(sURL)
{
// Open Window PopUp. HTML File Parameter
 wndApp=window.open(sURL,"Approfondimento","toolbar=no,resizable=yes,directories=no,location=no,status=yes,scrollbars=yes,menubar=no,width=620,height=400,top=10,left=10");
 wndApp.status="Approfondimento";
 wndApp.focus()
}
function GotoURL(sURL)
{
// Go to another page .....
// alert ("GotoURL: " + sURL);
 if ((sURL == null) || (sURL == "") || (sURL== "undefined.htm") || (sURL==".htm") || (sURL=="../testi/.htm"))
 { alert("Pagina NON ESISTENTE."); return }
 location.href = sURL
}

function PrintThis()
{
// Print current window
 var da = (document.all) ? 1 : 0;
 var pr = (window.print) ? 1 : 0;
 var mac = (navigator.userAgent.indexOf("Mac") != -1);

 if (pr)
 { // NS4, IE5
  window.print();
 }
 else if (da && !mac)
 { // IE4 (Windows)
  alert("Per stampare con Ms Explorer 4, cliccate con il tasto destro del mouse sulla zona da stampare e selezionate Stampa dal menu che appare.");
 }
 else
 { // other browsers
  alert("Spiacente. Il Browser installato sul tuo PC, non permette questa funzione.");
 }
}

function PrintFrame(sFramename)
{
 if (BrowserExplorer() && navigator.AppVersion<5)
  alert("Il Browser installato sul tuo PC, non permette questa funzione. Usate il tasto destro del mouse per la stampa");
 else
  parent.frames[sFramename].focus(); PrintThis()
}

function TestoScorrevole(msg)
{
// Testo scorrevole
 var i,k; k=(150/msg.length)+1;
 for(i=0;i<=k;i++) msg+=" "+msg;
 document.formtestoscorrevole.testo.value=msg.substring(position,position+150);
 if(position++==150) position=0;
 id=setTimeout("TestoScorrevole()",120);
}

function OpenWindow(URL,type,px,py)
{
// Apre Finestra in modo tradizionale...usata da altre + specifiche
 OpenWindow2(URL,type,'Finestra',px,py)
}

function OpenWindow2(URL,type,sNomeFinestra,px,py)
{
// Apre una finestra type, m=max, f=full/n=normal, px,py not 0, posx,y
// var nHeight=440;
 var nHeight=screen.height-20;
 var sPrefs = "toolbar=1,address=0,location=0,status=1,resizable=1,scrollbars=1,menubar=1,width="+screen.width+",height="+nHeight+",top=0,left=0";

 if (type=="f")
 { if (BrowserExplorer())
   { sPrefs = "fullscreen"; }
 else
   { sPrefs = "toolbar=0,address=0,location=0,status=1,resizable=1,scrollbars=1,menubar=0,width="+(screen.width-5)+",height="+(screen.height-50)+",top=0,left=0"; }
 }

 var wndOpen=window.open(URL,sNomeFinestra,sPrefs)
 wndOpen.status="Finestra";
 wndOpen.focus()
}

function OpenSito(URL,sNomeSito)
{
// Apre Sito Internet. in Max Screen
 wndOpenSito=OpenWindow2(URL,"m",sNomeSito,0,0);
}

function Playmediaclip(sURL,sFoto,sFototesto)
{
// Play Audio/VideoClip con nuova vinestra: Parametro ASF File
 wndPlay=window.open(sURL,"ClipMultimedialeWindow","toolbar=no,resizable=yes,directories=no,location=no,status=no,scrollbars=yes,menubar=no,width=620,height=400,top=5,left=5")
 wndPlay.status="Clip Multimediale - E' richiesto Microsoft Media Player per Sentirlo "
 wndPlay.focus()
}

function EmbedMediaFile(sFile,sLoop,nWidth,nHeight)
{
 document.write("<EMBED SRC='"+sFile+"' AUTOSTART=" + sAutostart + " WIDTH=" + nWidth + " HEIGHT=" + nHeight + ">")
 document.write("<NOEMBED>")
 document.write("<BGSOUND SRC='"+sFile+"'>")
 document.write("</NOEMBED>")
 document.writeln("</EMBED>")
}

function EmbedFile(sFile,sAutostart,nWidth,nHeight)
{
 document.write("<EMBED SRC='"+sFile+"' WIDTH=" + nWidth + " HEIGHT=" + nHeight + ">")
 document.writeln("</EMBED>")
}

function EmbedMediaPlayerFile(sFile,sAutostart,nWith,nHeight)
{
 document.write("<OBJECT ID=MediaPlayer CLASSID=CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95 CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 STANDBY='Loading Microsoft Windows Media Player components...' TYPE=application/x-oleobject>")
 document.writeln("<PARAM NAME=Filename VALUE='"+sFile+"'>")
 document.writeln("<EMBED TYPE=application/x-mplayer2  PLUGINSPAGE=http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/")
 document.writeln("SRC='"+sFile+"' NAME=MediaPlayer WIDTH=" + nWidth + " HEIGHT=" + nHeight + ">")
 document.writeln("</EMBED></OBJECT>")
}

function EmbedFlashFile(sFile,sAutostart,nWidth,nHeight,Version)
{
 //alert(sFile+"*"+sAutostart+"*"+nWidth+"*"+nHeight+"*"+Version)
 var sID; sID = strPathFilename(sFile);
 document.write("<div align='center'>")
 document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'")
 document.write(" WIDTH=" + nWidth + " HEIGHT=" + nHeight + " id='"+sID+"' ALIGN='middle'>")
 document.writeln(" <PARAM NAME=movie VALUE='"+sFile+"'>")
 document.writeln(" <PARAM NAME=loop VALUE=false>")
 document.writeln(" <PARAM NAME=quality VALUE=high>")
 document.writeln(" <EMBED name='"+sID+"' swLiveConnect=true src='" + sFile + "' loop=false quality=high WIDTH="+ nWidth + " HEIGHT=" + nHeight + " ALIGN='middle' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>")
 document.writeln("</EMBED></OBJECT></div>")

 with (navigator)
  if (appName.indexOf('Microsoft')!=-1 && appVersion.indexOf('Mac')==-1)
   document.write('<scr'+'ipt language="VBScript">\nOn error resume next\n'+'MM_dir = IsObject(CreateObject("SWCtl.SWCtl.1"))\n'+'MM_flash = NOT IsNull(CreateObject("ShockwaveFlash.ShockwaveFlash"))\n</scr'+'ipt>');

}

function EmbedPdfFile(sFile)
{
 var aT = new Array(); var i=0;
 var sID; sID = strPathFilename(sFile);

 aT[i++]='<OBJECT id=' + sID;
 aT[i++]=' style="WIDTH: 100%; HEIGHT: 100%" classid=clsid:CA8A9780-280D-11CF-A24D-444553540000>';
 aT[i++]='<PARAM NAME="_Version" VALUE="327680"> <PARAM NAME="_ExtentX" VALUE="26008"><PARAM NAME="_ExtentY" VALUE="1746"><PARAM NAME="_StockProps" VALUE="0">';
 aT[i++]='<PARAM NAME="SRC" VALUE=' + strBracket(sFile) + '></OBJECT>';

 document.writeln(array_join(aT));
}

function FlashSetVar(sMovie,sVariable,sValue)
{
 // Syntax: <body onload=javascript:FlashSetVar>
 window.document[sMovie].SetVariable("_root." + sVariable, sValue)
}

function PageDateChanged(mode)
{
// mode per ora non usato..Mettere sempre 0. Scrive Data ultima modifica pagina
 var LastModDate = new Date(document.lastModified);
 var sDate = (LastModDate.getDay()+11) + "/" + (LastModDate.getMonth()+1) + "/" + (LastModDate.getYear());
 return sDate;
}

function GotoFromList(list,type)
{
// Richiamo da lista.  Type 0:Da Pagina no Frame 1=Pagina con frame 2=Senza bottone vai (chiamata OnChange)
 if (list.options[list.selectedIndex].value=="") return 0;
 if (type==0) location.href = list.options[list.selectedIndex].value
 if (type==1) parent.main.href = list.options[list.selectedIndex].value
 if (type==2) location.href=document.formgoto.list.options[document.formgoto.list.selectedIndex].val
}

function args_init ()
{
// Call the args_init () function to set up the args [] array. args_init ();
 args = new Array ();
 var argstring = window.location.search;
 if (argstring.charAt(0) != '?') return;
 argstring = argstring.substring (1, argstring . length);
 var argarray = argstring.split('&');
 var i; var singlearg;
 for (i=0; i<argarray.length;++i)
 {
  singlearg = argarray[i].split('=');
  if (singlearg.length != 2) continue;
  var key = myunescape(singlearg[0]);
  var value = myunescape(singlearg[1]);
  args[key] = value;
 }
}

function CheckResolution(correctwidth,correctheight)
{
// Avviso se risoluzione non corretta
 if (screen.width<correctwidth||screen.height<correctheight)
 {
  var msg ="Attenzione!\nPer una visione ottimale del sito è consigliabile impostare\nla risoluzione ad almeno 800x600.\n\nL'attuale risoluzione del tuo video è "+screen.width+"*"+screen.height+"."
  alert (msg)
 }
}

function SetClipName(mobject,filename)
{
 var g_Browser = navigator.appName;
 if (g_Browser == "Netscape")
 { mobject.SetFileName(filename); }
 else
 { mobject.FileName = filename; }
}

function ImageLight(imgName,light)
{
// Visualizza ON/OFF Image
 if (document.images)
 {
  if (light!=0) {document[imgName].src = eval(imgName + "on.gif"); }
  if (light==0) {document[imgName].src = eval(imgName + "off.gif"); }
 }
}

function BrowserNetscape()
{ return ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3 )); }

function BrowserExplorer()
{ return ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 3 )); }

function BrowserVersion()
{
 var nome=(navigator.appName=="Microsoft Internet Explorer")?true:false;
 var wt=nome?(navigator.appVersion.split(';').toString().split(" ").toString().split(',')[4] ):null;
 if ((wt)>=5 && nome) return "IE5";
 if ((wt <5 && wt >=4) && nome) return "IE4";
 if (document.layers) return "NS4";
 if (document.getElementById && (navigator.appName=="Netscape")) return "NS6";
 return "*";
}

function PlaySoundEmbedded(filename)
{
// Play Sound Embedded in document
 if( BrowserExplorer() )
 { document.writeln('<BGSOUND SRC=' + filename + ' LOOP=1>'); }
 if( BrowserNetscape() )
 { document.writeln('<EMBED AUTOSTART="true" LOOP="1" WIDTH="2" HEIGHT="0" SRC=' + filename +'>'); }
}

function DisableRightButton()
{
// Copyright...Richiamare a inizio pagina
 document.onmousedown=TrapRightButton;
 if (document.layers) window.captureEvents(Event.MOUSEDOWN);
 window.onmousedown=TrapRightButton;
}

function strToTitle(sText)
{ return '<font color="#800000" face="Arial" size="3"><strong><center>'+sText+'</font></strong></center>'}

function strPathExt(sPath)
{
// Estrae ext dal File
 if (sPath.length==0) return '';
 var sExt=''; var nCounter=sPath.length-1; var bContinue=1;
 while (bContinue)
  if ( sPath.charAt(nCounter)=='.' || nCounter==0)
  { bContinue=0 } else { sExt = sPath.charAt(nCounter--)+sExt; }
//alert("strPathExt: "+sExt)
  return sExt;
}

function rpcCallStd(sRPC) { // In documento corrente
 //alert(sRPC);
 document.write(strBracketTag("img border=0 width=0 height=0 alight=right src=" + strBracket(sRPC)))
}

function rpcCallWnd(wnd, sRPC){ // In finestra
 wnd.document.write(strBracketTag("img border=0 width=0 height=0 alight=right src=" + strBracket(sRPC))) }

function strPathFile(sPath)
{
// Estrae filename+ext dal File
 if (sPath.length==0) return '';
 var nEnd=sPath.length; var nCounter=nEnd-1; var bContinue=1;
 while (bContinue)
 {
  if ( (sPath.charAt(nCounter)=='\\') || (sPath.charAt(nCounter)=='/') || nCounter==0)
  { bContinue=0 } else { nCounter--}
 }
 var sResult = sPath.substring(nCounter+1, nEnd)
//alert("strPathFile: "+sResult+", "+sResult.length)
 return sResult;
}

function strPad(sText, nLength, sPad, nMode)
{
 // Pad string with char
 // nMode=0.Left, 1.Right
 var sResult = sText; sPadtext='';
 if (sText.length>nLength) sResult = sResult.substring(0,nLength-1)

 if (sText.lenght<nLength)
  if (nMode=0) {sResult = sPadtext + sResult;} else {sResult = sPadtext + sResult;}

 return sResult;
}

function strBracket(sText)
{return "'"+sText+"'";}

function strBracketTag(sText)
{return "<"+sText+">";}

function strTag(sText,sTag)
{return strBracketTag(sTag) + unescape(sText) + strBracketTag("/"+sTag);}

function strTagExt(sText,sTag,sParam)
{return strBracketTag(sTag +" "+ sParam) + unescape(sText) + strBracketTag("/"+sTag);}

function strPathFilename(sPath)
{
// Estrae Nome del file senza ext da sPath
 if (sPath.length==0) return '';
 var sExt=strPathExt(sPath); if (sExt.length==0) return '';
 var nEnd=sPath.length-sExt.length-1; var nCounter=nEnd-1; var bContinue=1;
 while (bContinue)
 {
  if ( (sPath.charAt(nCounter)=='\\') || (sPath.charAt(nCounter)=='/') || nCounter==0)
  { bContinue=0 } else { nCounter--}
 }
 var sResult = sPath.substring(nCounter+1, nEnd)
//alert("strPathFilename: "+sResult+", "+sResult.length)
 return sResult;
}

// Nome del file Corrente
function strPathFilenameCurrent() { return strPathFilename(document.location.pathname); }

function addbookmark(pagina,titolo)
{
 if (isIE4)
  window.external.AddFavorite(pagina,titolo);
 else
  if (isNav4)
   alert ('ctrl-D per aggiungere ai preferiti');
  else
   alert ('non è possibile aggiungere bookmark');
}

function popUp(pPage)
{ var winOpts = 'resizable=yes,scrollbars=yes,width=500,height=350'; popUpWin = window.open(pPage,'popWin',winOpts); }

function doLoadSec(s)
{
// the timeout value should be the same as in the "refresh" meta-tag
 var tempo;
 tempo = 1000 * s;
 setTimeout( "refresh()", tempo);
}

function refresh()
{ window.location.href = window.location.href; }

function ArrayWrite(aText)
{ document.writeln(aText.join('')) }

function ArrayMake(darray,n)
{ darray.length = n; for(var i = 0; i < n; i++) darray[i] = new Array(); }

function ArrayMake2(n)
{
  this.length = n;
  for (i=1;i<=n;i++){ this[i]=0;  }
  return this;
}

function htm_button(sText, sLink)
{
// Write HTM_BUTTON  into page
 var aT = new Array(); var i=0;

 aT[i++]='<div align="center"><center>';
 aT[i++]='<table border="3" bgcolor="#808080"><tr>';
 aT[i++]='<td bgcolor="#FFFF00" bordercolorlight="#800000" bordercolordark="#000000" bordercolor="#800000"><font size="4"><strong><a href="'+ sLink +'" target="_parent"><font';
 aT[i++]='face="Arial" color="#FFFF00"><img src="../wmmedia/indietro.gif"';
 aT[i++]='border="0" width="18" height="14"></font></a></strong> <strong><font';
 aT[i++]='face="Arial" color="#FFFF00"><a href='+ sLink + ' target="_parent">' + sText + '</a></font></strong></font></td>';
 aT[i++]='</tr></table></center></div>';

 return aT.join('');
}

function NF_DebugPrint(sProc, sText)
{
 if (NT_Debug != 0)
  if (sProc==NT_DebugProc) document.writeln("<p align=left>Debug (" + sProc + "): " + sText + "</p>");
}

//code below found here:  http://www.marzie.com/devtools/javascript/functions.asp
function strLtrim(s)
{ return s.replace( /^\s*/, "" ); }
function strRtrim(s)
{ return s.replace( /\s*$/, "" ); }
function stRtrim ( s )
{ return strRtrim(strLtrim(s));   }

function strMid(str, start, len)
{
 if (start < 0 || len < 0) return "";
 var iEnd, iLen = String(str).length;
 if (start + len > iLen)
  iEnd = iLen;
 else
  iEnd = start + len;

 return String(str).substring(start,iEnd);
}