// JavaScript Document

/*********************** QUICKLINKS DROPDOWN MENU ************************/
// Research & Support Group Constants corresponding to Quicklinks dropdown
TCP = 1
MICE = 2
CMMR = 3
CMHD = 4
ResearchFacility = 5
Transgenic = 6

function goSite() {

	index = document.fQuicklinks.sQuicklinks.selectedIndex;

	switch (index) {
		case TCP:
			window.location = "http://www.phenogenomics.ca";
			break;
		case MICE:
			window.location = "http://www.mouseimaging.ca/";
			break;
		case CMMR:
			window.location = "http://www.cmmr.ca";
			break;
		case CMHD:
			window.location = "http://www.cmhd.ca";
			break;
		case ResearchFacility:
			window.location = "http://www.phenogenomics.ca/rs/research_facility.html";
			break;
		case Transgenic:
			window.location = "http://www.phenogenomics.ca/transgenics/index.html";
			break;
		default:
			window.location = "http://www.phenogenomics.ca";
	}
}

/*********************** DYNAMIC LEFT NAVIGATION MENU ************************/
/*
// The following is for Reference: each numerical ID corresponds to the html tag IDs and menu IDs assigned to each page
0_0_0 = Home
1_0_0 = About Us
1_1_0 = About Us -> Organization & Objectives
1_2_0 = About Us -> Members & Partners
1_3_0 = About Us -> Careers
1_4_0 = About Us -> Contact Us
1_5_0 = About Us -> Maps & Directions

2_0_0 = Research
2_1_0 = Research -> MICe
2_2_0 = Research -> CMMR
2_3_0 = Research -> CMHD
2_4_0 = Research -> TCP Research Operations
2_5_0 = Research -> TCP Facility Operations
2_6_0 = Research -> TCP Transgenic Core & Specialty Resources
2_7_0 = Research -> Research Ethics
2_8_0 = Research -> Publications

3_0_0 = Transgenic Core
3_1_0 = Transgenic Core -> Services
3_1_1 = Transgenic Core -> ES Cell
3_1_2 = Transgenic Core -> Chimeras
3_1_3 = Transgenic Core -> Pronuclear Microinjection
3_1_4 = Transgenic Core -> Rederivation
3_1_5 = Transgenic Core -> Miscellaneous
3_2_0 = Transgenic Core -> Service Fees
3_3_0 = Transgenic Core -> Policies & Procedures
3_4_0 = Transgenic Core -> Protocols & Forms
3_5_0 = Transgenic Core -> Links

4_0_0 = Services
4_1_0 = Services -> Mouse Imaging
4_2_0 = Services -> CMMR Services
4_2_1 = Services -> CMMR Services -> Embryo Services
4_2_2 = Services -> CMMR Services -> Sperm Services
4_2_3 = Services -> CMMR Services -> Mouseline Services
4_2_4 = Services -> CMMR Services -> Somatic Tissue & Cell Services
4_2_5 = Services -> CMMR Services -> ES Cells Services
4_3_0 = Services -> Phenotyping
4_4_0 = Services -> Genetic Mapping
4_5_0 = Services -> Pathology
4_6_0 = Services -> Pathology Service Charges
4_7_0 = Services -> Transgenic Services

5_0_0 = Databases
5_1_0 = Databases -> MICe Variational Mouse Brain Atlas
5_2_0 = Databases -> CMMR Mutants & Samples Database
5_3_0 = Databases -> CMHD Mouse Model Databases

6_0_0 = News & Events
6_1_0 = News & Events -> Calendar
6_2_0 = News & Events -> News
6_3_0 = News & Events -> Conferences
6_4_0 = News & Events -> Seminars & Workshops
6_5_0 = News & Events -> Awards

7_0_0 = Help & Reference
7_1_0 = Help & Reference -> Glossary
7_2_0 = Help & Reference -> FAQs

*/

// Multi Menu-Item Constants
CMMR_SERVICES = "";

// Each page will keep a line of Javascript that looks like the following for its menu ID

// var menuID = new String("#_#_#");

// Array to keep track of the number of submenu items
menu = new Array(7);		// main menu
menu[0] = new Array(5);		// About Us section
menu[1] = new Array(7);		// Research section
menu[2] = new Array(5);		// Transgenics section
menu[2][0] = new Array(5);		// Transgenics Services section
menu[3] = new Array(7);		// Services section
menu[3][1] = new Array(5);		// CMMR Services section
menu[4] = new Array(3);		// Databases section
menu[5] = new Array(5);		// News & Events section
menu[6] = new Array(2);		// Help & Reference section

// Get the menu level indices for the current page based on this page's menu id that has been assigned at that page
var x = new Array(3);
x = menuID.split("_");
item1 = x[0];
item2 = x[1];
item3 = x[2];

var subitem;
var prev_subitem;

// for keeping track of swap image
var prev_img;

// number of services on the CMMR services page
NUM_CMMR_SERVICES = 5;

function displayLeftMenu() {

	// Get the number of submenu items required for this page
	var length1 = menu.length; //number of menu items at the lowest level
	var length2=0, length3=0;

	if ((item1 != 0) && (menu[item1-1] != null)) {
		length2 = menu[item1-1].length;
		if ((item2 != 0) && (menu[item1-1][item2-1] != null)) {
			length3 = menu[item1-1][item2-1].length;
		}
	}

	// Using the page's url, check whether this page corresponds to multiple menu items
	// If it does, find the name of the menu item
	url = new String (window.location.toString());
	var index = url.lastIndexOf("#");
	if (index != -1) subitem = url.charAt(index+1);
	if (isMultiItem(menuID)) {
		display_CMMR_Services();
	}

	// Go through the menu, displaying the relevant items for the current page
	for (i=1; i<=length1; i++) {
		// if this menu item corresponds to the current page, display it selected and display its submenu if applicable
		// otherwise, display it unselected
		if (i==item1) {
			displaySelected (item1+"_0_0");
			if (length2 > 0) displaySectionBody (item1);
			for (j=1; j<=length2; j++) {
				// if this menu item corresponds to the current page, display it selected and display its submenu if applicable
				// otherwise, display it unselected
				if (j==item2) {
					if (!isMultiItem(menuID)) {
						displaySelected (String(i)+"_"+String(j)+"_0");
						prev_subitem = null;
					}
					else {
						displaySelectedMulti (String(i)+"_"+String(j)+"_0");
					}
					if (length3 > 0) displaySectionBody (item1+"_"+item2);
					for (k=1; k<=length3; k++) {
						if (k==item3) {
							displaySelected (String(i)+"_"+String(j)+"_"+String(k));
						}
						else {
							displayUnselected (String(i)+"_"+String(j)+"_"+String(k));
						}
					}
				}
				// if this menu item contains subitems, display expandable cue
				else if (menu[i-1][j-1] != null) {
					displayExpandable (String(i)+"_"+String(j)+"_0");
				}
				else {
					displayUnselected (String(i)+"_"+String(j)+"_0");
				}
			}
		}
		else {
			displayUnselected (String(i)+"_0_0");
		}
	}

	//display end of left menu
    var end_obj = document.getElementById("lhn_end");
	end_obj.style.display = "block";
}

function displaySelected(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	if (menu_id != null) {
	}
	menu_obj.style.listStyleImage ="url(/assets/TCP_arrow_sel.gif)";
	menu_obj.style.display = "list-item";
}

function displaySelectedMulti(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	menu_obj.style.display = "block";
	if (subitem!=null) {
		if (prev_subitem != null) {
			prev_subitem.style.listStyleImage = "url(/assets/TCP_arrow_spacer.gif)";
		}
		var submenu_id = menu_id+subitem;
		var submenu_obj = document.getElementById(submenu_id);
		submenu_obj.style.listStyleImage ="url(/assets/TCP_arrow_sel.gif)";
		submenu_obj.style.display = "none";
		submenu_obj.style.display = "list-item";
		prev_subitem = submenu_obj;
		subitem = null;
	}
}

function displayExpandable (menu_id) {
    var menu_obj = document.getElementById(menu_id);
	menu_obj.style.listStyleImage ="url(/assets/TCP_arrow_plus.gif)";
	menu_obj.style.display = "list-item";
}

function displayUnselected(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	menu_obj.style.display = "list-item";
}

/*
function displayUnselectedMulti(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	menu_obj.style.display = "list-item";
}
*/

function isMultiItem(menu_id) {
	switch (menu_id.valueOf()) 
	{ 
		case CMMR_SERVICES: 
			return true; 
		default: 
			return false; 
	}
}

function displaySectionBody(section_id) {
    var section_obj = document.getElementById(section_id);
	section_obj.style.display = "block";
}

function swapBullet (menu_id) {
    var menu_obj = document.getElementById(menu_id);
	prev_img = menu_obj.style.listStyleImage;
	menu_obj.style.listStyleImage = "url(/assets/TCP_arrow.gif)";
}

function swapBullet_sub (menu_id) {
    var menu_obj = document.getElementById(menu_id);
	prev_img = menu_obj.style.listStyleImage;
	menu_obj.style.listStyleImage = "url(/assets/TCP_arrow.gif)";
}

function swapRestore(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	menu_obj.style.listStyleImage = prev_img;
}

function swapRestore_sub(menu_id) {
    var menu_obj = document.getElementById(menu_id);
	url = new String (menu_obj.style.listStyleImage.toString());
	var index = url.lastIndexOf("/");
	if (index != -1) imgSrc = url.substr(index+1);
	if (imgSrc == "TCP_arrow.gif)") {
		menu_obj.style.listStyleImage = prev_img;
	}
}

// Display the service content that corresponds to the menu item (only applicable for CMMR services page)
function display_CMMR_Services() {
	// using the menu item, find the service content id and display the content\
	if (subitem != null) {
		switch (subitem) {
			case 'a':
				display_CMMR_Service('service1');
				break;
			case 'b':
				display_CMMR_Service('service2');
				break;
			case 'c':
				display_CMMR_Service('service3');
				break;
			case 'd':
				display_CMMR_Service('service4');
				break;
			case 'e':
				display_CMMR_Service('service5');
				break;
			default:
		}
	}
}

function display_CMMR_Service(service) {
	// first close all other services and display this service
	for (i=1; i<=NUM_CMMR_SERVICES; i++) {
		obj = document.getElementById("service"+i);
		if ("service"+i != service) {
			obj.style.display = "none";
		}
		else {
			obj.style.display = "block";
		}
	}
}

/************************ DREAMWEAVER PREDEFINED FUNCTIONS ***********************/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out") {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

