var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
function mouseMove(ev){
	ev           = ev || window.event;
	mousePos = mouseCoords(ev);
	//var tg = (window.event) ? ev.srcElement : ev.target;
	//document.getElementById('campochiave').value = mousePos.x + " "+ mousePos.y
	if (dragapproved){
        move()
		if ( isFirefox ) {
		//document.getElementById('campochiave').value = a + " - " + b.width + " " + b.height + " -- " +mousePos.x + " " + mousePos.y + " " + ris;
		if ( Position.within(eledrop, mousePos.x, mousePos.y) ){
			if ( sopra == false ) {
				//document.getElementById('campochiave').value = 'dentro sopra'
				//Element.setStyle('tracce', {border:'medium solid #666666'});
				Element.setStyle('tracce', {background: 'url(immagini/menu/sftracce2.jpg)'});
				sopra = true;
			}
		}
		else {
			if ( sopra ) {
				//document.getElementById('campochiave').value = 'fuori'
				//Element.setStyle('tracce', {border:'medium solid #D1EC67'});
				Element.setStyle('tracce', {background: 'url(immagini/menu/sftracce1.jpg)'});
				sopra = false;
			}
		}
		}
		return false;
    }
}
function mouseUp(ev){
	if (dragapproved){
	if ( BrowserDetect.browser == 'Firefox' ) {
		mousePos = mouseCoords(ev);
		if ( Position.within(eledrop, mousePos.x, mousePos.y) ){
			droppato()
		}
	}
	}
	dragapproved=false;
	parent.document.getElementById('imgdrag').style.left='-1000px'
    parent.document.getElementById('imgdrag').style.top='-1000px'
	
}
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y:ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
}
valoreric = 'false';
var popupWin = null;
var branoattuale = null;
function stoppa() {
	if( popupWin && !popupWin.closed ) {
		popupWin.stoppa();
	}
}
function prediv() {
	codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
    parent.document.getElementById('content').innerHTML = codice;
    parent.document.getElementById('testaric').innerHTML = '';
	parent.document.getElementById('footerricerca').innerHTML = '';
	parent.document.getElementById('contentprog').innerHTML = '';
	Element.show( 'content' );
	Element.show( 'testaric' );
	Element.show( 'footerricerca' );
}
function CaricaPlayer(quale) {
    ind='player.php' + "?id=" + quale;
    parent.document.getElementById('iplayer').src = ind;
}
function thisMovie(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function chiamaPlayer(idbrano,path,t1,t2,t3,din) {
   thisMovie("player").loadAudio(path,t1,t2,t3,din);
   dragapproved=false;
   date = new Date()
   ticksua = date.getTime()
   if ( idbrano == ultimoascolto && ticksua - ticksultimoascolto < 60000 ) {
	   return false
	}
	else {
		ultimoascolto = idbrano
		ticksultimoascolto = date.getTime()
	}
   ind='aggascolti.php?idbrano='+idbrano
   new Ajax.Updater('agglog', ind, {asynchronous:false, evalScripts:true});
}
function controllaPlayer() {
   thisMovie("player").controlla();
}
function ferma() {
   thisMovie("player").fermaAudio();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var finestra = window.open(theURL,winName,features);
  finestra.focus()
}

//function primopiano() {
//  var finestra
//  alert('aaa')
//  finestra.focus()
// }

function aggtesta() {
    new Ajax.Updater('testaric', 'aggtesta.php', {asynchronous:true, evalScripts:true});
	new Ajax.Updater('footerricerca', 'aggfooter.php', {asynchronous:true, evalScripts:true});
}
function cercab(par) {
  parent.document.getElementById('contentprog').innerHTML = '';
  mostraric()
  prediv()
  param = "cb=si&afric="+valoreric+"&"+par;
  new Ajax.Updater('content', 'cercabrani.php', {asynchronous:true, evalScripts:true, parameters: param});
}
function cercaks(par) {
  parent.document.getElementById('contentprog').innerHTML = '';
  mostraric()
  prediv()
  param = "cks=si&afric="+valoreric+"&"+par;
  new Ajax.Updater('content', 'cercabrani.php', {asynchronous:true, evalScripts:true, parameters: param});
}
function imposta(val) {
  valoreric = val;
  document.forms['mod1'].afric.value = val;
  document.forms['mod2'].afric.value = val;
  if ( val == 'true' ) {
      Element.show( 'luccon' );
	  Element.hide( 'luccoff' );
  }
  else {
      Element.hide( 'luccon' );
	  Element.show( 'luccoff' );
  }
}
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_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_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

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_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 nascondiricerca() {
   Element.hide( 'content' );
   Element.hide( 'testaric' );
   Element.hide( 'footerricerca' );
}

function mostraricerca() {
   mostraric()
   Element.show( 'content' );
   Element.show( 'testaric' );
   Element.show( 'footerricerca' );
}
function ControllaF() {
  hm('box');
  if ( document.forms[0].Campoutente.value == "") {
      alert("Please insert the user name");
	  sm('box',240,140);
	  document.forms[0].Campoutente.focus()
	  return false;
  }
  if ( document.forms[0].Campopwd.value == "") {
      alert("Please insert the password");
	  sm('box',240,140);
	  document.forms[0].Campoutente.focus()
	  return false;
  }
  stringa = "utente="+document.forms[0].Campoutente.value+"&pwd="+document.forms[0].Campopwd.value;
  new Ajax.Updater('divlg', 'contuser.php', {asynchronous:false, parameters:stringa, evalScripts:true});
  return false;
}

function ControllaRP() {
  hm('boxrp');
  if ( document.forms[0].Campoutenterp.value == "") {
      alert("Please insert the user name");
	  sm('boxrp',240,140);
	  document.forms[0].Campoutenterp.focus()
	  return false;
  }
  stringa = "utente="+document.forms[0].Campoutenterp.value;
  new Ajax.Updater('agglog', 'inviapwd.php', {asynchronous:false, parameters:stringa, evalScripts:true});
  return false;
}

function aggiungiP() {
  hm('boxprj');
  if ( document.forms[0].Campoprogetto.value == "") {
      alert("Please insert the project name");
	  sm('boxprj',240,80);
	  return false;
  }
  codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Loading projects...</div>";
  parent.document.getElementById('progetto').innerHTML = codice;
  stringa = "progetto="+document.forms[0].Campoprogetto.value;
  new Ajax.Updater('progetto', 'mostraprogetto.php', {asynchronous:false, parameters:stringa, evalScripts:true});
  
  return false;
}
function stasuonando(mostra,quale) {
    branoattuale = quale;
    for (i=1; i < 1001; i++) {
	   elemento="playnow"+i;
	   el = document.getElementById(elemento);
       if (el != null ) {
	   Element.hide( elemento );
	   }
	   else {
	   break;
	   }
    }
	  Element.show( mostra );
	}
function stopcd() {
   //finestracd.close();
}
function controllaattuale() {
      for (i=1; i < 101; i++) {
	   elemento="playnow"+i;
	   el = document.getElementById(elemento);
       if (el != null ) {
	       if ( el.name == branoattuale ) {
		       Element.show( el );
		   }
	   }
	   }
	   if ( isFirefox ) {
	      document.forms['mod1'].appo.focus()
	   }

}
function puliscilista() {
	prediv();
	new Ajax.Updater('content', 'pulisciric.php', {asynchronous:true});
	parent.document.getElementById('testaric').innerHTML = '';
	parent.document.getElementById('footerricerca').innerHTML = '';
}

function move(){
if (dragapproved){
//document.getElementById('campochiave').value = mousePos.x;
z.style.left=(mousePos.x + 10) + 'px'
z.style.top=( mousePos.y -30 ) + 'px'
}
}
function iniziadrag(quale,traccia,titolo){
date = new Date()
	ticksdrag = date.getTime()
	if ( ticksdrag - ticksultimobottone < 50 ) {
				return false
	}
if ( loggato && $('tracce') ) {
//el parent.document.getElementById(quale)
tracciacorrente= traccia
dragapproved=true;
mostradrag=false
eledrop = $('tracce');
sopra=false;
sopraov=false;
a = Position.cumulativeOffset(eledrop);
b = Element.getDimensions(eledrop);
el = document.getElementById(rigacorrente);
if (el != null ) {
	Element.setStyle(el, {'background':''});
}
Element.setStyle(parent.document.getElementById(quale), {background:'#DDDDDD'});
rigacorrente=quale
z=parent.document.getElementById('imgdrag');
codice = "<img src='immagini/audio.gif' width='30' height='33' align='absmiddle' />"+titolo ;
z.innerHTML = codice;
}
//document.getElementById('campochiave').value = Element.getStyle('tracce', 'top')
}
function controlladrop() {
	if (dragapproved ){

	Element.setStyle('tracce', {background: 'url(immagini/menu/sftracce2.jpg)'});
       //Element.setStyle('tracce', {border:'medium solid #666666'});
    }
}
function annulladrop() {
	Element.setStyle('tracce', {background: 'url(immagini/menu/sftracce1.jpg)'});
       // Element.setStyle('tracce', {border:'medium solid #D1EC67'});
}
function droppato() {
	if (dragapproved){
		aggiungit = true
		date = new Date()
		if ( ultimatraccia == tracciacorrente ) {
            ticks = date.getTime()
			if ( ticks - ticksultimatraccia < 1000 ) {
				aggiungit = false
			}
		}
		if ( aggiungit == true ) {
		  ultimatraccia = tracciacorrente
		  ticksultimatraccia = date.getTime()
          codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Adding track...</div>";
        parent.document.getElementById('tracce').innerHTML = codice;
		ind = 'aggiungitraccia.php?idt='+tracciacorrente
		new Ajax.Updater('tracce', ind, {asynchronous:true, evalScripts:true});
		}
    }
}
function aggiornazonabrani() {
	    codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Loading tracks...</div>";
	    parent.document.getElementById('tracce').innerHTML = codice;
		new Ajax.Updater('tracce', 'aggiungitraccia.php', {asynchronous:true, evalScripts:true});
}
function apricop(quale,nomecop) {
	if (!dragapproved){
	c = parent.document.getElementById('copG');
	parent.document.getElementById('copertinag').src = 'immagini/waitcop.gif';
	c.style.left=(380) + 'px'
    c.style.top=( mousePos.y - 70 ) + 'px'
	ind = 'http://www.flippermusic.it/copflipper/copertineg/' + nomecop
	parent.document.getElementById('copertinag').src = ind;
	}
}
function nascondicop(){
	c = parent.document.getElementById('copG');
	c.style.left='-1000px'
    c.style.top='-1000px'
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function mostralabel(stringa,oggetto) {
	c = parent.document.getElementById('etichettalabel');
	c.innerHTML = "<span>"+stringa+"</span>";
	px = findPosX(oggetto);
	py = findPosY(oggetto);
	c.style.left=(px-104) + 'px';
    c.style.top=(py+6) + 'px';
}
function nascondilabel(){
	c = parent.document.getElementById('etichettalabel');
	c.style.left='-1000px'
    c.style.top='-1000px'
}
function mostraCD(idCD){
	nascondicop()
    prediv()
	par = 'Cerca2=ok&tempo2=All&Menucompositori=0&Menucd=' + idCD+"&afric="+valoreric;
	new Ajax.Updater('content', 'cercabrani.php', {asynchronous:true, evalScripts:true, parameters:par})
	mostraricerca();
	//new Ajax.Updater('content', ind, {asynchronous:true, evalScripts:true})
	//parent.document.getElementById('footerricerca').innerHTML = '';
}
function mostraCAT(idcat) {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 indirizzo="elencocat.php?idlib="+idcat;
	 new Ajax.Updater('content', indirizzo, {asynchronous:true, evalScripts:true})
	 indirizzo="testacat.php?idlib="+idcat;
	 new Ajax.Updater('testaric', indirizzo, {asynchronous:true, evalScripts:true})
}
function loggautente(idut,nomeut,primavolta) {
	loggato=true;
	idutente = idut
    ind = "agglog.php?idut="+idut
	faggutente = new Ajax.PeriodicalUpdater('agglog', ind, {asynchronous:true, evalScripts:true, frequency:90});
	el = document.getElementById('progetto');
	codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Loading projects...</div>";
	parent.document.getElementById('progetto').innerHTML = codice;
	Effect.Appear('progetto',{ afterFinish: caricaprog });
	if ( primavolta == true ) {
	prediv(); 
	ind = 'welcome.php?nomeut='+nomeut
    new Ajax.Updater('content', ind, {asynchronous:true, evalScripts:true})
    mostraricerca();
	}
}
function loggautenteindex(idut,nomeut) {
	loggato=true;
	idutente = idut
    ind = "agglog.php?idut="+idut
	faggutente = new Ajax.PeriodicalUpdater('agglog', ind, {asynchronous:true, evalScripts:true, frequency:90});
}

function disconnettiutente() {
	 if(faggutente!=null) faggutente.stop();
	 loggato=false;
	 idutente = ''
     Element.hide( 'content' );
     Element.hide( 'testaric' );
     Element.hide( 'footerricerca' );
	 Element.hide( 'contentprog' );
     Element.hide( 'testaprog' );
     codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
     Element.show( 'content' )
	 new Ajax.Updater('divlg', 'contuser.php?op=logout', {asynchronous:true, evalScripts:true});
	 //faggutente = new Ajax.PeriodicalUpdater('agglog', ind, {asynchronous:true, frequency:20});
	 Effect.Fade('progetto');
}


function finitidownutente() {
     Element.hide( 'content' );
     Element.hide( 'testaric' );
     Element.hide( 'footerricerca' );
	 Element.hide( 'contentprog' );
     Element.hide( 'testaprog' );
     codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
     Element.show( 'content' );
	 parent.document.getElementById('testaric').innerHTML = '';
     Element.show( 'testaric' );
	 codice = "<div align='center' class='titolo'><br><br><br>Hai terminato i download disponibili.</div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('testaric', 'testabianca.php', {asynchronous:true, evalScripts:true});
	 downfiniti = true;
}

function caricaprog(idp) {
	 new Ajax.Updater('progetto','mostraprogetto.php',{asynchronous:true, evalScripts:true});
}
function aggfootprog(idp) {
	 ind = 'aggfooterprog.php?idp='+idp
	 new Ajax.Updater('footerricerca',ind,{asynchronous:true, evalScripts:true});
}
function cambiaprog(val) {
  codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Loading projects...</div>";
  parent.document.getElementById('progetto').innerHTML = codice;
  stringa = "progid="+val;
  new Ajax.Updater('progetto', 'mostraprogetto.php', {asynchronous:false, parameters:stringa, evalScripts:true});
}
function mostragen() {
  Element.hide( 'content' );
  Element.hide( 'testaric' );
  Element.hide( 'footerricerca' );
  Element.hide( 'contentprog' );
  Element.hide( 'testaprog' );
  codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
  parent.document.getElementById('content').innerHTML = codice;
  Element.show( 'content' )
}
function mostraric() {
  Element.hide( 'contentprog' );
  Element.hide( 'testaprog' );
}
function mostraprog() {
  Element.hide( 'content' );
  Element.hide( 'testaric' );
  Element.hide( 'footerricerca' );
}
function apriprog(idp) {
  parent.document.getElementById('content').innerHTML = '';
  mostraprog() ;
  Element.show( 'footerricerca' );
  Element.show( 'contentprog' );
  Element.show( 'testaprog' );
  codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
  parent.document.getElementById('contentprog').innerHTML = codice;
  //codice = "<br /><div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /></div>";
  parent.document.getElementById('testaprog').innerHTML = '';
  parent.document.getElementById('footerricerca').innerHTML = '';
  ind1 = 'formprogetto.php?idp='+idp
  ind2 = 'tracceprogetto.php?idp='+idp
  new Ajax.Updater('testaprog', ind1, {asynchronous:true, evalScripts:true});
  new Ajax.Updater('contentprog', ind2, {asynchronous:true, evalScripts:true});
}
function rimuovidaprog(idp) {
      numcod=0;
	  stringac='';
	  for (i=1; i < 10000; i++) {
	   elemento="chk"+i;
	   el = document.getElementById(elemento);
       if (el == null ) {
		   break;
	   }
	   if ( el.checked ) {
		   numcod++
		   if ( numcod == 1 ) {
		      stringac = 'tr' + numcod + "=" + el.name
		   }
		   else {
			  stringac = stringac + '&tr' + numcod + "=" + el.name
		   }
	   }
      }
	  if ( stringac == '' ) {
		  alert('Seleziona una o più tracce per la cancellazione!')
	  }
	  else {
		var confermato = confirm('Confermi la cancellazione delle tracce selezionate?');
		if ( confermato == false ) {
			return false;
		}
	    codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
        parent.document.getElementById('contentprog').innerHTML = codice;
        ind2 = 'tracceprogetto.php?op=d&idp='+idp+"&"+stringac
        new Ajax.Updater('contentprog', ind2, {asynchronous:true, evalScripts:true});
	  }
}
function rimuoviprog(idp) {
	    var is_confirmed = confirm('Confermi la cancellazione del progetto?');
        if ( is_confirmed == true ) {
	    mostragen()
	    codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
        parent.document.getElementById('content').innerHTML = codice;
        ind2 = 'mostraprogetto.php?op=d&idp='+idp;
        new Ajax.Updater('content', ind2, {asynchronous:true, evalScripts:true});
		}
}
function ceccatutti() {
	  for (i=1; i < 10000; i++) {
	   elemento="chk"+i;
	   el = document.getElementById(elemento);
       if (el == null ) {
		   break;
	   }
	   el.checked = true;
    }
}
function dececcatutti() {
	  for (i=1; i < 10000; i++) {
	   elemento="chk"+i;
	   el = document.getElementById(elemento);
       if (el == null ) {
		   break;
	   }
	   el.checked = false;
       }
}
function scaricatutti(idutente,idprog,tipofile) {
	  numcod=0;
	  stringac='idut='+idutente+'&idprog='+idprog+'&tipof='+tipofile;
	  for (i=1; i < 10000; i++) {
	   elemento="chk"+i;
	   el = document.getElementById(elemento);
       if (el == null ) {
		   break;
	   }
	   if ( el.checked ) {
		   numcod++
			  stringac = stringac + '&tr' + numcod + "=" + el.name
	   }
      }
	  if ( numcod == 0 ) {
		  alert('Seleziona una o più tracce per il downloading!')
	  }
	  else {
	  MM_openBrWindow('http://www.primroselibrary.com/downflipper/archivio.php?' + stringac,'download','width=400,height=120,scrollbar=yes')
	  }
}
function scaricasingolo(idbrano,tipo,idutente) {
	  stringac='idut='+idutente+'&id='+idbrano+'&tipo='+tipo
	  MM_openBrWindow('http://www.digitalpony.net/down/dlfile.php?' + stringac,'download','width=400,height=120,scrollbar=yes')
}
function upprog() {
	  codice = "<br /><div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Updating Project...</div>";
      parent.document.getElementById('testaprog').innerHTML = codice;
}
function keyHandlerDown(event){
     var keyResult; 
     if (Object.isNumber(event.keyCode))   keyResult = event.keyCode;   //DOM 
    else if (Object.isNumber(event.which))     keyResult = event.which;     //NS 4 compatible 
    else if (Object.isNumber(event.charCode))  keyResult = event.charCode; 
    else  keyResult = null;    
    if ( keyResult == 32
		&& event.element(event).name != 'contactchiave'
		&& event.element(event).name != 'contacttitolo'
		&& event.element(event).name != 'titolo'
		&& event.element(event).name != 'descrizione'
		&& event.element(event).name != 'note'
		&& event.element(event).name != 'Campoprogetto'
		&& event.element(event).name != 'Campoutente'
		&& event.element(event).name != 'Campopwd'
		&& event.element(event).name != 'nomemess'
		&& event.element(event).name != 'telefonomess'
		&& event.element(event).name != 'emailmess'
		&& event.element(event).name != 'messaggiomess'
		&& event.element(event).name != 'numcd'
		&& event.element(event).name != 'cognomecomp'
	    ) {
		//alert(event.element(event).name )
	    controllaPlayer()
		event.cancelBubble = true;
        event.returnValue = false;

        if (event.stopPropagation) {
            event.stopPropagation();
            event.preventDefault();
         }
        return false;
		
	}
	//if(event.KeyCode) alert('aa');
}
function controllalimite() {
	new Ajax.Updater('agglog','contlimite.php', {asynchronous:false, evalScripts:true});
}
function aggiungitraccia(idtraccia) {
    if ( loggato ) {
	if ( $('tracce') ) {
		aggiungit = true;
		date = new Date()
		if ( ultimatraccia == idtraccia ) {
            ticks = date.getTime()
			if ( ticks - ticksultimatraccia < 1000 ) {
				aggiungit = false
			}
		}
		if ( aggiungit == true ) {
	    ultimatraccia = idtraccia
		ticksultimatraccia = date.getTime()
	    codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Adding track...</div>";
        parent.document.getElementById('tracce').innerHTML = codice;
		ind = 'aggiungitraccia.php?idt='+idtraccia
		new Ajax.Updater('tracce', ind, {asynchronous:true, evalScripts:true});
		}
	}
	else {
		alert('Nessun progetto corrente!')
	}
	}
	else {
	    alert('Per aggiungere il brano musicale ad un progetto devi prima effettuare il login!')
	}
}
function mostracontatti() {
	 Element.show( 'testaric' );
	 mostraricerca();
	//codice = "<table width='99%' border='0' cellpadding='4' cellspacing='4'><tr><td><div align='right'><img src='immagini/contactus.png' alt='New releases' width='121' height='27' /></div></td></tr>";
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'contatti.php', {asynchronous:true,evalScripts:true})
	 new Ajax.Updater('testaric', 'testacontatti.php', {asynchronous:true, evalScripts:true});
}
function mostradvd() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'dvd.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testadvd.php', {asynchronous:true, evalScripts:true});
}
function mostrahelp() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'help.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testahelp.php', {asynchronous:true, evalScripts:true});
}
function mostralicensing() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'help.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testahelp.php', {asynchronous:true, evalScripts:true});
}
function mostrasiae() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'siae.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testasiae.php', {asynchronous:true, evalScripts:true});
}
function mostraks() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'mostrachiavi.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testaks.php', {asynchronous:true, evalScripts:true});
}
function mostracm() {
	 Element.show( 'testaric' );
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', 'mostraclassici.php', {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testacm.php', {asynchronous:true, evalScripts:true});
}
function mostraabout() {
     htmlplayer = parent.document.getElementById('spazioabout').innerHTML;
	 codice = "<div align='center'><br><br><br><img src='immagini/waitscuro.gif' alt='progress' width='16' height='16' /></div>";
     parent.document.getElementById('spazioabout').innerHTML = codice;
	 new Ajax.Updater('spazioabout', 'aboutus.php', {asynchronous:true, evalScripts:true});
}
function mostraplayer() {
	 codice = "<div align='center'><br><br><br><img src='immagini/waitscuro.gif' alt='progress' width='16' height='16' /></div>";
     parent.document.getElementById('spazioabout').innerHTML = codice;
	 parent.document.getElementById('spazioabout').innerHTML = htmlplayer;
	 Effect.Appear('abus');
}
function selpaese(selpaese) {
	 codice = "<div align='center'><br /><br /><br /><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Loading Agent info...<br /><br /><br /></div>";
	 parent.document.getElementById('paese').innerHTML = codice;
	 ind = 'aggpaese.php?idp='+selpaese.value
	 new Ajax.Updater('paese', ind, {asynchronous:true, evalScripts:true})
}
function aggcontatto() {
	codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /><br />Sending message...</div>";
    parent.document.getElementById('contatto').innerHTML = codice;
}
function aggiungilib(inp,stringa) {
	st = stringa + "&idlib="+document.forms['mod1'].Menulibrary1.value;
	return st
}
function aggiungilib2(inp,stringa) {
	st = stringa + "&idlib="+document.forms['mod2'].Menulibrary2.value;
	return st
}
function cambialib() {
	if ( document.forms['mod2'].Menulibrary2.value < 1 ) {
		Effect.Fade('elencocd');
		document.forms['mod2'].Menucd.value = 0
		Effect.Appear('inscd');
	}
	else {
	codice = "<div align='center'><img src='immagini/wait.gif' alt='progress' width='18' height='18' /></div>";
	parent.document.getElementById('elencocd').innerHTML = codice;
	document.forms['mod2'].numcd.value = ''
	Effect.Fade('inscd');
	Effect.Appear('elencocd');
	indirizzo="aggpopupcd.php?idlib="+document.forms['mod2'].Menulibrary2.value;
	new Ajax.Updater('elencocd',indirizzo, {asynchronous:true, evalScripts:true})
	mostralib2();
	}
}
function mostralib1() {
	if ( document.forms['mod1'].Menulibrary1.value > 0 ) {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 indirizzo="elencocat.php?idlib="+document.forms['mod1'].Menulibrary1.value;
	 new Ajax.Updater('content', indirizzo, {asynchronous:true, evalScripts:true})
	}
}
function mostralib2() {
	if ( document.forms['mod2'].Menulibrary2.value > 0 ) {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 indirizzo="elencocat.php?idlib="+document.forms['mod2'].Menulibrary2.value;
	 new Ajax.Updater('content', indirizzo, {asynchronous:true, evalScripts:true})
	}
}
function mostralib3(indricerca) {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 indirizzo="elencocat.php?indric="+indricerca;
	 new Ajax.Updater('content', indirizzo, {asynchronous:true, evalScripts:true})
}
function mostralib4(idlib) {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 indirizzo="elencocat.php?idlib="+idlib;
	 new Ajax.Updater('content', indirizzo, {asynchronous:true, evalScripts:true})
}
function mostraelencolib() {
	 mostraricerca();
	 parent.document.getElementById('testaric').innerHTML = '';
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 Element.show( 'testaric' );
	 parent.document.getElementById('footerricerca').innerHTML = '';
	 codice = "<div align='center'><br><br><br><img src='immagini/progress.gif' alt='progress' width='100' height='100' /></div>";
     parent.document.getElementById('content').innerHTML = codice;
	 new Ajax.Updater('content', "listalib.php", {asynchronous:true, evalScripts:true})
	 new Ajax.Updater('testaric', 'testaelencolib.php', {asynchronous:true, evalScripts:true});
}
function aggtestacat() {
    new Ajax.Updater('testaric', 'testacat.php', {asynchronous:true, evalScripts:true});
}
function resettalib() {
	document.forms['mod2'].Menulibrary2.value = 0
	 cambialib() 
}
function controllachiaviduplicate(campo,selezione) {
	 stringaini = campo.value.replace(","," ")
	 stringa = stringaini.toUpperCase()
	 array_campo = stringa.split(" ")
	 array_finale = []
	 for ( i = array_campo.length; i > -1; i--) {
		 posizione = array_finale.indexOf(array_campo[i])
		 if ( posizione == -1 ) {
          array_finale.push(array_campo[i]);
		 }
     }
	 array_finale.reverse()
	 campo.value = array_finale.join(' ')
	 
}
function impostabottone() {controllalimite
		date = new Date()
		ticksultimobottone = date.getTime()
}
function botsearch() {
		if ( loggato == true ) {
		   parent.document.location = 'search.php';
		}
		else {
		   parent.document.location = 'search.php?op=login';
		}
}

function scaricafile(idbrano,idut,idlink) {
    if ( loggato ) {
        if ( downfiniti ) {
           alert('Non hai download disponibili.');
        }
        else {
		if ( idut == '' ) {
			idu = idutente;
		}
		else {
			idu = idut;
		}
        document.getElementById(idlink).href= 'http://www.primroselibrary.com/downflipper/dlfile.php?tipo=m&id=' + idbrano + '&idut=' + idu;
        window.setTimeout('controllalimite()', 500)
        }
        }
	else {
	    document.getElementById(idlink).href='#';
	    alert('Per scaricare il file audio devi prima effettuare il login!');
	}
}