// Holds all info about locations
var dstDate = new xmlDate();
var gosLocations = new objLocations();
var BBLink = 'http://www.globaloutpostservices.com/default.asp?path=jc4kke8t&id=';
var teamLink = '/default.asp?path=n6lcg2w1&city=';
var imagePath = 'media/images/';
var locationPath = 'media/Locations/';
var docPath = '/admin/download.asp?file=';
var libPath = '/default.asp?path=n6lldy9x&fn=show&city=';
var calPath = '/popup.asp?path=qie24311&city=';
var mouseX = 0;
var mouseY = 0;
var showTime = 0;  // seconds until flags disappear
var hTimer = 0;		// Handle for the disappear timer
var flagHeight = 18;  // adjust this to fit the height of the name flags

var missInit=false;	// a toggle flag to skip the initialisation phase before trying to disable the helper demo function
var assistantOn=false;	// flag to tell us whether the assitant is present

var cHeight = 73;		// get the height of the info box when it is closed
var started = false;	// used to determine whether the location box should be expanded for the first call to GOS	

if (thmPath){ imagePath=thmPath+'images/';}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;


//====   jQuery function to slide info box in annd out with mouse over.. 
// will need to make this work when an 
$(document).ready(function(){
	// animate the info box to slide open instead of jump

	//run a function when the image is hovered over
	$('#locationInfo')
		//mouseOver effect
		.hover(function(){

			// get the height of the full size info box
			var iHeight = $('#infoBox').height();

			//take the currently targeted element
			$(this)
				//stops the event from happening in case of an abrupt mouseOut
				.stop()
				//custom animation effect to change the  height of the info box
				.animate({
					//take the original width/height X multipler and tag on the 'px'
					height: (iHeight + 10) +'px'
				//space the animation out over 0.2 sec (deals in milliseconds)
				},200);
		},
		//this is just like a mouseOut effect to take the img back to the original size
		function(){
			$(this)

				//stops the event from happening in case of an abrupt mouseOut
				.stop()
				.animate({
					height: cHeight +'px'
				},200);
		});
});
//========

//function dontShowAssistant()
//
// Shuts down the guided tour if the user knows how the web site works
// testing first if the assistant is present
function dontShowAssistant() {
	if (!missInit) {
		// need to skip the first call since this will be initialising the page to GOS information
		missInit=true;
		
	}else{
	
		if (assistantOn) stopAssistant();
	}
}


//  function GetElementByID()
//  
//  Looks through the element list and returns the first element with
//  this ID. Will need expanding for cross browser compatibility
function getElementByID( jsID ) {
	if (document.all) {
		return document.all.item(jsID);
	}else{
		//alert( jsID + ' - non IE browser' );		
		return document.getElementById(jsID);		
	}
}
			
//  function ShowLocationInfo()
//  
//  Passed the name of the Location and then shows the data for that
//  location, unless the location isn't in the dB.
//
function ShowLocationInfo( jsLocName ) {

	var jsLoc = gosLocations.Find(jsLocName);
	
	if (jsLoc == null) {
		// Location info not found
		// alert( 'Cannot find information for ' + jsLocName );
	
	}else{
		// Stops the assitant demo from starting up
		dontShowAssistant();
		
		// Show found location's info, by writing the info to the Intro table, and the Icons table
		// ShowIcons( jsLoc );
		// ShowIntro( jsLoc ); 
		if (!started) shutInfo();
		// This is the new function to display the block of info in the topright corner
		BuildLocationInfo(jsLoc,'infoBox');

		// expands the info box only if this isn't the intialisation ..
		if (started) {expandInfo(null);} else {started = true;}

		// Add the clocks to the clock element
		ShowClocks( jsLoc.Timezone, jsLoc.Location, jsLoc.Library );

		SetDropDown( jsLocName );
	}

}
//  function ShowIcons()
//
//  Fills the InformationIcon panel with icon and contact information from the 
//  passed InfoLocation
//
function ShowIcons( jsLoc ) {
	var jsElement = getElementByID('LocationIcons');
	
	if (jsElement == null){
		//alert( 'DIV LocationIcons couldn\'t be found' );
	
		return;
	}
	
	var jsIcons = ShowTableStart( 'Icons' );
	
	// Add a table header with the name of the location
	/*
	if (jsLoc.Location.indexOf('Outpost') == -1) {
		jsIcons += '<tr><td colspan=\"2\" class=\"IconHeader\"> Outpost ' + jsLoc.Location + ' Contact </tr></td>\r\n';
	} else {
		jsIcons += '<tr><td colspan=\"2\" class=\"IconHeader\"> ' + jsLoc.Location + ' Contact </tr></td>\r\n';
	}
	*/

	// the icon link part of the table
	//jsIcons += ShowContactInfo( jsLoc.FocalPoint, jsLoc.Address, jsLoc.Telephone );

	if (jsLoc.FocalPoint.length > 0) {
		jsIcons += '<tr><td class=\"InfoTitle\"> Focal point:</td><td class=\"InfoCell\">' + jsLoc.FocalPoint + '</td></tr>\r\n';		
	}

    if (jsLoc.FocalPoint.length > 0)
	  if (jsLoc.FocalPoint=='Global Outpost Services')
	  	  jsIcons += '<tr><td class=\"InfoTitle_orange\"> About us:</td><td class=\"InfoCell_orange\">' + jsLoc.Intro + '</td></tr>\r\n';		
	   else
	    jsIcons += '<tr><td class=\"InfoTitle\"> About us:</td><td class=\"InfoCell\">' + jsLoc.Intro + '</td></tr>\r\n';		
	  
	if (jsLoc.Email.length > 0) {
		jsIcons += ShowIcon( 'Email:', jsLoc.Email, imagePath + 'email.gif', true, 'mailto:' );
	}
	
	if (jsLoc.Web.length > 0) {	
		jsIcons += ShowIcon( 'Web site:', jsLoc.Web, imagePath + 'web.gif', true, 'http://' );
	}
	
	if  (jsLoc.Brief.length > 0) {
		jsIcons += ShowIcon( 'Business brief:', BBLink + jsLoc.Brief, imagePath + 'bb.gif', false, '' );
	}

	if ((jsLoc.InsideGuide.length > 0) || (jsLoc.CDGuide.length > 0)){	
	
		if (jsLoc.InsideGuide.length > 0) {	
			igcdg = '<a href=\"' + docPath + jsLoc.InsideGuide + '\"><img border=\"0\" src=\"' + imagePath + 'document.gif\"> Inside Guide </a> ';
		}else{
			igcdg = "";
		}
		
		if (jsLoc.CDGuide.length > 0) {	
			igcdg += '<a href=\"' + docPath + jsLoc.CDGuide + '\"><img border=\"0\" src=\"' + imagePath + 'document.gif\"> C&D Guide </a> ';
		}
		
		jsIcons += '<tr><td  class=\"InfoTitle\"> Documents:</td><td class=\"InfoCell\">' + igcdg + '</tr></td>\r\n';
	}
	
	if (jsLoc.Library != "") {
		jsIcons += ShowIcon( 'Library:', libPath + jsLoc.Library, imagePath + 'libdocs.gif', false, '' ); 
	}
			
	// Team link ..
	if (jsLoc.City.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{
		jsIcons += ShowIcon( 'The team:', teamLink + jsLoc.City, imagePath + 'team.gif', false, '' ); 
	}
	
	if (jsLoc.Telephone.length > 0) {
		jsIcons += '<tr><td class=\"InfoTitle\"> Telephone:</td><td class=\"InfoCell\">' + jsLoc.Telephone + '</td></tr>\r\n';		
	}	

	if (jsLoc.Address.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{
		jsIcons += '<tr><td class=\"InfoTitle\"> Address:</td><td class=\"InfoCell\">' + jsLoc.Address + '</td></tr>\r\n';		
	}
	jsIcons += ShowTableEnd();
	
	jsElement.innerHTML = jsIcons;
}

//  function ShowIntro()
//
//  replaces the current Introduction information with that
//  of the newly selected locations. This will also hold the clocks
//  as well as other incidental information such as Languages and GMT relative time
function ShowIntro( jsLoc ) {

	var jsElement = getElementByID( 'LocationIntro' );
	if (jsElement == null){
		//alert( 'DIV LocationIntro couldn\'t be found' );
	
		return;
	}
		
	var jsIntro = ShowTableStart( 'Intro' );

	// Add a table header with the name of the location
	/*
	if (jsLoc.Location.indexOf('Outpost') == -1) {
		jsIntro += '<tr><td class=\"IntroHeader\"> Outpost ' + jsLoc.Location + ' Information </tr></td>\r\n';
	} else {
		jsIntro += '<tr><td class=\"IntroHeader\"> ' + jsLoc.Location + ' Information </tr></td>\r\n';
	}
	*/

	// Add 4 clocks, Amsterdam, Houston, Kuala Lumpur and slightly larger the local time at this location
	jsIntro += '<tr><td class=\"IntroCell\"> <div id="noClocks" class="clocks">&nbsp;</div></tr></td>\r\n';
	
	if (jsLoc.Intro.length > 0){
		jsIntro += '<tr><td class=\"IntroCell\"> ' + jsLoc.Intro + '</tr></td>\r\n';
	}
	
	// GMT + hours
	if (jsLoc.Timezone.length > 0){
		var jsUTC = getLocationTime(jsLoc.Timezone, true );
		jsIntro += '<tr><td class=\"IntroCell\"> Time: UTC ' + (jsUTC > 0?'+'+jsUTC:jsUTC) + '</tr></td>\r\n';
	}else{
		jsIntro += '<tr><td class=\"IntroCell\"> Time: UTC+0 </tr></td>\r\n';
	}
	
	// Office hours
	if (jsLoc.Times.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{
		jsIntro += '<tr><td class=\"IntroCell\"> Office hours: ' + jsLoc.Times + '</tr></td>\r\n';
	}
	
	// Languages
	if (jsLoc.Languages.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{
		jsIntro += '<tr><td class=\"IntroCell\"> Languages spoken: ' + jsLoc.Languages + '</tr></td>\r\n';
	}

	jsIntro += '<tr><td>&nbsp;</td></tr><tr><td class=\"InfoTitle\" colspan=\"2\">For more information about ' + jsLoc.Location + ' please click on the links above. Outpost cannot provide any contractual information, for that please contact your line HR.</td></tr>\r\n';		

	jsIntro += ShowTableEnd();
	
	jsElement.innerHTML = jsIntro;

	// Add the clocks to the clock element
	ShowClocks( jsLoc.Timezone, jsLoc.Location, jsLoc.Library );
}

//  function ShowContactInfo()
//
//  Returns a string that contains the locations contact
//  info in a table Row

function ShowContactInfo( jsContact, jsAddress, jsTel ) {

	jsRtn = '';
	
	if (jsContact.length > 0) {
		jsRtn += '<tr><td class=\"InfoTitle\"> Focal point:</td><td class=\"InfoCell\">' + jsContact + '</td></tr>\r\n';		
	}
	if (jsAddress.length > 0) {
		jsRtn += '<tr><td class=\"InfoTitle\"> Address:</td><td class=\"InfoCell\">' + jsAddress + '</td></tr>\r\n';		
	}
	if (jsTel.length > 0) {
		jsRtn += '<tr><td class=\"InfoTitle\"> Telephone:</td><td class=\"InfoCell\">' + jsTel + '</td></tr>\r\n';		
	}		
	return  jsRtn;
}

//  function ShowIcon()
//
//  Adds an entry to the Icon table in the Icon layer by adding a Row.
//  This might be better achieved using Styles to hide and show icons.
//  The links will need changing for each change of location.
//  jsElement is the layer element that the Table is being added to.

function ShowIcon( jsTitle, jsLink, jsImage, jsShowLink, jsLinkType ) {
	// if there is no link info then don't create an on-screen entry
	if ((jsLink == null) || (jsLink.length == 0)) {
		return '';
	}
	
	// if the Image is not available then just show the link text ..
	if (jsImage.length != 0) {
		if (jsShowLink){
			return '<tr><td class=\"InfoTitle\"> '+ jsTitle + '</td><td class=\"InfoCell\"><a href=\"' + jsLinkType + jsLink + '\" target=\"_blank\"><img border=\"0\" src=\"' + jsImage + '\"/> ' + jsLink + '</a></td></tr>';
		}else{
			return '<tr><td class=\"InfoTitle\"> '+ jsTitle + '</td><td class=\"InfoCell\"><a href=\"' + jsLinkType + jsLink + '\" target=\"_blank\"><img border=\"0\" src=\"' + jsImage + '\"/></a></td></tr>';
		}
	}else{
		if (jsShowLink){
			return '<tr><td class=\"InfoTitle\"> '+ jsTitle + '</td><td class=\"InfoCell\"><a href=\"' + jsLinkType + jsLink + '\" target=\"_blank\">' + jsLink + '</a></td></tr>';
		}else{
			return '<tr><td class=\"InfoTitle\"> '+ jsTitle + '</td><td class=\"InfoCell\"><a href=\"' + jsLinkType + jsLink + '\" target=\"_blank\">WWW</a></td></tr>';
		}
	}
}

function ShowTableStart(jsID) {
	return '<Table id=\"' + jsID + '\" class=\"InfoTable\">';
}

function ShowTableStartJS(jsID, jsJS) {
	return '<Table id=\"' + jsID + '\" class=\"InfoTable\" onMouseOver=\"' + jsJS + '\">';
}

function ShowTableEnd(){
	return '</Table>';
}

function ShowName(js){
	// this will just change the DropDown box to show the item we are over
	// and show an inset location map if necessary
	// SetDropDown(js);
	
	showFlag( js );
	
	ShowInsetMap(js);
}

// Expands/Contracts the LocationInfo layer so that we can see the extra info..
//
function moreLocInfo(){
	// just change the style to suit 
	var jsLIB = getElementByID('locationInfo');
	
	if (jsLIB){
		if(jsLIB.className=="locInfoShrink"){expandInfo(null);jsLIB.className="locInfoExpand";}
		else{jsLIB.className="locInfoShrink"; shutInfo();}
	}
}

function expandInfo(e){
	// get the height of the full size info box
	var iHeight = $('#infoBox').height();

	//take the currently targeted element
	$('#locationInfo')
		//stops the event from happening in case of an abrupt mouseOut
		.stop()
		//custom animation effect to change the  height of the info box
		.animate({
			//take the original width/height X multipler and tag on the 'px'
			height: (iHeight + 10) +'px'
			//space the animation out over 0.2 sec (deals in milliseconds)
			},200,function() { // on animation complete
							 
							}
			);

	var jsLIB = getElementByID('locationInfo');
	if (jsLIB){jsLIB.className="locInfoExpand";}
}

function shrinkInfo(e){
	$('#locationInfo')
		//stops the event from happening in case of an abrupt mouseOut
		.stop()
		.animate({
			height: cHeight +'px'
		},200);
	
	var jsLIB = getElementByID('locationInfo');
	if (jsLIB){jsLIB.className="locInfoShrink";}
}

function shutInfo(){
	$('#locationInfo')
		//stops the event from happening in case of an abrupt mouseOut
		.stop()
		.animate({
			height: cHeight +'px'
		},1);
	
	var jsLIB = getElementByID('locationInfo');
	if (jsLIB){jsLIB.className="locInfoShrink";}
}

// Builds the std location info table and insert it into the specified element 
// jsLoc - a structure holding the locations info, and jsInsInto - the element to be inserted into
function BuildLocationInfo(jsLoc, jsInsInto){
	var jsElement = getElementByID(jsInsInto);
	if (jsElement){jsElement.innerHTML=BuildLocationInfoTable(jsLoc);}
}

// Build the Location information in a table format that we can insert into other elements.
// Returns a string to be used in an innerHTML instruction.
function BuildLocationInfoTable(jsLoc){
	// start by openning the table..
	//var html=ShowTableStartJS( 'locInfo', 'javascript:moreLocInfo();' );
	var html=ShowTableStart('locInfo');
	// add the title
	if (jsLoc.Location.indexOf('Outpost') == -1) {html += '<tr><td colspan=\"2\" class=\"InfoHeader\"> Outpost ' + jsLoc.Location + '</tr></td>\r\n';}
	else {html += '<tr><td colspan=\"2\" class=\"InfoHeader\"> ' + jsLoc.Location + '</tr></td>\r\n';}
	// General information
	if (jsLoc.FocalPoint.length > 0) {html += '<tr><td class=\"InfoTitle\"> Focal point:</td><td class=\"InfoCell\">' + jsLoc.FocalPoint + '</td></tr>\r\n';}
	
	//if (jsLoc.Intro.length > 0){html += '<tr><td class=\"InfoTitle\"> About us: </td><td class=\"InfoCell\">' + jsLoc.Intro + '</tr></td>\r\n';}
	if (jsLoc.Intro.length > 0)
	 if(jsLoc.FocalPoint =='Global Outpost Services') 
	 {html += '<tr><td class=\"InfoTitle_orange\"> About us: </td><td class=\"InfoCell_orange\">' + jsLoc.Intro + '</tr></td>\r\n';}
	 else
	{html += '<tr><td class=\"InfoTitle\"> About us: </td><td class=\"InfoCell\">' + jsLoc.Intro + '</tr></td>\r\n';}
	
	
	
	if (jsLoc.Email.length > 0) {html += ShowIcon( 'Email:', jsLoc.Email, imagePath + 'email.gif', true, 'mailto:' );}
	if (jsLoc.Web.length > 0) {html += ShowIcon( 'Web site:', jsLoc.Web, imagePath + 'web.gif', true, 'http://' );}

	// -------------  This is where the extended information starts to appear   ----------------------
	if  (jsLoc.Brief.length > 0) {html += ShowIcon( 'Business brief:', BBLink + jsLoc.Brief, imagePath + 'bb.gif', false, '' );}
	
	// Add the Inside Guide and C&D guide where possible
	var igcdg="";
	if ((jsLoc.InsideGuide.length > 0) || (jsLoc.CDGuide.length > 0)){	
		if (jsLoc.InsideGuide.length > 0) {igcdg = '<a href=\"' + docPath + jsLoc.InsideGuide + '\"><img border=\"0\" src=\"' + imagePath + 'document.gif\"> Inside Guide </a> ';}
		else{igcdg = "";}
		if (jsLoc.CDGuide.length > 0) {igcdg += '<a href=\"' + docPath + jsLoc.CDGuide + '\"><img border=\"0\" src=\"' + imagePath + 'document.gif\"> C&D Guide </a> ';}
		html += '<tr><td  class=\"InfoTitle\"> Documents:</td><td class=\"InfoCell\">' + igcdg + '</tr></td>\r\n';
	}
	if (jsLoc.Library != "") {html += ShowIcon( 'Library:', libPath + jsLoc.Library, imagePath + 'libdocs.gif', false, '' );}
			
	// Team link ..
	if (jsLoc.City.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{html += ShowIcon( 'The team:', teamLink + jsLoc.City, imagePath + 'team.gif', false, '' );}
	
	if (jsLoc.Telephone.length > 0){html += '<tr><td class=\"InfoTitle\"> Telephone:</td><td class=\"InfoCell\">' + jsLoc.Telephone + '</td></tr>\r\n';}	
	if (jsLoc.Address.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{html += '<tr><td class=\"InfoTitle\"> Address:</td><td class=\"InfoCell\">' + jsLoc.Address + '</td></tr>\r\n';}

	
	// GMT + hours
	if (jsLoc.Timezone.length > 0){var jsUTC = getLocationTime(jsLoc.Timezone, true );html += '<tr><td class=\"InfoTitle\"> Time: </td><td class=\"InfoCell\"> UTC' + (jsUTC > 0?'+'+jsUTC:jsUTC) + '</tr></td>\r\n';
	}else{html += '<tr><td class=\"InfoTitle\"> Time: </td><td class=\"InfoCell\"> UTC+0 </tr></td>\r\n';}
	
	// Office hours
	if (jsLoc.Times.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{html += '<tr><td class=\"InfoTitle\"> Office hours: </td><td class=\"InfoCell\">' + jsLoc.Times + '</tr></td>\r\n';}
	
	// Languages
	if (jsLoc.Languages.length > 0)
	if (jsLoc.FocalPoint!='Global Outpost Services')
	{html += '<tr><td class=\"InfoTitle\"> Languages spoken: </td><td class=\"InfoCell\">' + jsLoc.Languages + '</tr></td>\r\n';}

	// close the table ..
	html+=ShowTableEnd();

	// Send the code back to the caller..
	return html;
}

function SetDropDown(js){
	var jsDD = getElementByID('location');
	if (jsDD == null){
		// alert( 'Can\'t find DropDown box');
		
		return;
	}
	
	// set the new 
	for( var o=0; o<jsDD.length; o++ ){
	
		if (jsDD.options[o].value == js) {
			// found the location so show it in the dropdown
			jsDD.options[o].selected = true;
			
			// showFlag( js );
			
			return;
		}
	}
	
	//alert( 'Can\'t find the location: ' + js );		
}

function FillDropDown() {
	var jsDD = getElementByID('location');
	
	if (jsDD == null){
		//alert( 'Can\'t find DropDown box');
		
		return;
	}
	
	gosLocations.LoadDropdown(jsDD);
}

function ShowInsetMap(jsName){
	var jsLoc = gosLocations.Find(jsName);
	
	if (jsLoc == null) {
		// Location info not found
		//alert( 'Cannot find location ' + jsName );
	
		return;	
	}
	
	if (jsLoc.MapImage.length == 0) {
		// alert( 'Image map href = \"\"' + jsName );

		return;
	}
	
	var jsMap = getElementByID('InsetMapImage');
	if (jsMap == null){
		//alert( 'Cannot find the Inset Map Image.' );
	
		return;
	}

	// This image will be used to change the insetmap image ..
	// using a .gif regional map since it is half the size of the .jpg
	jsMap.src = imagePath + jsLoc.MapImage + '.gif';
	jsMap.useMap = '#'+jsLoc.MapImage + '_hotspots_map';
}

// this generates the HTML for 1 clock
function GenerateClockHTML( jsOffset, jsPix, jsCity, jsClass ) {
	var jsLocalOffset = UTCoffset.getTime() + (jsOffset * 3600000); 
	var jsHours = Math.floor(jsLocalOffset / 3600000);
	var jsMins = Math.floor(jsLocalOffset / 60000);
	
	jsHours = Normalise( jsHours, 24 );
	jsMins = Normalise( jsMins, 60 );
	
	//alert( 'Time for this clock is: ' + UTCoffset.getHours() + ' = ' + jsHours + ':' + jsMins );
	
	jsSize = 'WIDTH='+ jsPix + ' HEIGHT=' + jsPix;
	jsEmbed = '<DIV class=\"clock' + jsClass + '\"><OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"' + 
 			  ' codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" ' +
			  jsSize + '> <PARAM NAME=movie VALUE=\"gosclock.swf?adjHours=' + jsHours + '&adjMins=' + jsMins + '\"> <PARAM NAME=quality VALUE=high> <param name=wmode value=transparent>' + 
			  ' <PARAM NAME=adjHours VALUE=' + jsHours + '>' + '<PARAM NAME=adjMins VALUE=' + jsMins + '>' +
			  ' <EMBED src=\"gosclock.swf?adjHours=' + jsHours + '&adjMins=' + jsMins + '\" quality=high wmode=transparent ' + 
			  jsSize + ' TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">'+
			  '</EMBED> </OBJECT><br>' + jsCity + '</DIV>';
			  
	//alert( jsEmbed );
	return jsEmbed;
}

// Makes sure the passed value is in range 0 - jsMax 
function Normalise( jsVal, jsMax ) {
	if (jsVal > jsMax ) {
		jsVal %= jsMax;
	}
			
	while (jsVal < 0){
		jsVal += jsMax;
	}
			
	return jsVal;
}

// This function calculates the current UTC or CET time as passed from the server
// and also normalises it to 24 hours/60 minutes depending on the request
function NormaliseTime( jsOff ) {

	if (jsOff == null) {
		jsOff = 0;
	}
	
	if (jsMins) {
		// Requesting minutes
		jsResult = UTCoffset.getMinutes() + jsOff;
		
		jsResult = Normalise( jsResult, 60 );
	
	} else {
		// Requesting hours
		jsResult = UTCoffset.getHours() + jsOff;
		
		jsResult = Normalise( jsResult, 24 );
	}
	
	return jsResult;
}

function getLocationTime(jsTimezone, jsAbsolute) {
	var now = new Date();
	try {
		// Need to make sure that the xmlDate is using the current corrected UTC time and not the client computer time ..
		// Set the base [dstDate.date] UTC time by offsetting the now time by our onload calculated UTCoffset
		dstDate.date.setTime(now.getTime()+UTCoffset.getTime());
		
		// set the requested time zone value [dstDate] 
		dstDate.setTimezone(jsTimezone);
		
		// If absolute is set then we want it relative to the UTC otherwise it is relative to the clients UTC
		if ((jsAbsolute==null)|(!jsAbsolute)){
			return -(dstDate.getTimezoneOffset()/60)+(now.getTimezoneOffset()/60);   // 60 minutes to hours 
		}else{
			return -(dstDate.getTimezoneOffset()/60);   // 60 minutes to hours 
		}
	}catch(e){
		return 0;
	}
}

// this returns the code for the 4 clocks, Ams, KL, Hou + Local
function ShowClocks( jsTimezone, jsCity, jsID ) {
	// set the Timezone location as set in the database
	// get the clocks layer
	var clocks=document.getElementById("clocks");
	if (clocks){
		// Now build the clocks ..
		jsClock = '<div class="clocks">' + GenerateClockHTML( getLocationTime(jsTimezone), 40, jsCity, 1 );
		jsClock += GenerateClockHTML( getLocationTime("Europe/Amsterdam"), 30, 'The Hague', 2 ) + ' ';
		jsClock += GenerateClockHTML( getLocationTime("US/Central"), 30, 'Houston', 3 ) + ' ';
		jsClock += GenerateClockHTML( getLocationTime("Asia/Kuala_Lumpur"), 30, 'Kuala Lumpur', 4 );
		jsClock += '<div id="calIcon"><a href="javascript:showPlanner(\'' + calPath + jsID + '\');"><img src="'+imagePath+'cal.gif" border=0></a></div></div>';

		// update the clocks layer
		clocks.innerHTML = jsClock;
	}
	// return jsClock; 
}

function HideName(js) {
}

function ddShowLocationInfo(jsDrop){
	ShowLocationInfo( jsDrop.value );
}


function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
    	mouseX = event.clientX //+ document.body.scrollLeft
    	mouseY = event.clientY //+ document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS
    	mouseX = e.pageX
    	mouseY = e.pageY
	}
	  
	// catch possible negative values in NS4
	if (mouseX < 0){mouseX = 0}
	if (mouseY < 0){mouseY = 0}  
 
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	return true
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	if (IE) {
		return [curleft-document.body.scrollLeft,curtop-document.body.scrollTop];
	}else{
		return [curleft,curtop];
	}
}

function showFlag( jsLoc ) {
	var jsFlag = getElementByID('flag');
	if (jsFlag == null) {
		return;
	}
	
	// we have the flag so lets show the location ..
	jsFlag.innerHTML = jsLoc;
	
	if (jsFlag.style){
		jsFlag = jsFlag.style;
	}
	
	var jsMap = getElementByID('MapContainer');
	coOrds=findPos(jsMap);
	
	jsFlag.fontSize = 11+'px';
	jsFlag.left = mouseX - coOrds[0] ;
	jsFlag.top = mouseY - coOrds[1] - flagHeight - 5;
	jsFlag.visibility = 'visible';
	jsFlag.hidden = false;
	//jsFlag.height = '';
	
	startDisappear();
}

function hideFlag() {
	var jsFlag = getElementByID('flag');
	
	if (jsFlag == null) {
		return;
	}
	
	// we have the flag so lets show the location ..
	jsFlag.innerHTML = ''
	
	if (jsFlag.style){
		jsFlag = jsFlag.style;
	}
	
	//jsFlag.height	= '0px';
	jsFlag.visibility = 'hidden';
	jsFlag.hidden = true;
}

// Is called by the timer 
function Disappear() {
	showTime--;
	
	// reduce the size of the box
	if (showTime < 10) {
		var jsFlag = getElementByID('flag');
	
		if (jsFlag == null) {
			return;
		}
	
		if (jsFlag.style){
			jsFlag = jsFlag.style;
		}
	
		// Divide the font size by 2 to make the flag shrink
		jsFlag.fontSize	= showTime + 'px';
	}
	
	// if the flag has disappeared then stop the timer
	if (showTime <= 0){
		hideFlag();	
	
		clearInterval(hTimer);
	
		return;
	}
}

// starts the timer for the disappearing flags
function startDisappear() {
	if (showTime <= 0) {
	 	hTimer = setInterval( 'Disappear()', 100 );
	}

	showTime = 15;
}

function showPlanner( jsURL ) {
	var obj_calwindow = window.open( jsURL,	'Calendar', 'width=640,height=450,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes' );
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}