/*****************************************
	global array init
/*****************************************/
var menuItems = new Array();
var footerItems = new Array();
var citySelectItems = new Array();
var preloadImages = new Array();
var assignedImagesOnLoad = new Array();
var rightShortCutItems = new Array();

/*****************************************
	Image swapping and preload
/*****************************************/
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i]; }}
}
/*****************************************
	Assigning items to global array
/*****************************************
	Main Menu
/*****************************************/
function addMainMenuItem(sectionname, url){
	i = menuItems.length;
	menuItems[i] = new Array();
	menuItems[i]['sectionname'] = sectionname;
	menuItems[i]['url'] = url;
	menuItems[i]['selected'] = (menuselected == sectionname);
}
/*****************************************
	Country list in below the main menu
/*****************************************/
function addCitySelectItem(citykey, thelabel){
	i = citySelectItems.length;
	citySelectItems[i] = new Array();
	citySelectItems[i]['citykey'] = citykey;
	citySelectItems[i]['thelabel'] = thelabel;
}
/*****************************************
	Footer Menu
/*****************************************/
function addFooterMenuItem(sectionname, thelabel, url){
	i = footerItems.length;
	footerItems[i] = new Array();
	footerItems[i]['sectionname'] = sectionname;
	footerItems[i]['thelabel'] = thelabel;
	footerItems[i]['url'] = url;
	footerItems[i]['selected'] = (menuselected == sectionname);
}
/*****************************************
	Right Short Cut Items
/*****************************************/
function addRightShortCutItem(gifname, jpgname, url){
	i = rightShortCutItems.length;
	rightShortCutItems[i] = new Array();
	rightShortCutItems[i]['gifname'] = gifname;
	rightShortCutItems[i]['jpgname'] = jpgname;
	rightShortCutItems[i]['url'] = url;
	if (gifname != '') addPreloadImages(shortcutFolder+gifname+'_f2.gif');
}
/*****************************************
	Assigning image after whole html loads
/*****************************************/
function addAssignImages(imgID, url, loadfirst){
	i = assignedImagesOnLoad.length;
	assignedImagesOnLoad[i] = new Array();
	assignedImagesOnLoad[i]['imgID'] = imgID;
	assignedImagesOnLoad[i]['url'] = url;
	assignedImagesOnLoad[i]['loadfirst'] = loadfirst;
}
/*****************************************
	Assigning image for preload
/*****************************************/
function addPreloadImages(url){
	preloadImages[preloadImages.length] = url;
}
/*****************************************
	onLoad functions
/*****************************************
	Preload the images (assign + preload)
/*****************************************/
function loadImages(){
	imgLine_preload = "";
	imgLine_assignment = "";
	for (i=0; i<assignedImagesOnLoad.length; i++){	
		if (document.getElementById(assignedImagesOnLoad[i]['imgID']) != undefined){
			tmp = 'document.getElementById("'+assignedImagesOnLoad[i]['imgID']+'").src="'+assignedImagesOnLoad[i]['url']+'"; ';
			if (assignedImagesOnLoad[i]['loadfirst']){
				imgLine_assignment = tmp + imgLine_assignment;
			} else {
				imgLine_assignment = imgLine_assignment + tmp;
			}
			tmp = '';
		}
	}
	for (i=0; i<menuItems.length; i++){
		imgLine_preload += "'"+menufolder+"menu_"+menuItems[i]['sectionname']+"_f2.gif', ";		
	}
	for (i=0; i<preloadImages.length; i++){
		imgLine_preload += "'"+preloadImages[i]+"'";
		if (i < preloadImages.length -1 )	imgLine_preload += ", ";		
	}
	eval(imgLine_assignment);
	eval("MM_preloadImages("+imgLine_preload+")");
}
/*****************************************
	Draw main menu
/*****************************************/
function drawMainMenu(){
	html = '';
	height_between_sap = 17;
	for (i=0; i<menuItems.length; i++){
		theitem = menuItems[i];
		html += '<div><a href="'+theitem['url']+'"';
		if (!theitem['selected']){
			html += " onMouseOut=\"MM_swapImgRestore();\" onMouseOver=\"MM_swapImage('menu_"+theitem['sectionname']+"','','"+menufolder+"menu_"+theitem['sectionname']+"_f2.gif',1);\" "
		}
		html += "><img name='menu_"+theitem['sectionname']+"' src='"+menufolder+"menu_"+theitem['sectionname'];
		if (theitem['selected']){
			html += '_f2';
		}
		html += ".gif' border='0' alt=''></a></div>";
	}
	html += '<div><img src="images/spacer.gif" height="'+height_between_sap+'" width="5"></div>';
	html += '<div><select id="selectoffice" onchange="browseOffice(this);">';
	i=0;
	if (typeof(ddisplay)!='undefined'){
		if (ddisplay != ""){
			i=1;
		}
	}
	for (; i<citySelectItems.length; i++){
		theitem = citySelectItems[i];
		html += "<option value='"+theitem['citykey']+"'";
		
		if (typeof(ddisplay)!='undefined'){
			if (ddisplay == theitem['citykey']){
				html += " selected";
			}
		}
		html += ">"+theitem['thelabel']+"</option>";
	}
	html += '</select></div>';
	
	document.getElementById('themenu').innerHTML = html;
	
}
/*****************************************
	Draw Right Short Cut Items
/*****************************************/
function drawRightShortCuts(){
	shortcut_paddingtop = 23;
	shortcut_sapheight = 17;
	html = '<img src="images/spacer.gif" height="'+shortcut_paddingtop+'"/><br/>';
	for (i=0; i<rightShortCutItems.length; i++){
		theitem = rightShortCutItems[i];
		html += "<a href='"+theitem['url']+"' ";
		if (theitem['gifname'] != ""){
			html += " onMouseOut='MM_swapImgRestore();' onMouseOver='MM_swapImage(\""+theitem['gifname']+"\",\"\",\""+shortcutFolder+theitem['gifname']+"_f2.gif\",1);'\"";
		}
		html += ">";
		if (theitem['gifname'] != ""){
			html += "<img name='"+theitem['gifname']+"' id='"+theitem['gifname']+"' src='"+shortcutFolder+theitem['gifname']+".gif'/><br/>";
		}
		if (theitem['jpgname'] != ""){
			html += "<img src='"+shortcutFolder+theitem['jpgname']+".jpg'/>";
		}
		html +="</a><br/>";
		html +='<img src="images/spacer.gif" height="'+shortcut_sapheight+'"/><br/>';
		
	}
	document.getElementById('shortCuts').innerHTML = html;
}
/*****************************************
	Draw footer menu
/*****************************************/
function drawFooter(){
	html = '';
	for (i=0; i<footerItems.length; i++){
		theitem = footerItems[i];
		html += '<a href="'+theitem['url']+'"';
		if (theitem['selected']) html += ' class="selected"';
		html += '>'+theitem['thelabel']+'</a>';
		if (i<footerItems.length-1) html += ' &nbsp; | &nbsp; ';
	}
	document.getElementById('thefooter').innerHTML = html;
}
/*****************************************
	This is the onload function in html
/*****************************************/
function init(){
	drawMainMenu();
	drawFooter();
	if (rightShortCutItems.length > 0 && document.getElementById('shortCuts')!=null) {		
		drawRightShortCuts();
	}
	loadImages();
}
/*****************************************
	Load the flash
/*****************************************/
function loadflash(divid, swfname, w, h, swfobject, flashvars){
	if (flashvars == null)	flashvars =  { } ;		
	params = {
		allowScriptAccess: "sameDomain",
		quality: "high"
		//, wmode: "transparent"
		//, scale: "exactFit"
	};
	attributes = {
		id: divid,
		name: divid
	};
	swfobject.embedSWF(swfname, divid, w, h, "8.0.0", "images/expressInstall.swf", flashvars, params, attributes);
}
/*****************************************
	Browse Location
/*****************************************/
function browseOffice(obj){
	if (obj.options[obj.selectedIndex].value!=''){
		document.location.href='location.html?office='+obj.options[obj.selectedIndex].value;
	}
}
/*****************************************
	Functions for specific page
/*****************************************
	Location page - show the content 
	(also called by action script)
/*****************************************/
function show_location(locationid){	
	if (locationid != 'undefined' && locationid != ''){
		if (document.getElementById('contents_office_'+locationid)!=null) {		
			document.getElementById('contents_office_').style.display = 'none';	
			document.getElementById('contents_office_'+ddisplay).style.display = 'none';	
			document.getElementById('contents_office_'+locationid).style.display = 'block';
			ddisplay = locationid;
			return true;
		} 
	}
}
/*****************************************
	Location page - showCityProfile
/*****************************************/
function showCityProfile(loactionid){
	return true;
}
/*****************************************
	Destination Rate
/*****************************************/
function getDestinationRates() {
	testV = 1;
	trialend = 10;
	pass1 = prompt('Please Enter Password','');
	if (pass1==null){ return false };
	while (testV < trialend ) {
		errtxt = '';
		if (pass1==null){ return false };
		if (pass1 == acp) {
			window.location.href=docloc;			
			return false;
		} 
		testV+=1;
		errtxt = 'Access Denied - Password Incorrect, Please Try Again.';
		errtxt += ' (Trial '+testV+' of '+trialend+')';
		pass1 = prompt(errtxt,'');
	}
	alert('Access Denied - Password Incorrect');
	return false;
}
/*****************************************
	Function ends .
	global function call on the head
/*****************************************
	location for main menu
/*****************************************/
var menufolder = 'images/menu/';	
var shortcutFolder = 'images/shortcuts/';	
/*****************************************
	Main menu -- item filename and url
/*****************************************/
addMainMenuItem('home', 'index.html');
addMainMenuItem('aboutus', 'aboutus.html');
addMainMenuItem('news', 'news.html');
addMainMenuItem('services', 'our_services.html');
addMainMenuItem('rate', 'destination_rate.html');
addMainMenuItem('glossary', 'glossary.html');
addMainMenuItem('office', 'location.html');
/*****************************************
	Main menu -- item filename and url
/*****************************************/
addCitySelectItem('', 'Select a location');
addCitySelectItem('ca', 'Cambodia');
addCitySelectItem('cn', 'China');
addCitySelectItem('hk', 'Hong Kong');
addCitySelectItem('in', 'Indonesia');
addCitySelectItem('jp', 'Japan');
addCitySelectItem('mo', 'Macau');
addCitySelectItem('my', 'Malaysia');
addCitySelectItem('ph', 'Philippines');
addCitySelectItem('ko', 'Seoul, Korea');
addCitySelectItem('sg', 'Singapore');
addCitySelectItem('tw', 'Taiwan');
addCitySelectItem('th', 'Thailand');
addCitySelectItem('vi', 'Vietnam');
/*****************************************
	Footer menu -- item label and url
/*****************************************/
addFooterMenuItem('disclaimers', 'Disclaimers', 'disclaimers.html');
addFooterMenuItem('privacy', 'Privacy Statement', 'privacy.html');
/*****************************************
	add preload images for specific page
/*****************************************/
switch (menuselected){
	case 'office':
		addPreloadImages('images/links/gotoweb_f2.gif');
		addPreloadImages('images/links/city_profile_f2.gif');
	break;
	case 'rate':
		addPreloadImages('images/links/submit_btn_f2.gif');
		addPreloadImages('images/links/reset_btn_f2.gif');
		addRightShortCutItem('lnk_community_responsibility', 'img_community_responsibility', 'community_responsibility.html');
		addRightShortCutItem('lnk_testimonials', 'img_testimonials', 'testimonials.html');
		addRightShortCutItem('lnk_corporate_team', 'img_corporate_team', 'our_team.html');
	break;
	default:
		addRightShortCutItem('lnk_community_responsibility', 'img_community_responsibility', 'community_responsibility.html');
		addRightShortCutItem('lnk_testimonials', 'img_testimonials', 'testimonials.html');
		addRightShortCutItem('lnk_corporate_team', 'img_corporate_team', 'our_team.html');
	break;
}
