function getRef(id) {
		return (document.getElementById ? document.getElementById(id) : document.all[id]);
}

//*** COOOKIE STUFF *****//

// Write a cookie value
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
	document.cookie = curCookie;
}

// Retrieve a named cookie value
function getCookie(name) {
	var dc = document.cookie;

	// find beginning of cookie value in document.cookie
	var prefix = name + "=";
	
	var begin = dc.indexOf("; " + prefix);
	//alert(begin);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else begin += 2;

	// find end of cookie value
	var end = document.cookie.indexOf(";");
	if (end == -1) end = dc.length;

	// return cookie value
	return unescape(dc.substring(begin + prefix.length, end));
}

// finToolMenuState cookie values
var isOpen = 'menuIsOpen';
var isClosed = 'menuIsClosed';

// read cookie and set menu state open/closed
function setMenuState(){
	
	var menuState = getCookie('finToolMenuState');
	//var headerObject = getRef('finToolsHeader');
	var headerObjectAnchor = getRef('finToolsHeaderAtag');
	var openObject = getRef('finToolsList');
		
	if(menuState==null){
        //  headerObject.style.background = '#fff url(gm.ca/images/vehicles/common/finTool_header_off.gif) no-repeat';
		//headerObject.className = 'finToolsHeaderClosed';
		openObject.style.visibility = 'hidden'; 
		openObject.style.display = 'none';	
	}
	else if(menuState=='menuIsClosed'){		
        //  headerObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_off.gif) no-repeat';
        //headerObject.className = 'finToolsHeaderClosed';
		openObject.style.visibility = 'hidden'; 
		openObject.style.display = 'none';	
	}	
	else if(menuState=='menuIsOpen'){
        //  headerObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_open.gif) no-repeat';
        //headerObject.className = 'finToolsHeaderOpen';
		openObject.style.visibility = 'visible'; 
		openObject.style.display = 'block';	
	}	

}

// open or close menu on click
function showHideObject(objectId){ 

        var theObject = getRef(objectId); 	
		//var headerObject = getRef('finToolsHeader');
		var headerObjectAnchor = getRef('finToolsHeaderAtag');
		var closeObject = getRef('finToolsList');
		var expandObject = getRef('finExpandIcon');

		if (theObject.style.visibility == 'visible') {
			theObject.style.visibility = 'hidden'; 
			theObject.style.display = 'none';	
			//headerObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_off.gif) no-repeat';	
            //headerObject.className='finToolsItem';
           // headerObject.innerHTML="<b class='roundtop'><b class='round3'></b><b class='round4'></b></b>"+"+"+"<b class='roundbottom'><b class='round2'></b><b class='round1'></b></b>";
			expandObject.className='leftNavIcon expandIcon';
            expandObject.innerHTML='&nbsp;';
            setCookie('finToolMenuState',isClosed,'','/');
		}
		else {
			theObject.style.visibility = 'visible';
			theObject.style.display = 'block';
			//headerObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_open.gif) no-repeat';	
            //headerObject.className='finToolsItemOn';
            //headerObject.innerHTML="<b class='roundtop'><b class='round3'></b><b class='round4'></b></b>"+"-"+"<b class='roundbottom'><b class='round2'></b><b class='round1'></b></b>";
            expandObject.className='leftNavIcon collapseIcon';
            expandObject.innerHTML='&nbsp;';
            setCookie('finToolMenuState',isOpen,'','/');
		}
} 

function finToolItemOn(itemId,litemId){ 
        var theObject = getRef(itemId); 
		var theLinkObject = getRef(litemId);
		//theLinkObject.style.color = '#fff';
        theLinkObject.className='toolLinkOn';
		//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_item_on.gif) no-repeat';
        if(theObject){
        	theObject.className='finToolsItemOn';
        }
}

function finToolItemOff(itemId,litemId){ 
        var theObject = getRef(itemId); 	
		var theLinkObject = getRef(litemId);

		//theLinkObject.style.color = '#000';
        theLinkObject.className='toolLink';
		//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_item_off.gif) no-repeat';
        if(theObject){
            theObject.className='finToolsItem';
        }
}

function finToolDblItemOn(itemId,litemId){ 
        var theObject = getRef(itemId); 
		var theLinkObject = getRef(litemId);	
		//theLinkObject.style.color = '#fff';
        theLinkObject.className='toolLinkOn';
		//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_dbl_item_on.gif) no-repeat';
        theObject.className='finToolsDblItemOn';
}

function finToolDblItemOff(itemId,litemId){ 
        var theObject = getRef(itemId); 	
		var theLinkObject = getRef(litemId);

		//theLinkObject.style.color = '#000';
        theLinkObject.className='toolLink';
		//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_dbl_item_off.gif) no-repeat';
        theObject.className='finToolsDblItem';
}

function finToolHeaderOn(itemId,litemId){ 
        var theObject = getRef(itemId); 
		var theLinkObject = getRef(litemId);	
		var isOpen = getRef('finToolsList');
		
		if (isOpen.style.visibility == 'visible') {
			//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_open.gif) no-repeat';
            theObject.className='finToolsHeaderOpen';
            theObject.innerHTML="-";
		}
		else {
			//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_on.gif) no-repeat';
            theObject.className='finToolsHeaderOn';
            theObject.innerHTML="+";
		}
}

function finToolHeaderOff(itemId,litemId){ 
        var theObject = getRef(itemId); 	
		var theLinkObject = getRef(litemId);
		var isOpen = getRef('finToolsList');
		
		if (isOpen.style.visibility == 'visible') {
			//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_open.gif) no-repeat';
            theObject.className='finToolsHeaderOpen';
            theObject.innerHTML="-";
		}
		else {
			//theObject.style.background = '#fff url(http://gm.ca/images/vehicles/common/finTool_header_off.gif) no-repeat';
            theObject.className='finToolsHeaderClosed';
            theObject.innerHTML="+";
		}			
}
function addRound(){
	var domobjs = document.getElementsByClassName('roundState');
	for(var i=0;i<domobjs.length;i++){
		var domobj = domobjs[i];
		//domobj.innerHTML = "<b class='roundtop'><b class='round3'></b><b class='round4'></b></b>"+domobj.innerHTML+"<b class='roundbottom'><b class='round2'></b><b class='round1'></b></b>";
	}
}


