
var EngineGlobals = EngineGlobals || {};
EngineGlobals.site = 'IEEN2_ENGINE';
EngineGlobals.siteSetup = {"DistanceUnit":"km","EcatLocale":"en-ie","configuratorPrefixUrl":"BuildandPrice","SecondLevelDomain":"ford.ie","EcatMarketCode":"IE","OmnitureLanguage":"eng","SecureDomain":"secure.ford.ie","OmnitureScript":"1204986890525","MarketCode":"IRL","cvPrefixUrl":"CommercialVehicles","carsPrefixUrl":"Cars","cvConfiguratorPrefixUrl":"CV-BuildandPrice","HttpDomain":"www.ford.ie","carsModelsPrefixUrl":"Model-Range","cvRangePrefixUrl":"Model","Locale":"en_IE","CookieText":"1205010531533","HttpDomainAliases":"wwwprod-ie.engine.ford.com","OmnitureCountry":"ford-ie"};
EngineGlobals.isMobile = false;
// 3 letter ISO code
EngineGlobals.isoCountry = 'IRL';
EngineGlobals.i18n = {
currencySymbol : '\u20AC',
currencyCode : 'EUR',
currencySymbolPosition : 'prefix',
monetaryDecimalSeparator : '.',
thousandSeparator : ',',
currencyCodeToSymbolMap : {"USD":"$","PLN":"z\u0142","HUF":" Ft-t\u00f3l","BGN":"\u043b\u0432","EUR":"\u20ac","RSD":"\u0414\u0438\u043d.","SEK":"kr","ALL":"Lek","HRK":"kn","LTL":"Lt","BYR":"p.","BAM":"KM","EEK":"kr","RUB":" \u0440\u0443\u0431.","UAH":"\u20b4","CHF":"CHF ","ISK":"kr","NOK":"kr","GBP":"\u00a3","TRL":"\u20a4","MKD":"\u0434\u0435\u043d","RON":"lei","CZK":" K\u010d","LVL":"Ls","JPY":"\u00a5"},
// Formats currency in current locale's format
formatCurrency: function (val, currencyCode) {
var currencySymbol;
if (typeof currencyCode !== 'undefined') {
currencySymbol = this.currencyCodeToSymbolMap[currencyCode];
// Couldn't find the currency, stick to the code
if (typeof currencySymbol === 'undefined') {
currencySymbol = currencyCode;
}
} else {
// Moved the below statement within else block. 
// B'coz it's placed outside the else block which overrides currency symbol.
currencySymbol = this.currencySymbol;
}	    		    
// Support strings
if (typeof val !== 'number') {
val = parseFloat(val, 10);
}
if (isNaN(val)) {
val = 0;
}
var intPart = Math.floor(val);
var decimalPart = val - intPart;
intPart = ''+intPart;
// inject thousand separator into int part
var result = '';
for (var i = intPart.length - 1, n = i; i >= 0; i--) {
if ((n - i) % 3 === 0 && result !== '') {
result = this.thousandSeparator + result;
}
result = intPart.charAt(i) + result;
}
// add decimal part, if any
if (decimalPart !== 0) {
decimalPart = ('' + decimalPart.toFixed(2)).substring(2);
result = result + this.monetaryDecimalSeparator + decimalPart;
}
// Currency symbol
if (this.currencySymbolPosition === 'prefix') {
result = currencySymbol + result;
} else {
result = result + currencySymbol;            
}
return result;
}
};
// Event hooker
EngineGlobals.onLoad = function(callback) {
if (!!(window.addEventListener)) {
// normal browsers
window.addEventListener("DOMContentLoaded", callback);
} else {
// internet exploder 
window.attachEvent("onload", callback);
}
};
EngineGlobals.readQueryParam = function (name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
expr = regex.exec(url);
if (!expr) return null;
if (!expr[2]) return '';
return decodeURIComponent(expr[2].replace(/\+/g, " "));
}
// Adds javascript to body (jquery does more than it should to do it)
EngineGlobals.injectScript = function(url) {
var tag = document.createElement('script');
tag.type = 'text/javascript';
script.src = url;
document.body.appendChild(tag);
};
// Version
EngineGlobals.browser = {
ieVersion : function () {
var v = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(navigator.userAgent) != null)
v = parseFloat(RegExp.$1);
}
return v;
}
};
EngineGlobals.domain = function () {
var host = window.location.host;
var idx1 = host.lastIndexOf(".");
if (idx1 > -1) {
var idx2 = host.substr(0, idx1).lastIndexOf(".");
if (idx2 > -1) {
if (host.substring(idx2).length < 7) {
idx2 = host.substr(0, idx2).lastIndexOf(".");
if (idx2 < 0) {
idx2 = 0;
}
}
host = host.substring(idx2 +1);
}
}
return host; 	
};
// Cookie related methods 
EngineGlobals.cookie = {
// returns cookie value, if found, or nothing (undefined)
read : function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';'); 
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
}	
};
EngineGlobals.safeO = function(p, ctx, value, create) {
if(value != undefined) {
var a = p.split("."), s = a.pop(), result = EngineGlobals.o(a, true, ctx);
return result && s ? (result[s] = value) : null;
} else {
return EngineGlobals.o(p.split("."), create, ctx);
}
};
EngineGlobals.o = function(a, cr, ctx) {
var result = ctx || window;
for(var i = 0, s; result && (s = a[i]); i++) {
result = (s in result ? result[s] : (cr ? result[s] = {} : null));
} 
return result;
};
EngineGlobals.debug = function (f) {
document.cookie = "remdebug=" + f + ";path=/;maxage=36000000";
document.cookie = "omnidebug=" + f + ";path=/;maxage=36000000";
};
EngineGlobals.remdebug = function () {
var remdebug = this.cookie.read("remdebug");
if (typeof remdebug != null && remdebug == "true") {
return true;
} else return false;
};
EngineGlobals.Mediator = function(){};
EngineGlobals.Mediator.prototype = {
topics : {},
notify : function(topic, payload) {
console.log(topic);
if (this.topics[topic]==null) {
return;
}
var i = this.topics[topic].length;
while (i--) {
this.topics[topic][i].callback.call(this.topics[topic][i].context,payload);
}
},
subscribe : function(topic,callback,ctx) {
if(typeof ctx === 'undefined' || ctx === null) {
throw new Error('Subscribers must pass an execution context for callbacks');
}
subObj = {callback : callback, context : ctx};
topic = topic.split(' ');
var len = topic.length;
while(len--){
var t = topic[len];
if (this.topics[t]) {
this.topics[t].push(subObj);
} else {
this.topics[t] = [subObj];
}
}
}
}; 
EP2 = EP2 || {};
EP2.Mediator = EngineGlobals.Mediator;
EP2.mediator = new EP2.Mediator();
if (EngineGlobals.readQueryParam('fullsite') == 'true') {
// Mobile Redirect - set cookie.
document.cookie = "ford_mobile_sniffer_forcefullsite=true;path=/";
}
var GuxGlobals = GuxGlobals || {};
GuxGlobals.personalisationState = true;
GuxGlobals.personalisationUrl = 'http:\/\/eu.fps.ford.com';
GuxGlobals.personalisationTimeout = 6; 
// Global site terms, accessible from Javascript, used in automatic dialogs
EngineGlobals.txt = {
close: 'close',
closeWindow: 'closeWindow',
cancel: 'cancel',
help:  'help',
ok: 'ok',
enableAskFord : 'EnableAskFord',
labelAskFord : 'AskFordLabel',
labelAnyQuestions : 'AnyQuestionsLabel',
descriptionAskFord : 'AskFordDescription',
destinationLinkAskFord : 'https:\/\/ie.ask-ford.com'
};
// EP2 compatibility
var EP2 = EP2 || {};
EP2.Globals = EP2.Globals || {};
EP2.Globals.siteName = EngineGlobals.site;
EP2.Globals.gforceMode='LIVE'; 
