<!--
/***************************************************************************
* Program Name       : Javascript program
* Copyright Notice   : COPYRIGHT (C) 2001 BY HSBC
* Creation Date      : 13/11/2001
* Programmer         : Ion Global
* Abstract           : This file contains common functions required
*                      for all web pages
* Amendment History:
* Date       By            Description
* ---------  ------------- ------------------------------------------------
*                          PPCR No:
* 27Feb2003  CT            Disable popup in fixedWindow for NS6.21+
* 27Nov2003  Weng Santos   Added sendToFriend() function 
* 30Dec2003  DMI	   Added PIBLogonWindow() function
***************************************************************************/

// Provide some an interface to predefined functions for TeamSite user to user Javascript
function HSBCPredefinedFunction(functionString)
{
	var functionPara = functionString.split(";");

	if(functionPara[0] == "addToFavourites")
	{
		addToFavourites(functionPara[1]);
	}else if(functionPara[0] == "sendToFriend"){
		sendToFriend(functionPara[1]);
	}else if(functionPara[0] == "PIBLogonWindow"){
		PIBLogonWindow(functionPara[1]);

	}else
	{
		alert("The function : '" + functionPara[0] + "' is not valid");
	}
}

// pull in the corresponding style sheet - requires hsbc.js
// pcfile - style sheet for PC
// macfile - style sheet for MAC
function addCss(pcfile, macfile){
	if (!mac) {
		document.write('<link rel=\"stylesheet\" href=\"'+pcfile+'\" type=\"text/css\">');
	} else {
		document.write('<link rel=\"stylesheet\" href=\"'+macfile+'\" type=\"text/css\">');
	}
}


// add the current page to favourites
// name - Name to be displayed in the favourites
function addToFavourites(name){
  if ((navigator.appVersion.indexOf('MSIE') > 0) && (parseInt(navigator.appVersion) >= 4)) {
     window.external.AddFavorite(parent.location.href, name);
  } else if (navigator.appName == "Netscape") {
     alert ("To bookmark this page press - 'CTRL+D' for PC and 'Command+D' for MAC");
  }
}

// spawn a new browser (350x700 with all control bars) - requires hsbc.js
// url - URL
function newBrowser(url) {
	nb=window.open(url, "nb", "location,scrollbars,menubar,toolbar,resizable,HEIGHT=350,WIDTH=700");
    nb.focus();
}

// spawn a fixed windows (440x680 with no control bars) - requires hsbc.js
// url - URL
function fixedWindow(url) {
	
	var enhancePopup = true;
	
	var checkPath1 = url.indexOf("www.login.hsbc.com");		// hard coded path 1
	var checkPath2 = url.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
	{
		fw=window.open(url, "fw", "scrollbars,HEIGHT=440,WIDTH=680");
		fw.focus();
	}
	else
	{
		self.location.href=url;
	}
}


function sendToFriend(url) {
	openerLocation = window.location;
	neww = window.open(url+"&fromURL="+openerLocation,'sendtof',"resizable=yes,scrollbars,status,height=440,width=550");
	neww.focus();
}

function PIBLogonWindow(url) {
	var plw = window.open(url,"plw","width="+screen.width+",height="+screen.height*0.88+",location=no,directories=no,menubar=no,toolbar=no,scrollbars=yes,status=yes,resizable=yes,left='0',top='0'");
	plw.focus();
}

//-->
