// JavaScript Document


var FLAG_RELOAD=true; //false;

var xmlhttp;
var theId;
function loadXMLDoc(url, anId)
{
  xmlhttp=null;
  theId = anId;
  if (window.XMLHttpRequest)
    {// code for Firefox, Opera, IE7, etc.
    xmlhttp=new XMLHttpRequest();
    }
  else if (window.ActiveXObject)
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  if (xmlhttp!=null)
    {
    //xmlhttp.onreadystatechange=null; // state_Change;
    xmlhttp.open("GET",url,false); //true);
    xmlhttp.send(null);
    
    if (xmlhttp.status==200)
      {// 200 = "OK"
      document.getElementById(theId).innerHTML=xmlhttp.responseText;
      }
    else
      {
      alert("Problem retrieving data:" + xmlhttp.statusText);
      }
    }
  else
    {
    alert("Your browser does not support XMLHTTP.");
    }
}


// function state_Change()
// {
//   if (xmlhttp.readyState==4)
//     {// 4 = "loaded"
//     if (xmlhttp.status==200)
//       {// 200 = "OK"
//       document.getElementById(theId).innerHTML=xmlhttp.responseText;
//       }
//     else
//       {
//       alert("Problem retrieving data:" + xmlhttp.statusText);
//       }
//     }
//   //else alert("status = "+ xmlhttp.readyState);
// }

function loadPage(pageName)
{
     if (FLAG_RELOAD)
       window.location="index.html?topic="+pageName;
     else
       loadMyContents(pageName);
}

function loadMyContents(contentPageName)
{
  if(contentPageName!=null)
    loadXMLDoc(contentPageName + "_content.html", "id_content");
  menuSelect(contentPageName);

  return false;
}

var selectedMenu=new Array();
var selectedMenuBar=new Array();
function menuSelect(aMenu)
{
  menuUnSelect();
  //  document.getElementById("id_menu_" + aMenu).className="selected" //current menu item selection
  //  selectedMenu = aMenu;

  //alert('menuSelect ' + aMenu +   'selectedMenu = ' + selectedMenu);
  //   if(selectedMenu!=null){
  //     obj = document.getElementById("id_mbar_" + selectedMenu);
  //     if(obj != null)
  //       obj.style.visibility="hidden";
  //   }
  
    
    var obj; 
    var n;
    while( (n=aMenu.indexOf('/')) >= 0)
    {
      aMenu = aMenu.substring(n+1);
    }
  
    var l = aMenu.length;
    var aString = aMenu; 
  
//     n=aString.lastIndexOf('_');
//     if(n>0){
//       //alert('menuSelect ' + aMenu +   'selectedMenu = ' + aString.substring(0,n));
//       obj=document.getElementById("id_mbar_" + aString.substring(0,n))
//       if(obj != null)
//           obj.style.visibility="visible";
//     }
//     selectedmenu=aString;
    
//   obj=document.getElementById("id_menu_bars");
//   if(obj != null)
//     obj.style.height="60px";

    var h=0;
    do{
      //alert('menuSelect ' + aString);
      obj = document.getElementById("id_menu_" + aString)
      if(obj != null)
      {
        obj.className="selected" //current menu item selection
        selectedMenu.push(obj);
      }
      n=aString.lastIndexOf('_');
      //alert('menuSelect ' + aString);
      if(n>0){
          aString = aString.substring(0,n);
          obj = document.getElementById("id_mbar_" + aString)
          if(obj != null){
            obj.style.visibility="visible" //current menu item selection
            selectedMenuBar.push(obj);
//            obj.className=obj.className + " selected" //current menu item selection
            //alert(obj.clientHeight);
            h=h+obj.clientHeight;
              //obj.style.height="23px";
  //           ojb=document.getElementById("id_menu_bars");
  //           if(obj != null)
  //             obj.style.height="40px";
          }
          
        }
    }
    while(n>0);
    
    var val = new String();
    if(h>0){
      val =String(h+2)+ "px";
      obj=document.getElementById("id_menu_bars");
      if(obj != null)
        obj.style.height=val; 
    }

}


function menuUnSelect()
{
  var tmpObj;
  
  while(selectedMenu.length > 0)
  {
    tmpObj = selectedMenu.pop();
    tmpObj.className="";
  }
  while(selectedMenuBar.length > 0)
  {
    tmpObj = selectedMenuBar.pop();
    tmpObj.style.visibility="hidden";
  }
}

var pageName=null;
var topicName=null;
var searchArray = new Array();
function getPageParameter()
{
  var searchStr = location.search;
  var section = location.hash.substring(1,location.hash.length);
  pageName = location.pathname.toLowerCase();
  
  //alert(searchStr);
  
  var n=pageName.lastIndexOf('/');
  if( n >= 0){
    pageName = pageName.substring(n+1,pageName.length);
    n = pageName.lastIndexOf('.htm');
    if( n >= 0) pageName = pageName.substring(0,n);
    else
      pageName=null;
    }
  else
    pageName=null;
  //alert(pageName);
  
	var name, value;
  while (searchStr!='') {
  	// strip off leading ? or &
  	if ((searchStr.charAt(0)=='?')||(searchStr.charAt(0)=='&')) searchStr = searchStr.substring(1,searchStr.length);
  	// find name
  	name = searchStr.substring(0,searchStr.indexOf('='));
  	// find value
  	if (searchStr.indexOf('&')!=-1) value = searchStr.substring(searchStr.indexOf('=')+1,searchStr.indexOf('&'));
  	else value = searchStr.substring(searchStr.indexOf('=')+1,searchStr.length);
  	// add pair to an associative array
  	searchArray[name] = value;
  	// cut first pair from string
  	if (searchStr.indexOf('&')!=-1) searchStr =  searchStr.substring(searchStr.indexOf('&')+1,searchStr.length);
  	else searchStr = '';
  	// debug step
  } 
  value =  searchArray["topic"];
  if (value == undefined) topicName = null;
  else topicName = value;
  
}

function loadCommonSections()
{
  getPageParameter();
    
  if(topicName==null)
    topicName="index";

  loadMyContents(topicName);
  var obj = null;
 
  obj = document.getElementById("main-image");
  
  if(obj == null)
    return;
  
  obj.oncontextmenu = noContextMenu;  
  obj = document.getElementById("home-map");
  
  if(obj == null)
  return;
  
  obj.oncontextmenu = noContextMenu;
  obj.onmouseover = showCredits;
  obj.onmouseout = hideCredits;
}
function noContextMenu(){
  return false;
}
function showCredits(e) {
  obj = document.getElementById("credit-div");
  
  if(obj == null)
  return false;

  obj.style.visibility="visible"
  return false;
}

function hideCredits (e) {
  obj = document.getElementById("credit-div");
  if(obj == null)
  return false;
  obj.style.visibility="hidden"
  return false;
}


