//Copyright © 2002 Océan S.r.l., Roma, Italia. All rights reserved.

var DocumentRoot = new Object();
var DocumentSitePath = new Object();
var DocumentFileName = new Object();
var DocumentRelativePath = new Object();
var DocumentContentLanguage = new Object();

var DocumentStyle = new Object();

var SiteOwner = new Object();
var KeyWords = new Object();

var DocumentFileNameList = new Array();

var DocumentBaseTarget = new Object();
var DocumentTitle = new Object();
var DocumentDescription = new Object();

var LoadedWindowReference;

function DoNothing()
{
}

function MsgBox(Text)
{
   window.alert(Text);
}

function Instr(Start, Text, Srch)
{
   var Pointer;

   for (Pointer = Start; Pointer < (Text.length - Srch.length + 1); Pointer++)
   {
      if (Text.substr(Pointer, Srch.length) == Srch)
      {
         break;
      }
   }
   if (Pointer < (Text.length - Srch.length + 1))
   {
      return(Pointer);
   }
   else
   {
      return(-1);
   }
}

function RightInstr(Start, Text, Srch)
{
   var Pointer;

   if (Start == 0)
   {
      Start = (Text.length - Srch.length);
   }

   for (Pointer = Start; Pointer > -1; Pointer--)
   {
      if (Text.substr(Pointer,Srch.length) == Srch)
      {
         break;
      }
   }

   return(Pointer);
}

function Left(Text,Len)
{
   return(Text.substr(0, Len));
}

function Right(Text,Len)
{
   return(Text.substr(Text.length-Len, Len));
}

function LTrim(Text)
{
   var Pointer;

   for (Pointer = 0; Pointer < Text.length; Pointer++)
   {
      if (Text.substr(Pointer,1) != " ")
      {
         break;
      }
   }
   if (Pointer < Text.length)
   {
      return(Text.substr(Pointer));
   }
   else
   {
      return("");
   }
}

function RTrim(Text)
{
   var Pointer;

   for (Pointer = Text.length - 1; Pointer > -1; Pointer--)
   {
      if (Text.substr(Pointer,1) != " ")
      {
         break;
      }
   }
   if (Pointer > -1)
   {
      return(Text.substr(0,Pointer + 1));
   }
   else
   {
      return("");
   }
}

function Trim(Text)
{
   return(RTrim(LTrim(Text)));
}

function AddElementToArray(ArrayReference, Element)
{
   if (ArrayReference.length == 0)
   {
    ArrayReference[0] = Element;
   }
   else
   {
    ArrayReference[ArrayReference.length] = Element;
   }
}

function Max(Var1, Var2)
{
   if (Var1 > Var2)
   {
      return(Var1);
   }
   else
   {
      return(Var2);
   }
}

function DocumentWrite(Text)
{
   document.write(Text);
}

function SingleTag(Tag, Parameters)
{
   return("<" + Trim(Tag + " " + Parameters) + ">");
}

function DoubleTag(Tag, Parameters, Text)
{
   return(SingleTag(Tag, Parameters) + Text + SingleTag("/" + Tag, ""));
}

function DocumentWriteSingleTag(Tag, Parameters)
{
   DocumentWrite(SingleTag(Tag, Parameters));
}

function DocumentWriteDoubleTag(Tag, Parameters, Text)
{
   DocumentWrite(DoubleTag(Tag, Parameters, Text));
}

function SetBaseTarget(BaseTarget)
{
  DocumentWriteSingleTag("BASE", "target=\"" + BaseTarget + "\"");
}

function SetMeta(HTTPEquiv, Name, Content)
{
   var Parameters;

   Parameters = "";

   if (HTTPEquiv.length > 0)
   {
      Parameters = Parameters + "http-equiv=\"" + HTTPEquiv + "\"";
   }

   if (Name.length > 0)
   {
      Parameters = Trim(Parameters + " name=\"" + Name + "\"");
   }

   if (Content.length > 0)
   {
      Parameters = Trim(Parameters + " content=\"" + Content + "\"");
   }

   DocumentWriteSingleTag("META", Parameters);
}

function SetVBScript(VBScript)
{
   DocumentWriteDoubleTag("SCRIPT", "type=\"text/vbscript\"", VBScript);
}

function SetJScript(JScript)
{
   DocumentWriteDoubleTag("SCRIPT", "type=\"text/javascript\"", JScript);
}

function SetStyle(Style)
{
   var Text;

   SetMeta("Content-Style-Type", "", "text/css");

   Text = DoubleTag("P", "", "Your browser do not support CSS style sheets." 
                           + SingleTag("BR", "") 
                           + "Please upgrade your browser to read correctly this page." 
                           + SingleTag("BR", "") 
                           + SingleTag("BR", "")) 
        + DoubleTag("P", "", "Il browser non supporta i fogli di stile CSS." 
                           + SingleTag("BR", "") 
                           + "Aggiornare il browser per vedere correttamente questa pagina." 
                           + SingleTag("BR", "") 
                           + SingleTag("BR", ""));

   Text = "<!-- " + Style + " -->" + "/* " + Text + " */";
   Text = Style;

   DocumentWriteDoubleTag("STYLE", "", Text);
}

function SetTitle(Title)
{
   DocumentWriteDoubleTag("TITLE", "", Title);
}

function SetDescription(Description)
{
   SetMeta("", "Description", Description);
}

function SetContentLanguage(ContentLanguage)
{
   SetMeta("Content-Language", "", ContentLanguage);
}

function SetKeyWords(KeyWords)
{
   SetMeta("", "KeyWords", KeyWords);
}

function SetNoFrames()
{
   DocumentWrite("<p>Il browser non supporta i frame oppure i frame non sono abilitati.</p>");
   DocumentWrite("<p>Browser do not support frames or frames are not abilited.</p>");
}

function SetPageTitle(PageTitle)
{
   if (PageTitle.length > 0)
   {
      DocumentWriteDoubleTag("P", "class=titlepage", PageTitle);
   }
}

function SetLink(HRef, Target, Text)
{
   var Parameters;

   Parameters = "href=\"" + HRef + "\"";

   if (Target.length > 0)
   {
      Parameters = Parameters + " target=\"" + Target + "\"";
   }

   DocumentWriteDoubleTag("A", Parameters, Text);
}

function WaitDocumentLoadComplete(DocumentReference)
{
   while (DocumentReference.readyState != "complete")
   {
//      window.setTimeout("alert('Hello, world')", 1000);
   }
}

function FileLoadedInWindow(WindowReference, URLReference)
{
   var Index;
   var Result;

   Result = (WindowReference.document.URL == URLReference);

   if (!Result)
   { 
      for (Index = 0; Index < WindowReference.frames.length; Index++)
      {
         Result = FileLoadedInWindow(WindowReference.frames[Index], URLReference);

         if (Result)
         {
            break;
         }
      }
   }

   return(Result);
}

function SetDocumentAuthor()
{
   SetMeta("", "Author", "Océan S.r.l.");
}

function SetDocumentCopyright()
{
   SetMeta("", "Copyright", "Copyright © 1995-2002 Océan S.r.l.");
}

function SetDocumentContentLanguage()
{
   if (DocumentContentLanguage.Value.length > 0)
   {
      SetContentLanguage(DocumentContentLanguage.Value);
   }
}

function SetDocumentStyle()
{
   SetStyle(DocumentStyle.Value);
}

function SetDocumentBaseTarget()
{
   if (DocumentBaseTarget.Value.length > 0)
   {

      SetBaseTarget(DocumentBaseTarget.Value);
   }
}

function SetDocumentTitle(Title)
{
   var TitleLocal;

   TitleLocal = SiteOwner.Value;

   if (TitleLocal.length > 0 && Title.length > 0)
   {
      TitleLocal = TitleLocal + " - ";
   }

   TitleLocal = TitleLocal + Title;

   SetTitle(TitleLocal);
}

function SetDocumentDescription()
{
   if (DocumentDescription.Value.length > 0)
   {
      SetDescription(DocumentDescription.Value);
   }
}

function SetDocumentKeyWords()
{
   SetKeyWords(KeyWords.Value);
}

function SetDocumentPageTitle()
{
   SetPageTitle(DocumentTitle.Value);
}

function IsHomePage(FileName)
{
   return (FileName == "index.html"
       ||  FileName == "index.htm"
       ||  FileName == "home.html"
       ||  FileName == "home.htm"
       ||  FileName == "welcome.html"
       ||  FileName == "welcome.htm"
       ||  FileName == "default.asp");
}

function InitializeDocument()
{
   var SlashPointer;

   SlashPointer = Max(document.URL.lastIndexOf("/"), document.URL.lastIndexOf("\\"));

   DocumentFileName.Value = document.URL.substr(SlashPointer + 1)

   if (DocumentFileName.Value.length == 0)
   {
      DocumentFileName.Value = "index.html";
   }

   DocumentRelativePath.Value = "";
   DocumentSitePath.Value = "";
   DocumentContentLanguage.Value = "";
   DocumentRoot.Value = "";

   if (Right(Left(document.URL, SlashPointer), "italian".length) == "italian")
   {
      DocumentRoot.Value = Left(document.URL, SlashPointer - "italian".length - 1)
      DocumentSitePath.Value = "italian";
      DocumentRelativePath.Value = "../";
      DocumentContentLanguage.Value = "it";
   }
   else if (Right(Left(document.URL,SlashPointer),"english".length) == "english")
   {
      DocumentRoot.Value = Left(document.URL, SlashPointer - "english".length - 1)
      DocumentSitePath.Value = "english";
      DocumentRelativePath.Value = "../";
      DocumentContentLanguage.Value = "us";
   }
   else if (Right(Left(document.URL,SlashPointer),"french".length) == "french")
   {
      DocumentRoot.Value = Left(document.URL, SlashPointer - "french".length - 1)
      DocumentSitePath.Value = "french";
      DocumentRelativePath.Value = "../";
      DocumentContentLanguage.Value = "fr";
   }

   DocumentStyle.Value = "";
   DocumentStyle.Value = DocumentStyle.Value + "@import url(" + DocumentRelativePath.Value + "library/style.css);";
   DocumentStyle.Value = DocumentStyle.Value + "@import url(" + DocumentRelativePath.Value + "site/style.css);";

   SiteOwner.Value = "";
   KeyWords.Value = "";

   if (DocumentFileName.Value == "leftmiddle.htm")
   {
      DocumentFileNameList.length = 0;
      AddElementToArray(DocumentFileNameList, "start.htm");
   }

   InitializeLocalDocument();

   if (DocumentFileName.Value == "leftmiddle.htm")
   {
      AddElementToArray(DocumentFileNameList, "contact.htm");
   }
}

function SetPageData(RelativePath, SitePath, FileName, BaseTarget, Title, Description)
{
   BaseTarget.Value = "";
   Title.Value = "";
   Description.Value = "";

   if (RelativePath == "")
   {
      if (IsHomePage(FileName))
      {
         BaseTarget.Value = "main";
      }
      else
      {
         if (FileName == "mainhide.htm")
         {
            BaseTarget.Value = "mainhide";
            Title.Value = "Background";
            Description.Value = "Pagina di background (suoni ed altro).";
         }
         else if (FileName == "language.htm")
         {
            BaseTarget.Value = "main";
            Title.Value = "Frame Lingua";
            Description.Value = "Frame per la scelta della lingua del sito.";
         }
         else if (FileName == "start.htm")
         {
            BaseTarget.Value = "main";
            Title.Value = "Scelta Lingua";
            Description.Value = "Scelta della lingua del sito.";
         }
      }
   }
   else if (RelativePath == "../")
   {
      if (SitePath == "italian")
      {
         if (FileName == "site.htm")
         {
            BaseTarget.Value = "main";
            Title.Value = "Frame Sito";
            Description.Value = "Frame del sito.";
         }
         else if (FileName == "lefttop.htm")
         {
            BaseTarget.Value = "lefttop";
            Title.Value = "Logo";
            Description.Value = "Logo del proprietario del sito.";
         }
         else if (FileName == "leftmiddle.htm")
         {
            BaseTarget.Value = "middlemiddle";
            Title.Value = "Indice";
            Description.Value = "Indice delle pagine del sito.";
         }
         else if (FileName == "leftbottom.htm")
         {
            BaseTarget.Value = "leftbottom";
            Title.Value = "Contatore";
            Description.Value = "Contatore delle visite al sito.";
         }
         else if (FileName == "middletop.htm")
         {
            BaseTarget.Value = "middletop";
            Title.Value = "Titolo";
            Description.Value = "Titolo del sito.";
         }
         else if (FileName == "start.htm")
         {
            BaseTarget.Value = "middlemiddle";
            Title.Value = "Home";
            Description.Value = "Home page del sito.";
         }
         else if (FileName == "middlebottom.htm")
         {
            BaseTarget.Value = "middlebottom";
            Title.Value = "Copyright";
            Description.Value = "Copyright del sito.";
         }
         else if (FileName == "contact.htm")
         {
            BaseTarget.Value = "middlemiddle";
            Title.Value = "Contatto";
            Description.Value = "Modulo per la richiesta di informazioni.";
         }
         else if (FileName == "confirm.htm")
         {
            BaseTarget.Value = "middlemiddle";
            Title.Value = "Conferma invio modulo";
            Description.Value = "Conferma dell'invio del modulo di richiesta informazioni.";
         }
      }
      else if (SitePath == "english")
      {
      }
      else if (SitePath == "french")
      {
      }
   }

   SetLocalPageData(RelativePath, SitePath, FileName, BaseTarget, Title, Description);
}

function SetDocumentPageData()
{
   SetPageData(DocumentRelativePath.Value, DocumentSitePath.Value, DocumentFileName.Value, DocumentBaseTarget, DocumentTitle, DocumentDescription);
}

function WaitDocumentLoadedAndCheck(CallCounter)
{
   if (typeof(LoadedWindowReference) == "undefined")
   {
   }
   else if (LoadedWindowReference.frames.length < 9)
   {
      if (CallCounter > 50)
      {
         LoadedWindowReference = null;
      }
      else
      {
         CallCounter = CallCounter + 1;
         setTimeout("WaitDocumentLoadedAndCheck(" + CallCounter.toString() + ")", 100);
      }
   }
   else if (FileLoadedInWindow(LoadedWindowReference, document.URL))
   {
      LoadedWindowReference.setActive;
      LoadedWindowReference.focus;
      LoadedWindowReference = null;
   }
   else if (DocumentSitePath.Value.length > 0)
   {
      LoadedWindowReference.frames.middlemiddle.location.href = DocumentFileName.Value;
      LoadedWindowReference = LoadedWindowReference.frames.middlemiddle;
      LoadedWindowReference.setActive;
      LoadedWindowReference.focus;
      LoadedWindowReference = null;
   }
   else
   {
      LoadedWindowReference = null;
   }
}

function WaitIndex_HtmlLoadedAndCheck(CallCounter)
{
   if (typeof(LoadedWindowReference) == "undefined")
   {
   }
   else if (LoadedWindowReference.frames.length == 0)
   {
      if (CallCounter > 50)
      {
         LoadedWindowReference = null;
      }
      else
      {
         CallCounter = CallCounter + 1;
         setTimeout("WaitIndex_HtmlLoadedAndCheck(" + CallCounter.toString() + ")", 100);
      }
   }
   else if (FileLoadedInWindow(LoadedWindowReference, document.URL))
   {
      LoadedWindowReference.setActive;
      LoadedWindowReference.focus;
      LoadedWindowReference = null;
   }
   else if (DocumentSitePath.Value.length > 0)
   {
      LoadedWindowReference.frames.main.location.href = "site.htm";
      LoadedWindowReference = LoadedWindowReference.frames.main;
      WaitDocumentLoadedAndCheck(1);
   }
   else
   {
      LoadedWindowReference = null;
   }
}

function CheckFrameSet()
{
   var WindowReference;
   var FrameReference;

   if (IsHomePage(DocumentFileName.Value))
   {
      if (window != window.top)
      {
         open(DocumentRelativePath.Value + "index.html", "_top", "", (1 == 1));
      }
   }
   else
   {
      if (window == window.top)
      {
         LoadedWindowReference = open(DocumentRelativePath.Value + "index.html", "_blank", "", (1 == 1));

         WaitIndex_HtmlLoadedAndCheck(1);        
      }
   }
}

function Prova()
{
   var i;
   var MetaC;

   MsgBox(document.URL);

   MetaC = document.getElementsByTagName("META");

   MsgBox(MetaC.length);

   for (i = 0; i < MetaC.length; i++)
   {
      MsgBox(MetaC[i].httpEquiv + MetaC[i].name + ": " + MetaC[i].content);
   }
}

function SetDocumentAttributes()
{
   InitializeDocument();
   SetDocumentPageData();

   SetDocumentAuthor();
   SetDocumentCopyright();
   SetDocumentContentLanguage();
   SetDocumentBaseTarget();
   SetDocumentTitle(DocumentTitle.Value);
   SetDocumentDescription();
   SetDocumentKeyWords();
   SetDocumentStyle();

   //SetMeta("Site-Enter", "", "revealTrans(Duration=1,Transition=3)");
   //SetMeta("Site-Exit", "", "revealTrans(Duration=1,Transition=2)");
   //SetMeta("Page-Enter", "", "revealTrans(Duration=0,Transition=12)");
   //SetMeta("Page-Exit", "", "revealTrans(Duration=0,Transition=12)");

   CheckFrameSet();

}

function SetDocumentMenu()
{
   var Index;
   var Title = new Object();

   for (Index = 0;  Index < DocumentFileNameList.length; Index++)
   {
      SetPageData(DocumentRelativePath.Value, DocumentSitePath.Value, DocumentFileNameList[Index], "", Title, "");
      SetLink(DocumentFileNameList[Index], "", Title.Value);
      DocumentWriteSingleTag("BR", "");
      DocumentWriteSingleTag("BR", "");
   }

   SetPageData("", "", "start.htm", "", Title, "");
   SetLink("../language.htm", "main", Title.Value);
   DocumentWriteSingleTag("BR", "");
   DocumentWriteSingleTag("BR", "");
}

function SetDocumentFormRecipient()
{
   DocumentWriteSingleTag("input", "type=\"hidden\" name=\"recipient\" value=\"" + ContactEmail() + "\"");
}
