function ccPrintMenuItem(fooLabel, fooAnchor, fooSel, menuId, imageId) {
  document.write('<LI ');
  if(fooSel == 'true') {
    document.write(' class="ccMenuOn" ');
    ccCurMenu = fooLabel;
    ccCurMenuURL = fooAnchor;
    if (!ccAreaExpanded(menuId)) {ccShowMenu(menuId, imageId);}
  }
  document.write('>');
  document.write( ccPrintLink(fooAnchor, fooLabel) );
  document.write('</LI>');
}

function ccPrintMenuHeader(label, menuId, imageId, showed) {
  document.write('<DIV class="ccMenu">');
  document.write('<DIV CLASS="ccMenuHeader">');
  document.write('<a href="#" onclick="ccToggleMenu(' + "'" + menuId + "','" + imageId + "'" + ');return false;">');
  document.write('<img align="absmiddle" id="' + imageId + '"');
  if(showed) {document.write(' src="ico/expanded.gif" ');} 
  else {document.write(' src="ico/collapsed.gif" ');}
  document.write('title="Toggle Menu" alt="Toggle Menu" hspace="3" />'); //i18n, Toggle Menu
  if(label.indexOf("&lt;/") != -1) {
    label = label.replace(/&lt;/g, "<");
    label = label.replace(/&gt;/g, ">");
  }
  document.write(label);
  document.write('</a>');
  document.write('</DIV>');
  if(showed) {document.write('<UL id="' + menuId + '">');}
  else {document.write('<UL id="' + menuId + '" class="ccHidden">');}
 
}

function transformMenuXML(menus) { //xml island
  var cookie = ccGetCookie("ccMenus");
  for(var i=0; i<menus.length; i++) {  
    var showMenu = false;
    var label = menus[i].getAttribute('lb');
    var menuId = menus[i].getAttribute('id');
    var imageId = menuId + 'Img';
    if(cookie == null || cookie.indexOf(menuId, 0) == -1) {showMenu = true;}
    ccPrintMenuHeader(label, menuId, imageId, showMenu);  
    var options = menus[i].childNodes;
    for(var j=0; j<options.length; j++) {
      ccPrintMenuItem(options[j].getAttribute('lb'), 
        options[j].getAttribute('anchor'), options[j].getAttribute('selected'), menuId, imageId);
    }
    document.write('</UL></DIV>');
  }
}

function transformMenuJSON() { //js array
  var cookie = ccGetCookie("ccMenus");
  for(var i in menus) {
    var showMenu = false;
    var label = menus[i].lb;
    var menuId = i;
    var imageId = menuId + 'Img';
    if(cookie == null || cookie.indexOf(menuId, 0) == -1) { showMenu = true;}
    ccPrintMenuHeader(label, menuId, imageId, showMenu);
    var options = menus[i].options;
    for(var j in options) {
      ccPrintMenuItem(options[j].lb, options[j].lk, options[j].on, menuId, imageId);
    }
    document.write('</UL></DIV>');
  }
}

function ccHideMenu(menuId, imageId) {
  var menu = document.getElementById(menuId);
  if(menu == 'null') {return;}
  ccCollapseObj(menu, imageId, "ico/collapsed.gif");
  var cookie = ccGetCookie("ccMenus");
  if(cookie == null || cookie == '' || cookie == 'undefined') {
    ccSetCookie("ccMenus", menuId);
  }else if(cookie.indexOf(menuId, 0) == -1) {
    ccSetCookie("ccMenus", cookie + ";" + menuId);
  }
}

function ccShowMenu(menuId, imageId) {
  var menu = document.getElementById(menuId);
  if (menu == 'null') {return;}
  ccExpandObj(menu, imageId, "ico/expanded.gif");
  var cookie = ccGetCookie("ccMenus");
  if(cookie != null) {
    var array = cookie.split(";");
    var newCookie = "";
    for(i=0; i<array.length; i++) {
      if(array[i] != menu.id) {
        if(newCookie == "") {newCookie = array[i];} 
        else {newCookie = newCookie + ";" + array[i];}
      }
    }
    ccSetCookie("ccMenus", newCookie);
  }
}

function ccToggleMenu(menuId, imageId) {
  if (ccAreaExpanded(menuId)) {ccHideMenu(menuId, imageId);} 
  else {ccShowMenu(menuId, imageId);}
}