// JavaScript Document

//get the id of the current page - this is the page id we are trying to match against
currentpageid=findPageID(document.URL);

//highlight top nav
navs=getElementsByClassName('nav','td',document);
for(i=0;i<navs.length;i++){
    atag=navs[i].childNodes[0];
    trpageid=findPageID(atag.href)
    if (trpageid == currentpageid){
       atag.style.color='#DE2F2C';
    }

}



//highlight left menu
//get all div tags
alldivs=document.getElementsByTagName('div');



//loop through all the div tags
for(i=0;i<alldivs.length;i++){

      //find all the div tags that have the LHS-menu class - these are the div tags that are used to control the look and feel
      if(alldivs[i].className=='LHS-menu'){

            childnodelength=alldivs[i].childNodes.length;

            //loop through all the child nodes
            for(j=0;j<childnodelength;j++){
                  node=alldivs[i].childNodes[j];

                  //if there is a DIV tag, that means that there is a sub menu
                  if(node.tagName == 'DIV'){
                        subchildnodelength=node.childNodes.length;
                        //loop through all the submenu items to try to find the link
                        for(k=0;k<subchildnodelength;k++){
                              subnode = node.childNodes[k];

                              //find the page id for the link
                              atagpageid=findPageID(subnode.href);
                              //a tag
                              if (currentpageid == atagpageid){
                                    //a tag with the right value
                                    //change link colour
                                    subnode.style.color='#ff0000';
                                    //open div
                                    document.getElementById(node.id).style.display="block";
                              }//end if
                              
                        }//end for
                  }else{
                        //a tag of top level menu
                        //get page id for the link
                        atagpageid=findPageID(node.href);
                        if (currentpageid == atagpageid)
                        {
                              //change link
                             node.style.color='#ff0000';
                        }//end if
                        
                  }//end if
            
            }//end for
      }//end if
}//end for

function findPageID(surl){
      if(surl == null){
          return -1;
      } else {
      atagurl=surl;
      atagstart=atagurl.indexOf('?pid=')+5;
      atagstop=atagurl.indexOf('srcid=')-1;
      atagpageid=atagurl.substring(atagstart,atagstop);
      return atagpageid;
      }
}


function getElementsByClassName(className, tag, elm){
      var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
      var tag = tag || "*";
      var elm = elm || document;
      var elements = elm.getElementsByTagName(tag);
      var returnElements = [];
      var current;
      var length = elements.length;
      for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                  returnElements.push(current);
            }
      }
      return returnElements;
}


function ToggleMenu(list){ 
var listElementStyle=document.getElementById(list).style; 
var listElementDisplay=listElementStyle.display;

//close open submenu items
var menuelements=getElementsByClassName('LHS-submenu', 'div', document);
menulength=menuelements.length;
for(k=0;k<menulength;k++){
      menuelements[k].style.display="none";
      }

//open the appropriate submenu
if (listElementDisplay=="none" || listElementDisplay==""){ 
listElementStyle.display="block"; }
else { listElementStyle.display="none"; } 
} 

