function defined(v) {
  return (typeof v == typeof UNDEFINED);
}

function arrayContains(array, item) {
  for (var i = 0; i < array.length; i++) {
    if (array[i] == item) {
      return true;
    }
  }
  return false;
}

function arrayPush(array, item) {
  array[array.length] = item;
}

// GlobalNavigationSettings
function GlobalNavigationSettings(siteId, cookieValue) {
  this._siteId = siteId;

  // default values
  this._medCertification = '0000';
  this._whiteList = new Array();
  this._blackList = new Array();
  this._serviceAgreementList = new Array();
  this._doctorFlag = false;
  this._version = '1.0';
 
  this._cookieValue = cookieValue;
}

GlobalNavigationSettings.prototype.COOKIE_PARAM_SEPARATOR = 'Z';
GlobalNavigationSettings.prototype.COOKIE_PARAM_NAME_VALUE_SEPARATOR = '.';
GlobalNavigationSettings.prototype.COOKIE_PARAM_LIST_SEPARATOR = 'x';
GlobalNavigationSettings.prototype.DOCTOR_MED_CERTIFICATION = '0001';
GlobalNavigationSettings.prototype.NURSE_MED_CERTIFICATION = '0003';
GlobalNavigationSettings.prototype.NURSE_STUDENT_MED_CERTIFICATION = '0022';
GlobalNavigationSettings.prototype.PHARMACIST_MED_CERTIFICATION = '0009';
GlobalNavigationSettings.prototype.OTHER_MED_CERTIFICATION = '0000';

GlobalNavigationSettings.prototype.getCookieValue = function() {
  return this._cookieValue;
}
GlobalNavigationSettings.prototype.parseCookieValue = function(cookieValue) {
  if (!defined(cookieValue)) {
    return;
  }
  var params = this.getCookieValue().split(this.COOKIE_PARAM_SEPARATOR);
  if (params.length != 6) {
    return;
  }
  this.setMedCertification(params[0].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1]);
  this.setWhiteList(params[1].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1].split(this.COOKIE_PARAM_LIST_SEPARATOR));
  this.setBlackList(params[2].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1].split(this.COOKIE_PARAM_LIST_SEPARATOR));
  this.setServiceAgreementList(params[3].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1].split(this.COOKIE_PARAM_LIST_SEPARATOR));
  this.setDoctorFlag(params[4].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1]);
  this.setVersion(params[5].split(this.COOKIE_PARAM_NAME_VALUE_SEPARATOR)[1].replace(this.COOKIE_PARAM_LIST_SEPARATOR, '.'));      
}
GlobalNavigationSettings.prototype.getMedCertification = function() {
  this.parseCookieValue();
  return this._medCertification;
}
GlobalNavigationSettings.prototype.setMedCertification = function(medCertification) {
  if ((medCertification == this.DOCTOR_MED_CERTIFICATION) || (medCertification == this.NURSE_MED_CERTIFICATION) || (medCertification == this.NURSE_STUDENT_MED_CERTIFICATION) || (medCertification == this.PHARMACIST_MED_CERTIFICATION)) {
    this._medCertification = medCertification;
  } else {
    this._medCertification = this.OTHER_MED_CERTIFICATION;
  }
}
GlobalNavigationSettings.prototype.getSiteId = function() {
  this.parseCookieValue();
  return this._siteId;
}
GlobalNavigationSettings.prototype.setSiteId = function(siteId) {
  this._siteId = siteId;
}
GlobalNavigationSettings.prototype.getWhiteList = function() {
  this.parseCookieValue();
  return this._whiteList;
}
GlobalNavigationSettings.prototype.setWhiteList = function(whiteList) {
  this._whiteList = whiteList;
}
GlobalNavigationSettings.prototype.getBlackList = function() {
  this.parseCookieValue();
  return this._blackList;
}
GlobalNavigationSettings.prototype.setBlackList = function(blackList) {
  this._blackList = blackList;
}
GlobalNavigationSettings.prototype.getServiceAgreementList = function() {
  this.parseCookieValue();
  return this._serviceAgreementList;
}
GlobalNavigationSettings.prototype.setServiceAgreementList = function(serviceAgreementList) {
  this._serviceAgreementList = serviceAgreementList;
}
GlobalNavigationSettings.prototype.isDoctor = function() {
  this.parseCookieValue();
  return this._doctorFlag;
}
GlobalNavigationSettings.prototype.getDoctorFlag = GlobalNavigationSettings.prototype.isDoctor;
GlobalNavigationSettings.prototype.setDoctorFlag = function(doctorFlag) {
  if (doctorFlag == "1" || doctorFlag == true) {
    this._doctorFlag = true;
  } else {
    this._doctorFlag = false;
  }
}
GlobalNavigationSettings.prototype.getVersion = function() {
  this.parseCookieValue();
  return this._version;
}
GlobalNavigationSettings.prototype.setVersion = function(version) {
  this._version = version;
}
GlobalNavigationSettings.prototype.getDoctorServiceIds = function() {
  var doctorServiceIdList = new Array();
  arrayPush(doctorServiceIdList, "1001");
  arrayPush(doctorServiceIdList, "1002");
  arrayPush(doctorServiceIdList, "1003");            
  arrayPush(doctorServiceIdList, "1004");
  arrayPush(doctorServiceIdList, "1006");
  arrayPush(doctorServiceIdList, "1007");
  arrayPush(doctorServiceIdList, "1012");
  return doctorServiceIdList;
}
GlobalNavigationSettings.prototype.getNurseServiceIds = function() {
  var nurseServiceIdList = new Array();
  arrayPush(nurseServiceIdList, "1005");
  return nurseServiceIdList;
}
GlobalNavigationSettings.prototype.setVersion = function(version) {
  this._version = version;
}
GlobalNavigationSettings.prototype.isServiceAllowed = function(serviceId) {
  if (arrayContains(this.getDoctorServiceIds(), serviceId)) {
    if (this.DOCTOR_MED_CERTIFICATION != this.getMedCertification()) {
      return false;
    }
    
    // black list check
    if (arrayContains(this.getBlackList(), serviceId)) {
      return false;
    }

    // white list or DCF code check
    if (!this.isDoctor() && !arrayContains(this.getWhiteList(), serviceId)) {
      return false;
    }

    // AskDoctors and usage agreement
    if (serviceId == "1002" && !arrayContains(this.getServiceAgreementList(), serviceId)) {
      return false;
    }

    // The user who has the m3_pass_code or is in the white_list is permitted for SNS
    if (serviceId == "1006" && !arrayContains(this.getServiceAgreementList(), serviceId) && !arrayContains(this.getWhiteList(), serviceId)) {
      return false;
    }

    return true;
    
  } else if (arrayContains(this.getNurseServiceIds(), serviceId)) {
    if (this.NURSE_MED_CERTIFICATION != this.getMedCertification() && this.NURSE_STUDENT_MED_CERTIFICATION != this.getMedCertification()) {
      return false;
    }

    // black list check
    if (arrayContains(this.getBlackList(), serviceId)) {
      return false;
    }
    
    return true;
  }
  return false;
}
GlobalNavigationSettings.prototype.isCategoryAllowed = function(categoryId) {
  if (categoryId == GlobalNavigationCategory.prototype.DOCTOR_CATEGORY_ID) {
    return (this.DOCTOR_MED_CERTIFICATION == this.getMedCertification());
  } else if (categoryId == GlobalNavigationCategory.prototype.NURSE_CATEGORY_ID) {
    return (this.NURSE_MED_CERTIFICATION == this.getMedCertification() || this.NURSE_STUDENT_MED_CERTIFICATION == this.getMedCertification());
  } else if (categoryId == GlobalNavigationCategory.prototype.PHARMACIST_CATEGORY_ID) {
    return (this.PHARMACIST_MED_CERTIFICATION == this.getMedCertification());
  } else if (categoryId == GlobalNavigationCategory.prototype.OTHER_CATEGORY_ID) {
	    return (this.OTHER_MED_CERTIFICATION == this.getMedCertification());
  }
  return true;
}

GlobalNavigationSettings.prototype.toString = function() {
  return '[GlobalNavigationSettings: siteId=' + this.getSiteId() + 
    ', medCertification=' + this.getMedCertification() +
    ', whiteList=' + this.getWhiteList() + ', blackList=' + this.getBlackList() + 
    ', serviceAgreementList=' + this.getServiceAgreementList() + 
    ', isDoctor=' + this.isDoctor() + ', version=' + this.getVersion() + ']';
}

function GlobalNavigationCategory(id, name) {
  this._id = id;
  this._name = name;
  this._itemList = new Array();
}
GlobalNavigationCategory.prototype.DOCTOR_CATEGORY_ID = 2;
GlobalNavigationCategory.prototype.NURSE_CATEGORY_ID = 4;
GlobalNavigationCategory.prototype.PHARMACIST_CATEGORY_ID = 5;
GlobalNavigationCategory.prototype.OTHER_CATEGORY_ID = 0;
GlobalNavigationCategory.prototype.getId = function() {
  return this._id;
}
GlobalNavigationCategory.prototype.getName = function() {
  return this._name;
}
GlobalNavigationCategory.prototype.addItem = function(item) {
  arrayPush(this._itemList, item);
}
GlobalNavigationCategory.prototype.getItemList = function() {
  return this._itemList;
}
GlobalNavigationCategory.prototype.size = function() {
  return this.getItemList().length;
}
GlobalNavigationCategory.prototype.getWidth = function() {
  var itemList = this.getItemList();
  var totalWidth = 0;
  for (var i=0; i < itemList.length; i++) {
    var item = itemList[i];
    totalWidth += item.getWidth();
  }
  return totalWidth;
}
GlobalNavigationCategory.prototype.containsBySiteId = function(siteId) {
  var itemList = this.getItemList();
  for (var i=0; i < itemList.length; i++) {
    var item = itemList[i];
    if (siteId == item.getId()) {
      return true;
    }
  }
  return false;
}
GlobalNavigationCategory.prototype.containsMoreM3 = function(siteId) {
  var itemList = this.getItemList();
  for (var i=0; i < itemList.length; i++) {
    var item = itemList[i];
    if (i >= 9 && siteId == item.getId()) {
      return true;
    }
  }
  return false;
}
GlobalNavigationCategory.prototype.getItemBySiteId = function(siteId) {
  var itemList = this.getItemList();
  for (var i=0; i < itemList.length; i++) {
    var item = itemList[i];
      if (siteId == item.getId()) {
        return item;
      }
    }
  return null;
}
GlobalNavigationCategory.prototype.toString = function() {
  return '[GlobalNavigationCategory:\nid=' + this.getId() + ', name=' + this.getName() + ', itemList=' + this.getItemList() + ']';
}


function GlobalNavigationItem(id, url, label, sslOK, imgSrc) {
  this._id = id;
  this._url = url;
  this._label = label;
  this._sslOK = sslOK;
  this._imgSrc = imgSrc;
}
GlobalNavigationItem.prototype.getId = function() {
  return this._id;
}
GlobalNavigationItem.prototype.getUrl = function() {
  return this._url;
}
GlobalNavigationItem.prototype.getLabel = function() {
  return this._label;
}
GlobalNavigationItem.prototype.isSSLOK = function() {
  return this._sslOK;
}
GlobalNavigationItem.prototype.getImgSrc = function() {
  return this._imgSrc;
}
GlobalNavigationItem.prototype.getLink = function() {
  if (this.isSSLOK()) {
    return window.location.protocol + '//' + this.getUrl();
  } else {
    return "http://" + this.getUrl();
  }
}
GlobalNavigationItem.prototype.getOnOffMode = function(siteId) {
  if (this.getId() == siteId) {
    return siteId;
  }
  return "off";
}
GlobalNavigationItem.prototype.toString = function() {
  return '[GlobalNavigationItem:\nid=' + this.getId() + 
    ', url=' + this.getUrl() + 
    ', link=' + this.getLink() + 
    ', label=' + this.getLabel() + 
    ', sslOK=' + this.isSSLOK() + 
    ', imgSrc=' + this.getImgSrc() + ']';
}

function GlobalNavigationRenderer(siteId, cookieValue, id) {
  this._settings = new GlobalNavigationSettings(siteId, cookieValue);
  this._categoryList = this.createCategoryList();
  this._id = id;
}
GlobalNavigationRenderer.prototype.getSettings = function() {
	  return this._settings;
}
GlobalNavigationRenderer.prototype.getCategoryList = function() {
  return this._categoryList;
}
GlobalNavigationRenderer.prototype.getCategoryById = function(id) {
	  var categoryList = this._categoryList;
	  for (var i=0; i < categoryList.length; i++) {
	    var category = categoryList[i];
	      if (id == category.getId()) {
	        return category;
	      }
	    }
	  return null;
}
GlobalNavigationRenderer.prototype.getId = function() {
	  return this._id;
}
GlobalNavigationRenderer.prototype.createCategoryList = function() {
  var categoryList = new Array();
  var trackingCode = this.getSettings().getSiteId() + "-header";
  
  var concierge = new GlobalNavigationItem("concierge", "mrkun.m3.com/mrq/top.htm?tc=" + trackingCode + "&mkep=" + trackingCode, "MR君・QOL君", false);
  var news = new GlobalNavigationItem("news", "www.m3.com/news/index.jsp?tc=" + trackingCode, "医療ニュース", false);
  var ishin = new GlobalNavigationItem("ishin", "www.m3.com/iryoIshin/index.jsp?tc=" + trackingCode, "医療維新", false);
  var community = new GlobalNavigationItem("community", "community.m3.com/?tc=" + trackingCode, "Community", false);
  var sns = new GlobalNavigationItem("sns", "sns.m3.com/showSNSTopPage.htm?tc=" + trackingCode, "SNS", false);
  var ask = new GlobalNavigationItem("ask", "askdoctors.m3.com/?tc=" + trackingCode, "AskDoctors", false);
  var career = new GlobalNavigationItem("career", "career.m3.com/?tc=" + trackingCode, "医師求人", false);
  var clinic = new GlobalNavigationItem("clinic", "clinic.m3.com/showTopPage.htm?tc="+trackingCode, "開業・経営", false);
  var select = new GlobalNavigationItem("select", "select.m3.com/select/showTopPage.htm?tc=" + trackingCode, "優待・特典", false);
  var blog = new GlobalNavigationItem("blog", "blog.m3.com/?tc=" + trackingCode, "ブログ", false);
  var rx = new GlobalNavigationItem("rx", "rx.m3.com/?tc=" + trackingCode, "薬剤情報", false);
  var pcommunity = new GlobalNavigationItem("pcommunity", "pcommunity.m3.com/pharmacist/index.do?tc=" + trackingCode, "薬剤師掲示板", false);
  var pcareer = new GlobalNavigationItem("pcareer", "pcareer.m3.com/?tc=" + trackingCode, "薬剤師求人", false);
  var research = new GlobalNavigationItem("research", "www.m3.com/research/?tc=" + trackingCode, "リサーチ", false);
  var medqa = new GlobalNavigationItem("medqa", "medqa.m3.com/doctor/index.do?tc=" + trackingCode, "診断治療Q&A", false);
  
  var category = new GlobalNavigationCategory();
  category.addItem(concierge);
  category.addItem(news);
  category.addItem(ishin);
  
  // 医師
  if (this.getSettings().isCategoryAllowed(category.DOCTOR_CATEGORY_ID)) {
    if (this.getSettings().isServiceAllowed("1003")) {
        category.addItem(community);
    }
    if (this.getSettings().isServiceAllowed("1012")) {
        category.addItem(medqa);
    }
    category.addItem(research);
    category.addItem(career);
    category.addItem(clinic);
    category.addItem(select);
    if (this.getSettings().isServiceAllowed("1006")) {
        category.addItem(sns);
    }
    if (this.getSettings().isServiceAllowed("1002")) {
        category.addItem(ask);
    }
    if (this.getSettings().isServiceAllowed("1004")) {
      category.addItem(rx);
    }
    category.addItem(blog);
    arrayPush(categoryList, category);
    category = new GlobalNavigationCategory("other", "その他");
    category.addItem(pcareer);
    arrayPush(categoryList, category);
  }
  
  // 看護師
  if (this.getSettings().isCategoryAllowed(category.NURSE_CATEGORY_ID)) {
    category.addItem(research);
    category.addItem(select);
    category.addItem(blog);
    arrayPush(categoryList, category);
    category = new GlobalNavigationCategory("other", "その他");
    category.addItem(career);
    category.addItem(pcareer);
    category.addItem(clinic);
    arrayPush(categoryList, category);
  }
  
  // 薬剤師
  if (this.getSettings().isCategoryAllowed(category.PHARMACIST_CATEGORY_ID)) {
    category.addItem(research);
    category.addItem(pcommunity);
    category.addItem(pcareer);
    category.addItem(select);
    category.addItem(rx);
    arrayPush(categoryList, category);
    category = new GlobalNavigationCategory("other", "その他");
    category.addItem(blog);
    category.addItem(career);
    category.addItem(clinic);
    arrayPush(categoryList, category);
  }
  
  // その他医療従事者
  if (this.getSettings().isCategoryAllowed(category.OTHER_CATEGORY_ID)) {
    category.addItem(research);
    category.addItem(select);
    category.addItem(blog);
    arrayPush(categoryList, category);
    category = new GlobalNavigationCategory("other", "その他");
    category.addItem(career);
    category.addItem(pcareer);
    category.addItem(clinic);
    arrayPush(categoryList, category);
  }
  return categoryList;
}
GlobalNavigationRenderer.prototype.render = function() {
  var siteId = this.getSettings().getSiteId();
  var categoryList = this.getCategoryList();
  var inner_html = '<table><tr>';
  // table
  for (var n=0; n < categoryList.length; n++) {
    var category = categoryList[n];
    var itemList = category.getItemList();
    for (var i=0; i < itemList.length; i++) {
      var item = itemList[i];
      if (category.getName() == null) {
       	if (i < 9) {
       	  if (siteId == item.getId()) {
            inner_html += '<td class="m3_stay-item"><a href="' + item.getLink() + '">' + item.getLabel() + '</a></td>';
       	  } else {
            inner_html += '<td><a href="' + item.getLink() + '">' + item.getLabel() + '</a></td>';
       	  }
       	} else {
       	  if (!inner_html.match("m3_extra_items")) {
       	    if (category.containsMoreM3(siteId)) {
       	      label = category.getItemBySiteId(siteId).getLabel();
              inner_html += '<td id="m3_extra" class="m3_stay-item"><a class="m3_stay-other" href="#m3_extra_items" title="' + label + '">' + label + '<img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01.gif" width="15" height="15" alt="" /><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01o.gif" width="15" height="15" alt="" style="display: none;" /></a></td>';
       	    } else if (this.getCategoryById("other").containsBySiteId(siteId)) {
       	      label = this.getCategoryById("other").getItemBySiteId(siteId).getLabel()
              inner_html += '<td id="m3_extra" class="m3_stay-item"><a class="m3_stay-other" href="#m3_extra_items" title="' + label + '">' + label + '<img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01.gif" width="15" height="15" alt="" /><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01o.gif" width="15" height="15" alt="" style="display: none;" /></a></td>';
            } else {
              inner_html += '<td id="m3_extra"><a class="m3_stay-other" href="#m3_extra_items" title="more m3"><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01.gif" width="15" height="15" alt="" /><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01o.gif" width="15" height="15" alt="" style="display: none;" />more m3</a></td>';
            }
       	  }
        }
      } else if (category.getName() == "その他") {
        if (!inner_html.match("m3_extra_items")) {
          if (category.containsBySiteId(siteId)) {
            label = category.getItemBySiteId(siteId).getLabel();
            inner_html += '<td id="m3_extra" class="m3_stay-item"><a class="m3_stay-other" href="#m3_extra_items" title="' + label + '">' + label + '<img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01.gif" width="15" height="15" alt="" /><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01o.gif" width="15" height="15" alt="" style="display: none;" /></a></td>';
          } else {
            inner_html += '<td id="m3_extra"><a class="m3_stay-other" href="#m3_extra_items" title="その他"><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01.gif" width="15" height="15" alt="" /><img class="more_m3_icon" src="' + location.protocol + '//s.m3img.com/images/shared/more_m3_icon_01o.gif" width="15" height="15" alt="" style="display: none;" />その他</a></td>';
          }
        }
      }
    }
  }
  inner_html += '</tr></table> ';
  // m3_extra_items
  for (var n=0; n < categoryList.length; n++) {
    var category = categoryList[n];
    var itemList = category.getItemList();
    for (var i=0; i < itemList.length; i++) {
      var item = itemList[i];
      if (category.getName() == null) {
        if (i >= 9) {
          if (!inner_html.match("m3_extra_items_more-m3")) {
            inner_html += '<div id="m3_extra_items" class="pseudo-opened">';
            inner_html += '<ins class="BAEffectResizeBase" style="text-decoration: none;">';
            inner_html += '<dl class="BAEffectBlindBase" style="margin: 0pt; display: none;">'
            inner_html += '<dt id="m3_extra_items_more-m3">more m3</dt>';
            inner_html += '<dd><ul>';
          }
          if (siteId != item.getId()) {
            inner_html += '<li><a href="' + item.getLink() + '">' + item.getLabel() + '</a></li>';
          }
        }
      } else if (category.getName() == "その他") {
        if (inner_html.match("m3_extra_items_more-m3")) {
          if (!inner_html.match("その他")) {
            inner_html += '</ul></dd>';
            inner_html += '<dt id="m3_extra_items_others">その他</dt>';
            inner_html += '<dd><ul>';
          }
        } else {
          inner_html += '<div id="m3_extra_items" class="pseudo-opened">';
          inner_html += '<ins class="BAEffectResizeBase" style="text-decoration: none;">';
          inner_html += '<dl class="BAEffectBlindBase" style="margin: 0pt; display: none;">'
          inner_html += '<dt id="m3_extra_items_more-m3">その他</dt>';
          inner_html += '<dd><ul>';
        }
        if (siteId != item.getId()) {
          inner_html += '<li><a href="' + item.getLink() + '">' + item.getLabel() + '</a></li>';
        }
      }
    }
  }
  if (inner_html.match("m3_extra_items")) {
    inner_html += '</dl></ins></div> ';
  }
  
  jQuery('#' + this.getId()).html(inner_html);
  jQuery("body").addClass("dom-enabled");
  jQuery("#m3_extra").click(function () {
	  jQuery(".BAEffectBlindBase").css("min-width", jQuery("#m3_extra").outerWidth(true)).slideToggle();
      jQuery(".more_m3_icon").toggle();
      return false;
  });

  if (jQuery("#m3_extra_items_others + dd > ul:first").text() == '') {
      jQuery("#m3_extra_items_others + dd").remove();
      jQuery("#m3_extra_items_others").remove();
  }
  
}

function SideNavigationRenderer(siteId, cookieValue, id) {
	  this._settings = new GlobalNavigationSettings(siteId, cookieValue);
	  this._categoryList = this.createCategoryList();
	  this._id = id;
}
SideNavigationRenderer.prototype.getSettings = function() {
	  return this._settings;
}
SideNavigationRenderer.prototype.getCategoryList = function() {
return this._categoryList;
}
SideNavigationRenderer.prototype.getId = function() {
	  return this._id;
	}
SideNavigationRenderer.prototype.createCategoryList = function() {
var categoryList = new Array();
var trackingCode = this.getSettings().getSiteId() + "-header";

var concierge = new GlobalNavigationItem("concierge", "mrkun.m3.com/mrq/top.htm?tc=" + trackingCode + "&mkep=" + trackingCode, "MR君・QOL君", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_01.gif");
var news = new GlobalNavigationItem("news", "www.m3.com/news/index.jsp?tc=" + trackingCode, "医療ニュース&ジャーナル", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_02.gif");
var ishin = new GlobalNavigationItem("ishin", "www.m3.com/iryoIshin/index.jsp?tc=" + trackingCode, "医療維新", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_03.gif");
var community = new GlobalNavigationItem("community", "community.m3.com/?tc=" + trackingCode, "Doctors Community", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_06.gif");
var sns = new GlobalNavigationItem("sns", "sns.m3.com/showSNSTopPage.htm?tc=" + trackingCode, "Doctors SNS", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_07.gif");
var ask = new GlobalNavigationItem("ask", "askdoctors.m3.com/?tc=" + trackingCode, "AskDoctors", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_11.gif");
var career = new GlobalNavigationItem("career", "career.m3.com/?tc=" + trackingCode, "医師求人", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_04.gif");
var clinic = new GlobalNavigationItem("clinic", "clinic.m3.com/showTopPage.htm?tc="+trackingCode, "開業・経営", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_08.gif");
var select = new GlobalNavigationItem("select", "select.m3.com/select/showTopPage.htm?tc=" + trackingCode, "優待・特典", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_05.gif");
var blog = new GlobalNavigationItem("blog", "blog.m3.com/?tc=" + trackingCode, "Doctors Blog", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_10.gif");
var rx = new GlobalNavigationItem("rx", "rx.m3.com/?tc=" + trackingCode, "薬剤情報", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_09.gif");
var pcareer = new GlobalNavigationItem("pcareer", "pcareer.m3.com/?tc=" + trackingCode, "薬剤師求人", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_04.gif");
var pcommunity = new GlobalNavigationItem("pcommunity", "pcommunity.m3.com/pharmacist/index.do?tc=" + trackingCode, "薬剤師掲示板", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_06.gif");
var research = new GlobalNavigationItem("research", "www.m3.com/research/?tc=" + trackingCode, "リサーチ", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_13.gif");
var medqa = new GlobalNavigationItem("medqa", "medqa.m3.com/doctor/index.do?tc=" + trackingCode, "診断治療Q&A", false, location.protocol + "//s.m3img.com/images/shared/m3_top_nav_icon_14.gif");

var category = new GlobalNavigationCategory();
category.addItem(concierge);
category.addItem(news);
category.addItem(ishin);
category.addItem(research);

// 医師
if (this.getSettings().isCategoryAllowed(category.DOCTOR_CATEGORY_ID)) {
  category.addItem(career);
  category.addItem(clinic);
  category.addItem(select);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "医師限定コンテンツ");
  if (this.getSettings().isServiceAllowed("1003")) {
    category.addItem(community);
  }
  if (this.getSettings().isServiceAllowed("1012")) {
	    category.addItem(medqa);
  }
  if (this.getSettings().isServiceAllowed("1006")) {
      category.addItem(sns);
    }
  if (this.getSettings().isServiceAllowed("1004")) {
    category.addItem(rx);
  }
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "一般公開コンテンツ");
  category.addItem(blog);
  if (this.getSettings().isServiceAllowed("1002")) {
    category.addItem(ask);
  }
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "その他のサービス");
  category.addItem(pcareer);
  arrayPush(categoryList, category);
}

// 看護師
if (this.getSettings().isCategoryAllowed(category.NURSE_CATEGORY_ID)) {
  category.addItem(select);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "一般公開コンテンツ");
  category.addItem(blog);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "その他のサービス");
  category.addItem(career);
  category.addItem(pcareer);
  category.addItem(clinic);
  arrayPush(categoryList, category);
}

// 薬剤師
if (this.getSettings().isCategoryAllowed(category.PHARMACIST_CATEGORY_ID)) {
  category.addItem(pcommunity);
  category.addItem(pcareer);
  category.addItem(select);
  category.addItem(rx);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "一般公開コンテンツ");
  category.addItem(blog);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "その他のサービス");
  category.addItem(career);
  category.addItem(clinic);
  arrayPush(categoryList, category);
}

// その他医療従事者
if (this.getSettings().isCategoryAllowed(category.OTHER_CATEGORY_ID)) {
  category.addItem(select);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "一般公開コンテンツ");
  category.addItem(blog);
  arrayPush(categoryList, category);
  category = new GlobalNavigationCategory(null, "その他のサービス");
  category.addItem(career);
  category.addItem(pcareer);
  category.addItem(clinic);
  arrayPush(categoryList, category);
}
return categoryList;
}
SideNavigationRenderer.prototype.render = function() {
  var inner_html = '<dl class="m3_navigation">';
  var categoryList = this.getCategoryList();
  for (var n=0; n < categoryList.length; n++) {
    var category = categoryList[n];
    var itemList = category.getItemList();
    if (itemList.length < 1) {
      continue;
    }
    if (category.getName() == null) {
      inner_html += '<dd class="m3_navigation-contents"><ul>';
    } else if (category.getName() == "その他のサービス") {
      inner_html += '</dd></dl>';
      inner_html += '<dl class="m3_option-nav">';
      inner_html += '<dt class="m3_option-nav-title">その他のサービス</dt>';
      inner_html += '<dd class="m3_option-nav-contents"><ul class="m3_link-list">';
    } else {
      inner_html += '<dt class="m3_navigation-title">' + category.getName() + '</dt>';
      inner_html += '<dd class="m3_navigation-contents"><ul>';
    }
    for (var i=0; i < itemList.length; i++) {
      var item = itemList[i];
      if (category.getName() == "その他のサービス") {
        inner_html += '<li><a href="' + item.getLink() + '">' + item.getLabel() + '</a></li>';
      } else {
        inner_html += '<li><a href="' + item.getLink() + '"><img src="' + item.getImgSrc() + '" width="21" height="21" alt="" />' + item.getLabel() + '</a></li>';
      }
    }
    inner_html += '</ul></dd>';
  }
  inner_html += '</dl>';
  
  jQuery('#' + this.getId()).html(inner_html);
}

var loadStylesheet = function(href) {
	var css = document.createElement("link");
	css.rel = "stylesheet";
	css.type = "text/css";
	css.href = href;
	document.getElementsByTagName('head')[0].appendChild(css);
}

var getABtest = function(seed) {
	var charCodes = 0;
	for (i = 0; i < seed.length; i = i +1) {
		charCodes += seed.charCodeAt(i);
	}
	return charCodes % 2 ? "a" : "b";
}