
function expand_collapse(ind)
{
 s = document.getElementById("sp_" + ind);
 i = document.getElementById("im_" + ind);
 i2 = document.getElementById("im2_" + ind);
 if (s.style.display == 'none')
 {
   s.style.display = 'block';
   if (i) { i.src = "/centre/navutility/images/header/CFA_Program_arrow_0.gif"; }
   if (i2) { i2.src = "/centre/navutility/images/header/CFA_Program_arrow_0.gif"; }
 }
 else if (s.style.display == 'block')
 {
   s.style.display = 'none';
   if (i) { i.src = "/centre/navutility/images/header/CFA_Program_arrow_0.gif"; }
   if (i2) { i2.src = "/centre/navutility/images/header/CFA_Program_arrow_0.gif"; }
 }
}

function spawn(expr, qty, reversed) {
	var spawnee = [expr];
	for(s = 1; s < qty; s++) {
		spawnee[s] = expr+spawnee[s-1];
	}
	return reversed ? spawnee.reverse() : spawnee();
}


function inArray(needle, haystack){
	for (h in haystack) {
		if (haystack[h] == needle) {
			return true;
			// return h;

		}
	}
	return false;
} 


/* 
	this is the main breadcrumb function.  
	it controls the L3 breadcrumb line
	Based largely on the URL, it does use namearray (as defined in leftnav.html)
		to match the pathname with the words to use for it.  If that pathname 
		exists in namearray, it looks for the parent also.
	This was never meant for more than 2 levels of depth.
		
	This requires no arguments and simply outputs using javascript write of the 
		string that is put together in the function.

*/
function crumbs2() {
 	var el, i, j, k;
 	var divider=" : ";
	var h = "<a href='/index.html'>Home</a>";
	var ignore = new Array('','2006webtemplates');
	//the ignore array was for when this used the url for all it's information.  
	//this ignored certain directories.  may be useful in the future
	
	
	//when testing locally, uncomment the second path and give it the url minus the domain as below
	path = window.location.pathname;
	//path = "/centre/issues/comment/2001/01bcsc-asc_exempt.html";
	
	
	
	var partpath = path.split("\/");
	
	var temppath = '';
	var breakvar = 0;
	
	
	/*******************8*
	this code will do breadcrumbs based off of the namearray if ever needed refer to this
	**********************/
	/*
	if(namearray[path][0] != undefined){
		var id1 = namearray[path][0];
		var name1 = namearray[path][1];
		var parent1 = namearray[path][2];
		var parent1name;
		var parent1link;
		
		if(parent1 != ''){
			for(var arr in namearray){
				if(namearray[arr][0] == parent1){
					//alert(arr);
					parent1name = namearray[arr][1];
					parent1link = arr;
				
				}
			}
		
			if(parent1name != undefined){
				h += divider + "<a href=" + parent1link + ">" + parent1name + "</a>" + divider + name1;
			}
			else {
				h += divider + parent1 + divider + name1;
			}
		
		}
		else {
			h += divider + name1;		
		}		
	
	}
	else {
		//nothing?
	
	}
****************************************************/	
	
	
	
	for (var i in partpath) {
		temppath += partpath[i]+"/";
		//alert(temppath);
		if(!inArray(partpath[i], ignore)){
			if(i == partpath.length - 1){
				if(namearray[path] == undefined || partpath[i] == 'index.html'){
	
					//h += document.title;
				
				}
				else {
				
					if(namearray[path] != undefined){
					
						h += divider + namearray[path][1];
									
					}
					
				}
			}
			else {
				if(namearray[temppath] != undefined){
					if(temppath == path || temppath + "index.html" == path){
						h += divider + namearray[temppath][1];
					} else {
						
						rExp = /2$/gi;
	
						if(namearray[temppath][0].match(rExp)){
							var newname = namearray[temppath][0].replace(rExp, '');
							for(var link in namearray){
							
								if(namearray[link][0] == newname){
									h += (divider + "<a href="+link+">"+ namearray[temppath][1] + "</a>");
									breakvar = 1;
								}
							
							}
							
							
						
						}
					
						if(breakvar != 1){
							h += (divider + "<a href="+temppath+">"+ namearray[temppath][1] + "</a>");		
						}
						breakvar = 0;
					
					}
				} else {
					//h += (divider + "<a href="+temppath+">"+ partpath[i][1] + "</a>");		
				
				}
			
			}
		}
	}
	
	//alert(h);
	
	return h;

}



/*
	This is the main function for the control of the L3 leftnav
	It uses almost entirely the namearray that is defined in the leftnav.html file
	It also relies heavily on the idea that the leftnav html is formatted correctly.
*/
function formatleftnav(){
	/* window.location */
	//when testing locally, uncomment the second path and give it the url minus the domain as below
	path = window.location.pathname;
	//path = "/centre/issues/comment/2001/01bcsc-asc_exempt.html";
	
	//alert(document.getElementById('calid').className);
	
	rExp = /index.html$/gi;
	path = path.replace(rExp, '');
	
	var breakvar = 0;

	/*
	X's are the hidden-by-default unlinked boxes
	L's are the hidden-by-default L4 sublevel items
	
	ips is a special case because Investment Professional Standards 
		wraps to the next line and requires a taller box
		This is a hack.
	*/



	/*
		if this path is not one of our special namearray entities (this usually means the page
			does not show up on the leftnav
	
		getElementById(namearray[path][0]) will be referring to the unhidden by default
			L3_lftCenter_linkbox.
		getElementById(namearray[path][2]) will be referring to the parent of the above
		
		getElementById(namearray[path][0] + "X") will be referring to the hidden by default
			linkbox with no link unto itself
			
		getElementById(namearray[path][0] + "L") will be referring to the hidden by default L4
			linkbox.  This contains the sublevel navigation items
		
	
	*/
	if(namearray[path] != undefined){
		//alert(namearray[path][0]);
		document.getElementById(namearray[path][0]).style.display='none';
		if(document.getElementById(namearray[path][0] + "X") != undefined){
			document.getElementById(namearray[path][0] + "X").style.display='block';
		}
		if(document.getElementById(namearray[path][2] + "L") != undefined){
			document.getElementById(namearray[path][2] + "L").style.display='block';
		}		

		if(document.getElementById(namearray[path][0]).className == 'L3_lftCenter_linkBox'){

			document.getElementById(namearray[path][0]).className='L3_lftCenter_linkBox_active';
			if(document.getElementById(namearray[path][0] + "X") != undefined){
				document.getElementById(namearray[path][0] + "X").className='L3_lftCenter_linkBox_active';
			}			
		}		
		if(document.getElementById(namearray[path][2]).className == 'L3_lftCenter_linkBox'){
			document.getElementById(namearray[path][2]).className='L3_lftCenter_linkBox_active';
			document.getElementById(namearray[path][2]).style.fontWeight="bold";
 			if(namearray[path][2] == "ips"){
 				document.getElementById(namearray[path][2]).style.height="33px";
 			}
			if(document.getElementById(namearray[path][2] + "X") != undefined){
				//alert(document.getElementById(namearray[path][2] + "X").style.fontWeight);
				document.getElementById(namearray[path][2] + "X").className='L3_lftCenter_linkBox_active';
				document.getElementById(namearray[path][2] + "X").style.fontWeight="bold";
			}			
		}		


	}
	else {
		/*if the url is not included in the namearray, 
				the url needs to be split
				The url is the reconstructed in reverse order so it will go
				/centre/ips/gips/
				then
				/centre/ips/
				then
				/centre/

				This is so if /centre/ips/gips/ is an L3 nav item and
				/centre/ips/ is also an L3 item, it will only expand the gips item
				
				breakvars are used to stop processing of the url at that point


		*/
		
		var patharray = new Array();
		patharray = path.split("\/");
		var newpath = "/";
		var sortedpatharray = new Array();
		var counter = patharray.length - 1;

		for(i in patharray){
			if(patharray[i] != ''){
				newpath += patharray[i];					
				if(patharray[i].indexOf(".html") == -1){
					newpath += "/";
				}
				sortedpatharray[counter] = newpath;
				//alert(counter + ", " + sortedpatharray[counter]);
			}
			counter -= 1;
		}
		
		patharray = sortedpatharray;


		for(i = 0; i < sortedpatharray.length; i++){
			
			//newpath += patharray[i];
			//newpath = thenewpath + "/";
			newpath = sortedpatharray[i];
			//alert(i + ", " + sortedpatharray[i]);
			//if(patharray[i].indexOf(".html") == -1 && patharray[i] != ''){
			//	newpath += "/";		
			//}
			
			//alert(newpath);
			
			//the primary name(namearray[newpath][0]) might be fictional, the parent name(namearray[newpath][2]) can never be
			if(namearray[newpath] != undefined){
				
				if(document.getElementById(namearray[newpath][0]) != undefined){
					if(document.getElementById(namearray[newpath][0]).className == 'L3_L4link_indentBox' && breakvar != 2){
						document.getElementById(namearray[newpath][0]).style.fontWeight="bold";
			 			if(namearray[newpath][2] == "ips"){
			 				document.getElementById(namearray[newpath][2]).style.height="33px";
			 			}
						breakvar = 2;
					}

					if(document.getElementById(namearray[newpath][0]).className == 'L3_lftCenter_linkBox'){
						document.getElementById(namearray[newpath][0]).className='L3_lftCenter_linkBox_active';
						document.getElementById(namearray[newpath][0]).style.fontWeight="bold";
			 			if(namearray[newpath][0] == "ips"){
			 				document.getElementById(namearray[newpath][0]).style.height="33px";
			 			}
						if(document.getElementById(namearray[newpath][0] + "X") != undefined){
							document.getElementById(namearray[newpath][0] + "X").className='L3_lftCenter_linkBox_active';
						}			
						breakvar = 1;
					}
					//alert("bam");
				
				}
				
				
				if(document.getElementById(namearray[newpath][2]) != undefined){
					if(document.getElementById(namearray[newpath][2]).className == 'L3_L4link_indentBox' && breakvar != 2){
						document.getElementById(namearray[newpath][2]).style.fontWeight="bold";
						breakvar = 2;
					}
				}
				if(document.getElementById(namearray[newpath][2]).className == 'L3_lftCenter_linkBox'){
					document.getElementById(namearray[newpath][2]).className='L3_lftCenter_linkBox_active';
					document.getElementById(namearray[newpath][2]).style.fontWeight="bold";
					if(document.getElementById(namearray[newpath][2] + "X") != undefined){
						document.getElementById(namearray[newpath][2] + "X").className='L3_lftCenter_linkBox_active';
					}			
					breakvar = 1;
				}
				
				
				if(document.getElementById(namearray[newpath][2] + "L") != undefined){
					document.getElementById(namearray[newpath][2] + "L").style.display = 'block';
				}		
			
			
			
				if(breakvar == 1){
					break;
				}
			
			}//end if	

		}//end for
	}//end else


//alert(document.getElementById(path).className);

//	alert(path);




}



