function userHasFlash() {
	// Major version of Flash required
	var requiredMajorVersion = 6;
	// 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 closeTour() {
	top.close();
}

function launchTour(whichLang, whichTourType, whichTour ,whichSection, whichFeature, whichFormat, whichPublic) {
//opens the tour popup window
/*parameters are:
whichLang
	-language in which to display the tour
	-examples: "en", "fr"
whichTourType
	-which tour to load
	-examples: "personal", "business"
whichTour
	-a reference to the proper tour node in the main XML file.
	-examples: "mkTour", "featTour"
whichSection
	- which section to to look in must match id in main XML file.
	-examples: "secure", "easy"
whichFeature
	-which feature to load, must match feature id attribute in the main xml file.
	examples: "viewcheque" , "applyforproducts"
*/
	var rootPath = "/tour/";
	
	var launchFlash = userHasFlash() == true;	
	if (whichFormat == "html") {
		var rootPath = "/tour/";
		launchFlash = false;
	}
	if(whichFormat == "flashSwitch"){
		var rootPath = "/tour/";
	}

	var tourURL, winHeight, winWidth, winFeatures;
	if (launchFlash == true) {
		tourURL = rootPath + 'published/flash/easy_web.html?ln=' + whichLang + '&tourType=' + whichTourType;
		//at minimum for a deep link we need the whichTour and whichSection
		if (whichTour != undefined && whichTour != "" && whichSection != undefined && whichSection != "") {
			//there is a featureId go to feature page
			if(whichFeature != undefined && whichFeature != ""){
				tourURL = tourURL + "&tourId=" + whichTour + "&sectionId=" + whichSection + "&featureId=" + whichFeature;
			//there is no featureId so go to category page
			}else{
				tourURL = tourURL + "&tourId=" + whichTour + "&sectionId=" + whichSection;
		
			}	
		}
		if(whichPublic != undefined && whichPublic != null && whichPublic != ""){
			tourURL = tourURL + "&public=" + whichPublic;
		}

		winHeight = 527;
		winWidth = 780;
		winFeatures = 'scrollbars=no,menubar=no,height='+winHeight+',width='+winWidth+',resizable=yes,toolbar=no,location=no,status=no';
	} else {
		tourURL = rootPath + 'published/' + whichLang + '/';

		var htmlFileName = whichTourType + "_";
		
		if(whichTour != undefined && whichTour != "" && whichSection != undefined && whichSection != ""){
			if(whichFeature != undefined && whichFeature != ""){
				htmlFileName += "whatwhy_" + whichFeature + ".html";
			}else{
				htmlFileName += checkForUniquePage(whichSection) + ".html";
			}
		}else{
			htmlFileName += "welcome.html"
		}
		
		tourURL += htmlFileName;

		winHeight = 555;
		winWidth = 798;
		winFeatures = 'scrollbars=yes,menubar=yes,height='+winHeight+',width='+winWidth+',resizable=yes,toolbar=yes,location=yes,status=yes';
	}

	var p = window.open(tourURL, '', winFeatures);
	p.focus();
}

//called from flash when user clicks the button in the flash tour to switch between the Personal and Small Business Tour
function switchFlashTour(whichLang, whichTourType) {
	launchTour(whichLang, whichTourType, null, null, null, "flashSwitch");
	window.close();
}

function switchToHTMLTour() {
	launchTour(ln, tourType, tourId, sectionId, featureId ,"html");
	window.close();
}

//used to generate the HTMLfilename
function checkForUniquePage(sectionId) {
	var section = "";
	switch(sectionId) {
		case "welcomePage":
			section = "welcome";
			break;
		case "exitPage":
			section = "exit";
			break;
		case "bridgePage":
			section = "bridge";
			break;
		default:
			section = sectionId;
			break;
	}
	
	return section;
}

//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');
}

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;
}

function toggleDesc(whichId){
	if (document.getElementById(whichId).className == "featureDescOn"){
		document.getElementById(whichId).className = "featureDescOff";
	}else{
		document.getElementById(whichId).className = "featureDescOn";
	}
}

//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;
}