var subMenuInterval;
var mapIntervalOn;
var currentSubMenu;
var mapInterval;


function initMenu(id)
{
	currentSubMenu = id;
	showSubMenu(currentSubMenu);
}

function doTabRoll(id, color, sides, bg)
{
	var tabLeft = document.getElementById('tab_'+id+'_left');
	var tabCenter = document.getElementById('tab_'+id+'_center');
	var tabRight = document.getElementById('tab_'+id+'_right');
	
	tabCenter.style.backgroundColor = color;
	tabCenter.style.backgroundImage = "url('"+bg+"')";
	tabLeft.style.backgroundImage = "url('"+sides+"')";
	tabRight.style.backgroundImage = "url('"+sides+"')";
}

function rollOffTab(id)
{
	color = '#BABBB6';
	tab_sides_img = 'res/img/tab_gray.gif';
	tab_bg_img = 'res/img/tab_gray_bg.gif';
	
	doTabRoll(id, color, tab_sides_img, tab_bg_img);
}

function rollOverTab(id)
{
	color = '#8C8C8C';
	tab_sides_img = 'res/img/tab_dark_gray.gif';
	tab_bg_img = 'res/img/tab_dark_gray_bg.gif';
	
	doTabRoll(id, color, tab_sides_img, tab_bg_img);
}

function delayShowCurrentSubMenu(id)
{
	subMenuInterval = window.setTimeout("showSubMenu('"+id+"')",200);
}

function showSubMenu(id)
{
	window.clearInterval(subMenuInterval);

	//clear currently active tab
	rollOffTab('whatsnew');
	rollOffTab('aboutus');
	rollOffTab('pressroom');
	//rollOffTab('relief');
	rollOffTab('homeorder');
	
	if (id == 'products')
	{
		color = '#2A4B9C';
		sub_img = 'res/img/sub_blue_bg.gif';
		
	}
	else if (id == 'equipment')
	{
		color = '#F4AE00';
		sub_img = 'res/img/sub_yellow_bg.gif';
		
	}
	else if (id == 'education')
	{
		color = '#68A231';
		sub_img = 'res/img/sub_green_bg.gif';
		
	}
	else if (id == 'service')
	{
		color = '#c47b35';
		sub_img = 'res/img/sub_blue_2_bg.gif';
		
	}
	else if (id == 'order')
	{
		color = '#BE3918';
		sub_img = 'res/img/sub_red_bg.gif';
		
	}
	else if (id == 'home')
	{
		color = '#B9B9B9';
		sub_img = 'res/img/sub_gray_bg.gif';
		
	}
	else
	{
		color = '#8C8C8C';
		sub_img = 'res/img/sub_dark_gray_bg.gif';
		rollOverTab(id);
		
	}

	//hide other submenus
	document.getElementById('equipment_submenu').style.display='none';
	document.getElementById('products_submenu').style.display='none';
	document.getElementById('education_submenu').style.display='none';
	document.getElementById('order_submenu').style.display='none';
	document.getElementById('whatsnew_submenu').style.display='none';
	document.getElementById('aboutus_submenu').style.display='none';
	document.getElementById('pressroom_submenu').style.display='none';
	document.getElementById('service_submenu').style.display='none';
	document.getElementById('homeorder_submenu').style.display='none';
	
	//show the right submenu
	document.getElementById(id+'_submenu').style.display='block';

	//change the submenu color and background image
	var subMenu = document.getElementById('sub_menu');
	subMenu.style.backgroundColor = color;
	subMenu.style.borderColor=color;
	subMenu.style.borderWidth='1';
	subMenu.style.backgroundImage = "url('"+sub_img+"')";
}

function rollOverMain(id)
{
	rollOffMain();
	document.getElementById(id+'_home_over').style.display='block';
}

function rollOffMain()
{
	document.getElementById('products_home_over').style.display='none';
	document.getElementById('education_home_over').style.display='none';
	document.getElementById('equipment_home_over').style.display='none';
	document.getElementById('service_home_over').style.display='none';
}


function delayRollOffMap()
{
	mapInterval = window.setTimeout("rollOffMap()",300);
	//rollOffMap();
}

function delayRollOnMap(id)
{
	window.clearInterval(mapIntervalOn);
	window.clearInterval(mapInterval);
	rollOffMap(id);
	document.getElementById(id).style.display='block';
}

function rollOverMap(id)
{
	//mapIntervalOn = window.setTimeout("delayRollOnMap('"+id+"')",300);
	 delayRollOnMap(id);
	
}

function rollOffMap()
{
	document.getElementById("region_SW").style.display='none';
	document.getElementById("region_W").style.display='none';
	document.getElementById("region_NW").style.display='none';
	document.getElementById("region_NC").style.display='none';
	document.getElementById("region_C").style.display='none';
	document.getElementById("region_EC").style.display='none';
	document.getElementById("region_AL").style.display='none';
	document.getElementById("region_SCb").style.display='none';
	document.getElementById("region_SCa").style.display='none';
	document.getElementById("region_SC").style.display='none';
	document.getElementById("region_NE").style.display='none';
	document.getElementById("region_E").style.display='none';
	document.getElementById("region_ME").style.display='none';
	document.getElementById("region_SE").style.display='none';
	document.getElementById("region_SEb").style.display='none';
	document.getElementById("region_SCw").style.display='none';
}

function showBullet(n)
{
	document.getElementById(n+'_1').style.visibility = 'visible';
	//document.getElementById(n+'_2').style.visibility = 'visible';
}

function hideBullet(n)
{
	document.getElementById(n+'_1').style.visibility = 'hidden';
	//document.getElementById(n+'_2').style.visibility = 'hidden';
}

function gotoPage(id)
{
	location.href=id;
}

function checkImage(img) {
	img.onerror="";
    img.style.display='none';
}

function openWindow(url)
{
	window.open(url,'','width=250,height=300, resizable=no,toolbar=no, scrollbar=no '); 
}

function openPDF(fileName)
{
	if (fileName != "")
		window.open(fileName,'','width=750,height=500,toolbar=no');

}

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
