function p1(t,lev) {
  var a=t.length;
  for (var i=0; i<lev; i++) {
    a =  t.lastIndexOf("/",a-1); }
  return t.slice(0,a);
}

function p2(t,lev) {
  var a=t.length;
  for (var i=0; i<lev; i++) {
    a =  t.lastIndexOf("/",a-1); }
  return t.slice(a,t.length);
}

// Carica la struttura a frame se non presente
// dest e' destinazione. Nullo se a se stesso.
// livello indica il livello nell'albero del path.
function topLevel(dest,livello) {
  seaframe = /noframe/;
  sealang = /_i.html/;

  // Lo script funziona correttamente solo su Internet explorer e Mozilla
  aName = navigator.appName;
  if (aName!="Netscape" && aName!="Microsoft Internet Explorer") {
    return; }

  // E' gia' presente la struttura a frames
  if (top.token==1 || document.cookie=="token=1") {
    return; }
  // Browser non supporta i frames
  if (seaframe.test(location.search)==true) {
    return; }

  var part1 = p1(location.href,livello);
  var part2 = p2(location.href,livello);
  if (dest=="") {
    dest=part2; }

  var newUrl = part1;
  if (sealang.test(part2))
    newUrl = newUrl + "/" + "index_i.html?" + dest;
  else
    newUrl = newUrl + "/" + "index.html?" + dest;
  location.href = newUrl;
}

// Ridirige verso la pagina desiderata
// Chiamata solo da intro.html e intro_i.html
function bottomLevel() {
  if (parent.location.search=="") {
    return; }
  var currentUrl = location.href;
  currentUrl = currentUrl.slice(0,currentUrl.length-location.search.length);

  var part1 = p1(currentUrl,2);
  var part2 = parent.location.search;
  part2 = part2.slice(1,part2.length);

  sea1 = /sistema/;
  sea2 = /intro/;
  var newUrl = part1+part2;
  if (sea1.test(part2)==false && sea2.test(part2)==false) {
    location.href = newUrl; }
}
