// JavaScript Document

/*********************************************************/
/* Function that handles drop-down, model trims          */
/* and Tab Component simultaneously. Sets trim model     */
/* divs to display 'block' or 'none' from user selection */
/*    ::To be used with prototype and toggleLayer:: 		 */
/* Author: Christian Dumais                              */
/*********************************************************/

/*Variables 'subTrimKey' and 'trimModelKey' are retrieved by printable pop-up */
/* Variable used to determine which Trim model to display (from left to right) */
var trimModelKey = 0; // value is changed by ts_tabHilite function in 'tabStripWide.js' (value passed by onclick in tab strip button)
/* Variable used to determine the Trim item(s) displayed */
var subTrimKey = -1; //default state shows all (mainly for use by printable pop-up)

// Function to hide or show a div depending on its current state
function toggleDropDown(obj,pos,container){
	var dropDown = $('ds_drDnList');
	var selectedItem = $('ds_drDnHdTxt'+trimModelKey);
	var allSpec = $('ds_ddAS'); /* Div that Contains the temporary "All Specification" */
	/* The Drop-down IS CLOSED and need to be open */
	if (dropDown.style.display != 'block'){
		getDropDownPosition(obj,dropDown,container);
	}
	/* The Drop-Down IS OPEN and need to be closed*/
	else{
		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 */
				subTrimKey = pos;
				/*showAllSG();*/
			}
			else{ /* Make the "All Specifications" visible in the list */
				allSpec.style.display = "block";
				subTrimKey = pos;
				/*showSelectedSG(pos); *//* Display only the selected Spec Group */
			}
			dropDown.style.display = "none"; /* Hide Drop-down */
		}
	}
}
/* Position Drop Down List below drop-down selected element (custom drop-down) */
function getDropDownPosition(obj,dropDown, container){
		var rect = Dom.getBoundries(obj);
		container = (container!=null)?container:'wrapper';
		dropDown.style.display = 'block';
		dropDown.style.left = Dom.getLeftXAsPx(obj, $(container));
		dropDown.style.top = Dom.getBottomYAsPx(obj, $(container));
}
/* Sets a delay for the drop-down to close */
function closeDropDown(){
	delayToClose = setTimeout("$('ds_drDnList').style.display = 'none'",250);
}
/* Clears the delay above a force drop-down to close */
function clearDropDown(){ /* Clears the counter, hide any sub menus opened, and allows other sub menus to re-use it */
	if (typeof delayToClose!="undefined"){clearTimeout(delayToClose);}
}

//THIS IS FOR THE SECOND DROP DOWN FOR STATE SEARCH

// Function to hide or show a div depending on its current state
function toggleDropDown1(obj,pos,container){
	var dropDown = $('ds_drDnList1');
	var selectedItem = $('ds_drDnHdTxt1');
	var allSpec = $('ds_ddAS1'); /* Div that Contains the temporary "All Specification" */
	/* The Drop-down IS CLOSED and need to be open */
	if (dropDown.style.display != 'block'){
		getDropDownPosition1(obj,dropDown,container);
	}
	/* The Drop-Down IS OPEN and need to be closed*/
	else{
		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 */
				subTrimKey = pos;
				/*showAllSG();*/
			}
			else{ /* Make the "All Specifications" visible in the list */
				allSpec.style.display = "block";
				subTrimKey = pos;
				/*showSelectedSG(pos); *//* Display only the selected Spec Group */
			}
			dropDown.style.display = "none"; /* Hide Drop-down */
		}
	}
}
/* Position Drop Down List below drop-down selected element (custom drop-down) */
function getDropDownPosition1(obj,dropDown, container){
		var rect = Dom.getBoundries(obj);
		container = (container!=null)?container:'wrapper';
		dropDown.style.display = 'block';
		dropDown.style.left = Dom.getLeftXAsPx(obj, $(container));
		dropDown.style.top = Dom.getBottomYAsPx(obj, $(container));
}
/* Sets a delay for the drop-down to close */
function closeDropDown1(){
	delayToClose = setTimeout("$('ds_drDnList1').style.display = 'none'",250);
}
/* Clears the delay above a force drop-down to close */
function clearDropDown1(){ /* Clears the counter, hide any sub menus opened, and allows other sub menus to re-use it */
	if (typeof delayToClose!="undefined"){clearTimeout(delayToClose);}
}