//------ the tab toggle on the product page ---------------------------
var onState = "tab1";
var temp = "";
var tempOnState = "";
var tempB = "";
var tempG = "";
function toggleTab(state) {
	temp = state + "Content";
	tempOnState = onState + "Content";
	tempB = onState + "B"; tempG = onState + "G";
	document.getElementById(tempB).style.display = "none";
	document.getElementById(tempG).style.display = "block";
	tempB = state + "B"; tempG = state + "G";
	document.getElementById(tempB).style.display = "block";
	document.getElementById(tempG).style.display = "none";
	

	prevRightNavTabIdx = onState.charAt(3)-1
	newRightNavTabIdx = state.charAt(3)-1
	prevRightNavTab = "rn"+onState;
	newRightNavTab = "rn"+state;
	
	
	//alert(rNavLink[prevRightNavTabIdx]);
	//alert(rNavLink[newRightNavTabIdx]);
	
	if (document.getElementById) {
		if (document.getElementById(tempOnState)) {
			document.getElementById(tempOnState).style.display = "none";
			//document.getElementById(onState).setAttribute("class", "greenBG"); //doesn't work in IE
		}
		if (document.getElementById(temp)) {
			document.getElementById(temp).style.display = "block";
			//document.getElementById(state).setAttribute("class", "blueBG"); //doesn't work in IE
		}
		//TRADING SPECIFIC - Looks to see if the one of the first two tabs is open and the layer within the third tab is not layer one. If so re-open the first layer inside the third tab.
		if ((onState == "tab1" || onState == "tab2") && (openedLayer != "layer1")) {
			//alert("Layer 1 will open");
			toggleLayers("layer1");
		}
		
		if (document.getElementById(prevRightNavTab)) {
			document.getElementById(prevRightNavTab).innerHTML = '<a href="'+rNavLink[prevRightNavTabIdx]+'">'+rNav[prevRightNavTabIdx]+'</a>';
			document.getElementById(newRightNavTab).innerHTML = '<b>'+rNav[newRightNavTabIdx]+'</b>';
		}	
		
	}
	onState = state;
}


var openedLayer = "layer1";
	
function toggleLayers(layer){
		var theLayer = document.getElementById(layer);
		if (theLayer != null || theLayer != ""){
			if(theLayer.style.display == "none"){
				//when expanding a layer, check to see if there is a sublayer expanded
				//if so close the sublayer
				if (openedLayer != ""){
					var theSubLayer = document.getElementById(openedLayer);
					theSubLayer.style.display="none";
				}
				//expand layer
				theLayer.style.display="block";
				//set new openedLayer
				openedLayer = layer;
			
			}else{
				theLayer.style.display = "none";
				//set new openedLayer
				openedLayer = "";
			}
		
		}
	}
	

//------ FUNCTION TO ACTIVE A DIV ON PAGELOAD -----------------------------------------
var locate = window.location.href;
function pageLoad() {
	var layer = getParameter(locate, "tab");
	//if(layer!="null") change(layer);
/* 	if (locate.indexOf('#') !=-1) {
		var section = locate.substring(locate.indexOf("#") +1);
		
		toggleTab("tab"+section)
	}
	else
		onState = 'tab1';
 */	
/* 	if ((layer != "null") && (layer != "") && (layer != "1")) {
		toggleTab("tab"+layer) 
		return layer
	}
	else {
		onState = 'tab1';
		return 1
	}		
 */
 
	if ((layer == "null") || (layer == "")) {
		layer = getTabNumber(locate);
	}
	
	if ((layer != "null") && (layer != "") && (layer != "1")) {
		toggleTab("tab"+layer) 
		return layer
	}
	else {
		onState = 'tab1';
		return 1
	}		
		
}// end function pageLoad	


function getTabNumber (queryString) {
	if (queryString.length > 0) {
		// Find the beginning of the string
		begin = queryString.indexOf("#");
		// If the anchor character is found use it, otherwise return null
		if (begin != -1) {
			//Start at the beginning of the tab digits...   skip the "tab" chars
			begin+= 4;
			//End at the end of the string
			end = queryString.length;
			
			//return the substring
			return unescape(queryString.substring(begin, end));
		}
		else  //return "null" if "#" was not found 
			return "null";
	}
	else  //return "null" if no queryString has been specified or it's length was 0
		return "null";
}//end function getTabNumber	

function getParameter (queryString, parameterName ) {
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";
	if (queryString.length > 0 ) {
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) {
			// Add the length (integer) to the beginning
			begin += parameterName.length;
			// Multiple parameters are separated by the "&" sign
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			// Return the string
			return unescape ( queryString.substring ( begin, end ) );
		}
		// Return "null" if no parameter has been found
		return "null";
	}
	else return "null";
}// end function getParameter


//-------- FUNCTION FOR BLANK WINDOWS, In the strict DTD's target="_blank" is not accepted in the </a> tag. -------

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
//window.onload = externalLinks;
/*function tabs(){
if(document.getElementById(tab1Content).style.display == "block";){
	document.getElementById(rightNavList).getElementByTagName(a).style.color = "black";
	}
}*/