
		function getRef(id) {
			return (document.getElementById ? document.getElementById(id) : document.all[id]);
		}
	
	
		/* GENERIC HEADER IMAGE DISPLAY */

		// generates a psuedo-random number between 0 and argument-1.  
		// i.e. range=4 would return a number from 0-3
		function getRandom(range) 
		{
			var rnd = Math.floor(Math.random() * range);
			return rnd;
		}

		/* IMPORTANT GLOBAL VAR FOR MIGRATED CONTENT */
		/* The function call to output a random img is in the 
		   financing layout and not in the migrated layout.
		   The isMigrated() function tests the value of this
		   var to see if getRndImg() has been initiated or not.
		   If it hasn't we call it to output the images.	
		   shandford: 06/01/04
		*/
		var hasRandomInit = false;
		function getRndImg() 
		{
			var noDef1 = getRef("gen1"); // get a reference to the spacer images we're going to change
			var noDef2 = getRef("gen2");
			var randNum1;
			var randNum2;
			var strLocation;
			var strIdx;
			
			hasRandomInit = true; // see above comment block
			
			if(noDef1 && noDef2) { // get the random banner

				// special treatment for commercial section
				strLocation = document.location;
				strLocation += ""; //convert to a string
				strIdx = strLocation.indexOf("comm");
			
				if(strIdx == -1){ // normal image
					randNum1 = getRandom(6)+1;
					randNum2 = getRandom(8)+1;
					noDef1.src = "/images/financing/head_image_l0" + randNum1 + "_en_CA.gif";
					noDef2.src = "/images/financing/head_image_r0" + randNum2 + "_en_CA.gif";
				} else { // commercial image
					randNum1 = getRandom(6)+1;
					randNum2 = getRandom(7)+1;
					noDef1.src = "/images/financing/head_com_image_l0" + randNum1 + "_en_CA.gif";
					noDef2.src = "/images/financing/head_com_image_r0" + randNum2 + "_en_CA.gif";
				}
				
			} else {
				return;
			}
		}
		
		//for migrated content.  refer to above comments for context.
		function isMigrated(){
			if(hasRandomInit){
				return;
			} else {
				getRndImg();
			}
		}
		setTimeout("isMigrated();", 2000);
		
		
		/* HOME PAGE TICKER  */
		
		// holds the headline and headline url
		var headlineArray = new Array;
		headlineArray[0] = [
							/*[ "Receive an Equifax on-line personal credit report", "javascript:var equi=window.open('https://www.econsumer.equifax.ca/ca/main?link=GMAC1&lang=en','equifx','width=680,height=500,screenX=25,screenY=190,left=25,top=190,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes');"],*/
							[ "Current Customers - valuable information<br />and tools", "/english/financing/cust/cust_overview.html"],
							[ "GMAC Commercial - serving your vehicle<br/>financing needs", "/english/financing/comm/comm_over.html"],
							[ "GMAC - a diversified family of companies", "/financing/abut/abut_overview_en_CA.html"]
						];
		
		
		// set up global vars to use in following function
		function initHeadVars()
		{
			headIdx = 0;
			headDivObj = getRef("headlinesDiv");
			headLen = headlineArray[0].length;
		}		
		function rotateHead() 
		{
			var headStr = "";
			if(headIdx < headLen){
				headStr = "<a href=\"" + headlineArray[0][headIdx][1] + "\"><span class=\"headline\">" + headlineArray[0][headIdx][0] +  "</span></a>";
				headDivObj.innerHTML = headStr;
				headIdx++;
				setTimeout("clearHead()", 4000);
			} else {
				headIdx = 0;
				setTimeout("rotateHead()", 500);
			}
		}
		function clearHead() 
		{
			var headStr = "";
			headDivObj.innerHTML = headStr;
			setTimeout("rotateHead()", 900);
		}
		
		/* HABITAT POPUP - SCROLLING IMAGES FUNCTIONALITY */
		
		var habitImgArray = [
							["/images/financing/gmac_habitat_01_en_CA.jpg"],
							["/images/financing/gmac_habitat_02_en_CA.jpg"],
							["/images/financing/gmac_habitat_03_en_CA.jpg"],
							["/images/financing/gmac_habitat_04_en_CA.jpg"],
							["/images/financing/gmac_habitat_05_en_CA.jpg"],
							["/images/financing/gmac_habitat_06_en_CA.jpg"],
							["/images/financing/gmac_habitat_07_en_CA.jpg"],
							["/images/financing/gmac_habitat_08_en_CA.jpg"],
							["/images/financing/gmac_habitat_09_en_CA.jpg"]
						];
		
		imgIdx = 0;  // counter for the images
		
		/* create an image object for each image listed in the array - index starts at zero */
		function initImgObj()
		{
		  	for(var x=0;x<habitImgArray.length;x++) {
				eval("img" + x + " = new Image()");
				eval("img" + x + ".src = " + "\"" + habitImgArray[x][0] + "\"");
			}
			initDisplay();
		}
		
		/* show first image */
		function initDisplay()
		{
			var mainImgObj= getRef("mainImg");
			mainImgObj.src =  eval("img" + imgIdx + ".src");
			dispImgNum();
		}
		
		
		function dispImgNum()
		{
			var totalImg = habitImgArray.length;
			var imgnumdivObj = getRef("imgNumDiv");
			imgnumdivObj.innerHTML = "<span class=\"habitatTxt\">" + (imgIdx+1) + " / " + totalImg + "</span>";
		}
		
		
		function prev()
		{
			var mainImgObj= getRef("mainImg");
			if(imgIdx!=0){
				imgIdx--;
				mainImgObj.src = eval("img" + imgIdx + ".src");
				dispImgNum();
			} 
			checkArrowStateRew();
		}
		
		function next()
		{
			var mainImgObj= getRef("mainImg");
			if(habitImgArray.length!=imgIdx+1){
				imgIdx++;
				mainImgObj.src = eval("img" + imgIdx + ".src");
				dispImgNum();
			}
			checkArrowStateFwd();
		}
		
		
		function checkArrowStateFwd()
		{
			if(imgIdx==1){// second img - show double arrows
				var bothDivObj = getRef("bothDiv");
				var firstDivObj = getRef("firstDiv");
				bothDivObj.style.visibility = "visible";
				firstDivObj.style.visibility = "hidden";
			} else if(habitImgArray.length==imgIdx+1){ // last img - show previous arrows
				var bothDivObj = getRef("bothDiv");
				var lastDivObj = getRef("lastDiv");
				bothDivObj.style.visibility = "hidden";
				lastDivObj.style.visibility = "visible";
			}		
		}
		
		function checkArrowStateRew()
		{
			if(imgIdx==habitImgArray.length-2){// second last img - show double arrows
				var bothDivObj = getRef("bothDiv");
				var lastDivObj = getRef("lastDiv");
				bothDivObj.style.visibility = "visible";
				lastDivObj.style.visibility  = "hidden";
			} else if(imgIdx==0){ // first img - show next arrow
				var bothDivObj = getRef("bothDiv");
				var firstDivObj = getRef("firstDiv");
				bothDivObj.style.visibility = "hidden";
				firstDivObj.style.visibility = "visible";
			}
		}


		/* FUNCTION USED TO TARGET PARENT WINDOWS */
		function openLink(file,target) {
			if(opener.closed){ // the parent window is closed
				var adviseWin = window.open(file, 'newAdvisorWin', 'height=550,width=770,screenX=25,left=25,screenY=150,top=150,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes');
			} else { // target the parent
				target.window.location.href = file;
			}
		}
		

	/* SPECIAL POPUP FOR ADVISOR WINDOW */
	
	// these vars are declared in gmcl_extjs.js - left here for debugging
	//var ie5 = (document.all && document.getElementbyID) ? false : true;
	//var isMac = (navigator.appVersion.indexOf("Mac") == -1) ? false : true;

	var adWin;	
	function openAdvisorWin(url, popWidth, popHeight, popScroll, popStatus) {
		var winName =  "adPopup";
		// popStatus is a new parameter; it is optional so that old calls will not cause an error
		var statusBar = popScroll; 
		
		if (popStatus != null) { 
			statusBar  = popStatus;
			// 'fix' for Mac IE's problem when including a status bar in the pop up window
			// - the browser chops off the bottom 18 pixels of the window to accomodate for the
			//   the status bar, and so we add 18 pixels to the height			
			if (!ie5 && !ns && isMac) { popHeight += 18; }
		}

		if(adWin) {
			if(!adWin.closed) {
				adWin.focus();
				return;
			} else {
				adWin = null;	
			}
		}
		
		adWin=window.open(url, winName, 'width=' + popWidth + ',height=' + popHeight + ',screenX=25,screenY=150,left=25,top=150,scrollbars=' + popScroll + ',resize=no,status=' + statusBar + '');
		
		if (adWin.opener == null) adWin.opener = self;
		adWin.focus();
	}

   function toggleSection(eleID) {
				closeSection('leasing');
				closeSection('purchase');
				closeSection('comm');
				closeSection('payments');
				closeSection('account');
				closeSection('insurance');
                if(document.all) {
				document.all(eleID).style.display = 'block';			
			} else if (document.getElementById) {
				document.getElementById(eleID).style.display = 'block';
			}
		}
						
		function closeSection (eleID) {
			if(document.all) {
				document.all(eleID).style.display = 'none';			
			} else if (document.getElementById) {
				document.getElementById(eleID).style.display = 'none';
			}
		}	
