
//*****************************************************************************************************************************************************
// filename: utils.js
// purpose:	 JavaScript file containing utility functions that are used in multiple areas of the site. Incorporating all these functions in one common
//			 location ensures that all behaviour is the same in each location and provides a simpler method for maintenance.
// 
// project:	 CIBC Mellon
// date:	 2005.04.22
// version:  1.0
//
// function listing:
// -----------------
//	- dd_nav( param1 )
//	- ToggleMenuVisibility( param1, param2 )
//	- leftNavNavigate (param1 )
// 	- leftNavOver ( param1 ) 
// 	- leftNavOut ( param1 ) 
//	- adjustFontSize ( param1 )
//
//
// history:	2005.04.05  --  file created.  (Unknown)
//			2005.04.12  --  ToggleMenuVisibility() function added.  (Andrew Jardine)
//			2005.04.19  --  Rollover and Navigation added to left nav  (NC)
//*****************************************************************************************************************************************************


	//------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	dd_nav()
    // purpose:		This function changes the page location based on a url in a drop down
    // 
    // author:		NC - Organic Inc.
    // date:		2005.04.01
    // version:		1.0
    //
    // parameters:	- reference to the form field
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <select onChange="dd_nav( this );">
    //      <option value="/someurl/here/">tem 1</option>
    //      <option value="/another url/here/">item 2</option>
    //   </select>
	//------------------------------------------------------------------------------------------------------------------------------------------------
	function dd_nav(_t) 
	{
		dd_v = _t.options[_t.selectedIndex].value;
	
		if (dd_v != "") 
		{
			if("new_" == dd_v.substring(0,4))
			{
			    
			     window.open(dd_v.substring(4));
			}
			else
			{
			      document.location = dd_v;
			}
		}
	}


    //------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	ToggleMenuVisibility()
    // purpose:		This function is used to toggle the visibility of collapsible menus.
    // 
    // author:		Andrew Jardine - Organic Inc.
    // date:		2005.04.11
    // version:		1.1
    //
    // parameters:	- refrence to the link
    //				- String representing the ID of the menu that should be hidden/visible
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <a OnClick="ToggleMenuVisibility( this, 'menuID' );">Click here to expand menu</a>
    //   <div id="menuID" style="visibility:hidden;display:none;">
    //      <a href="http://someurl/here/>menu item 1</a>
    //      <a href="http://someurl/here/>menu item 2</a>
    //      <a href="http://someurl/here/>menu item 3</a>
    //   </div>
    //------------------------------------------------------------------------------------------------------------------------------------------------
    function ToggleMenuVisibility( sRef, menu )
    {	
		// check to see if the menu is currently hidden. If the menu is currently hidden,
		// then modify its CSS style so that it will be visible. The block/none setting
		// of the display attribute will make sure to compress any white space that is 
		// displayed when the menu is being hidden.\
		
		var cName = sRef.className;
		if ( document.getElementById(menu).style.visibility =="hidden" )
		{
			document.getElementById(menu).style.visibility = "visible";
			document.getElementById(menu).style.display = "block";
			sRef.className = cName.substr(0,cName.length-4) + 'Turn';
		}
		else
		{
			document.getElementById(menu).style.visibility = "hidden";
			document.getElementById(menu).style.display = "none";
			sRef.className = cName.substr(0,cName.length-4) + 'Over';	
		}
		
		if (arguments[2]) {
			document.location = arguments[2];	
		}
    }
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	leftNavNavigate()
    // purpose:		This function is used to navigate from the left nav
    // 
    // author:		NC - Organic Inc.
    // date:		2005.04.18
    // version:		1.0
    //
    // parameters:	- String representing the destination page
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <div onClick="leftNavNavigate('somepage.html')">Accounting</div>
    //------------------------------------------------------------------------------------------------------------------------------------------------
    function leftNavNavigate(page)
    {
		document.location = page;
    }
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	leftNavOver() && leftNavOut()
    // purpose:		These functions control the nav highlighting
    // 
    // author:		NC - Organic Inc.
    // date:		2005.04.18
    // version:		1.0
    //
    // parameters:	- String representing the page
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <div onmouseover="leftNavOver(this)" onmouseout="leftNavOut(this)">Accounting</div>
    //------------------------------------------------------------------------------------------------------------------------------------------------
    function leftNavOver(_t)
    {
    	var cName = _t.className;
    	if (cName.indexOf('Turn') == -1)
    	{
    		_t.className = cName + 'Over';
    	}
    }
    
    function leftNavOut(_t)
    {
    	var cName = _t.className;
    	if (cName.indexOf('Turn') == -1)
    	{
    		_t.className = cName.substr(0,cName.length-4);
    	}
    }
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	adjRollover()
    // purpose:		Used to control the highlighting on the font adjustment
    // 
    // author:		NC - Organic Inc.
    // date:		2005.04.22
    // version:		1.0
    //
    // parameters:	- reference to the href
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <div onMouseOver="adjRollover(this)">Accounting</div>
    //------------------------------------------------------------------------------------------------------------------------------------------------
    
    function adjRollover(_t)
    {
    	var cName = _t.className;
    	if (cName.indexOf('Over') == -1)
    	{
    		_t.className = cName + 'Over';
    	} else {
    		_t.className = 	cName.substr(0,cName.length-4);
    	}
    }
    
    
    //------------------------------------------------------------------------------------------------------------------------------------------------
    // function:	adjustFontSize()
    // purpose:		Page level control of font size
    // 
    // author:		NC - Organic Inc.
    // date:		2005.04.22
    // version:		1.0
    //
    // parameters:	- String representing the page
    // return:      - none
    //
    //
    // sample usage:
    // ------------- 
    //   <div onMouseOver="adjustFontSize('small')">A</div>
    //------------------------------------------------------------------------------------------------------------------------------------------------
    function adjustFontSize(_s) 
    {
    	var newFontSize;
    	var rightSideFont;
    	switch (_s)
    	{
    	case "small":
    		newFontSize = '1.0em';
    		rightSideFont = '0.7em';
    		break;
    	case "large":
    		newFontSize = '1.3em';
    		rightSideFont = '1.0em';
    		break;
    	case "huge":
    		newFontSize = '1.6em';
    		rightSideFont = '1.3em';
    		break;
    	}
    	document.getElementById('mainContent01').style.fontSize = newFontSize;
    	document.getElementById('rightContentRetiree').style.fontSize = rightSideFont;
    }
    
//-->    

/** Open a new window with parametres
 *  @ param url the link for the new window 
 */
function popUpWindow(url, name){
   var feature = "height=250,width=566,status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes,copyhistroy=no";
   popup=window.open(url, name, feature);
   popup.focus();
}

// to get radio button value
function get_radio_value(fieldname) {
  var rad_val ="";

  for (var i=0; i < fieldname.length; i++){
   if (fieldname[i].checked) {
         rad_val = fieldname[i].value;
      }
   }
   return rad_val;
}


function ToggleVisibility( sRef, menu )
    {	
		// check to see if the menu is currently hidden. If the menu is currently hidden,
		// then modify its CSS style so that it will be visible. The block/none setting
		// of the display attribute will make sure to compress any white space that is 
		// displayed when the menu is being hidden.\
		
		var cName = sRef.className;

/*
		if ( document.getElementById(menu).style.visibility == "hidden" )
		{
			document.getElementById(menu).style.visibility = "visible";
			document.getElementById(menu).style.display = "block";
			sRef.className = cName.substr(0,cName.length) + 'On';
		}
		else
		{
			document.getElementById(menu).style.visibility = "hidden";
			document.getElementById(menu).style.display = "none";
			sRef.className = cName.substr(0,cName.length-2);
		}
*/


                for (var i=0; i<26; i++){
                     
                    var group = groupList[i];
                    if ( group == menu){
                    
                    	document.getElementById(group).style.visibility = "visible";
		    	document.getElementById(group).style.display = "block";
			//sRef.className = cName + 'On';
                    }else{
			document.getElementById(group).style.visibility = "hidden";
			document.getElementById(group).style.display = "none";
                    }
                    
                }
		
		document.location = sRef;
		
    }


// Hide parts of the content for display
function hide(fieldname){
    if (null != document.getElementById(fieldname) ) {
         var style1 = document.getElementById(fieldname).style;
         style1.display = "none";
         return true;
    } else {
    	return false;
    }
}

// Show parts of the content
function show(fieldname){
   if (null != document.getElementById(fieldname) ) {
         var style1 = document.getElementById(fieldname).style;
         style1.display = "";
         return true;
    } else {
    	return false;
    }
}


/************************************************************************
*  date formatting functions ....                                       *
************************************************************************/
 
//declare arrays for month names in each language
var arrMonthsNL = new Array(12);
var arrMonthsFR = new Array(12);
var arrMonthsEN = new Array(12);
 
//set Dutch month name values
arrMonthsNL[0] = "januari";
arrMonthsNL[1] = "februari";
arrMonthsNL[2] = "maart";
arrMonthsNL[3] = "april";
arrMonthsNL[4] = "mei";
arrMonthsNL[5] = "juni";
arrMonthsNL[6] = "juli";
arrMonthsNL[7] = "augustus";
arrMonthsNL[8] = "september";
arrMonthsNL[9] = "oktober";
arrMonthsNL[10] = "november";
arrMonthsNL[11] = "december";
 
//set French month name values
arrMonthsFR[0] = "janvier";
arrMonthsFR[1] = "f&#233;vrier";
arrMonthsFR[2] = "mars";
arrMonthsFR[3] = "avril";
arrMonthsFR[4] = "mai";
arrMonthsFR[5] = "juin";
arrMonthsFR[6] = "juillet";
arrMonthsFR[7] = "ao&#251;t";
arrMonthsFR[8] = "septembre";
arrMonthsFR[9] = "octobre";
arrMonthsFR[10] = "novembre";
arrMonthsFR[11] = "d&#233;cembre";
 
//set English month name values
arrMonthsEN[0] = "January";
arrMonthsEN[1] = "February";
arrMonthsEN[2] = "March";
arrMonthsEN[3] = "April";
arrMonthsEN[4] = "May";
arrMonthsEN[5] = "June";
arrMonthsEN[6] = "July";
arrMonthsEN[7] = "August";
arrMonthsEN[8] = "September";
arrMonthsEN[9] = "October";
arrMonthsEN[10] = "November";
arrMonthsEN[11] = "December";
 
//declare arrays for day names in each language
var arrDaysNL = new Array(7);
var arrDaysFR = new Array(7);
var arrDaysEN = new Array(7);
 
//set Dutch day name values
arrDaysNL[0] = "zondag";
arrDaysNL[1] = "maandag";
arrDaysNL[2] = "dinsdag";
arrDaysNL[3] = "woensdag";
arrDaysNL[4] = "donderdag";
arrDaysNL[5] = "vrijdag";
arrDaysNL[6] = "zaterdag";
 
//set French day name values
arrDaysFR[0] = "dimanche";
arrDaysFR[1] = "lundi";
arrDaysFR[2] = "mardi";
arrDaysFR[3] = "mercredi";
arrDaysFR[4] = "jeudi";
arrDaysFR[5] = "vendredi";
arrDaysFR[6] = "samedi";
 
//set Dutch day name values
arrDaysEN[0] = "Sunday";
arrDaysEN[1] = "Monday";
arrDaysEN[2] = "Tuesday";
arrDaysEN[3] = "Wednesday";
arrDaysEN[4] = "Thursday";
arrDaysEN[5] = "Friday";
arrDaysEN[6] = "Saturday";
 
function today(strLang,strYYYYMMDD) {
var dtToday = new Date();
var strLang = new String(strLang.toUpperCase());
if (strYYYYMMDD != null && strYYYYMMDD != "" && strYYYYMMDD.length == 8){
   setYYYYMMDD(strYYYYMMDD);
}
 //the date
 function getDateVal() {
 intDay = dtToday.getDate();
 var strDay = "";
 if (intDay < 10) {
  strDay += "0"+intDay;
  }
 else {
  strDay += intDay;
  }
 return strDay;
 }
 //the month
 function getMonthVal(){
 intMonth = dtToday.getMonth();
 var strMonth = "";
 strMonth = eval("arrMonths"+strLang.toUpperCase())[intMonth];
 return strMonth;
 }
 //abbreviated month
 function getShortMonthVal(){
 strMonth = getMonthVal();
 strMonth = strMonth.substr(0,3);
 if (strMonth.substr(1,1) == "&"){
  strMonth = getMonthVal().substr(0,8);
  }
 return strMonth;
 }
 //year
 function getYearVal() {
 return dtToday.getFullYear();
 }
   //show full date
 function getFullDate(){
 	 if (strLang.toUpperCase() == "FR") {
		 return getDateVal()+" "+getMonthVal()+" "+getYearVal();
	 } else {
		 return getMonthVal()+" "+getDateVal()+", "+getYearVal();
	 }
 }
 //show short date
 function getShortDate() {
 return getDateVal()+" "+getShortMonthVal()+" "+getYearVal();
 }
 //show numeric date (YYYYMMDD)
 function getNumDate(){
 strM = (dtToday.getMonth()+1);
 if (strM < 10) { strM = "0"+strM; }
 return getYearVal() + strM + getDateVal();
 }
  //adjust the date
 function setDateVal(intDays){
 //intDt = dtToday.getDate();
 dtToday.setDate(intDays);
 }
 function resetDate(intDate){
 dtToday.setDate(intDate);
 }
 function setMonthVal(intMonth){
 dtToday.setMonth(intMonth-1);
 }
 function setYearVal(intYear){
 dtToday.setYear(intYear);
 }
function setYYYYMMDD(strYYYYMMDD){
	 var strYYYY = "";
	 var strMM = "";
	 var strDD = "";
	 var intYYYY = 0;
	 var intMM = 0;
	 var intDD = 0;
	 strYYYY = strYYYYMMDD.substring(0,4);
	 strMM = strYYYYMMDD.substring(4,6);
	 strDD = strYYYYMMDD.substring(6,8);
	 intYYYY = strYYYY;
	 intMM = strMM;
	 intDD = strDD;
	 setYearVal(intYYYY);
	 setMonthVal(intMM);
	 setDateVal(intDD);
 }
 //get the day of the week
 function getDay(){
  return(eval("arrDays"+strLang.toUpperCase())[dtToday.getDay()]);
 }
this.getDateVal = getDateVal;
this.getMonthVal = getMonthVal;
this.getYearVal = getYearVal;
this.getShortMonthVal = getShortMonthVal;
this.getFullDate = getFullDate;
this.getShortDate = getShortDate;
this.setDateVal = setDateVal;
this.getNumDate = getNumDate;
this.setMonthVal = setMonthVal;
this.setYearVal = setYearVal;
this.resetDate = resetDate;
this.getDay = getDay;
this.setYYYYMMDD = setYYYYMMDD;
}

