	var isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
/* HOMEPAGE ROLLOVER FUNCTIONS */
		function getRef(id) {
		return (document.getElementById(id));
	}
	function init() 
	{
		artidivObj = getRef("artidiv");
		artibgdivObj = getRef("artibgdiv");
		//newsdivObj = getRef("newsdiv");
		//newsbgdivObj = getRef("newsbgdiv");
		eventsdivObj = getRef("eventsdiv");
		eventsbgdivObj = getRef("eventsbgdiv");
		ownrgaldivObj = getRef("ownrgaldiv");
		ownrgalbgdivObj = getRef("ownrgalbgdiv");
		//servicedivObj = getRef("servicediv");
		//servicebgdivObj = getRef("servicebgdiv");
		geardivObj = getRef("geardiv");
		gearbgdivObj = getRef("gearbgdiv");
	}
	function hideDivs() 
	{
		artidivObj.style.visibility = "hidden";
		artibgdivObj.style.visibility = "hidden";
		//newsdivObj.style.visibility = "hidden";
		//newsbgdivObj.style.visibility = "hidden";
		eventsdivObj.style.visibility = "hidden";
		eventsbgdivObj.style.visibility = "hidden";
		ownrgaldivObj.style.visibility = "hidden";
		ownrgalbgdivObj.style.visibility = "hidden";
		//servicedivObj.style.visibility = "hidden";
		//servicebgdivObj.style.visibility = "hidden";
		geardivObj.style.visibility = "hidden";
		gearbgdivObj.style.visibility = "hidden";

	}
	function showDiv(div, div2)
	{
		var divObj = getRef(div);
		var div2Obj = getRef(div2);
		hideDivs();
		divObj.style.visibility = "visible";
		div2Obj.style.visibility = "visible";
	}
	function hideDiv(div, div2)
	{
		var divObj = getRef(div);
		var div2Obj = getRef(div2);
		divObj.style.visibility = "hidden";
		div2Obj.style.visibility = "hidden";
	}
	
/* EVENT ITEM DISPLAY FUNCTIONS */

	function getToday()
	{
		var now = new Date();
		
		var year = now.getYear();
		var month = now.getMonth();
		var day = now.getDate();
		
		month += 1; // convert to month of year based from 1
		
		// convert to string and test length
		month = month + "";
		if(month.length==1){
			month = "0" + month;
		}
		day = day + "";
		if(day.length==1){
			day = "0" + day;
		}
		if(year<1000){// ns and opera
			year += 1900;
		}
		
		//assemble today's date
		var today =  year + "" + month + "" + day;
		
		// convert to int for comparison
		today -= 0;
		
		return today;
	}
	function showEvents() 
	{
	/*
		Display Logic
		- no more than 8 events are shown
		- show a maximum of 2 past events
		- show up to 6 future events
		- flaged items come first in past/future groups
		
		shandford update 04/28/04: change in display logic*
		- no more than 8 events are shown
		- flaged items come first
		- display events in chronilogical order starting from current date
	*/
		var count = 0;
		if(isMac){
			var divTop = 180; // starting position for event divs
		} else {
			var divTop = 330; // starting position for event divs
		}
		var today = getToday();  //get today's date
		// output flagged items first - shandford new  04/28/04
		for(var x=0; x<eventArray.length && count<8; x++){
				if(eventArray[x][2]){ //is flagged ?
					var divObj = getRef(eventArray[x][0]);
					divObj.style.display = "block";
					count++;
				}
		}
	// output remaining future events
		for(var x=0; x<eventArray.length && count<8; x++){
			var eventDate = eventArray[x][1];
			if(!eventArray[x][2] && eventArray[x][2]!=null && eventDate > today){
				var divObj = getRef(eventArray[x][0]);
				divObj.style.display = "block";
				count++;
			}
		}
	}
	function initDivs()
	{
		var divObj;
		
		for(var x=0; x<eventArray.length; x++){
			divObj = getRef(eventArray[x][0]);
			divObj.style.display = "none";
		}
		divObj = getRef("noevent");
		divObj.style.display = "none";
	}
	/* SIMILAR TO SHOW EVENTS BUT FOR ARTICLES */	
	function showNonEvents() 
	{
		var count = 0;
		if(isMac){
			var divTop = 180; // starting position for event divs
		} else {
			var divTop = 330; // starting position for event divs
		}
		// output most current events
		for(var x=eventArray.length-1; x!=-1 && count<8; --x){
			if(eventArray[x][2]!=null){
				var divObj = getRef(eventArray[x][0]);
				divObj.style.display = "block";
				count++;
			}
		}
	}

/* GENERIC BANNER DISPLAY */
		// if no default image has been specified for a section, 
		// a randomly choosen banner image is displayed
		
		// generates a psuedo-random number between 0 and argument-1.  
		// i.e. range=4 would return a number from 0-3
		function getRandom(max)
		{
			var min = 1
			var rnd = Math.floor(Math.random() * (max - min + 1)) + min;
			if (rnd < 9) { rnd = "0"+rnd }
			return rnd;
		}

		function genBanner() 
		{
			var noDefault = getRef("generic"); // test to see if the xsl has output a spacer with an id of "generic"
			var randNum;
			if(noDefault) { // get the random banner
				randNum = getRandom(5);
				noDefault.src = "/images/vehicles/ton/gmc/banners/gmc_header_" + randNum + ".jpg";
			} else {
				return;
			}
		}
		
/* GENERAL FUNCTION FOR HANDLING DROP-DOWN NAVIGATION */		

	function dropDownNav()
	{
		var formObj = document.forms['frmNav'].secNav;
		var optVal = formObj.options[formObj.selectedIndex].value;	

		document.location = optVal;
		return; // exit

	}
/* common page composition objects used in varioous DHTML features */
	var divObj = eval(getRef("mediaDiv"));//note mediaDiv is really a td
	var captionObj = eval(getRef("captionCell"));
	
/* SHANDFORD -RENO - NEW FUNCTIONS ! */
/* changes the display gallery picture */
/* April 2005 - removed extra div element */
	function showPhoto(src,caption)
	{
		var divObj = eval(getRef("mediaDiv"));//note mediaDiv is really a td
		var captionObj = eval(getRef("captionCell"));
		var strOut = "<img src=\"" + src + "\" alt=\"\" border=\"0\" >";
		divObj.innerHTML = strOut;
		captionObj.innerHTML = toString(caption);
	}
	function outputMovie(src, caption)
	
	{
		var divObj = eval(getRef("mediaDiv"));//note mediaDiv is really a td
		var captionObj = eval(getRef("captionCell"));
		var strOut = "";
		strOut += "		<object id=\"objFlash\" type=\"application/x-shockwave-flash\" data=\"/media/vehicles/common/ton/player.swf?LoadMovieFile=" + src + "\" width=\"315\" height=\"275\" id=\"movie_player\" align=\"left\">";
		strOut += "			<param name=\"movie\" value=\"/media/vehicles/common/ton/player.swf?LoadMovieFile=" + src + "\" />";
		strOut += "			<param name=\"wmode\" value=\"transparent\" />";
		strOut += "			<param name=\"menu\" value=\"false\" />";
		strOut += "			<param name=\"quality\" value=\"high\" />";
		strOut += "			<param name=\"bgcolor\" id=\"bgcolor\" value=\"#FFFFFF\" />";
		strOut += "		</object>";
		divObj.innerHTML = strOut;
		captionObj.innerHTML = caption;
	}
	
	// BB Output the vr using a similar technique as above
	//See show360() funcion below for how args are passed from pages
	//To DO refactor these into generic functions to handle each media type
	function output360(src, caption)
	{
		var divObj = eval(getRef("mediaDiv"));//note mediaDiv is really a td
		var captionObj = eval(getRef("captionCell"));
		var strOut = "";
		strOut += "		<object id=\"objFlash\" type=\"application/x-shockwave-flash\" data=\""+ src +"\" width=\"560\" height=\"275\" id=\"movie_player\" align=\"left\">";
		strOut += "			<param name=\"movie\" value=\"" + src + "\" />";
		strOut += "			<param name=\"wmode\" value=\"transparent\" />";
		strOut += "			<param name=\"menu\" value=\"false\" />";
		strOut += "			<param name=\"quality\" value=\"high\" />";
		strOut += "			<param name=\"bgcolor\" id=\"bgcolor\" value=\"#FFFFFF\" />";
		strOut += "		</object>";
		divObj.innerHTML = strOut;
		captionObj.innerHTML = caption;
	}
	
	function outputAudio(src,caption)
	{
		var divObj = eval(getRef("mediaDiv"));//note mediaDiv is really a td
		var captionObj = eval(getRef("captionCell"));
		var strOut = "";
		strOut += "		<embed id=\"objAudio\" type=\"audio/x-mpeg\" src=\"" + src + "\" id=\"mp3_player\" valign=\"bottom\" align=\"left\" width=\"240\" height=\"16\" style=\"margin\-top\:261px\;\">";
		strOut += "			<param name=\"src\" value=\"" + src + "\" />";
		strOut += "			<param name=\"controller\" value=\"true\" />";
		strOut += "		</embed>";
		divObj.innerHTML = strOut;
		captionObj.innerHTML = caption;
	}
	/*
	pages with the multi column dhtml page method 
	are built with an array 'pageList' that contains the id attributes of
	the divs representing dhtml 'pages' 
	the following functions traverse that array, keeping track of what
	has been shown or hidden (stored as 'currentPage') as values corresponding to
	positions in the array. 
	*/
	var currentPage = 0; 
	var forwardButton;
	var backButton;
	function showNextPage(){
	var pageTotal = pageList.length-1;//if we try to set this as the page loads we are skuppered cos the array is in the page
		if(currentPage < pageTotal){//if we are still in bounds of values that correspond to real pages 
			nextPage = currentPage + 1;//add one to the value of currentPage to identify the nextPage to show then
			getRef(pageList[currentPage]).style.display = 'none';//hide the current dhtml 'page'
			getRef(pageList[nextPage]).style.display = 'block';//show the next one in line
			currentPage=nextPage; //add one to currentPage so that its value corresponds to tha current page.
		}
		else{//if we have reached the end of the valid pages in the array, or are otherwise out of bounds
			 nextPage = 0; //set the next page to the start of all things
			 getRef(pageList[currentPage]).style.display = 'none'; //as above hide the current page
			 getRef(pageList[nextPage]).style.display = 'block'; //show the first page
			 currentPage = nextPage; //and store the current page as the start.
		}
		getRef('pageNumber').innerHTML = currentPage + 1;
	}
	function showPreviousPage(){
	var pageTotal = pageList.length;// as above
		if(currentPage < pageTotal && currentPage != 0 ){//if the current page is inbounds and at least the second page because  
			nextPage = currentPage - 1; // we are going back wards here after all.
			getRef(pageList[currentPage]).style.display = 'none'; 
			getRef(pageList[nextPage]).style.display = 'block';
			currentPage = nextPage;
		}
		else{// we are at the first page  and still want to go back
			 nextPage = pageTotal-1; //we will go to the last page from the first
			 getRef(pageList[currentPage]).style.display = 'none';
			 getRef(pageList[nextPage]).style.display = 'block';
			 currentPage = nextPage;
		}
		getRef('pageNumber').innerHTML =  currentPage + 1;
	}
	
		/*the back and forward image functionality is buit around traversing an array 
			that contains image uris.
			Below we use the photos' elements to build an array of image URIs 
			Here is where the array is declared	*/
var currentPhoto=0; 
function showNextPhoto(){
	var photoTotal = photoList.length-1;//if we try to set this as thephoto loads we are skuppered cos the array is in thephoto
		if(currentPhoto < photoTotal){//if we are still in bounds of values that correspond to realphotos 
			nextPhoto = currentPhoto + 1;//add one to the value of currentPhoto to identify the nextPhoto to show then
			showPhoto(photoList[nextPhoto][0]);
			currentPhoto++; //add one to currentPhoto so that its value corresponds to tha currentphoto.
		}
		else{//if we have reached the end of the validphotos in the array, or are otherwise out of bounds
			 nextPhoto = 0; //set the nextphoto to the start of all things
			 showPhoto(photoList[nextPhoto][0]);
			 currentPhoto=0; //and store the currentphoto as the start.
		}
	getRef('captionCell').innerHTML = photoList[nextPhoto][1]
	currentPhoto = nextPhoto;		
	getRef('photoCount').innerHTML = currentPhoto + 1 + ' / ' + photoList.length;
	}
	function showPreviousPhoto(){
	var photoTotal = photoList.length;// as above
		if(currentPhoto < photoTotal && currentPhoto >= 1 ){//if the currentphoto is inbounds and at least the secondphoto because  
			nextPhoto = currentPhoto - 1; // we are going back wards here after all.
			showPhoto(photoList[nextPhoto][0]);
		}
		else{// we are at the firstphoto  and still want to go back
			 nextPhoto = photoTotal-1; //we will go to the lastphoto from the first
			 showPhoto(photoList[nextPhoto][0]);

		}
	getRef('captionCell').innerHTML = photoList[nextPhoto][1]
	currentPhoto = nextPhoto;		
	getRef('photoCount').innerHTML = currentPhoto + 1 + ' / ' + photoList.length;	
	}	
var currentMovie= 0; 
function changePhoto(direction){
			getRef('photoCount').innerHTML = currentMovie + 1 + ' / ' + photoList.length;
			if(direction =='back'){
				showPreviousPhoto();
			}
			else{
				showNextPhoto();
			}
		}	
var tmpLayer;
function showMovie(psn){
		movieId = psn-1;
		var src = movieList[movieId][0];
		var cap = movieList[movieId][1];
		outputMovie(src, cap);
	
	}	

function show360(psn){
		movieId = psn-1;
		var src = vrList[movieId][0];
		var cap = vrList[movieId][1];
		output360(src, cap);
	}		
	
function showAudio(psn){
		var src = audioList[psn-1][0];
		var cap = audioList[psn-1][1];
		outputAudio(src, cap);
	}
	
// USED FOR TON ARTICLE COMMENTS FORM
function charCounter(field, cntfield, maxlimit)
{
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
    else
        cntfield.value = maxlimit - field.value.length;
}

