  	onPageLoadEvents.addAction(function() {toggleTrim(0);});
  	//vent.observe(window, 'load', function() {toggleTrim(0);})
  	var dropdownTimeOuts = new Object();
	var currentTrim;
	
	function toggleDropDown(obj, left, bottom) {
		var dropDown = $(obj);
		
		if(left && bottom) {
			dropDown.style.left = left;
			dropDown.style.top  = bottom;
			
		}
		if(dropDown.style.display != 'block') {
			dropDown.style.display = 'block';
			dropDown.style.zIndex = '99999';
		}
		else {
			dropDown.style.display = 'none';
		}
	}
	
	function toggleDropDownYear(obj, dropdown) {
		$('mlCurrentModelYear').innerHTML = obj.innerHTML;
		toggleDropDown(dropdown);
	}
	function toggleDropDownYearList(dropdown) {;
		var rect = Dom.getBoundries('qfd_drDnHd', 'ml_select');
		dropdown.style.left  = Dom.getLeftXAsPx('qfd_drDnListDrPn', 'wrapper');
		toggleDropDown(dropdown);
	}
	function toggleDropDownSpec(obj, pos) {
		// Function to hide or show a div depending on its current state
		var dropDown = $('qfd_drDnListSpec');
		var selectedItem = $('qfd_drDnHdTxtSpec');
		var allSpec = $('ml_ddAS'); /* Div that Contains the temporary "All Specification" */
		
		if(obj) {
			/* The Drop-down IS CLOSED and need to be open */
			if (dropDown.style.display == 'block'){				
				if (obj.innerHTML.indexOf("<")!=-1){ /* IF the Drop-Down button was clicked twice (No selection) */
					dropDown.style.display = "none";
				}
				else {
					 /* A selection was made in the list */
					selectedItem.innerHTML=obj.innerHTML; /* Swap the Name of the selected Item on top of the list */
					if (pos==-1){ /* If the selection was 'All Specifications' */ 
						allSpec.style.display = "none"; /* Make All Specifications option invisible in the list */
						showAllSG(pos);
					}
					else{ /* Make the "All Specifications" visible in the list */
						allSpec.style.display = "block";
						showSelectedSG(pos); /* Display only the selected Spec Group */
					}
					adjustFooter();
					/* Ajusting the footer vs content spacing */
				}
			}
			toggleDropDown(dropDown, '253px', Dom.getBottomYAsPx('mlSpecDropDownContainer'));
		}
		else {
			allSpec.style.display = "none";	
			selectedItem.innerHTML = 'All Detailed Specs';
			showAllSG(pos);
		}
	}
	/* Display all Spec Groups in the current model trim */
	
	function showAllSG(pos){
		Debug.debug(currentTrim);
		var totalSubMT = $('ml_specArea_' + currentTrim).getElementsByTagName('TABLE');
		for (var i = 0; i < totalSubMT.length; i++){
			totalSubMT[i].style.display = "block";
		}
	}
	/* Display Selected Spec Group and Hide all others in the current model trim */
	function showSelectedSG(pos){
		var totalSubMT = $('ml_specArea_' + currentTrim).getElementsByTagName('TABLE');
		for (var i = 0; i < totalSubMT.length; i++){
			if ($("subTrim"+currentTrim+pos).id == totalSubMT[i].id){
				totalSubMT[i].style.display = "block";
			}
			else{
				totalSubMT[i].style.display = "none";
			}
		}
	}
	/* Sets a delay for the drop-down to close */
	function closeDropDown(obj){
		dropdownTimeOuts[obj.id] = setTimeout(function() {obj.style.display = 'none'},250);
	}
	/* Clears the delay above a force drop-down to close */
	function clearDropDown(obj){ /* Clears the counter, hide any sub menus opened, and allows other sub menus to re-use it */
		if (dropdownTimeOuts[obj.id]){
		  clearTimeout(dropdownTimeOuts[obj.id]);
		}
	}
	
	
	function ml_tabHilite(ml_thisTab){
		
		if(ml_thisTab) {
			var thisLi = ml_thisTab.parentNode;
			var lis = $A(thisLi.parentNode.getElementsByTagName('LI'));
			
			lis.each(function(li) {
			   if(li != this) {
			     li.className = 'ml_tabOff';
			   }
			   else {
			     li.className = 'ml_tabOn';
			   }
			}.bind(thisLi));
		}
	}
	
	function toggleTrim(pos) {
		currentTrim = pos;
		ml_tabHilite($('ml_btnTab_' + pos), pos);
		toggleCopy(pos);
		toggleSpecs(pos);
		toggleDisclaimers(pos);
		adjustFooter();
	}
	function toggleCopy(pos) {
		var children = document.getElementsByClassName('ml_copy','ml_pictureContainer','DIV');
		var onId = 'ml_copy_' + pos;
		
		toggleChildren(children, onId);
	}
	function toggleText(pos) {
		var children = $A( $('ml_trimTextContainer').getElementsByTagName('SPAN') )
		var onId = 'ml_text_' + pos;
		
		toggleChildren(children, onId);
	}
	function toggleSpecs(pos) {
		var children = $A( $('ml_mainArea').getElementsByTagName('DIV') )
		var onId = 'ml_specArea_' + pos;
		
		toggleChildren(children, onId);
		/*
		 children.each(function(child) {
			child.style.display = (child.id == onId) ? 'block' : 'none';
		});
		*/
		toggleDropDownSpec(null) 
	} 
	function toggleChildren(children, onId) {
		children.each(function(child) {
			child.style.display = (child.id == onId) ? 'block' : 'none';
		});
	}
	function toggleDisclaimers(pos) {
		if($("mll_disclaimers_group"+pos)){
			var children = $A($('mll_ftDisclaimers').getElementsByTagName('DIV'));
			var onId = 'mll_disclaimers_group' + pos;
			children.each(function(child) {
				child.style.display = (child.id == onId) ? 'block' : 'none';
			});
		}
	}
	function adjustFooter(){
		var ftContainerArray = new Array('clearContainer');
		var spacingW3C = 27;
		var spacingIE = 23;
		footer(ftContainerArray, spacingW3C, spacingIE);
	}

/* Vehicle Search functionality */	

var cpo_queryString = "/lexuscpo/cpo_poresults.psp?certified=1&"; 

/* Validates Zip Code for digits only */
//function by Danny Goodman
function mustBeZip(evt){
	evt = (evt) ? evt : window.event;
	var charCode = (evt.which) ? evt.which : evt.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		status = "This field accepts numbers only.";
		return false;
	}
	status = "";
	return true;
}


function ml_buildQuery(modelString,yearString){
	var queryStringZip = "";
	if($('ml_Search').value == "Enter Zip Code") {
		$('ml_Search').value = "";
	} else {
		queryStringZip = "&zip="+$('ml_Search').value;
	}
	cpo_queryString += "model="+modelString+"&year="+yearString+queryStringZip;
	window.location = cpo_queryString;
}
