// SHOW/HIDE the Sub Navigation
Menu = {timer : null, current : null, currentClass : null, currentClassID : null};
Menu.navArray= new Array();
Menu.getStyle = function(name){
	if(document.getElementById) return document.getElementById(name).style;
	else if(document.all) return document.all[name].style;
	else if(document.layers) return document.layers[name];
}
Menu.show = function(name){
	if(this.timer) clearTimeout(this.timer);
	if (name.substring(name.length-1,name.length) == 1){//set instace of 0 in the array	
		this.navArray[0] = name.substring(0,name.length-1)+"0";	
	}
	this.navArray[name.substring(name.length-1,name.length)] = name; //set the instance position/value
	for (i= this.navArray.length-1; i>=0; i--){
		this.getStyle(this.navArray[i]).display = "inline"; //parse the array & set the visibilities
		this.main_change(name);
	}
	this.current = name;
	return false;
}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide()",1750);
	return false;
}
Menu.doHide = function(toLayer){
	if(this.current){
		if (toLayer == null){toLayer=0;this.current = null;}
		for (i= this.navArray.length-1; i>toLayer; i--){
			this.getStyle(this.navArray[i]).display = "none";
			this.main_changeback(i, toLayer);
			this.navArray.pop();
		}
	}
	return false;
}
Menu.main_change = function(name){
	var theID = name.substring(0,name.length-1)+(name.substring(name.length-1,name.length) - 1);
	if (document.getElementById(theID).className != '' && document.getElementById(theID).className != "hovered"){
		this.currentClassID = theID;
		this.currentClass = document.getElementById(this.currentClassID).className;
	}
	document.getElementById(theID).className =  "hovered";
	return false;
}
Menu.main_changeback = function(i, toLayer){
	var theID = this.navArray[i].substring(0,this.navArray[i].length-1)+(toLayer);
	if (this.currentClassID == theID) {//matches currentpage css class
		document.getElementById(this.currentClassID).className =  this.currentClass;
		this.currentClass = '';
	} else if (document.getElementById(theID)){//has parent to switch
		document.getElementById(theID).className =  "";
	} else {//doesn't have parent so just change this
		document.getElementById(this.navArray[i].substring(0,this.navArray[i].length-1)+(toLayer + 1)).className =  "";
	}
	return false;
}

/*********************************************************
 UI Functions for Travel Guard
**********************************************************/
function ChangeProductCategory(selectID,URL) {
	var drpCategory = document.getElementById(selectID);
	var selectValue;
	
	if (drpCategory) { //make sure select is found
		selectValue = drpCategory.options[drpCategory.selectedIndex].value;
		if (URL) { //url needs to be used from clicked button
			if (selectValue) { //make sure user has chosen item in drop down
				try {__utmLinker(URL+selectValue);} //redirect using Urchin = button url + select value
				catch(err) {document.location.href=URL+selectValue;} //Urchin not present so just redirect using button url + select value		
			}
			else { //User hasn't chosen yet
				try {alert(errAlert);} //custom message defined in page
				catch(err) {alert('Please choose an item from the drop down.');}		
			}
		}
		else { //just redirect using Urchin
			try {__utmLinker(selectValue);} //redirect using Urchin = button url + select value
			catch(err) {document.location.href=selectValue;} //Urchin not present so just redirect using button url + select value
		}
	}
	return false;
}
function straightTalkDisclaimer(){
	var test = document.getElementById('straightTalkDisclaimer').style;
	if (test.display == '' || test.display == null || test.display == 'none') {
		test.display = 'inline';
	} else {
		test.display = 'none';
	}
}

function ValidState(theSelectBoxID){ // make sure it is valid selling state
	var isValidState = true;
	if (theSelectBoxID){
		var SelectedState = document.getElementById(theSelectBoxID).options[document.getElementById(theSelectBoxID).selectedIndex].text.toLowerCase();
	}else{
		var SelectedState = document.getElementById("ctl00_pageContent_drpStateList").options[document.getElementById("ctl00_pageContent_drpStateList").selectedIndex].text.toLowerCase();
	}
	
	// Get Invalid State list
		// var InvalidStates - moved to masterpage

	// Turn String to Array of States
	var stateList = InvalidStates.split(';');

	// Find if selected state is part of Invalid State List
	for (var index=0; index<= stateList.length - 1; index++) {

		if (SelectedState.toLowerCase() == stateList[index].toLowerCase()) {
			isValidState = false;
			break;
		}
	}

	// If on direct & invalid State was selected show Error Message
	if (isValidState == false) { 
		// var InvalidStatesMessage - moved to masterpage
		alert(InvalidStatesMessage);
		return false;
	} else {
		return true;
	}
} 