function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// LIST ALL SHOW/HIDE ELEMENT IDS HERE
menus_array = new Array ('ddNonProfitServices', 'ddFinancialServices', 'ddLuxuryMarkets', 'ddPartners', 
						 'ddCustomerService', 'ddAboutWE', 'ddNews');

menus_status_array = new Array ();// remembers state of switches
menus_status_array["ddNonProfitServices"]="";
menus_status_array["ddFinancialServices"]="";
menus_status_array["ddLuxuryMarkets"]="";
menus_status_array["ddPartners"]="";
menus_status_array["ddCustomerService"]="";
menus_status_array["ddAboutWE"]="";
menus_status_array["ddNews"]="";


img_close = '/pub/images/close.gif';
img_open = '/pub/images/open.gif';


function closeTab(p_Tab, p_ID) {
   var tab = document.getElementById(p_Tab);
   var sources = tab.getElementsByTagName("dd");
   var imgid, button_id;
   for(var i = 0; i < sources.length; i++) {
		if(sources[i].id != p_ID)
		{
			imgid = sources[i].id + 'Button';
			button_id = document.getElementById(imgid);
			sources[i].className = "hideSwitch";
			button_id.setAttribute ('src', img_open);
			menus_status_array[sources[i].id] = 'hide; path=/';
			document.cookie = sources[i].id + '=hide; path=/';
		}    
   }
   return;
 } 
 
 
function showHideSwitch (parentId, theid) {
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var imgid = theid+'Button';
    var button_id = document.getElementById(imgid);
    if (menus_status_array[theid] != 'show') {
      button_id.setAttribute ('src', img_close);
      switch_id.className = 'showSwitch';
	  menus_status_array[theid] = 'show; path=/';
	  document.cookie = theid+'=show; path=/';
	  closeTab(parentId, theid);
	  return;
    }
	else
	{
      button_id.setAttribute ('src', img_open);
      switch_id.className = 'hideSwitch';
	  menus_status_array[theid] = 'hide; path=/';
	  document.cookie = theid+'=hide; path=/';	 
    }
  }
  return;
}
function resetMenu () { // read cookies and set menus to last visited state
  if (document.getElementById) {
    for (var i=0; i<menus_array.length; i++) {
      var idname = menus_array[i];
      var switch_id = document.getElementById(idname);
      var imgid = idname+'Button';
      var button_id = document.getElementById(imgid);
	  
      if (getCookie(idname) == 'show') {
	    button_id.setAttribute ('src', img_close);
        switch_id.className = 'showSwitch';
	    menus_status_array [idname] = 'show; path=/';
	  }else{
	    button_id.setAttribute ('src', img_open);
        switch_id.className = 'hideSwitch';
	    menus_status_array [idname] = 'hide; path=/';	
	  }
	  
    }
  }
}

/*
 * This function is used to set the cookies from the index page for the drop down navigation menus
 * when a link is clicked from the index page
*/
function openTabs( tabName ){
	for( var i=0; i<menus_array.length; i++ ){
		if( menus_array[i] == tabName ){
			menus_status_array [tabName] = 'show; path=/';
			document.cookie = menus_array[i] + '=show; path=/';
		}
		else{
			 menus_status_array [tabName] = 'hide; path=/';
 			 document.cookie = menus_array[i] + '=hide; path=/';
		}
			
	}
}