// SHOW/HIDE the Sub Navigation
Menu = {timer : null, current : null, currentClass : null, currentClassID : null, IEfix1 : null, IEfix2 : 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){
	this.IEfix1 = document.getElementById('IEselectBoxFixNav');
	this.IEfix2 = document.getElementById(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.IEfix1.style.display = 'inline'; //IE6 issue w select box showing through
		this.IEfix1.style.width = this.IEfix2.offsetWidth+ 'px';
		this.IEfix1.style.height = this.IEfix2.offsetHeight+ 'px';
		this.IEfix1.style.top = this.IEfix2.offsetTop+ 'px';
		this.IEfix1.style.left = this.IEfix2.offsetLeft+ 'px';
		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.IEfix1.style.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
		if(drpCategory.options[drpCategory.selectedIndex].value && drpCategory.options[drpCategory.selectedIndex].value != 'null'){
			selectValue = drpCategory.options[drpCategory.selectedIndex].value;
		} else {
			alert('Please choose an item from the drop down.');
			return false;
		}
		
		var splitSelectValue = selectValue.split(';');
		if (splitSelectValue[0].toLowerCase() =="modal") { //call Modal instead of document.location
			popInfo.INFOdivClose();//close any open modals
			popDiv1.POPdivShow(splitSelectValue[1],splitSelectValue[2], splitSelectValue[3]);//open indicated modal
		}
		else if (URL) { //url needs to be used from clicked button
			if (selectValue) {document.location.href=URL+selectValue;} //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 {document.location.href=selectValue;} //redirect using button url + select value
	}
	return false;
}
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();
	}
	
	// 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 invalid State was selected show Error Message
	if (isValidState == false) { 
        if(document.getElementById('coveragePOPErrState')){
			popDivErr.POPdivShow('coveragePOPErrState','', '1');
		} else{
			alert(InvalidStatesMessage);//pull from ADX via masterpage
		}
		return false;
	} else {
		return true;
	}
}
function getRadioValue(group){
	//NOTE: ADX removes the 'value' attribute so use 'lang' instead
	
	// first, just in case there is only one radio button or check box in the group:
	if ( group.length == null ){return group.checked ? group.lang : "";}
	var val = "";
	for ( var i = 0; i < group.length; ++i ){if ( group[i].checked ) {val += "," + group[i].lang;}}
	if ( val != "" ) {val = val.substring(1);} // chop off leading comma    
	return val;
}
function errorCheckRadio(group){
	var test = getRadioValue(eval('document.aspnetForm.'+group));
	if (test == "" || test == null){ //either show error message or procede to next page
		try {alert(errorCheckRadioMSG);} //custom message defined in page
		catch(err) {alert('Please choose a coverage type that fits your traveling needs.');}
	} else {document.location=test;}
	return false;
}
