// Popup menu script copyright Tom Clague 12/02 - tbc@tig.com.au

var timer;

function show(div,menu,e) {

	// clean up routine
	clearTimer();
	for (i=0;i<10;i++){
		if(typeof eval("window.menu"+i) != "undefined") {
		
			// hide all menus
			if(document.all) otherMenu = document.all["menu"+i]; 
			if(document.getElementById()) otherMenu = document.getElementById("menu"+i);
			otherMenu.style.visibility = "hidden";
		}	
	}
	
	// Get positioning div left position
	if (document.all) currentTab = document.all[div];
	if (document.getElementById) currentTab = document.getElementById(div);
	var left = currentTab.offsetLeft;
	while(currentTab.offsetParent != null)
	{
		left += currentTab.offsetParent.offsetLeft;
		currentTab = currentTab.offsetParent;
	}
	
	// Get positioning div top position
	if (document.all) { currentTab = document.all[div] }
	if (document.getElementById) { currentTab = document.getElementById(div) }
	var top = currentTab.offsetTop;
	while(currentTab.offsetParent != null)
	{
			top += currentTab.offsetParent.offsetTop;
			currentTab = currentTab.offsetParent;
	}
	
	// compensate for IE5.5 relative div problems http://www.xs4all.nl/~ppk/js/findpos.html
	//	if(!HM_IE4 && (navigator.appVersion.indexOf("MSIE") !=-1) &&(navigator.appVersion.indexOf("MSIE 5.0")==-1)) top=top/2;

	// show the menu	
	if(document.all) theMenu = document.all[menu]; 
	if(document.getElementById()) theMenu = document.getElementById(menu);
	theMenu.style.top = top + 25;
	theMenu.style.left = left;
	theMenu.style.visibility = "visible";	
}

function hide(menu) {
	if(document.all) theMenu = document.all[menu]; 
	if(document.getElementById()) theMenu = document.getElementById(menu);	
	timer = setTimeout('theMenu.style.visibility = "hidden"', 200) ;
}

function clearTimer(){
	clearTimeout(parseInt(timer));
}


// temporary variable used to distinguish between dev and production paths
var serverPath;
serverPath = "";
if (window.location.href.indexOf("/stage") != -1) serverPath = "/stage";

menu1 = [
[166],
["Eurail - Europe",serverPath+"/pass_index.asp?company_id=1"],
["National Passes - Europe",serverPath+"/pass_index.asp?company_id=2"],
["Britrail Passes - UK",serverPath+"/pass_index.asp?company_id=3"],
["Amtrak - USA",serverPath+"/pass_index.asp?company_id=4"],
["Swiss Rail Packages",serverPath+"/pass_index.asp?company_id=8"],
["Tranzscenic - New Zealand",serverPath+"/pass_index.asp?company_id=10"],
["Via Rail - Canada",serverPath+"/pass_index.asp?company_id=9"]
]

menu2 = [
[210],
["Eurostar - Europe",serverPath+"/train_index.asp?train_category_id=1"],
["Premier Trains - Europe",serverPath+"/train_index.asp?train_category_id=2"],
["Hotel Trains - Europe",serverPath+"/train_index.asp?train_category_id=3"],
["High Speed Trains - Europe",serverPath+"/train_index.asp?train_category_id=4"],
["Scenic Trains - Europe",serverPath+"/train_index.asp?train_category_id=5"],
["Venice Simplon Orient Express - Europe",serverPath+"/train_index.asp?train_category_id=8"],
["Eastern Orient Express - Asia",serverPath+"/train_details.asp?train_id=43"],
["Acela Express - USA",serverPath+"/train_details.asp?train_id=34"],
["Tranzscenic - New Zealand",serverPath+"/train_index.asp?train_category_id=9"],
["Rocky Mountaineer",serverPath+"/train_index.asp?train_category_id=10"]
]

/*
menu3 = [
[130],
["Sector Fare Search - top 200 sectors","some url 1"],
["Rail Europe search - all sectors","some url 2"]
]
*/

menu4 = [
[135],
["Europe",serverPath+"/schedules.asp?pageMode=1"],
["UK",serverPath+"/schedules.asp?pageMode=2"],
["USA",serverPath+"/schedules.asp?pageMode=3"]
]

menu5 = [
[76],
["Europe",serverPath+"/maps.asp?pageMode=1"],
["UK",serverPath+"/maps.asp?pageMode=2"],
["USA",serverPath+"/maps.asp?pageMode=3"],
["Japan",serverPath+"/maps.asp?pageMode=4"],
["Canada",serverPath+"/maps.asp?pageMode=5"]
]

menu6 = [
[119],
["New User",serverPath+"/bookings/travel_agent_details.asp?pageMode=new"],
["Existing User",serverPath+"/bookings/"]
]

//build menus
for (i=0;i<10;i++){

	if(typeof eval("window.menu"+i) != "undefined") {
		
		menu = eval("menu"+i);
		width = 150;
		if(typeof eval(menu[0][0]) != "undefined") width = menu[0][0];
		
		str = '<div id="menu'+i+'" style="position:absolute;width:'+width+'px;top:0px;left:0px;visibility:hidden;border:1px #B7C1D5 solid"';
		// add form hider code to trains in europe
		if (i == 2) str +=  'onMouseOver="clearTimer();hideForm()" onMouseOut="hide(this.id);showForm()">';
		else str += 'onMouseOver="clearTimer()" onMouseOut="hide(this.id)">';
		//
		str+= '<table cellpadding=0 cellspacing=0 border=0 width='+width+'>';
	
		
		for (j=1;j<menu.length;j++){
			str+= '<tr>';
			str+= '<td class="nav1" onMouseOver="this.style.background = \'#2163A5\';this.style.color = \'white\'"  onMouseOut="this.style.background = \'white\';this.style.color = \'white\';this.style.color = \'black\'" onClick="window.location.href=\''+menu[j][1]+'\'">';
			str+= '<div style="margin:4px">' +menu[j][0]+'</div>';
			str+='</td>';
			str+= '</tr>';
			if(j!=menu.length-1) str+='<tr><td style="background-color:#B7C1D5"><img src="/stage/img/s.gif" width=1 height=1></td></tr>';
		}		
		str+= '</table>';
		str+= '</div>';
		document.write(str);
	}	
}

//rollover effects
function r1(object) {object.style.background = "#639CCE"}
function r2(object){object.style.background = "#1F61A9"}


// popup for eurail passes
function adjoiningCountries() {window.open('adjoining_countries.asp','','width=550,height=560,location=0,scrollbars=1,toolbar=0,status=0')}

// popup for maps
function mapPopup(img,logo) {window.open('map_popup.asp?img='+img+'&logo='+logo,'','width=600,height=600,location=0,scrollbars=1,toolbar=0,status=0,resizable')}

// hide & show search form element being hit by menus
function hideForm(){
	for (i=1;i<5;i++)
	{
		if (document.getElementById("hideForm" + i) != null) 
		{
			document.getElementById("hideForm" + i).style.visibility = "hidden";
		}
	}	
}
function showForm(){
	for (i=1;i<5;i++)
	{
		if (document.getElementById("hideForm" + i) != null) 
		{
			document.getElementById("hideForm" + i).style.visibility = "visible";
		}
	}
}
