//---------------------------------------------------------
//
// onload
//
//---------------------------------------------------------
function scriptOnLoad() {

   setup ();

   nr_languages = 0;

   //******************************************************
   //build up the language menu
   //******************************************************
   element = document.getElementById ("lang");
   el_lang = element.cloneNode(true);
   up_lang = element.parentNode;

   for (i=0; i < nr_lang_items; i++) {
      if (langarray[i][0] == true) {
         nr_languages = nr_languages + 1
      }
   }

   if (nr_languages < 2) {
      //only one language available -> no display
      // set the correct language
      for (i=0; i < nr_lang_items; i++) {
         if (langarray[i][0] == true) {
            language = i;
         }
      }
   }
   else {
      // set up the menu for each language
      for (i=0; i < nr_lang_items; i++) {
         if (langarray[i][0] == true) {
            new_lang = el_lang.cloneNode(true);
            inelement = up_lang.insertBefore(new_lang, element);
            inelement.setAttribute("id",langarray[i][1]);
            //the text is located in the first child of the element
            down = inelement.firstChild;
            //paragraph text is available in the property nodeValue
            down.nodeValue=langarray[i][2];
         }
      }
   }

   // remove the template
   throwaway_node = up_lang.removeChild(element);


   //******************************************************
   //copy the menu structure
   //******************************************************
   element = document.getElementById ("menu1");
   el_menu1 = element.cloneNode(true);
   up = element.parentNode;
   throwaway_node = up.removeChild(element);

   element = document.getElementById("menu2");
   el_menu2 = element.cloneNode(true);
   up = element.parentNode;
   throwaway_node = up.removeChild(element);

   //******************************************************
   //build up the menu
   //******************************************************
   for (i=0; i < nr_menu_items; i++) {
      if (menuarray[i][1].length <= 2) {
         insertmenu1(i)

         if (i==0) {//open the second level of the first item
            menuarray[i][2] = "open";
            after = "endmenu";

            for (j=0; j < nr_menu_items; j++) {
               if (menuarray[j][1].length > 2) {
                  if (menuarray[j][1].substring(0,2) == menuarray[i][1]) {
                     insertmenu2(j, after);
                  }
               }
            }
         }
      }
   }
   
   //Provide the correct E-mail address
   //build it up to confuse the automatic search functions
   Name = "webmaster"
   domain = "carrosserie.lauwyck"
   country ="belgium"	
   together = Name
   together = together + "@"
   together = together + domain + "." + country.substring(0,2)
   document.getElementById("adres").attributes[79].value = "mailto:" + together

}


//---------------------------------------------------------
//
// insertmenu1
//
// in: nr = contains the table element to be inserted
//
//---------------------------------------------------------
function insertmenu1(nr) {

   element = document.getElementById("endmenu");

   //create an "menu1" element
   new_menu1 = el_menu1.cloneNode(true);
   up = element.parentNode;
   inelement = up.insertBefore(new_menu1, element);
   inelement.setAttribute("id",menuarray[nr][1]);

   //the text is located in the first child of the element
   down = inelement.firstChild;

   //paragraph text is available in the property nodeValue
   down.nodeValue=menuarray[nr][0][language][0];
}

//---------------------------------------------------------
//
// insertmenu2
//
// in: nr = contains the table element to be inserted
//     after = the id of the element after the element to be inserted
//
//---------------------------------------------------------
function insertmenu2(nr, after) {

   element = document.getElementById(after);

   //create an "menu2" element
   new_menu2 = el_menu2.cloneNode(true);
   up = element.parentNode;
   inelement = up.insertBefore(new_menu2, element);
   inelement.setAttribute("id",menuarray[nr][1]);

   //the text is located in the first child of the element
   down = inelement.firstChild;

   //paragraph text is available in the property nodeValue
   down.nodeValue=menuarray[nr][0][language][0];

}

//---------------------------------------------------------
//
// menu onmouseover
//
//---------------------------------------------------------
function scriptMouseover(who) {
  if (who.className == "menu1")
          who.className = "menu1selected"; 

  if (who.className == "menu2")
          who.className = "menu2selected"; 
}

//---------------------------------------------------------
//
// menu onmouseout
//
//---------------------------------------------------------
function scriptMouseout(who) {
  if (who.className == "menu1selected")
          who.className = "menu1"; 

  if (who.className == "menu2selected")
          who.className = "menu2"; 
}

//---------------------------------------------------------
//
// menu ondoubelclick
//
//---------------------------------------------------------
function scriptClick(who) {
  // Determine the array index of the selected element
  nr = 0;
  for (i=0; i < nr_menu_items; i++) {
      if (menuarray[i][1] == who.id) {
            nr = i;
      } 
  }

  //************************************//
  // A level 1 menu is selected
  // open or close the submenus, if available
  // display the selected page, if available
  //************************************//
  if (who.className == "menu1selected") {
      // handle the submenu's
      if (menuarray[nr][2] == "closed") { // open the selection
	  //close an already opened menu
	  for (j=0; j < nr_menu_items; j++) {
	      if (menuarray[j][2] == "open") {
             	  //already opened menu found
	          menuarray[j][2] = "closed";
        	  for (z=0; z < nr_menu_items; z++) { 
	             if (menuarray[z][1].length > 2) {
        	       if (menuarray[z][1].substring(0,2) == menuarray[j][1]) { 
	                  element = document.getElementById (menuarray[z][1]);
	                  up = element.parentNode;
	                  throwaway_node = up.removeChild(element);
	               } 
	             } 
	          } 
	      } 
	  }

	  //open the selected menu
          menuarray[nr][2] = "open";
          //find the element after this item
          afterel = who.nextSibling;
          after = afterel.id;

            for (i=0; i < nr_menu_items; i++) { 
               if (menuarray[i][1].length > 2) { 
                  if (menuarray[i][1].substring(0,2) == who.id) { 
                     insertmenu2(i, after);
                  } 
               } 
            } 
      } else { // the selection should be closed again
          menuarray[nr][2] = "closed";
          for (i=0; i < nr_menu_items; i++) { 
             if (menuarray[i][1].length > 2) {
               if (menuarray[i][1].substring(0,2) == who.id) { 
                  element = document.getElementById (menuarray[i][1]);
                  up = element.parentNode;
                  throwaway_node = up.removeChild(element);
               } 
             } 
          } 
      } 

      //if a linked page exist, open the linked page
      if (menuarray[nr][3] != "") {
        //get the internal frame by name="info"
         internal_infor_frame = document.getElementById("info");
         //replace the content of the internal frame
         internal_infor_frame.setAttribute("src",langarray[language][3].concat("/", menuarray[nr][3]));
      } 
  } 

  //************************************//
  // A level 2 menu is selected
  // display the selected page
  //************************************//
  if (who.className == "menu2selected"){
          //get the internal frame by name="info"
          internal_infor_frame = document.getElementById("info");
          //replace the content of the internal frame
          internal_infor_frame.setAttribute("src",langarray[language][3].concat("/", menuarray[nr][3]));
  } 
}

//---------------------------------------------------------
//
// mouse over the language selection
//
//---------------------------------------------------------
function langover(who) {
   who.className = "languageOnChoise";
}

//---------------------------------------------------------
//
// mouse of the language selection
//
//---------------------------------------------------------
function langout(who) {
   who.className = "languageChoise";
}

//---------------------------------------------------------
//
// Update the language on the screen
//
//---------------------------------------------------------
function langUpdate(language) {

  //******************************************************
  //update the menu
  //******************************************************

  for (i=0; i < nr_menu_items; i++) {
      element = document.getElementById(menuarray[i][1]);

      if ( element != null) {
         //the text is located in the first child of the element
         down = element.firstChild;

         //paragraph text is available in the property nodeValue
         down.nodeValue=menuarray[i][0][language][0];
      }
  }

  //******************************************************
  //update the displayed page
  //******************************************************

  //get the internal frame by name="info"
  internal_infor_frame = document.getElementById("info");

  //alert("nr attributes :" + internal_infor_frame.attributes.length);
  //for (i=0; i < internal_infor_frame.attributes.length; i++) {
  //   alert("attribute :" + i + " = " + internal_infor_frame.attributes[i].name + " = " + internal_infor_frame.attributes[i].value);
  //   }

  //get the current page
  ipage = internal_infor_frame.getAttribute("src");

  //get the index of the last "/"
  pos = ipage.lastIndexOf("/")

  page = ipage.substring(pos);

  //replace the content of the internal frame
  internal_infor_frame.setAttribute("src",langarray[language][3].concat(page));

}

//---------------------------------------------------------
//
// clicked on the language selection
//
//---------------------------------------------------------
function langClick(who) {
   if (who.id == "nederlands") {
        language = 0;
        langUpdate(language);
   }
   if (who.id == "frans") {
        language = 1;
        langUpdate(language);
   }
   if (who.id == "duits") {
        language = 2;
        langUpdate(language);
   }
   if (who.id == "engels") {
        language = 3;
        langUpdate(language);
   }
}

//---------------------------------------------------------
//
// date time
//
//---------------------------------------------------------

function date_time() {

var mydate  = new Date()
var year    = mydate.getYear()
var day     = mydate.getDay()
var month   = mydate.getMonth()
var daym    = mydate.getDate()
var hours   = mydate.getHours()
var minutes = mydate.getMinutes()
var seconds = mydate.getSeconds()

if (year < 1000)
        year+=1900

if (hours == 0)
        hours=12

if (minutes <= 9)
        minutes = "0" + minutes

if (seconds <= 9)
        seconds = "0" + seconds

if (daym < 10)
        daym = "0" + daym
if (language == english) {
	datetime1 = dayarray[language][day] + ", " + montharray[language][month] + " " + daym + ", " + year
} else {
	datetime1 = dayarray[language][day] + ", " + daym + " " + montharray[language][month] + " " + year
}
datetime2 = hours + ":" + minutes + ":" + seconds

document.getElementById("datetime").childNodes[0].nodeValue = datetime1 + "   " + datetime2 + "                                                                                                  ©" + year + " " 
setTimeout ("date_time()",1000)
}

