/////////////////////////////// OLD Tree View Code /////////////////////////////// 
//added by ucsf
function ShowHideRow(row){
	/* new codes used to remember previous pages
	if(row.style.display=="none"){
		row.style.display=""
		return true;
	}else{
		row.style.display="none"
		return false;
	}
	*/
	if(row.style.display=="none"){
	row.style.display=""
	}else{
		row.style.display="none"
	}
}
function ShowHideChildNodes(id,plus,minus){
	
	var sPrefix="tv:cop"
	var oRow
	var iCnt=1
	var bHideAll=false
	var bBoldCheck=false
	
	//exit function if from mac.
	//the expand and contract feature has been disabled for macs.
	//is mac?
	if(navigator.appVersion.indexOf("Mac")!=-1){
		//only show if it is i.e.
		if(navigator.appName.indexOf("Microsoft") !=-1){
			return false;
		}
	}
	//if id is empty then toggle all nodes.
	if (id!=null){
		sPrefix= id + "."
		//alert(window.navigator.platform.instr("Mac") )

	}else{
		bHideAll=true
	}
	
	//loop through and hide all possible rows to a number that I don't think we will reach 30
	do{
		oRow=document.getElementById(sPrefix + iCnt)	
		if (oRow!=null){
			if(bHideAll){
				ShowHideChildNodes(sPrefix + iCnt,plus,minus)
			}else{
				if(bBoldCheck!=true){
					if (bHideAll!=true){
						BoldNodeTogglePlusMinus(id,plus,minus)	
						bBoldCheck=true
					}
				}
				ShowHideRow(oRow)
			}
		}
		iCnt++;
	}while(iCnt<30);
	return false;
}


/////////////////////////////// New Tree View Code /////////////////////////////// 
function BoldNodeTogglePlusMinus(id,plus,minus){
	var oimg=document.getElementById("img" +id)
	if (oimg.src.indexOf(plus)>=0){
		oimg.src=minus
	}else{
		oimg.src=plus
	}	
}
var COOKIE_KEY = String();
/*
function ShowHideRow(row){
	if(row.style.display=="none"){
		row.style.display=""
		return true;
	}else{
		row.style.display="none"
		return false;
	}
	
}
*/
function formShowNodes(cookiename,ids,plus,minus){
	var arIds = new Array;
	var i 
	var cookieIds	
	var arCookieIds	
	//sets the global cookie name.
	COOKIE_KEY = cookiename;
	cookieIds = getCookie(COOKIE_KEY);
	
	if((ids!="") || (cookieIds !="")){
		if (cookieIds!= null){
			if(cookieIds !=""){
				if ((ids!="") && (ids!=null)){
					ids = ids + "," + cookieIds;
				}else{
					ids = cookieIds;
				}				
				arCookieIds = ids.split(",");
				arCookieIds.sort();
				arCookieIds = arCookieIds.unique(true);
				ids = arCookieIds.join(",");					
			}
		}
		if (ids !=""){
			setCookie(COOKIE_KEY,ids,1);		
		}
		arIds = ids.split(",");
		for(i=0; i<arIds.length; i++){	
			var item =document.getElementById(arIds[i]);
			if (item != null){
				ShowHideRow(item);			
				BoldNodeTogglePlusMinus(arIds[i],plus,minus);
			}
		}	
	}
	return false;
}
function ShowHideChildNodesNew(id,plus,minus,parentid,URL){

	var arCookieIds = new Array;
	var cookieIds =new String;
	var openNodestring;
	cookieIds = getCookie(COOKIE_KEY);
	if (cookieIds == null){
		cookieIds = ""
	}
	var item =document.getElementById(id);
	var bShow = new Boolean;
	BoldNodeTogglePlusMinus(id,plus,minus);
	bshow = ShowHideRow(item);							
	//alert(bshow)
	//if it was a show action then add the id to the show list.
	if (bshow){
		//if the cookies are empty then 
		if (cookieIds =="" ){
			cookieIds = id 
		}else{
			if(inList(cookieIds,id)==false){				
				cookieIds = cookieIds + ',' + id							
			}
		}
		if (parentid != "null"){
			if(inList(cookieIds,parentid)==false){
				cookieIds = cookieIds + ',' + parentid
			}
		}											
		setCookie(COOKIE_KEY, cookieIds);
		/*	
		openNodestring = getCookie('OpenNodes');
		if (openNodestring  == null)
		{
			openNodestring = URL
		}
		else
		{
			openNodestring = openNodestring  +URL		
		}
		//alert(openNodestring)
	
		setCookie('OpenNodes', openNodestring, 60)
		*/
	//otherwise, it was a hide action and it should be removed from the list.
	}else{
	
		arCookieIds = cookieIds.split(",");
		var iRemove
		for(iRemove=0; iRemove<arCookieIds.length;iRemove++){
			if (arCookieIds[iRemove]==id){				
				arCookieIds.splice(iRemove,1);
			}
		}		
		setCookie(COOKIE_KEY,arCookieIds.join(","));
/*
		openNodestring = getCookie('OpenNodes');	
		
		if (openNodestring!="")
		{
			//alert('deleting')
			//alert(openNodestring)
			openNodestring = openNodestring.toLowerCase()
			URL = URL.toLowerCase()
			openNodestring = openNodestring.replace(URL, '')
			//alert(openNodestring)
			setCookie('OpenNodes', openNodestring, 60)	
		}			
		
		//alert(openNodestring)		
*/			
	}
	return false;
}
/*
function LinkOnMouseOver(trId, aId, tblId){
	var myTr=document.getElementById("trId")
	if (myTr !=null) 
	{
		myTr.style.backgroundColor = '#FAF2E3';
	}
	var myLink=document.getElementById("aId")
	if (myLink !=null) 
	{
		myLink.style.fontWeight = "bold";
	}
	var myTable=document.getElementById("tblId")
	if (myTable !=null) 
	{
		myTable.style.backgroundColor = '#FAF2E3';
	}
	
}
function LinkOnMouseOut(trId, aId, tblId){
	var myTr=document.getElementById("trId")
	if (myTr !=null) 
	{
		myTr.style.backgroundColor = '#FFFFFF';
	}
	var myLink=document.getElementById("aId")
	if (myLink !=null) 
	{
		myLink.style.fontWeight = "normal";
	}
	var myTable=document.getElementById("tblId")
	if (myTable !=null) 
	{
		myTable.style.backgroundColor = '#FFFFFF';
	}
	
}
*/

function LinkOnMouseOver(trId, aId, tblId, CurrentPage, css){
	var bgcolor=''
	if (css =="tvbluemedium") 
	{
		bgcolor = '#B4C0D3';
	}
	else if (css =="tvtealmedium") 
	{
		bgcolor = '#B2D4D4';
	}
	else
	{
		bgcolor = '#FAF2E3';
	}
	
	
	if (getCookie('DOM_TV_page') != null)
	{
		if (getCookie('DOM_TV_page').indexOf(CurrentPage) ==-1)
		{
			document.getElementById(trId).style.backgroundColor = bgcolor;
			if (aId !='')
			{
				document.getElementById(aId).style.fontWeight = "bold"; 
			}	
			document.getElementById(tblId).style.backgroundColor = bgcolor;
		}
		else
		{
			if (document.getElementById(tblId)!= null)
			{
				document.getElementById(tblId).style.backgroundColor = bgcolor;
			}
		}
	}
	
	else
	{
		if(document.getElementById(trId) != null)
		{
			document.getElementById(trId).style.backgroundColor = bgcolor;
		}
		if (document.getElementById(aId) != null)
		{
			document.getElementById(aId).style.fontWeight = "bold"; 
		}
		if (document.getElementById(tblId)!= null)
		{
			document.getElementById(tblId).style.backgroundColor = bgcolor;
		}
	}

}
function LinkOnMouseOut(trId, aId, tblId, CurrentPage){
	if (getCookie('DOM_TV_page') != null)
	{
		if (getCookie('DOM_TV_page').indexOf(CurrentPage) ==-1)
		{
			document.getElementById(trId).style.backgroundColor = '#FFFFFF';
			if (aId !='')
			{
				document.getElementById(aId).style.fontWeight = "normal"; 
			}
			document.getElementById(tblId).style.backgroundColor = '#FFFFFF';
		}
	}
	else
	{
		if (document.getElementById(trId) != null)
		{
			document.getElementById(trId).style.backgroundColor = '#FFFFFF';
		}
		if (document.getElementById(aId) != null)
		{
			document.getElementById(aId).style.fontWeight = "normal"; 
		}	
		if (document.getElementById(tblId) != null)
		{
			document.getElementById(tblId).style.backgroundColor = '#FFFFFF';
		}
	}
	
}

function inList(list,val){
	if(list.indexOf(val)>-1 ){
		return true;
	}else{
		return false;
	}
}
function setCookie(name,value,days){
	if (days){
		var date = new Date();
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		date.setTime(date.getTime()+(days*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}


// Array.push() - Add an element to the end of an array, return the new length
if( typeof Array.prototype.push==='undefined' ) {
 Array.prototype.push = function() {
  for( var i = 0, b = this.length, a = arguments, l = a.length; i<l; i++ ) {
   this[b+i] = a[i];
  }
  return this.length;
 };
}

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
Array.prototype.indexOf = function( v, b, s ) {
 for( var i = +b || 0, l = this.length; i < l; i++ ) {
  if( this[i]===v || s && this[i]==v ) { return i; }
 }
 return -1;
};

// Array.unique( strict ) - Remove duplicate values
Array.prototype.unique = function( b ) {
 var a = [], i, l = this.length;
 
 for( i=0; i<l; i++ ) {
  if( a.indexOf( this[i], 0, b ) < 0 ) 
	{ a.push( this[i] ); }
 }
 return a;
};