function switchtab(which){
	document.getElementById("tab_box_01").style.display = "none";
	document.getElementById("tab_box_02").style.display = "none";
	document.getElementById("tab_01").setAttribute("class", "");
	document.getElementById("tab_01").setAttribute("className", "");
	document.getElementById("tab_02").setAttribute("class", "");
	document.getElementById("tab_02").setAttribute("className", "");
	document.getElementById("tab_0" + which).setAttribute("class", "selected");
	document.getElementById("tab_0" + which).setAttribute("className", "selected");
	document.getElementById("tab_box_0" + which).style.display = "block";
}

function switchtab2(which){
	document.getElementById("highlight_box_01").style.display = "none";
	document.getElementById("highlight_box_02").style.display = "none";
	document.getElementById("highlight_box_03").style.display = "none";
	document.getElementById("highlight_01").setAttribute("class", "");
	document.getElementById("highlight_01").setAttribute("className", "");
	document.getElementById("highlight_02").setAttribute("class", "");
	document.getElementById("highlight_02").setAttribute("className", "");
	document.getElementById("highlight_03").setAttribute("class", "");
	document.getElementById("highlight_03").setAttribute("className", "");
	document.getElementById("highlight_0" + which).setAttribute("class", "selected");
	document.getElementById("highlight_0" + which).setAttribute("className", "selected");
	document.getElementById("highlight_box_0" + which).style.display = "block";
	if(which == '1'){
		document.getElementById("highlight_link").innerHTML = "All News";
		document.getElementById("highlight_link").href = "news";
	}else if(which == '2'){
		document.getElementById("highlight_link").innerHTML = "All Events";
		document.getElementById("highlight_link").href = "events";		
	}else if(which == '3'){
		document.getElementById("highlight_link").innerHTML = "All Specials";
		document.getElementById("highlight_link").href = "specials";			
	}else{
		
		document.getElementById("highlight_link").innerHTML = "All News";
		document.getElementById("highlight_link").href = "news";	}
}

function switchtab3(which){
	document.getElementById("tab_box_01").style.display = "none";
	document.getElementById("tab_box_02").style.display = "none";
	document.getElementById("tab_01").setAttribute("class", "");
	document.getElementById("tab_01").setAttribute("className", "");
	document.getElementById("tab_02").setAttribute("class", "");
	document.getElementById("tab_02").setAttribute("className", "");
	document.getElementById("tab_0" + which).setAttribute("class", "selected");
	document.getElementById("tab_0" + which).setAttribute("className", "selected");
	document.getElementById("tab_box_0" + which).style.display = "block";
}
function changeSection(section){
	//get corresponding nav num by finding string length 
	//and getting last two digits
	var sectionName = sectionObj.id;
	var sectionNum = sectionName.substr(sectionName.length - 2, 2);
	
	var section;
	if(sectionName.match("tab") != null){
		section = "tabs";
	} else if (sectionName.match("highlight") != null){
		section = "highlights";
	}
	
	
	var sectionBoxName;
	switch (section){
		case "tabs":
			sectionBoxName = "tab_box_" + sectionNum;
			hideAllSectionBoxes("tabs");
			break;
		case "highlights":
			sectionBoxName = "highlight_box_" + sectionNum;
			hideAllSectionBoxes("highlights");
			changeIconAndLink(parseInt(sectionNum));
			break;
	}
	
	changeTab(section, sectionNum);
	showSectionBox(sectionBoxName);
}

function hideAllSectionBoxes(sectionName){
	switch (sectionName){
		case "tabs":
			var sectionBoxHolder = document.getElementById("tab_boxes");
			var sectionClassName = "tab_box";
			break;
		case "highlights":
			var sectionBoxHolder = document.getElementById("highlight_boxes");
			var sectionClassName = "highlight_box";
			break;
	}
	
	var divs = sectionBoxHolder.getElementsByTagName("div");
	var sectionBoxes = [];
	var j = 0;
	
	for(var i = 0; i < divs.length; i++){
		if(divs[i].className == sectionClassName){
			sectionBoxes[j] = divs[i];
			j++;
		}
	}

	for(var i = 0; i < sectionBoxes.length; i++){
		document.getElementById(sectionBoxes[i].id).style.display = "none";
	}
}

function showSectionBox(sectionBoxName){
	console.log(sectionBoxName);
	document.getElementById(sectionBoxName).style.display = "block";
}

function changeIconAndLink(num){
	switch(num){
		case 1:
			document.getElementById("highlight_icon").src = "images/highlight_icon_news.gif";
			document.getElementById("highlight_link").innerHTML = "All news";
			document.getElementById("highlight_link").href = "news";
			break;
		case 2:
			document.getElementById("highlight_icon").src = "images/highlight_icon_events.gif";
			document.getElementById("highlight_link").innerHTML = "All events";
			document.getElementById("highlight_link").href = "events";
			break;
		case 3:
			document.getElementById("highlight_icon").src = "images/highlight_icon_specials.gif";
			document.getElementById("highlight_link").innerHTML = "All specials";
			break;
	}
}

function changeTab(sectionName, num){
	var section = sectionName.substring(0,sectionName.length - 1);
	
	var enclosure = document.getElementById(sectionName);
	var tabs = enclosure.getElementsByTagName("a");
	
	//make all non selected
	for(var i = 0; i < tabs.length; i++){
		if(tabs[i].id == section + "_" + num){
			tabs[i].className = 'selected';
		} else {
			tabs[i].className = '';
		}
	}
}

function show_distributors(region){
	document.getElementById('north_america').style.display = "none";
	document.getElementById('caribbean').style.display = "none";
	document.getElementById('europe').style.display = "none";
	
	document.getElementById(region).style.display = "block";
}
