function userHasFlash() {

	// Major version of Flash required

	var requiredMajorVersion = 7;

	// Minor version of Flash required

	var requiredMinorVersion = 0;

	// Minor version of Flash required

	var requiredRevision = 0;

	

	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	return hasRequestedVersion;;

}



var ieDiffWidth;

var ieDiffHeight;

function initSize() {

	var w, h, offW, offH, diffW, diffH;

	var fixedW = 800;

	var fixedH = 600;

	

	if (browser == "Internet Explorer") {

		offW = document.documentElement.offsetWidth;

		offH = document.documentElement.offsetHeight;

		window.resizeTo(fixedW, fixedH);

		diffW = document.documentElement.offsetWidth  - offW;

		diffH = document.documentElement.offsetHeight - offH;

		w = fixedW - diffW;

		h = fixedH - diffH;

		ieDiffWidth  = w - offW;

		ieDiffHeight = h - offH;

		window.resizeTo(w, h);

	}

}



function outerWd() {

	if (browser == "Internet Explorer") {

		return document.documentElement.offsetWidth  + ieDiffWidth;

	} else {

		return window.outerWidth;

	}

}



function outerHt() {

	if (browser == "Internet Explorer") {

		return document.documentElement.offsetHeight  + ieDiffHeight;

	} else {

		return window.outerHeight;

	}

}



function launchSim(whichID, whichLang, whichSegment) {

	initSize();

	

	if (browser == "Internet Explorer") {

		window.returnWidth = document.documentElement.offsetWidth  + ieDiffWidth;

		window.returnHeight = document.documentElement.offsetHeight  + ieDiffHeight;

	} else {

		window.returnWidth = window.outerWidth;

		window.returnHeight = window.outerHeight;

	}

	

	//the HTML tour pages will not have the ln/segment set as variable, so we pass them in on the function call

	if (window.ln == undefined) {

		window.ln = whichLang;

		window.segment = whichSegment;

	}

	

	var curSrc = "../../simulation/sim_holder.html?ln=" + ln + "&segment=" + segment + '&sid=' + whichID;

	

	if (window.simFrame == null) {

		var newFrame = document.createElement('iframe');

		newFrame.id = "simFrame";

		newFrame.src = curSrc;

		newFrame.frameBorder = "0";

		newFrame.style.position = "absolute";

		newFrame.style.top = "0px";

		newFrame.style.left = "0px";

		newFrame.style.zIndex = "1000";

		newFrame.style.border = "0px";

		newFrame.style.width = "100%";

		if (browser == "Internet Explorer") {

			var h = document.documentElement.offsetHeight;

			newFrame.style.height = h + "px";

		} else {

			newFrame.style.height = "100%";

		}

		document.body.appendChild(newFrame);

		window.simFrame = document.getElementById("simFrame");

		

		if (browser == "Internet Explorer") {

			window.onresize = scaleSimFrame;

		}

		

		window.curScroll = document.documentElement.scrollTop;

		window.scroll(0,0); 

	} else {

		window.simFrame.location.href = curSrc;

	}

	

	if (OS == "Mac") {

		document.getElementById("flashHolder").style.top = "-500px";

	}

	

	if (document.getElementById("wrapper") != undefined && document.getElementById("wrapper").style.display != undefined) {

		document.getElementById("wrapper").style.display = "none";

	}

}



function scaleSimFrame() {

	simFrame.style.height = "25px";



	//scale the internal iframe

	if (frames[0].scaleIFrame != undefined) frames[0].scaleIFrame();

	

	var availHeight = document.documentElement.offsetHeight - 5;

	simFrame.style.height = availHeight + "px";

}



function closeSim() {

	if (window.simFrame != undefined) {

		document.body.removeChild(simFrame);

		window.simFrame = null;

		if (browser == "Internet Explorer") {

			window.onresize = null;

		}

		

		window.scroll(0,curScroll); 

		window.resizeTo(returnWidth, returnHeight);

		

		if (OS == "Mac") {

			document.getElementById("flashHolder").style.top = "0px";

		}

	

		if (document.getElementById("wrapper") != undefined) {

			document.getElementById("wrapper").style.display = "block";

		}

	}

}



function closeTour() {

	top.close();

}



function launchTour(whichLang, whichSegment, whichShortcutID, whichHTMLFile, whichFormat) {

//opens the tour popup window

/*parameters are:

whichLang

	-language in which to display the tour

	-examples: "en", "fr"

whichSegment

	-segment to display

	-examples: "personal", "smallbiz"

whichShortcutID

	-feature or section ID to jump to when tour loads (must match the "id" attribute of the node in the online_banking_tour XML file)

	-examples: "myAccounts", "accountBalances"

whichHTMLFile

	-feature or section filename to jump to if the user doesn't have flash (must match the "filename" attribute of the node in the online_banking_tour XML file)

	-examples: "personal_myaccounts.html", "feature_account_balances.html"

*/

	var rootPath = "welcome/";

	if(whichLang == "fr") {

		rootPath = "bienvenue/";

	}

	

	var launchFlash = userHasFlash() == true;	

	if (whichFormat == "html") {

		launchFlash = false;

	}

	

	var tourURL, winHeight, winWidth, winFeatures;

	if (launchFlash == true) {

		tourURL = 'demobd/' + whichSegment + '/accueil/main.html';

		if (whichShortcutID != undefined && whichShortcutID != "") {

			tourURL = tourURL + "&sid=" + whichShortcutID;

		}

		if (whichHTMLFile != undefined && whichHTMLFile != "") {

			tourURL = tourURL + "&sfile=" + whichHTMLFile;

		}

		

		winHeight = 700;

		winWidth = 850;

		winFeatures = 'scrollbars=yes,menubar=no,height='+winHeight+',width='+winWidth+',resizable=yes,toolbar=no,location=no,status=no';

	} else {

		tourURL = rootPath + 'published/html/' + whichSegment + '_home.html';

		if (whichHTMLFile != undefined && whichHTMLFile != "") {

			tourURL = rootPath + 'published/html/' + whichHTMLFile;

		}

		

		winHeight = 555;

		winWidth = 798;

		winFeatures = 'scrollbars=yes,menubar=yes,height='+winHeight+',width='+winWidth+',resizable=yes,toolbar=yes,location=yes,status=yes';

	}

	

	tourURL = prependSessionID(tourURL);

	

	var p = window.open(tourURL, '', winFeatures);

	p.focus();

}



function switchToHTMLTour() {

	launchTour(ln, segment, sid, sfile, "html");

	window.close();

}



function launchTourFromServiceMap(whichLang, whichSegment, whichShortcutID, whichHTMLFile) {

//this just calls the generic launcher, but this wrapper function is here in case we need to do anything different for these links

	launchTour(whichLang, whichSegment, whichShortcutID, whichHTMLFile);

}



function gotoServiceMap(whichFilename) {

	//this uses "hard-coded" filenames, but the include infrastructure makes this necessary

	var rootPath = "online/";

	if(window.location.href.indexOf("endirect") != -1) {

		rootPath = "endirect/";

	}

	

	var targetFile = "personal-features.html";

	if (whichFilename.indexOf("smallbiz") != -1) {

		targetFile = "business-features.html"

	}

	var fileURL = rootPath + targetFile;

	fileURL = prependSessionID(fileURL);

	window.location.href = fileURL;	

}



function getSessionID() {

//	var curURL = "http://silver.rbcroyalbank.com/RBC:RSWvKY71ATIAAGLwHFQ/welcome/index.html";

	var curURL = window.location.href;

	var u = curURL.split("//");

	var v = u[1].split("/");

	var curSessionID = v[1];

	if (curSessionID.indexOf("RBC:") == -1) {

		curSessionID = "";

	} else {

		curSessionID += "/";

	}

	

	return curSessionID;

}



function prependSessionID(whichURL) {

	var sessionID = getSessionID();

	

	var curURL = window.location.href;

	var urlPieces = curURL.split("//");

	var protocol = urlPieces[0] + "//";

	urlPieces = urlPieces[1].split("/");

	var server = urlPieces.shift() + "/";

	

	var newURL = protocol + server + sessionID + whichURL;

	return newURL;

}



function mergeURLWithSessionID(whichURL) {

	var sessionID = getSessionID();

	var url = whichURL;

	var urlPieces = url.split("//");

	var protocol = urlPieces[0] + "//";

	urlPieces = urlPieces[1].split("/");

	var server = urlPieces.shift() + "/";

	var path = "";

	for (var i=0; i<urlPieces.length; i++) {

		path += "/" + urlPieces[i];

	}

	var newURL = protocol + server + sessionID + path;

	return newURL;

}



//new window functions used to open wk flash & to open links from wk flash

/*

function openHTMLTour(url) {

	//opens new window to contain html version of tour, if possible

	//if the new window can't be created, then we load the HTML tour in the current window

	var winWidth = 800;

	var winHeight = 595;

	var newWin = window.open(url,'','scrollbars=yes,menubar=yes,height=' + winHeight + ',width=' + winWidth + ',resizable=yes,toolbar=yes,location=yes,status=yes');

	

	if (newWin == undefined) {

		this.resizeTo(winWidth, winHeight);

		this.location.href = url;

	} else {

		window.close();

	}

}*/



//opens links from Flash file in new window (default size defined in function)

function openURL(url) {

	var winWidth = 800;

	var winHeight = 500;

	var newWin = window.open(url,'newWin','scrollbars=yes,menubar=yes,height=' + winHeight + ',width=' + winWidth + ',resizable=yes,toolbar=yes,location=yes,status=yes');

	newWin.focus();

}



function gotoURL(url) {

	try {

		window.opener.location.href = url;

		window.opener.focus();

	}

	catch(e) {

		openURL(url);

	}

}



//opens links in new window, dimensions must be set when function is called

function openWin(url,winWidth,winHeight) {

	var newWin = window.open(url,'newWin','scrollbars=no,menubar=no,height=' + winHeight + ',width=' + winWidth + ',resizable=no,toolbar=no,location=no,status=no');

}



function openTour(whichLang, whichSegment) {

//used to open applicable tour from links within flash/HTML tours

	var tourURL = 'olb_tour.html?ln=' + whichLang + '&segment=' + whichSegment;

	

	if (document.getElementById("wk_flash") == undefined) {

		tourURL = '../html/' + whichSegment + '_home.html';

	}

	

	window.location.href = tourURL;

}



//browser detect

var detect = navigator.userAgent.toLowerCase();

var OS,browser,version,total,thestring;



if (checkIt('konqueror')) {

	browser = "Konqueror";

	OS = "Linux";

}

else if (checkIt('safari')) browser = "Safari"

else if (checkIt('omniweb')) browser = "OmniWeb"

else if (checkIt('opera')) browser = "Opera"

else if (checkIt('webtv')) browser = "WebTV";

else if (checkIt('icab')) browser = "iCab"

else if (checkIt('msie')) browser = "Internet Explorer"

else if (!checkIt('compatible')) {

	browser = "Netscape Navigator"

	version = detect.charAt(8);

}

else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS) {

	if (checkIt('linux')) OS = "Linux";

	else if (checkIt('x11')) OS = "Unix";

	else if (checkIt('mac')) OS = "Mac"

	else if (checkIt('win')) OS = "Windows"

	else OS = "an unknown operating system";

}



function checkIt(string) {

	place = detect.indexOf(string) + 1;

	thestring = string;

	return place;

}



//Nav menu functions

document.menuTimer = 0;	

function menuShow(){

	clearTimeout(document.menuTimer);

	document.getElementById("subnav").className="subNavOpen";

}

function menuOut(){

	document.menuTimer = setTimeout('menuHide()', 100);

}

function menuHide(){

	document.getElementById("subnav").className="subNavClosed";

}



function showCurrentSection() {

	if (document.getElementById("navBar") == undefined) {

		var cTable = document.getElementById("contentTable");

		var bgHolder = document.getElementById("bgImgHolder");

		cTable.style.background = bgHolder.style.background;

		bgHolder.style.background = "";

	} else {

		var numSections = 5; //will be generated dynamically

		//turn all items to off state

		for (i=0; i<numSections; i++) {

			document.getElementById("currentNav"+i).className = "currentNavOff"; //current nav indicators

			document.getElementById("nav"+i).className = "nav"; //nav table cells

			document.getElementById("section"+i).className = "menu"; //nav links

		}

		//turn current rollover section to on state

		document.getElementById("currentNav"+currSection).className = "currentNavOn";

		document.getElementById("nav"+currSection).className = "nav navOn";

		document.getElementById("section"+currSection).className = "menuOn";

	}

}



function toggleDesc(whichId){

	if (document.getElementById(whichId).className == "featureDescOn"){

		document.getElementById(whichId).className = "featureDescOff";

	}else{

		document.getElementById(whichId).className = "featureDescOn";

	}

}



// This hack insures that last word and the arrow image always wrap together

// Method assumes a list of node ids passed as array. Each node has text as

// first child and image as the second child.

function fixChevrons(list)

{

	for(var i = 0; i < list.length; i++)

	{

		var tag = document.getElementById(list[i]);

		

		if(!tag)

			continue;

		

		var label = tag.firstChild;

		var image = tag.childNodes[1];

		var lastWord = label.nodeValue.substr(label.nodeValue.lastIndexOf(' ') + 1);

		var span = document.createElement('span');

		

		span.style.whiteSpace = 'nowrap';

		span.appendChild(document.createTextNode(lastWord));

		span.appendChild(image.cloneNode(true));

		

		label.nodeValue = label.nodeValue.substr(0, label.nodeValue.length - lastWord.length);

		tag.insertBefore(span, image);

		tag.removeChild(image);

	}

}



//get values from querystring (used in wk flash olb_tour.html)

function getURLParam(strParamName){

  var strReturn = "";

  var strHref = window.location.href;

  if ( strHref.indexOf("?") > -1 ){

    var strQueryString = strHref.substr(strHref.indexOf("?")); //.toLowerCase();

    var aQueryString = strQueryString.split("&");

    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){

      if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ){

        var aParam = aQueryString[iParam].split("=");

        strReturn = aParam[1];

        break;

      }

    }

  }

  return strReturn;

}



function preloadImages() {

		var f = document.createElement('img');

		f.id = "preloadImg";

		f.src = "/welcome/images/btn_yellow_fwd_bgd.gif";

		document.body.appendChild(f);

}

/*

if (window.onload != undefined) {

	window._onload = window.onload;

	window.onload = function () {

		preloadImages();

		_onload();

	}

} else {

	window.onload = preloadImages;

}

*/
