/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

if (document.getElementById){ //DynamicDrive.com change
	document.write('<style type="text/css">\n')
	document.write('.submenu{display: none;}\n')
	document.write('</style>\n')
}

function SwitchMenu(obj, hdr_name, mnu_name){
	//- Here we clean all styles from menu/submenu because
	//- it's assumed user move to a new menu block
	cleanHeaderStyle();
	cleanMenuStyle();
	cleanSubmenuStyle();
	highlightHeader(hdr_name);
	highlightMenu(mnu_name);
	
	//- Show/hide submenu block
	if(document.getElementById){
		var el = document.getElementById(obj);
		var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change

		//- only if there's submenu	
		if(el) {
			if(el.style.display != "block"){ //DynamicDrive.com change
				for (var i=0; i<ar.length; i++) {
					if (ar[i].className=="submenu") //DynamicDrive.com change
						ar[i].style.display = "none";
				}
				el.style.display = "block";
			} else {
				el.style.display = "none";
			}
		} else {
			for (var i=0; i<ar.length; i++) {
				if (ar[i].className=="submenu") //DynamicDrive.com change
					ar[i].style.display = "none";
			}
		}
	}
}



function cleanHeaderStyle() {
  var all_hdr = document.getElementsByTagName('div');
  for(var i=0; i < all_hdr.length; i++) {
    var myhdr = all_hdr.item(i);
    if ((myhdr.style.backgroundColor == 'rgb(255, 204, 0)') || (myhdr.style.backgroundColor == '#ffcc00')) {
      myhdr.style.backgroundColor = '#0000ff';
	  myhdr.style.color = '#ffffff';
    }
  }
}

/***************************************************
 * cleanMenuStyle
 ***************************************************
 * Remove backgroundColor from a menu item if its current
 * background is yellow.
 * NOTE: remember to change the color value if other color is used
 ***************************************************/
function cleanMenuStyle() {
  var all_mnu = document.getElementsByTagName('div');
  for(var i=0; i < all_mnu.length; i++) {
    var mymnu = all_mnu.item(i);
    if ((mymnu.style.backgroundColor == 'rgb(255, 255, 204)') || (mymnu.style.backgroundColor == '#ffffcc')) {
      mymnu.style.backgroundColor = '#ffffff';
    }
  }
}

/***************************************************
 * cleanSubmnuStyle
 ***************************************************
 * Set font weight of a menu item to normal if its current
 * fontWeight property is bold.
 ***************************************************/
function cleanSubmenuStyle() {
  var all_sub = document.getElementsByTagName('a');
  for(i=0; i < all_sub.length; i++) {
    var mysub = all_sub.item(i);
    if (mysub.style.fontWeight == 'bold') {
      mysub.style.fontWeight = 'normal';
    }
  }
}

/***************************************************
 * loadSelected
 ***************************************************
 * Parse query string to get selected menu and
 * highlight accordingly
 ***************************************************/
function loadSelected() {
	var qryString = window.location.search;
	var query = qryString.charAt(0) == '?' ? qryString.substring(1) : qryString;
	var args = new Object();
	if(query) {
		var fields = query.split('&');
		for(var f = 0; f < fields.length; f++) {
			var field = fields[f].split('=');
			args[unescape(field[0].replace(/\+/g, ''))] = unescape(field[1].replace(/\+/g, ''));
		}
		for(var arg in args) {
			if(arg == 'h') { myhdr = args[arg]; }
			if(arg == 'm') { mymnu = args[arg]; }
			if(arg == 's') { mysubmnu = args[arg]; }
			if(arg == 'd') { mysubdiv = args[arg]; }
		}
			
		SwitchMenu(mysubdiv, myhdr, mymnu);
		boldMenu(mysubmnu);
	}		

}

/***************************************************
 * highlightHeader
 ***************************************************
 * Change background color of input object to a color
 * different from background. Input is _name_ (or ID) of
 * an object, not the object itself!!
 * E.g. <a id="myobj" href='#' onClick="highlightHeader('myobj')">example</a>
 * NOTE: remember to change the color value in cleanHeaderStyle 
 * if other color is used
 ***************************************************/
function highlightHeader(obj_name) {
	var el = document.getElementById(obj_name);
	el.style.backgroundColor = '#ffcc00';
	el.style.color = '#000000';
	return true;
}

/***************************************************
 * highlightMenu
 ***************************************************
 * Change background color of input object to a color

 * different from background. Input is _name_ (or ID) of
 * an object, not the object itself!!
 * E.g. <a id="myobj" href='#' onClick="highlightMenu('myobj')">example</a>
 * NOTE: remember to change the color value in cleanMenuStyle 
 * if other color is used
 ***************************************************/
function highlightMenu(obj_name) {
	var el = document.getElementById(obj_name);
	el.style.backgroundColor = '#ffffcc';
	return true;
}

/***************************************************
 * boldMenu
 ***************************************************
 * Change input object font to bold. Input is _name_ (or ID) of
 * an object, not the object itself!!
 * E.g. <a id="myobj" href='#' onClick="boldMenu('myobj')">example</a>
 * Note: remember to change the color value if other color is used
 ***************************************************/
function boldMenu(obj_name) {
  var el = document.getElementById(obj_name);
  if(el) {
	  el.style.fontWeight = 'bold';
  }
  return true;
}

