// JavaScript Document

// EVENTI
function valida_ins_news()
{
 places=document.mod_ins.places.value;
 sfoglia=document.mod_ins.sfoglia.value;
 if (places=="")
 {
  alert("Inserire i dati nel campo Places"); return false
  
 }
 if (sfoglia!="")
  {   
      document.getElementById("up").style.display="block";
      //alert(sfoglia); return false; 
  }else
    {
	  document.getElementById("reg").style.display="block";
      //alert(sfoglia); return false; 

	}
}

// LIVESET
function valida_ins_liveset()
{
 titolo=document.mod_ins.titolo.value;
 sfoglia=document.mod_ins.sfoglia.value;
 if (titolo=="")
 {
  alert("Inserire i dati nel campo Titolo"); return false
  
 }
 
}

// DJ
function valida_dj()
{
  
  nome=document.mod_ins.nome.value;
  sfoglia=document.mod_ins.sfoglia.value;

  if (nome=="")
  {
   alert("Inserire i dati nel campo nome"); return false
  }
  
  	if (sfoglia!="")
       {   
        document.getElementById("up").style.display="block";
        //alert(sfoglia); return false; 
       }else
         {
	       document.getElementById("reg").style.display="block";
           //alert(sfoglia); return false; 

	     }


}


function del_news(P_id)
{
  conferma=window.confirm("confermi eliminazione?")
  if (conferma)
  {
   document.formcanc.id_canc.value=P_id;
   document.formcanc.submit();
  }else
    {
	 return false;
	}
}



//GALLERY
function valida_gallery()
{
   evento=document.mod_ins.evento.value;
   data=document.mod_ins.data.value;
   descrizione=document.mod_ins.descrizione.value;
   cart_foto=document.mod_ins.cart_foto.value;
   cart_video=document.mod_ins.cart_video.value;
  
   if (evento=="")
   {
    alert("Inserire i dati nel campo evento"); return false
   }
   if (data=="")
      {
	   alert("Inserire i dati nel campo data"); return false
	  }
	  
	if (descrizione=="")
	    {
    	    alert("Inserire i dati nel campo descrizione"); return false
		}
	if (cart_foto=="")
	    {
    	    alert("Inserire i dati nel campo cartella foto"); return false
		}
	if (cart_video=="")
	    {
    	    alert("Inserire i dati nel campo cartella video"); return false
		}


}

countwin=1;
function show_foto(param)
{
  window.open("finestra.html?show="+param, "foto"+countwin, "width=100 ,height=100 ,toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no");
  countwin++;
}


//LINK
function valida_link()
{
	nlink=document.mod_ins.nlink.value;
	indirizzo=document.mod_ins.indirizzo.value;
	categoria=document.mod_ins.categoria.value;
	if (nlink=="")
	    {
    	    alert("Inserire i dati nel campo nome link"); return false
		}
   if (indirizzo=="")
	    {
    	    alert("Inserire i dati nel campo indirizzo"); return false
		}
   if (categoria=="")
	    {
    	    alert("Inserire i dati nel campo categoria"); return false
		}


}

//EQUIPEMENT
function valida_equipe()
{
	prodotto=document.mod_ins.prodotto.value;
	descrizione=document.mod_ins.descrizione.value;
	categoria=document.mod_ins.categoria.value;
	marca=document.mod_ins.marca.value;
    sfoglia=document.mod_ins.sfoglia.value;

	
	if (prodotto=="")
	    {
    	    alert("Inserire i dati nel campo prodotto"); return false
		}
   if (descrizione=="")
	    {
    	    alert("Inserire i dati nel campo descrizione"); return false
		}
	if (categoria=="")
	    {
    	    alert("Inserire i dati nel campo categoria"); return false
		}
   if (marca=="")
	    {
    	    alert("Inserire i dati nel campo marca"); return false
		}
		
	if (sfoglia!="")
       {   
        document.getElementById("up").style.display="block";
        //alert(sfoglia); return false; 
       }else
         {
	       document.getElementById("reg").style.display="block";
           //alert(sfoglia); return false; 

	     }



}


//TRACK OF THE WEEK
function valida_track()
{
	titolo=document.ins_tr.track.value;
	wmp=document.ins_tr.wmp.value;
	treal=document.ins_tr.treal.value;

	
	if (titolo=="")
	    {
    	    alert("Inserire i dati nel campo Track Of The Week"); return false
		}
   if (wmp=="" && treal=="")
	    {
    	    alert("Inserire almeno un indirizzo per la traccia ascoltabile."); return false
		}


}

//PERMESSI
function valida_log()
{
  admin=document.logon.admin.value;
  user=document.logon.user.value;
  pass=document.logon.psw.value;

 if (admin==""){alert("Immettere nome Administrator"); return false} 
 if (user==""){alert("Immettere username"); return false} 
 if (pass==""){alert("Immettere Password"); return false}
}

// NEWS

function valida_news()
{
 	titolo=document.mod_ins.titolo.value;
	area=document.mod_ins.area.value;

	if (titolo=="")
	    {
    	    alert("Inserire i dati nel campo titolo"); return false
		}
	if (area=="")
	    {
    	    alert("Inserire i dati nel campo testo"); return false
		}


}


//================================================================================================================================
// FUNZIONI GENERICHE (cioč che possono essere richiamate da script in pagine diverse)

function redirect_guest ()
{
  document.location.href="guestbook.php";
}

function checkall(param)   //select all checkbox
  {
   sa=false;
  if(eval("document."+param+".check_all.checked"))
    sa=true;

  for (i=0;i<eval("document."+param+".elements.length");i++)
    {
   
      if(sa)
         eval("document."+param+".elements["+i+"].checked=true");
      else
         eval("document."+param+".elements["+i+"].checked=false");
    }
  }

countwin=1;
function update_win(param)
{
	 win_upd=window.open(param, "win"+countwin, 'width=500, height=500, toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no');
	 win_upd.focus();
	 countwin++;
}

/*function search_win(param)
{
	 win_search=window.open(param, "winSearch", 'width=550, height=500, ,toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no');
	 win_search.focus();
	 
}*/



Arr_Opentag = new Array("<b>", "<font color='#FF9900'>", "<a href='" );
Arr_Cltag = new Array("</b>", "</font>", "</a>");

function esegui(param, p_form)
{
  parametro=p_form;
  selezione = document.selection.createRange().text;
  area=eval("document.mod_ins."+p_form+".value");
  if (selezione!="")
  {
	  
    if (param==0)
	area=area.replace(selezione, Arr_Opentag[param]+selezione+Arr_Cltag[param]);
    
	if (param==2)
	{
		 txtlink=window.prompt("digitare l'indirizzo a cui punta il link: ", "http://")
		 if (txtlink!="http://" && txtlink!=null)
    	 area=area.replace(selezione, Arr_Opentag[param]+txtlink+"' target='blank'>"+selezione+Arr_Cltag[param]);
		 
	}
	
	eval("document.mod_ins."+parametro+".value=area");
	scrivi();
  }else
    {
		 alert("selezionare il testo a cui applicare il comando")
	}
 
}


function scrivi()
{
  area=eval("document.mod_ins."+parametro+".value");;
    
  area=area.replace(/\n/g, "<br />")
  document.getElementById('anteprima').innerHTML=area;
}


//================================================================================================================================
