//
// 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;

// Added by Chris to support existing hsbc functions

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;


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.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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&&id.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 swapImage(layerStem,imageSpace,imageName) {
  var ns4 = (document.layers)? true:false;
  var ie4 = (document.all)? true:false;
	if(!ie){	if(layerStem == ""){imageObj = document.images[imageSpace];}
				else
			{imageObj = eval(layerStem+".document.images[imageSpace]");}
		}
	if(ie){imageObj = document.all[imageSpace]}

        imageObj.src = imageName;

}

function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openWindow(winUrl, winName, properties) {

switch (properties) {

    case "win_a":
        newWindow = window.open(winUrl,winName,"scrollbars,menubar,toolbar,resizable,HEIGHT=460,WIDTH=790");
        newWindow.focus();
	break

    case "win_b":
	  	var enhancePopup = true;	
		var checkPath1 = winUrl.indexOf("www.login.hsbc.com");		// hard coded path 1
		var checkPath2 = winUrl.indexOf("www.register.hsbc.com");	// hard coded path 2

		if(checkPath1 > -1 || checkPath2 > -1) // special handling for the URLs
		{
			var appName = navigator.appName.toLowerCase();
			var appVersion = parseFloat(navigator.appVersion);

			if(appName.indexOf("netscape") > -1 && !isNaN(appVersion) && appVersion >= 5 ) // netscape 6.0+
			{
				var appProduct = navigator.product.toLowerCase();
				if(appProduct.indexOf("gecko") > -1) // Gecko is being used
				{
					if(navigator.vendorSub != "6.2") // skip Netscape 6.2
					{
						if(!isNaN(parseFloat(navigator.vendorSub)) && parseFloat(navigator.vendorSub) >= 6.2) // Should be Netscape 6.21+
						{
							enhancePopup = false;
						}				
					}
				}
				else // Gecko is not being used
				{
					var ua = navigator.userAgent.toLowerCase();
					var ns6_index = ua.lastIndexOf("netscape6");
					var versionNum = 0;
				
					if(ns6_index > -1)  // Netscape 6
					{
						if(ua.substring(ns6_index+10, ua.length) != "6.2")
						{
							versionNum = parseFloat(ua.substring(ns6_index+10, ua.length));
						}
					}	
					else
					{
						var ns_index = ua.lastIndexOf("netscape");
						if(ns_index > -1)  // Netscape 7 or +
						{
							versionNum = parseFloat(ua.substring(ns_index+9, ua.length));
						}
					}
					if(!isNaN(versionNum) && versionNum >= 6.2)
					{
						enhancePopup = false;
					}
				}		
			}
		}
		if(enhancePopup) // usual case
		{
			newWindow = window.open(winUrl,winName,"scrollbars,HEIGHT=470,WIDTH=525");
			newWindow.focus();
		}
		else
		{
			self.location.href=winUrl;
		}
	break

    case "win_b_no_scroll":
        newWindow = window.open(winUrl,winName,"HEIGHT=470,WIDTH=525");
        newWindow.focus();
        break

    default:
        newWindow = window.open(winUrl,winName,properties);
        newWindow.focus();
    }
}  

