var tabattivo;

function popup(url,w,h,sb)
{
	var d = new Date();
	myWin = window.open(url,'popupwindow'+escape(d.getTime()),'left='+((screen.width/2)-(w/2))+',top='+((screen.height/2)-(h/2)-40)+',screenX='+((screen.width/2)-(w/2))+',screenY='+((screen.height/2)-(h/2)-40)+',Width='+w+',height='+h+',alwaysRaised=yes,history=no,resizable=yes,status=no,scrollbars=' + sb +',menubar=no,toolbar=no,location=no')	
	myWin.opener = self;	
	//PopupArray[PopupArray.length] = myWin;
	myWin.focus();
}


function mostra(x)
{
	document.getElementById(x).style.display = '';
}


function nascondi(x)
{
  document.getElementById(x).style.display = 'none';
}

function mostranascondi(x)
{
	if(document.getElementById(x).style.display == '')
  {
	  document.getElementById(x).style.display = 'none';
  }
  else
  {
    document.getElementById(x).style.display = '';
  }
}

function SwitchTab(x)
{
  if(tabattivo != '')
  {
    document.getElementById(tabattivo).style.display = 'none';
    document.getElementById('li'+tabattivo).className = '';
    
    document.getElementById(x).style.display = '';
    document.getElementById('li'+x).className = 'selected';
    
    tabattivo = x;
  }
}

function ExpandCollapse(doOnThis)
{

	if(document.getElementById(doOnThis).style.display == '')
  {
		document.getElementById(doOnThis).style.display = 'none';
    document.getElementById(doOnThis + '_img').src='img/expand.gif';
	}
  else
  {
		document.getElementById(doOnThis).style.display = '';
    document.getElementById(doOnThis + '_img').src='img/collapse.gif';
  }

}

function ExpandCollapseAll(tag,doOnThisPrefix)
{
  var lists = document.getElementsByTagName(tag);

  if (document.getElementById(doOnThisPrefix + '_all_img').src.indexOf('expand.gif')>0) {
  
    for (var j = 0; j < lists.length; j++) {
     id = lists[j].id;
     if (id.substr(0,doOnThisPrefix.length) == doOnThisPrefix) {
       lists[j].style.display = '';
       document.getElementById(lists[j].id + '_img').src='img/collapse.gif';
       ultimo = id;
      }   
    }
    document.getElementById(doOnThisPrefix + '_all_img').src='img/collapse.gif';

  } 
  else
  {

    for (var j = 0; j < lists.length; j++) {
     id = lists[j].id;
     if (id.substr(0,doOnThisPrefix.length) == doOnThisPrefix) {
       lists[j].style.display = 'none';
       document.getElementById(lists[j].id + '_img').src='img/expand.gif';
       ultimo = id;
      }   
    }
    document.getElementById(doOnThisPrefix + '_all_img').src='img/expand.gif';

  }

}


// Encoding Email: inserisce nel testo un link di tipo mailto.
// ------------------------------------------------------------------------------------------
// mailToId    : l'id di un elemento span (o altro) che conterrą la mail.
// emUsername  : la parte prima della chiocciola della mail
// emDomain    : la parte dopo la chiocciola della mail
// emText      : il testo del link; se null viene usata la stessa mail come anchor text

function mailTo(mailToId, emUsername, emDomain, emText)
{
  if (!document.getElementById(mailToId)) return false;
  var spanobj = document.getElementById(mailToId);
  var anch = document.createElement("a");
  var email = emUsername + "@" + emDomain;
  var mailto = "mailto:" + email;
  anch.setAttribute("href",mailto);
  spanobj.appendChild(anch);
  if ( emText == null )
   emText = email;
  var txt = document.createTextNode(emText);
  anch.appendChild(txt);
  return true;
}


function validation(rifform){
  num = rifform.elements.length;
  cont = 0;
  strMes = "";
  while (cont < num)
  {
    campo = toString(rifform.elements[cont]);
    idcampo = String(rifform.elements[cont].id);
    nomecampo = String(rifform.elements[cont].name);
    //alert(idcampo + " - " + idcampo.indexOf("ob_"));
    if (idcampo.indexOf("ob_") == 0 )
    { 
      valuecampo = String(rifform.elements[cont].value);
      if (valuecampo.length < 1 )
      {
        //alert(document.getElementById("lbl_" + nomecampo).innerHTML);
        label = document.getElementById("lbl_" + nomecampo).innerHTML;
        strMes = strMes + "Campo '" + label + "' non valido.\n";
      }
    }
    cont++;
  }
  if (strMes.length > 1 )
  {
    alert(strMes);
    return false;
  }else{
    return true;
  }
}