<!-- Vignette V6 Thu Jan 19 23:09:11 2012 -->


var currentURL = window.location.href;
var isEnglish = 0; // Francais (par défault)

// Assignation des Libellés
var title = new Array();
title[0] = "Bienvenue sur le site de la Banque Nationale";
title[1] = "Welcome to the National Bank website";

var logoValue = new Array();
logoValue[0] = '<img src="/images/mobile/bnc/common/img/fr/logo.png" />';
logoValue[1] = '<img src="/images/mobile/bnc/common/img/en/logo.png" />';

var goWhere = new Array();
goWhere[0] = "Où désirez-vous aller?";
goWhere[1] = "Where would you like to go?";

var mobileBVILink = new Array();
mobileBVILink[0] = "Solutions bancaires mobiles";
mobileBVILink[1] = "Mobile Banking Solutions";

var mobileGuideLink = new Array();
mobileGuideLink[0] = "Mon Guide Mobile";
mobileGuideLink[1] = "My Mobile Guide";

var webInfoLink = new Array();
webInfoLink[0] = "Site web complet";
webInfoLink[1] = "Full website";

var copyright = new Array();
copyright[0] = "&copy; BANQUE NATIONALE DU CANADA<br>Tous droits réservés 2011 - <a href=\"https://www.bnc.ca\">bnc.ca</a>";
copyright[1] = "&copy; NATIONAL BANK OF CANADA<br>All rights reserved 2011 - <a href=\"https://www.nbc.ca\">nbc.ca</a>";

var changeLangLink = new Array();
changeLangLink[0] = "ENGLISH";
changeLangLink[1] = "FRANÇAIS";

// Assignation des URL
var smartphoneTimer = 1000 * 60 * 15; // 1000milisec/sec X 60sec/min X 15fois = 15min de timer
var smartphoneMenuURL = "https://bvi.bnc.ca/index/index_redirect.html";


var mobileGuideURL = new Array();
mobileGuideURL[0] = "https://www.bnc.ca/mobileaidebnc";
mobileGuideURL[1] = "https://www.nbc.ca/mobilehelpbnc";

var webInfoURL = new Array();
webInfoURL[0] = "http://www.bnc.ca/bnc/cda/index/0,4229,divId-2_langId-2_navCode-1000,00.html";
webInfoURL[1] = "http://www.nbc.ca/bnc/cda/index/0,4229,divId-2_langId-1_navCode-1000,00.html";
var webInfoURLEnglishPattern1 = "www.nbc.ca";
var webInfoURLEnglishPattern2 = "langId-1";
var webInfoURLFrenchPattern1 = "langId-2";
var webInfoLinkPattern="navCode";
var webInfoURLPattern = "www.bnc.ca";

var bviMobileURL = new Array();
bviMobileURL[0] = "https://bvi.bnc.ca/index/mobilebnc/indexfr.html";
bviMobileURL[1] = "https://bvi.bnc.ca/index/mobilebnc/indexen.html";
var bviMobileURLPattern1 = "/mobilebnc";
var bviMobileURLPattern2 = "m.bnc.ca";
var bviMobileURLEnglishPattern1 = "m.nbc.ca";
var bviMobileURLEnglishPattern2 = "indexen";
var bviMobileURLEnglishPattern3 = ".nbc.";
//var isBviMobileURL = false;

var bviTraditionalURL = new Array();
bviTraditionalURL[0] = "https://bvi.bnc.ca/index/bnc/indexfr.html";
bviTraditionalURL[1] = "https://bvi.bnc.ca/index/bnc/indexen.html";
var bviTraditionalURLPattern = "bvi.";
var bviTraditionalURLEnglishPattern1 = "indexen";
var bviTraditionalURLEnglishPattern2 = ".nbc.";
//var isBviTraditionalURL = false;

// Analyzing what type of URL we are receiving...
if (currentURL.indexOf(webInfoURLEnglishPattern1) != -1 || currentURL.indexOf(webInfoURLEnglishPattern2) != -1) {
	//isWebInfoURL = true;
	isEnglish = 1;
} else if (currentURL.indexOf(webInfoURLFrenchPattern1) != -1 || currentURL.indexOf(webInfoURLPattern) != -1) {
	//isWebInfoURL = true;
} else if (currentURL.indexOf(bviMobileURLEnglishPattern1) != -1) {
	//isBviMobileURL = true;
	isEnglish = 1;
} else if (currentURL.indexOf(bviMobileURLPattern1) != -1 || currentURL.indexOf(bviMobileURLPattern2) != -1) {
	//isBviMobileURL = true;
	if (currentURL.indexOf(bviMobileURLEnglishPattern2) != -1 || currentURL.indexOf(bviMobileURLEnglishPattern3) != -1) {
		isEnglish = 1;
	}
} else if (currentURL.indexOf(bviTraditionalURLPattern) != -1) {
	//isBviTraditionalURL = true;
	if (currentURL.indexOf(bviTraditionalURLEnglishPattern1) != -1 || currentURL.indexOf(bviTraditionalURLEnglishPattern2) != -1) {
		isEnglish = 1;
	}
}
 
 
var isSmartphone = DetectSmartphone();
var isSmartphoneCompatible = isSmartphoneCompatible();
 
 
if(currentURL.indexOf(bviMobileURLEnglishPattern1) != -1 || currentURL.indexOf(bviMobileURLPattern2) != -1){
	if(isSmartphone){
		window.location.replace(bviMobileURL[isEnglish]);
	}
}


function isSmartphoneCompatible() {
	if (isSmartphone) {
		if (DetectIphoneOrIpod()) {
			var version = getDeviceMainVersion(uagent, 'iphone os ', '_');
			var supportedVersion = 4;
			if (version >= supportedVersion) {
				return true;
			} else {
				return false;
			}
		} else if (DetectAndroidPhone()) {
			var version = getDeviceMainVersion(uagent, 'android ', '.');
			var supportedVersion = 2; // Note : 2.0 n'ayant jamais été distribué au public, on débute à 2.1...
			if (version >= supportedVersion) {
				return true;
			} else {
				return false;
			}
		} else if (DetectBlackBerry()) {
			
			var version = getDeviceMainVersion(uagent, 'version/', '.');
			if (version == -1 || version == 0) {
				// Les version antérieure des BlackBerry n'avait pas un User Agent standard...
				version = getDeviceMainVersion(uagent, '/', '.');
				if (version == -1 || version == 0) {
					version = 999; // Ayant détecté un device valide, mais ne pouvant pas déterminer sa version, on laisse passer par défaut (device du futur???)...
				}
			}
			var supportedVersion = 6;
			if (version >= supportedVersion) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function getDeviceMainVersion(userAgent, deviceMarker, versionMarker) {
	var version = -1; // Version invalide pour indiqué qu'elle n'a pas été trouvée.
	var deviceBegin = uagent.indexOf(deviceMarker);
	if (deviceBegin == -1) {
		return version; // On ne trouve pas le marqueur de device...
	}
	var deviceEnd = deviceBegin + deviceMarker.length;
	var versionEnd = uagent.indexOf(versionMarker, deviceEnd);
	if (versionEnd == -1) {
		return version; // On ne trouve pas le marqueur de version...
	}
	version = uagent.substring(deviceEnd, versionEnd);
	return version;
}

function displaySmartphoneMenu(forwardingURL) {
	if (isSmartphone) {
		updateTimestampFromParentWindow();
		if (currentURL.indexOf(webInfoLinkPattern) == -1 && DetectBlackBerry()){
			return;
		}
		
		var smartphoneTimestamp = sessvars.username;
		var currentTimestamp = +new Date();
		if (smartphoneTimestamp == null) {
			sessvars.$.prefs.crossDomain = true;
			//alert('Initializing...');
			updateSmartphoneTimestamp(currentTimestamp, forwardingURL)
		} else {
			if (currentTimestamp > smartphoneTimestamp) {
				//alert('Resetting...');
				updateSmartphoneTimestamp(currentTimestamp, forwardingURL)
			} else {
				//alert('Keeping...');
			}
		}
	}
}

function updateTimestampFromParentWindow(){
	if(window.opener!= null && window.opener.sessvars.username!="undefined" && typeof(sessvars.username)=="undefined") { 
		sessvars.username=window.opener.sessvars.username;		
		return;
	}

}

function displayFullSite(forwardingURL) {
	var currentTimestamp = +new Date();
	var newTimerTimestamp = currentTimestamp + smartphoneTimer;
	sessvars.username = newTimerTimestamp;
	sessvars.$.flush();
	myWindow =window.open (forwardingURL);
}

function updateSmartphoneTimestamp(currentTimestamp, forwardingURL) {
	var newTimerTimestamp = currentTimestamp + smartphoneTimer;
	sessvars.username = newTimerTimestamp;
	sessvars.$.flush();
	window.location.replace(forwardingURL);
	
}




