// **********************************************************************************************
//  MyVoice® Net Facile
//  v.2.0.1
//  developed & engineered by Piero Alcamo & Francesco Spadoni
//  ©2004 Rigel Engineering S.r.l.
// **********************************************************************************************

/******************           DATI LICENZA MyVoice® Net           ***********/
var companyDefault="Zone Umide Toscane";
var domainDefault="zoneumidetoscaneit";
var serial="MV11-A721-94FD-B888-1144-43A4-780A";


/*****************************   ACCESS KEY      ********************************** 
* Per aggiungere nuovi accesskey definirli in questa sezione e modificare la funzione getkey. */
var keyplaysel="6" // sintesi del testo selezionato	
var keyplay="7";   // Play
var keystop="8";   // Stop
var keyloop="9";   // Loop
var keypause="0";  // Pause
var keyshow="5";   // Show floating panel

// *********************************************************************************

// Var globali
var myvautolib=0;
var tsind = 0;
var dirhome='';
/*Sets the dirhome variable*/
function setDirhome()
{ if (dirhome!='') return;
var scripts = document.getElementsByTagName('script');
for (var i=0;i<scripts.length;i++)
   if (scripts[i].src!=null && scripts[i].src.toLowerCase().indexOf('myv-facile.js')>-1)
		dirhome=scripts[i].src.substring(0,scripts[i].src.toLowerCase().indexOf('myv-facile.js'));
}
setDirhome();

var namePlugin = "MyVoice Plugin"
var InternetExplorer=navigator.appName.indexOf("Microsoft")!=-1

var bVer = parseInt(navigator.appVersion);
var gMyVoiceTalk;

// Oggetto Myvoice corrente
var myVoiceObj;
var MyVoiceId;
var UseMyVoice=0;

//variabile usata per mostrare la finestra che avverte quando l'oggetto myvoice non è installato o non è disponibile per l'OS corrente
var showNoMyvUsable=true;
// variabile usata per rendere invisibile il floating panel quando nel caso di CreaOggettoMyVoice('id','false','true'), cioè in caso di floating panel invisibile al caricamento della pagina
var hideFloatPanel=false;
var topFloat=10;
	

//Variabili di default per la creazione dell'oggetto MyVoice e per il pannello
var codebaseDefault="http://www.myvoice.it/myvoice"
var srcDefault=dirhome+"dummy.myv";
var ramDefault="false"
var autostartDefault="false"
var layoutDefault="true"
var floatingDefault="true"
var currFloat=floatingDefault;
var width;
var widthDefault=138
var heightDefault=19
var height;

var timestamp; //indica il momento in cui è stata fatta l'ultima getMyVoiceObject()

var debug = true; //visualizzare alert sul funzionnamento di myvoice se è true
var installationDebug=false;

// var globale testo selezionato con mouse
var selezione="selezionare prima una porzione di testo";

/*
   Le variabil seguenti servono a gestire diversi speakers
   Caratteristiche di uno Speaker:
       - id
       - voice (male,female)
       - speed (1-10)
       - tone (1-10)
*/
var speakers=new Array();
var currSpeaker='default'; //Speaker corrente
var modifyCurrSpeaker=false;
var defaultSpeaker='default'; //Speaker di default
var preferredSpeaker='';

/********************* Gestione profili *****************************/
var withProfiles=false; //Utilizzata per sapere se si utilizza creaoggetto con profili o no

/*********************************************************************/
var reset=0;
var audio=true; //se il plug-in è abilitato o meno

/* Ogni volta che viene caricato un URL (SpeakURL e SetSource) questa variabile si aggiorna;
	Quando si disabilita il plugin (setAudio(false)), viene simulata la disabiltazione del plugin
	caricando l'url empty.myv; quando si riabilita il plugin viene ricaricato l'ultimo URL valido prima
	della disabilitazione, che è contenuto dentro questa variabile.
	(vedi SpeakURL, SetSource e setAudio per funzionamento)
*/
var lastURLLoaded=srcDefault;

var nostop = false; //utilizzato da PlayURLCond, PlayTestoCond e ManageSpeakerProfile

var numinit = 0;

//utilizzato solo per netscape
var initialized = false;
var srctxt;
var parlatxt;
var continit = 0;

/* Evita l'esecuzione delle funzioni quando la pagina viene scaricata (vedi managespeakerprofile) */
var unloaded=false;
window.onunload=closeall;
function closeall(){unloaded=true; Stop();}


//function init() {}

/********************************************************************/
/******************   FUNZIONI BASE      ****************************/
/********************************************************************/
function SpeakText(txt,rep)
{
	if (!audio) return;
	if (!InternetExplorer)
		{
		if (!initialized)
			{
			if (rep==null) parlatxt = txt;
			window.setTimeout('SpeakText("testo","repeat")',50);
			return;
			}
		else {if (rep=="repeat") txt = parlatxt;}
		}
	var myvobj = getMyVoiceObject()
	if (myvobj==null) return;
	myvobj.Speak(txt);
}


function SpeakLink(txt)
{
	SpeakText(txt)
}



function SetSource(str,rep)
{
	if (!audio) return;
	if (!InternetExplorer)
		{
		if (!initialized)
			{
			if (!rep) srctxt = str;
			window.setTimeout('SetSource("' + srctxt + '","repeat")',50);
			return;
			}
		else
			{if (rep=="repeat") str = srctxt;
			}
		}
	var MyVoiceObj = getMyVoiceObject()
	if (MyVoiceObj==null) return;
    MyVoiceObj.SetSource(str);
	lastURLLoaded = str;
}


function SpeakURL(url)
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.SpeakURL(url);
   lastURLLoaded = url;
}


function Play()
{
   if (!audio) return;
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.Start();
}


function Stop()
{
   if (!InternetExplorer && !initialized) return;
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.Stop();
}

function PauseResume() {if (isRunning()) Pause(); else Resume();}

function Pause()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.Pause();
}


function Resume()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.Resume();
}


function GetSpeed()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj== null) return;
   return MyVoiceObj.GetSpeed();
}


function SetSpeed(vv)
{ //set speed when vv is a string containing a number
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   var n = parseInt(vv);
   MyVoiceObj.SetSpeed( n );
}


function GetTone()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   return MyVoiceObj.GetTone();
}


function SetTone(vv)
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   var n = parseInt(vv);
   MyVoiceObj.SetTone(n);
}


function GetLoop()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   if (MyVoiceObj.IsLooping()) {return 'ON';}
   else {return 'OFF';}
}


function SetLoop(n)
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   if (n == 1) {MyVoiceObj.Loop(true);}
   else {MyVoiceObj.Loop(false);}
}

function LoopToggle() {if (GetLoop()=="ON") SetLoop(false); else SetLoop(true);}

function GetVoice()
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   return MyVoiceObj.GetVoice();
}


function SetVoice(voice)
{
   MyVoiceObj = getMyVoiceObject()
   if (MyVoiceObj==null) return;
   MyVoiceObj.SetVoice(voice);
}


function isRunning()
{
	myvobj = getMyVoiceObject()
	if (myvobj==null) return;
	return myvobj.IsRunning();
}

/********************************************************************/
/*********************  FUNZIONI UTENTE  ****************************/
/********************************************************************/

/*
	Inserisce un oggetto MyVoice nella pagina html con i seguenti parametri:
	 __________________________________________________________________________________________
	| id		     | Identificativo														   |
	| visibile       | true (Default) = visibile ,  false=nascosto							   |
	| floating	     | true (Deafult) = pannello float, false = pannello fisso				   |
	 ------------------------------------------------------------------------------------------
    Di questi parametri solo il primo (id) è obbligatorio.
    Tutti gli altri hanno dei valori di default.
*/
function CreaOggettoMyVoice(id, visibile, floating)
{
	width=widthDefault
	height=heightDefault
	var b = InsertMyVoiceObject(id,width,height,visibile,floating,srcDefault,codebaseDefault,autostartDefault,ramDefault,companyDefault,domainDefault)
	return b;
}


/** Carica l'url specificato nell'oggetto; */
function CaricaURL(url)
{
   SetSource(url);
}


/**
	Le tre funzioni seguenti riproducono rispettivamente:
	- Il testo contenuto nell'url (ParlaURL);
	- Il testo passato come parametro (ParlaTesto)
	- Il testo contenuto nell'url caricato nell'oggetto myvoice (Riproduci);
		tale url può essere caricato usando la funzione CaricaURL oppure passandolo
		con il parametro src in fase di creazione dell'oggetto MyVoice
	Inoltre le tre funzioni hanno due parametri opzionali, speaker e profilo, utilizzati,
	rispettivamente, per specificare lo speaker che si vuole utilizzare per la riproduzione,
	e sotto quale profilo la riproduzione è ritenuta valida.
*/
function ParlaURL(url,speaker,profilo,rep)
{
	if (!manageSpeakerProfile(speaker,profilo)) return;

	if (!InternetExplorer)
		{
		if (!initialized)
			{
			if (!rep) {urlinit=url; speakerurl = speaker; profilourl=profilo}
			if (speakerurl != null) speaker = '"' + speakerurl + '"'; else speaker=null;
			if (profilourl != null) profilo = '"' + profilourl + '"'; else profilo=null;
			window.setTimeout('ParlaURL("' + urlinit + '",'+ speaker +','+ profilo +',"repeat")',100);
			return;
			}
		else
			{if (rep=="repeat") {url = urlinit; speaker=speakerurl; profilo=profilourl}
			}
		}

	SpeakURL(url);
}


function ParlaTesto(text,speaker,profilo,rep)
{
   if (!manageSpeakerProfile(speaker,profilo)) {return;}
   if (!InternetExplorer)
		{
		if (!initialized)
			{
			if (!rep) {textinit=text; speakertext=speaker; profilotext=profilo}
			if (speakertext != null) speaker = '"' + speakertext + '"'; else speaker=null;
			if (profilotext != null) profilo = '"' + profilotext + '"'; else profilo=null;
			window.setTimeout('ParlaTesto("' + textinit + '",'+ speaker +','+ profilo +',"repeat")',100);
			return;
			}
		else
			{if (rep=="repeat") {text = textinit; speaker=speakertext; profilo=profilotext}
			}
		}
	SpeakText(text);
}


function Riproduci(speaker,profilo,rep)
{
   if (!manageSpeakerProfile(speaker,profilo)) return;
   Play();
}


/*
	I tre metodi seguenti hanno lo stesso significato delle tre precedenti.
	L'unica differenza è che queste sono utilizzate per poter inserire un "RITARDO",
	dopo il quale la riproduzione può iniziare.
	Un possibile utilizzo si ha quando si vogliono concatenare testi provenienti da fonti
	diverse; in questo caso il primo testo viene riprodotto subito, l'altro dopo il ritardo specificato;
	Un altro utilizzo è quando si vogliono concatenare testi utilizzando profili o speaker
	diversi, etc...
*/
function ParlaURLDopo(url,ritardo,speaker,profilo) {SpeakAtEnd(url,ritardo,speaker,profilo,null,'url')}

function ParlaTestoDopo(testo,ritardo,speaker,profilo) {SpeakAtEnd(testo,ritardo,speaker,profilo,null,'text')}

function RiproduciDopo(ritardo,speaker,profilo) {SpeakAtEnd(' ',ritardo,speaker,profilo,null,'play')}


/*
	I tre metodi seguenti, come le precedenti terne di metodi, servono, rispettivamente, a
	riprodurre il testo riferito da un URL, il testo passato come parametro, o quello
	caricato nell'oggetto MyVoice.
	La riproduzione, però, in questo caso, inizia solo se l'oggetto MyVoice no sta già
	riproducendo qualcosa.
	Un utilizzo possibile è quello di utilizzarlo quando si raccoglie l'evento 'onmouseover'
	su un oggetto grande, quale un'intera tabella; in questo caso, infatti, se, durante la
	riproduzione delle informazioni legate alla tabella, l'utente muove il mouse, pur
	restando all'interno della tabella, viene rilevato un nuovo evento onmouseover e quindi
	la riproduzione ricomincia da capo. Con i tre metodi seguenti si evita questo inconveniente.
*/

function ParlaURLCond(url,speaker,profilo) {SpeakIfNotRunning(url,speaker,profilo,'url')}

function ParlaTestoCond(testo,speaker,profilo) {SpeakIfNotRunning(testo,speaker,profilo,'text')}

function RiproduciCond(speaker,profilo) {SpeakIfNotRunning(' ',speaker,profilo,'play')}


/** Aggiunge un nuovo speaker */
function AggiungiSpeaker(id,tipovoce,velocita,tono)
  {
  if (getSpeaker(id,'noalert')!=null) {alert('Speaker '+ id + 'già esistente'); return;}
  var n = speakers.length
  speakers[n] = new Array()
  speakers[n][0]= id
  speakers[n][1]= tipovoce
  speakers[n][2]= velocita
  speakers[n][3]= tono
  }



/** Modifica le caratteristiche dello speaker di default */
function ImpostaSpeakerDefault(tipovoce,velocita,tono)
{
	ModificaSpeaker('default',tipovoce,velocita,tono);
}


/** Modifica le caratteristiche di uno speaker già esistente  */
function ModificaSpeaker(id,tipovoce,velocita,tono)
  {
  var sp = getSpeaker(id,'noalert')
  if (sp!=null)
	  {sp[1]= tipovoce; sp[2]= velocita; sp[3]= tono;
	  }
  else AggiungiSpeaker(id,tipovoce,velocita,tono)
  }


/** dice se MyVoice è abilitato o meno */
function MyVoiceAbilitato() {return getAudio();}

/** b=false -> MyVoice disabilitato; b=true -> MyVoice abilitato */
function AbilitaMyVoice(b)
{
   setAudio(b);
   if (document.images['enableimage'])
      {
      if (b)
		 {
		 document.images['enableimage'].src=dirhome+'checkx.gif'
		 document.images['enableimage'].alt="Clicca per disabilitare MyVoiceNet"
		 }
	  else
	     {
	     document.images['enableimage'].src=dirhome+'check.gif'
	     document.images['enableimage'].alt="Clicca per abilitare MyVoiceNet"
	     }
	  }
}


/********************************************************************/
/********************************************************************/
/********************  FUNZIONI DI SUPPORTO  ************************/
/********************************************************************/
/********************************************************************/
function SpeakAtEnd(url,time,speaker,profile,timest,type)
{
   if (profile!=null) {if (profile!=currProfile) return;}
   else
      {
      if (existsProfile(speaker)) {if (speaker!=currProfile) return;}
      }

   if (timest!=null) {if (timest!=timestamp) return;}
   var sp = speaker
   var pr = profile
   if (sp!=null) sp = '"'+sp+'"'
   else sp = null;
   if (pr!=null) pr = '"'+pr+'"'
   else pr = null;

   if (timest==null)
      {window.setTimeout('SpeakAtEnd("'+url+'",'+ time +','+ sp +',' + pr + ',"' + timestamp + '","'+ type+'")',time)
      }
   else
      {
	  MyVoiceObj = getMyVoiceObject();
	  if (MyVoiceObj!=null)
		 {
		 if (!MyVoiceObj.IsRunning())
            {
			if (type=='url') ParlaURL(url,speaker,profile);
			else if (type=='text') ParlaTesto(url,speaker,profile);
				 else if (type=='play') Riproduci(speaker,profile);
			}
		 else
            {window.setTimeout('SpeakAtEnd("'+url+'",'+ time +','+ sp +',' + pr + ',"' + timestamp + '","'+ type+'")',500)
		    }
		}
      }
   return;
}


function SpeakIfNotRunning(url,speaker,profile,type,ok)
{
   if (profile!=null)
      {if (profile!=currProfile) return;
      }
   else
      {
      if (existsProfile(speaker))
         {if (speaker!=currProfile) return;
         }
      }
   if (!nostop)
	  {
	  if (type=='url') ParlaURL(url,speaker,profile);
			else if (type=='text') ParlaTesto(url,speaker,profile);
				 else if (type=='play') Riproduci(speaker,profile);
	  nostop=true;
	  }
   return;
}


function getAudio() {return audio;}

function setAudio(b)
{
   if (!b)
   	{
	if (myVoiceObj!=null) myVoiceObj.SetSource(dirhome+'empty.myv');
	Stop();
	}
   audio = b;
   if (b) SetSource(lastURLLoaded);
}


function getMyVoiceObject()
{
   if (!UseMyVoice) return null;
   if (!audio) return null;
   timestamp = getTimestamp()
   if (myVoiceObj==null)
      {myVoiceObj=setMyVoiceObject(MyVoiceId);
      }
   return myVoiceObj;
}


function getTimestamp()
{
	ts = new Date().toGMTString()
	tsind++
	if (tsind>500) tsind=0
	return ts+tsind;
}


function setMyVoiceObject(objname)
{
   var myvObj = InternetExplorer ? document.all(objname) : document.embeds[objname];
   return myvObj;
}


function getSpeaker(id,yy)
{
   var tp=-1
   for (var i=0; i<speakers.length && tp==-1; i++)
      {if (speakers[i][0] == id) tp=i
      }
   if (tp == -1)
      {
      if (yy==null) alert('Speaker ' + id + ' inesistente.');
      return null
      }
   else
      {return speakers[tp];
      }
}


function setSpeaker(id)
{
   if (unloaded) return;

   if (id==null)
      {
	resetSpeaker();
      return;
      }
   Stop();

   if (id==currSpeaker && !modifyCurrSpeaker) return;
   var pp = getSpeaker(id)
   if (pp!=null)
   	 {
	 SetVoice(pp[1]);
     SetSpeed(pp[2]);
     SetTone(pp[3]);
     }
   currSpeaker=id;
   modifyCurrSpeaker = false;
}


function resetSpeaker()
{
   if (currSpeaker!=defaultSpeaker || reset>10 || modifyCurrSpeaker)
      {
      setSpeaker(defaultSpeaker)
	  reset=0
      }
   else reset++
}


function listSpeakers()
{
   var s='Elenco degli Speakers.\n \nSpeaker         Voice     Speed     Tone\n'
   for (var i=0; i<speakers.length; i++)
      {
      s=s +speakers[i][0]
      for (var j=0; j<(16-speakers[i][0].length);j++) s=s+' ';
      s=s+speakers[i][1]
      for (var j=0; j<(13-speakers[i][1].length);j++) s=s+' ';
      s=s+speakers[i][2]
      for (var j=0; j<11;j++) s=s+' ';
      s=s+speakers[i][3]+'\n'
      }
    alert(s);
}


//Gestisce i profili e gli speakers;
//ritorna true se myvoice deve riprodurre qualcosa; false se si deve interrompere
function manageSpeakerProfile(speaker,profile)
{
	if (unloaded) return false;
	if (!UseMyVoice) return false;
	if (!audio) return false;
	if (nostop)
	   {
	   var myvobj = getMyVoiceObject();
	   if (myvobj.IsRunning()) return false;
	   else nostop=false;
	   }
	if (InternetExplorer || (!InternetExplorer && initialized))
		setSpeaker(speaker);
	return true;
}


/********************************************************************/
/********  FUNZIONI PER IL CARICAMENTO DI UN OGGETTO MYVOICE  *******/
/********************************************************************/
function IsMyVoicePluginInstalled()
{
   if (navigator.appName == 'Netscape')
      {
      if (installationDebug) alert("Netscape");
      if (navigator.platform == "Win32")
         {
         if (installationDebug)
			{
			alert('win32 '+navigator.plugins.length)
			var out=''
			for (var i=0; i<navigator.plugins.length; i++)
				{out = out+i+':  '+navigator.plugins[i].name +'\n';
				}
			alert(out)
			}
         if (navigator.plugins["MyVoice Plugin "])
            {
            if (installationDebug) alert("Netscape Win32 - Spazio");
            return (1);
            }
          else
             if (navigator.plugins["MyVoice Plugin"])
                {
                if (installationDebug) alert("Netscape Win32 - NO Spazio");
                return (1);
                }
             else
                {
                if (installationDebug) alert('PlugIn not found')
                return (0);
                }
         }
      else //platform Mac
         if (navigator.plugins["MyVoice Plugin"])
            {
            if (installationDebug) alert("Netscape Mac");
            return (1);
            }
         else
            {
            if (installationDebug) alert("Netscape - NO OS");
            return (0);
            }
      }
   else if (navigator.appName == "Microsoft Internet Explorer")
      {
      if (installationDebug) alert("Internet Explorer");
      if (navigator.platform == "Win32")
         {
         if (installationDebug) alert("Internet Explorer Win32"+"  "+CheckIEControl());
         return (CheckIEControl()); //CheckIEControl è una funzione vbscript (vedi InsertMyVoiceObject)
         }
      else
         if (navigator.platform == "MacPPC")
            {
            if (navigator.plugins["MyVoice Plugin"])
               {
               if (installationDebug) alert("Internet Explorer Mac");
               return (1);
               }
            else
               {
               if (installationDebug) alert('PlugIn not found')
               return (0);
               }
            }
          else
             {
             if (installationDebug) alert('invalid platform')
             return (0);
             }
      }
}


function MyVoiceUsable(showAlert)
{
   var UseMyVoice = 0
   if (showAlert==null) showAlert=true;
   gMyVoiceTalk = IsMyVoicePluginInstalled();	
   if (installationDebug) alert('gMyvoiceTalk: '+gMyVoiceTalk)
   if (gMyVoiceTalk)
     {
     if (navigator.platform == "Win32")
        {
        if ((navigator.appName == "Netscape") && (bVer < 3)) { if (showAlert) MacOSNetscapeAlert();}
        else
           if ((navigator.appName == "Netscape")||(navigator.appName == "Microsoft Internet Explorer")) 
		   	  {UseMyVoice = 1;
			  }
           else {if (showAlert) WinOSAlert();}
        }
     else //MAC
        if (navigator.platform == "MacPPC")
           {
           if (navigator.appName == "Netscape")
              {
              if (bVer > 3) {UseMyVoice = 1;}
              else {if (showAlert) MacOSNetscapeAlert();}
              }
           else {if (showAlert) MacOSNetscapeAlert();}
           }
        else {if (showAlert) OSAlert();}
     }
  else {if (showAlert) NoMyVoiceAlert();}

  return UseMyVoice;
}


function restoreFloatValues()
	{
	showpanel(false,false); 
	if (InternetExplorer) panelobj.style.top=topFloat+'px'; 
	panelobj.style.zIndex=3;
	}


function InsertMyVoiceObject(id,width,height,layout,floating,src,codebase,autostart,ram,company,domain)
   {
   if (layout==null) layout=layoutDefault 
   if (floating==null) floating=floatingDefault
   if (codebase==null) codebase=codebaseDefault
   if (src==null) src=srcDefault
   if (ram==null) ram=ramDefault
   if (autostart==null) autostart=autostartDefault
   if (company==null) company=companyDefault
   if (domain==null) domain=domainDefault
  
   // Inserisco la funzione javascript CheckIEControl
   document.write('<SCRIPT type="text/vbscript"> \n')
   document.write('Function CheckIEControl() \n')
   document.write('Dim MyVoiceControl \n')
   document.write('On Error Resume Next \n')
   document.write('CheckIEControl = 0 \n')
   document.write('Set MyVoiceControl = CreateObject("MVCONTROL.MVControlCtrl.1") \n')
   document.write('if (IsObject(MyVoiceControl)) then CheckIEControl = 1 \n')
   document.write('set MyVoiceControl = nothing \n')
   document.write('End Function \n')
   document.write('</SCRIPT>')
	
	var out='';
	currFloat=floating;
	
	UseMyVoice = MyVoiceUsable(false);
	if (floating=="true" && (showNoMyvUsable || UseMyVoice)) 
		{
		if (layout=='false') hideFloatPanel=true;  // Utilizzato per rendere il myvdrag invisibile al caricamento della pagina
		//Div principale
		out+='<div id="myvdrag" style="left:10px;'
		if (hideFloatPanel) 
			{
			if (InternetExplorer) {out+=' top:1100px;'} else {out+=' top:'+topFloat+'px;'}
			out+=' z-index:0;' //on window.onload restore real values invoking restoreFloatValues() function
			}
		else out+=' top:'+topFloat+'px; z-index:5;'
		out+=' position:absolute; border-width:thin;'
		out+=' height:50px; border-style:ridge; background-color:#EFEFEF; padding:0px; margin:0px;" >'
		//Inizio MyvBar
		var myvbarwidth=170;
		if (withProfiles) myvbarwidth+=20;
		out+='<div id="myvbar" style="cursor:move; width: '+myvbarwidth+'px; font-weight:bold; font-size:11px; font-family:\'Lucida Grande\', verdana, arial, helvetica, sans-serif; padding:2px; margin:0; margin-bottom:5px; color:white; background-position:left; background-image:url('+dirhome+'bgbar.bmp); background-repeat:no-repeat">'
		out+='<a href="http://www.myvoice.it" title="vai al sito di myvoice" onmouseover="ParlaTesto(\'Vai al sito di my voice\')" onfocus="ParlaTesto(\'vai al sito di my voice\')">'
		out+='<img src="'+dirhome+'logo.gif" style="width:15px; border:0; background:transparent;" alt="logo myvoice" />'
		out+='</a>' // Logo myvoice
		var ww=25; if (withProfiles) ww+=20;
		out+='<span style="vertical-align:top; padding:0; padding-right:'+ww+'px; padding-left:2px;">MyVoice&reg; Plugin'
		if (!InternetExplorer) out+='&nbsp;';
		out+='</span>'
		out+='<span>'
		out+='<a onclick="showpanel(false)" style="cursor:default; text-align:right" onmouseover="ParlaTesto(\'Clicca per chiudere il pannello\')" onfocus="ParlaTesto(\'Clicca per chiudere il pannello\')">'
		out+='<img src="'+dirhome+'cancel.gif" style="border:0;" onmousedown="this.src=\''+dirhome+'cancelx.gif\'" onmouseup="this.src=\''+dirhome+'cancel.gif\'" alt="Chiudi il pannello" />'
		out+='</a></span>'
		out+='</div>' //FINE MYVBAR */
		document.write(out); 
		out='';
		layout="true"; //Se voglio il pannello floating il layout mi indica solo se inizialmente il pannello è visibile o meno
		
		/*Used for drag the floating panel*/
		setpanelobject();
		panelobj.onmousedown=mousedown;
		}
		
   UseMyVoice = MyVoiceUsable();
	
   if (UseMyVoice)
     {
     if (getSpeaker('default','noalert')==null) AggiungiSpeaker('default','male',5,5);
     if (MyVoiceId==null) MyVoiceId=id;
	 	 	
    out+='<div id="myvdiv" style="cursor:default;'
	if (layout=='false') 
		{
		out+=' visibility:hidden;'
		width=1; height=1;
		}
	out+='">'
	if (layout!='false') 
		{
		out+='<a onclick="enabledisable()" style="padding:0; margin:0; padding-left:4px; float:left">'
		out+='<img name="enableimage" style="border:0" src="'+dirhome+'checkx.gif" height="'+height+'" width="22" alt="Clicca per disabilitare MyVoiceNet" />'
		out+='</a>'
		}
	if (withProfiles && layout!='false')
	   {
		out+='<a href="#" onclick="openProfileWindow()" style="float:left;">';
		out+='<img src="'+dirhome+'manageprofile.gif" style="border:0; height:"'+height+'px;"';
	    out+=' onmousedown="this.src=\''+ dirhome +'manageprofilex.gif\'" onmouseup="this.src=\''+ dirhome +'manageprofile.gif\'"';
	    out+=' alt="Gestione profili" /></a>';
		}
		
	out=out + '<OBJECT style="background:gray; float:left;" classid="clsid:4866B425-40EA-11D3-97D2-0060085F3E07"';
	out=out + ' codebase="'+codebase+'"';
	out=out + ' ID="' +id+ '" WIDTH="' + width + '" HEIGHT="' + height + '">\n';
	out=out + '<PARAM NAME="SRC" VALUE="' + src + '">\n';
	out=out + '<PARAM NAME="LANGUAGE" VALUE="ita">\n';
	out=out + '<PARAM NAME="VOICE" VALUE="' + speakers[0][1] + '">\n';
	out=out + '<PARAM NAME="RAM" VALUE="' + ram + '">\n';
	out=out + '<PARAM NAME="SPEED" VALUE="' + speakers[0][2] + '">\n';
	out=out + '<PARAM NAME="TONE" VALUE="' + speakers[0][3] + '">\n';
	out=out + '<PARAM NAME="LOOP" VALUE="false">\n';
	out=out + '<PARAM NAME="AUTOSTART" VALUE="' + autostart + '">\n';
	out=out + '<PARAM NAME="LAYOUT" VALUE="' + layout + '">\n';

    out=out + '<PARAM NAME="COMPANY" VALUE="' + company + '">\n';
    out=out + '<PARAM NAME="DOMAIN" VALUE="' + domain + '">\n';
    out=out + '<PARAM NAME="SN" VALUE="' + serial + '">\n';
	out=out + '<embed type="plugin/x-myvoice" src="' + src + '"';
    out=out + ' name="'+id+'" width="' + width + '" height="' + height + '"';
    out=out + ' language="ita"';
    out=out + ' voice="' + speakers[0][1] + '"';
    out=out + ' ram="' + ram  + '"';
    out=out + ' speed="' + speakers[0][2] + '"';
    out=out + ' tone="' + speakers[0][3] + '"';
    out=out + ' loop="false"';
    out=out + ' autostart="' + autostart +  '"';
    out=out + ' layout="' + layout + '"';

    out=out + ' company="' + company + '"';
    out=out + ' domain="' + domain + '"';
    out=out + ' sn="'+ serial + '"';
	out=out + ' pluginpage= "'+ codebase +  '">\n';

    out=out + '</embed>';
	//LINE ADDED 30/06/2003 for accessibility reasons (1.1.6)
    out=out+'<noembed>Oggetto MyVoice</noembed>'
    out=out + '</OBJECT>';
	out+='</div>'
	document.write(out);
	
	if (floating=="true") {document.write('</div>');}
	
    if (installationDebug) alert(out)
	
    //procedura utilizzata per attendere la fine del caricamento del plugin
    if (!InternetExplorer) waitInitialization()
	
	if (hideFloatPanel && !myvautolib) {window.onload=function(){showpanel(false,false);}}
	
	return true;
     }
   else
     {
	if (floating=="true" && (showNoMyvUsable || UseMyVoice)) {document.write('</div>');}
     if (installationDebug)
		{
		document.write('<br /><br />INSTALLAZIONE NON CORRETTA<br /><br />');
		document.write('Prova a reinstallare il Plugin o ActiveX<br />');
		document.write('Se il problema persiste contattare il supporto tecnico.<br />');
		}
	 return false;
     }	
}

/********************************************************************/
/********************************************************************/
/************  FUNZIONI UTILIZZATE IN CASO DI ERRORE  ***************/
/********************************************************************/
/********************************************************************/
function MacOSNetscapeAlert()
{
   if (!showNoMyvUsable) return;
   before();
   document.write("<b>MyVoice&reg; Plugin</b> non supportato dal tuo browser ma solo da NS 3.0");
   after();
}

function WinOSAlert()
{
   if (!showNoMyvUsable) return;
   before();
   document.write("<b>MyVoice&reg; Plugin</b> non supportato dal tuo browser ma da NS e IE.");
   after();
}

function OSAlert()
{
	if (!showNoMyvUsable) return;
   before();
   document.write("<b>MyVoice&reg; Plugin</b> disponibile solo per Windows e MacOS.");
   after();
}

function NoMyVoiceAlert()
{
	if (!showNoMyvUsable) return;
   before();
   document.write('<b>MyVoice&reg; Plugin</b> non installato.<br />');
   document.write('<a href="#" style="color:blue;" onkeypress="window.open(\'http://www.myvoice.it/download.shtml\')" onclick="window.open(\'http://www.myvoice.it/download.shtml\')">');
   document.write('Installa il Plugin</a>');
   after();
}

function before()
{
	var fontSize=InternetExplorer?'xx-small':'x-small';
    var out='<div style="font-family:Verdana; font-size:'+fontSize+'; width:170px;">'
	if (currFloat=="false") out+='<div style="background-color:#000099; color:white; text-align:center">Attenzione!!!!</div>';
   	out+='<div style="padding-left:2px; padding-bottom:5px; font-family:Arial; font-size:1.1em; '
	if (currFloat=="false") out+='background-color:#FFFF77; color:000066;';
	out+='">'
   	document.write(out);
}

function after() {document.write('</div></div>')}
/***************************************************************************/

function enabledisable() {AbilitaMyVoice(!getAudio())}

function newwindow()
{
	newWindow = window.open("mverror.htm", "ERRORE", "top=50,left=50,width=200,height=150,scrollbars=no,toolbar=no,noresize,menubar=no")
}

function IsInitialized() {return initialized;}

function waitInitialization()
{
	if (!initialized && continit<50)
		{
		window.setTimeout('waitInitialization()',200);
		myvobj = getMyVoiceObject();
		if (myvobj!=null) {initialized = myvobj.IsInitialized;}
		continit++;
		}
	else {initialized=true;}
return true;
}


function getkey(keyStroke) {
	isNetscape=(keyStroke && keyStroke.which);
	eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
	which = String.fromCharCode(eventChooser).toLowerCase();
	if ((isNetscape && keyStroke.altKey && keyStroke.shiftKey) || (!isNetscape && window.event.altKey  && window.event.shiftKey))
	   {
	   if (!MyVoiceAbilitato() && which!=keyshow) return;
	   switch (which)
			{
			case keyplaysel: {ParlaTesto(selezione); break;}
			case keyplay: {Riproduci(); break;}
			case keystop: {Stop(); break}
			case keyloop: {if (GetLoop()=="ON") SetLoop(false); else SetLoop(true); break;}
			case keypause: {if (isRunning()) Pause(); else Resume();break;}
			case keyshow: {showpanel(!panelvisible(),false);}
	   		}
	}
}

document.onkeydown = getkey;

/*******************************************************************************************
*************************       SELEZIONA E PARLA         **********************************
*******************************************************************************************/
var selectedString=""
function CopiaSelezione()
{
	if (InternetExplorer)
	   {rng = document.selection.createRange(); selectedString=rng.text; 
	   }
	else 
	   {
	   if (window.getSelection()) selectedString = window.getSelection(); 
	   else selectedString = document.getSelection();
	   }
	if (selectedString == "") return ;
	selezione=selectedString;
	ParlaTesto(selezione); 
} 

function LanciaCopiaSelezione()
{
	setTimeout("CopiaSelezione()",50);
	return true;
}

document.onmouseup=LanciaCopiaSelezione;
/**********************************************************************************************/

function existsProfile(p){return false;}

/************************************************************
 *** FUNZIONI PER ESEGUIRE IL DRAG DEL PANNELLO FLOTTANTE ***
************************************************************/
var lastbutton, mousebutton, left, top, xx, yy, panelobj, firedobj;
var scrollcomp;
var dragapproved=false;

//invoked when start drag on the floating panel (myvdrag). Ref: Seek "panelobj.onmousedown=mousedown" in InsertMyVoiceObject function
function mousedown(evt)
{
	if (panelobj==null) {setpanelobject();}
	if (InternetExplorer) {mousebutton = window.event.button} else {mousebutton = evt.which;}
	if (panelvisible() && mousebutton<=1) {return drags(evt);}
	return false;
}

function drags(evt)
	{
	firedobj = InternetExplorer ? event.srcElement : evt.target;
	var topelement = InternetExplorer ? "BODY" : "HTML";   
	
	if (InternetExplorer)
	   {if (firedobj.componentFromPoint(event.clientX, event.clientY).substring(0,6) == "scroll") return false}
	   
	while (firedobj.tagName != topelement && firedobj.id != "myvbar")
       {firedobj=InternetExplorer ? firedobj.parentElement : firedobj.parentNode
       }
	if (firedobj.id=="myvbar")
		{
	   	dragapproved=true
		panelobj.onmouseup=mouseup
		firedobj.onmousemove=move
		//panelobj = firedobj;
	    left = parseInt(panelobj.style.left+0);
       	top = parseInt(panelobj.style.top+0);
		xx=InternetExplorer? event.clientX : evt.clientX
       	yy=InternetExplorer? event.clientY : evt.clientY
		}
     return false
	 }

function mouseup(evt) {dragapproved = false; firedobj=null; return true}

function move(e)
	{
	if (dragapproved && panelobj!=null)
		{
	 	if (panelobj==null) {return false;}
	   	panelobj.style.left=InternetExplorer? left+event.clientX-xx : left+e.clientX-xx+'px'
       	panelobj.style.top=InternetExplorer? top+event.clientY-yy : top+e.clientY-yy+'px'
     	}
	return false;
	}
	
function showpanel(show, showAlert) 
	{
	if (showAlert==null) {showAlert=true;}
	if (panelobj==null) setpanelobject();
	if (panelobj==null) return;
		
	if (!show && showAlert) {alert('Il pannello di controllo può essere riaperto utilizzando la combinazione di tasti SHIFT + ALT + '+keyshow); /*confirm()*/}
	panelobj.style.visibility = show ? 'visible' : 'hidden';
	}

function setpanelobject(){panelobj=document.getElementById('myvdrag');}
	
function panelvisible() {if (panelobj!=null) return panelobj.style.visibility!='hidden'; return false;}
/** FINE DELLE FUNZIONI PER IL DRAG DEL PANNELLO FLOTTANTE*/
