//
// Platform and browser detect variables
//

var isUnix = false;
var isLinux = false;
var isMacintoshPPC = false;
var isMacintosh68K = false;
var isWindows95 = false;
var isWindows98 = false;
var isWindowsNT= false;
var isWindows3x = false;

var isNew = false;
var isIE = false;
var isIE4 = false;
var isIE5 = false;
var isNetscape = false;
var isNetscape4 = false;
var isNetscape6 = false;

var userAgent = navigator.userAgent.toLowerCase();
var appName = navigator.appName;
var appVersion = parseInt(navigator.appVersion);
var platform = (navigator.platform).substring (0, 5);

// Browser detection
if (appVersion > 5) isNew = true;
else if (appName == "Netscape") {
  isNetscape = true;
  if (appVersion == 4) isNetscape4 = true;
  else if (appVersion == 5) isNetscape6 = true;
}
else if (appName == "Microsoft Internet Explorer") {
  isIE = true;
  if (appVersion == 4) {
    isIE4 = true;
    if (msieversion() == 5) isIE5 = true;
  }
}

function msieversion() {
  var ua = window.navigator.userAgent
  var msie = ua.indexOf ( "MSIE " )
  if ( msie > 0 ) return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
  else return 0;
}

// Platform detection
if ( ( userAgent.indexOf("win95") !=-1) || ( userAgent.indexOf("windows 95") !=-1) ) isWindows95 = true;
if ( ( userAgent.indexOf("win98") !=-1) || ( userAgent.indexOf("windows 98") !=-1) ) isWIndows98 = true;
if ( ( userAgent.indexOf("winnt") !=-1) || ( userAgent.indexOf("windows nt") !=-1) ) isWindowsNT= true;
if ( ( userAgent.indexOf("win16") !=-1) || ( userAgent.indexOf("windows 3.1") !=-1) ) isWindows3x = true;
if ( navigator.appVersion.indexOf("Mac") != -1 ) {
  if ( userAgent.indexOf("pc)") !=-1 ) isMacintoshPPC = true;
  else isMacintosh68K = true;
}
if ( platform == "SunOS" ) isUnix = true;
else if ( platform == "HP-UX" ) isUnix = true;
else if ( platform == "IRIX " ) isUnix = true;
else if ( ( ( navigator.platform ).substring (0, 3) ) == "AIX" ) isUnix = true;
else if ( userAgent.indexOf("linux") != -1 ) isLinux = true;

if(isIE || isIE4 || isIE5) ie=true;
else ie=false;
if(isMacintoshPPC || isMacintosh68K) mac=true;
else mac=false;
if(isWindowsNT) nt=true;
else nt=false;
if(isUnix || isLinux) unix=true;
else unix=false;
if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("5.5") != -1) ie5_5=true;
else ie5_5=false;

// Establish which version of Shockwave Flash browser is running
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var maxFlashVersion = 5;
var flashVersion = detectFlash();
	
function detectFlash(){

	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

	if (isIE && isWin) {
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('</SCRIPT\> \n');

	}

	if (navigator.plugins) {
		if (navigator.plugins/*["Shockwave Flash 2.0"] || navigator.plugins*/["Shockwave Flash"]) {
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			flash2Installed = flashVersion == 2;
			flash3Installed = flashVersion == 3;
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash5Installed = flashVersion == 6;
		}
	} 

	for (var i = 2; i <= maxFlashVersion; i++) {
		if (eval("flash" + i + "Installed") == true) flashVersion = i;
	}

	return flashVersion;
}

//
// Generic functions
//

// Used for selecting window size
function openWindow(winUrl, winName, properties) {

switch (properties) {

    case "win_a":
   newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=460,WIDTH=790,TOP=0,LEFT=0");
        newWindow.focus();
   break

    case "win_b":
        newWindow = window.open(winUrl,winName,"scrollbars,HEIGHT=470,WIDTH=525,TOP=0,LEFT=0");
        newWindow.focus();
        break

    case "win_b_no_scroll":
        newWindow = window.open(winUrl,winName,"HEIGHT=470,WIDTH=525,TOP=0,LEFT=0");
        newWindow.focus();
        break

    case "win_c":
        newWindow = window.open(winUrl,winName,"scrollbars,resizable,HEIGHT=555,WIDTH=570,TOP=0,LEFT=0");
        newWindow.focus();
        break

    case "win_c_no_scroll":
        newWindow = window.open(winUrl,winName,"HEIGHT=555,WIDTH=570,TOP=0,LEFT=0");
        newWindow.focus();
        break

    case "win_c_padlock":
        newWindow = window.open(winUrl,winName,"scrollbars,resizable,status,HEIGHT=555,WIDTH=570,TOP=0,LEFT=0");
        newWindow.focus();
        break

   case "win_lad":
      newWindow = window.open(winUrl,winName,"scrollbars,resizable,HEIGHT=540,WIDTH=670,TOP=0,LEFT=0");
        newWindow.focus();
      break

	case "win_f":
   		newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=360,WIDTH=785,TOP=50,LEFT=0");
        newWindow.focus();
   		break

    default:
        newWindow = window.open(winUrl,winName,properties);
        newWindow.focus();
    }
}  

//Closes the current window
function windowClose(){
  window.close();
}

// Open new window for branch locator tool
function branchLocator(){
   openWindow('http://www.hbeu1.hsbc.com/ukservices/branchlocator/country.asp','lad','win_lad');
}

// Open new window for sitemap tool
function sitemap(){
	openWindow('../sitemap/sitemap.htm','sitemap','win_c')
}


// Close window this has been ported from leave-hsbc/offsite.js
function closeWindow() 
{
		window.opener.focus();
		window.close();
}

// Refresh parent or tool window with homepage
var w = window.screen.availWidth; 
var h = window.screen.availHeight;
	
function linkHome(homeUrl)
{
	try
	{
		if (window.opener.closed==true) // check if there is no parent window
		{	
			location.href = homeUrl;	// load URL in current window
			window.resizeTo(w,h);
			window.moveTo(0,0);
		}
		else
		{
			try
			{
				window.opener.parent.location= homeUrl;
				self.close();
			}
			catch ( errorCode ) 
			{
				location.href = homeUrl;
				window.resizeTo(w,h);
				window.moveTo(0,0);
			}
		}
	}
	catch ( errorCode )
	{
		location.href = homeUrl;
		window.resizeTo(w,h);
		window.moveTo(0,0);
	}
}
