// ----------------------------------------------------------- //
// nel template foglia ha una redirect
function advanced_action() {}

// ----------------------------------------------------------- //
function change_color(liv, colore) {
	
  if(colore == '')
    bg_colore = '#ffffff';
  else
    bg_colore = colore;
	
  liv.style.backgroundColor = bg_colore;
  return true;
}

// ----------------------------------------------------------- //
function add_fckeditor(nome, dir_root, kit, H)
{
  var oFCKeditor = new FCKeditor(nome);
  oFCKeditor.BasePath = dir_root + 'fckeditor/';

  // toolkit
  if(kit==null)
    oFCKeditor.ToolbarSet = 'pubblico';
  else
    oFCKeditor.ToolbarSet = kit;
  
  // altezza
  if(H==null)
    oFCKeditor.Height = '350';
  else
    oFCKeditor.Height = H;
  
  // out
  oFCKeditor.ReplaceTextarea();
}

// ----------------------------------------------------------- //
// funziona anche su firefox
function show_hid(liv_name)
{
  if(document.getElementById(liv_name).style.visibility == 'visible')
  {
    document.getElementById(liv_name).style.visibility = 'hidden';
  }
  else
  {
    document.getElementById(liv_name).style.visibility = 'visible';
  }
}

// ----------------------------------------------------------- //
// attenzione non funziona su firefox
function show_it(layer_id) {
  // document.getElementById(layer_id).style.visibility = 'visible';
  
  if(layer_id.style.visibility == 'visible')
  {
    layer_id.style.visibility = 'hidden';
    layer_id.style.position = 'absolute';
  }
  else
  {
    layer_id.style.visibility = 'visible';
    layer_id.style.position = 'static';
  }
}

// ----------------------------------------------------------- //
function ctr_max_dim(campo, max_dim)
{
  //alert(document.f.elements['o-logline'].value.length);
  if(document.f.elements[campo].value.length > max_dim)
  {
  	alert("ALERT: field " + campo + " max length " + max_dim + " char.");
  	document.f.elements[campo].value = document.f.elements[campo].value.substring(0, max_dim);
  	document.f.elements[campo].focus();
  	
  	return false;
  }
  return true;
}

// ----------------------------------------------------------- //
function ctr_iscrizione()
{
  //alert(document.f.elements[1].name.substring(0,2));
  for(var i=1; i<=document.f.length; i++)
  {
	//alert(document.f.elements[i].name);
    
    // per convenzione i campi che iniziano con o- sono obbligatori
    if((document.f.elements[i].name.substring(0,2)=='o-') & (document.f.elements[i].value==""))
    {
	  var risposta;

	  if(f.elements['label-'+document.f.elements[i].name].value=='')
	    risposta = document.f.elements[i].name.substring(2);
	  else
		risposta = document.f.elements['label-'+document.f.elements[i].name].value;

      alert("ALERT: field \"" + risposta + "\" requested.");
      document.f.elements[i].focus();
      return false;
    }
  }
	
  return true;
}

// ----------------------------------------------------------- //
function invia(form_name)
{
  eval("document."+ form_name +".submit();");
  //window.location.href=url;
}

// ----------------------------------------------------------- //
function link_blank() {
    for (var i=0; i<document.links.length; i++)
        if (document.links[i].className=="blank") {
            document.links[i].target="_blank";
        }
}
window.onload = link_blank;

// ----------------------------------------------------------- //
// controlla la validità della password inserita
function ctr_validate_pwd(pwd, conf)
{
  if(!pwd & !conf)
    return true;
  
  if(pwd.length<8)
  {  
    alert('Min length for password is 8 char.');
    return false;
  }
  
  if(pwd != conf)
  {
    alert('New password and confirmed is different.');
    return false;
  }
    
  var carattere = false;
  var numero = false;
  var chr;
  for(i=0 ; i<pwd.length ; ++i)
  {
    var chr = pwd.substr(i, 1);
    if((chr==' ') | (chr=='.') | (chr==',') | (chr=='/') | (chr=='\\'))
    {
      alert('La password non può contenere spazi, punti, virgole, ecc.');
      return false;
    }
    
    if(isNaN(chr))
      carattere = true;
    else
      numero = true;
  }
  
  if(numero & carattere)
    return true;
  else
  {
    alert('La password deve contenere \nalmeno un numero e almeno un carattere');
    return false;
  }
}

// -------------------------------------------------------- //
function costruzione()
{
  alert("on-line soon");
    return false;
}

// ----------------------------------------------------------- //
function evidenzia(form_campo)
{
  eval("document."+ form_campo +".focus();");
}

// -------------------------------------------------------- //
function messaggio(msg)
{
  alert(msg);
    return false;
}

// -------------------------------------------------------- //
function cambia_testo(elemento, valore)
{
  document.getElementById(elemento).innerText = valore;
}

// -------------------------------------------------------- //
function ctr_fields(modulo, campo)
{
  if(modulo.elements[campo].value=='')
  {
    alert(modulo.elements[campo].name+' obbligatorio');
      return false;
  }
  
    return true;

}

// -------------------------------------------------------- //
function colora(liv, stato)
{
  if(stato==0)
  {
    bg = '333333';
    testo = '999999';
  }
  else
  {
    bg = 'CCCCCC';
    testo = '333333';  
  }
  
  document.getElementById(liv).style.backgroundColor=bg;
  document.getElementById(liv).style.color=testo;
}

// -------------------------------------------------------- //
function mostra(livello)
{
  // visualizza il nome del cliente all'onMouseOver (in portfolio)
  document.getElementById(livello).style.visibility = 'visible';
  document.getElementById(livello).style.position = 'static';
}

// -------------------------------------------------------- //
function nascondi(livello)
{
  // visualizza il nome del cliente all'onMouseOver (in portfolio)
  document.getElementById(livello).style.visibility = 'hidden';
  document.getElementById(livello).style.position = 'absolute';
}

// -------------------------------------------------------- //
function vai(dest)
{
  window.location.href=dest;
}

// -------------------------------------------------------- //
function chiudi()
{
  //window.opener.location.reload();
  window.close();
}

// -------------------------------------------------------- //
function apri (URL, w, h)
{
  x = w+20;
  y = h+20;
  
  // cerca di centrare la posizione della popup
  posX = (screen.width - w)/2;
  posY = ((screen.height - h)/2)-40;
  
  // controlla che non ci siano posiz fuori schermo
  if(posX<0)
    posX = 0;
  if(posY<0)
    posY = 0;

  fin = window.open(URL,'popup','scrollbars=yes,resizable=yes,width='+x+',height='+y+'');
  fin.focus();
  fin.moveTo(posX,posY);
}

// -------------------------------------------------------- //
function conferma()
{
  if (!confirm("\r\nYou are sure?"))
    return false;
	
  return true;
}

//-----------------------------------------------------------------------------------------------//

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function 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_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];}}
}

// ----------------------------------------------------------- //