                                                             // Functions
                                                             // =========
var debug = false;


function checkTop()
{
   if ( top == self )
   {
      if (debug)
      {
         alert("Debug ON :- Ignoring TOP == SELF");
         return;
      }
      
      var i, j;
      var srcName;
   
      var scripts = document.getElementsByTagName('SCRIPT');
   
      for ( i = 0; i < scripts.length; i++ )
      {
         j = scripts[i].src.lastIndexOf("/");
      
         if ( j == -1 )
            srcName = scripts[i].src;
         else
            srcName = scripts[i].src.substring(j+1, scripts[i].src.length);
         
         if ( srcName == "gabbiano.js" )
            break;
      }
   
      top.location.href = scripts[i].src.substring(0, j) + "/index.htm";
   }
}


function goHome(lang)
{
   if ( debug )
       alert("goHome(): index.htm?lang=" + lang + ";");
   else
       top.location.href = "index.htm?lang=" + lang + ";";
}



function getLang()
{
   var q = unescape(location.search);
   var x = q.indexOf("lang");
   var y = q.indexOf(";");

   if ( x == -1 )
   {
      q = unescape(parent.location.href);
      x = q.indexOf("lang");
      y = q.indexOf(";");
   }
   
   if ( x == -1 )
   {
      return("it");
   }
   else if ( y == -1 )
   {
      return(q.substring(x+5, q.length));
   }
   else
   {
      return(q.substring(x+5, y));
   }
}




function getFrameLang()
{
   var q = unescape(parent.location.href);
   var x = q.indexOf("lang");
   var y = q.indexOf(";");

   if ( x == -1 )
   {
      return("it");
   }
   else if ( y == -1 )
   {
      return(q.substring(x+5, q.length));
   }
   else
   {
      return(q.substring(x+5, y));
   }
}




function changeLang(lang)
{
   var startIndex = top.menu.location.href.lastIndexOf("/") + 1;
   var endIndex = top.menu.location.href.indexOf("?");
   if ( endIndex == -1 )
       endIndex = top.menu.location.href.length;
       
   var menuPage = top.menu.location.href.substring(startIndex, endIndex);
   
   top.menu.location.href = menuPage + "?lang=" + lang + ";";

   startIndex = top.location.href.lastIndexOf("/") + 1;
   endIndex = top.body.location.href.indexOf("?");
   
   if ( endIndex == -1 )
       endIndex = top.body.location.href.length;
       
   var bodyPage = top.body.location.href.substring(startIndex, endIndex);

   if ( bodyPage.substring(0, 7) == "listino" )
   {
      endIndex = top.body.location.href.indexOf("_");
      bodyPage = top.body.location.href.substring(startIndex, endIndex);
      top.body.location.href = bodyPage + "_" + lang + ".htm";
   }
   else
   {
      top.body.location.href = bodyPage + "?lang=" + lang + ";";
   }
}



function getSize()
{
   if ( typeof( document.body.clientWidth) == "number" )
      return(document.body.clientWidth);
   else
      return(1024);
}

