﻿
var JCB = window.JCB || {}; JCB.Common = (function () {
    function checkForFrame() {
        if (window.top != window.self)
            window.top.location = window.self.location;
    }
    function clearSelectedState(target) { $("#contentNavigation a").each(function () { $(this).removeClass("active"); }); }
    return { constants: { contentPath: "/content", currentLocation: "", defaultLocation: "GB" }, initScreen: function () { checkForFrame(); }, insertFlashContent: function (path, container, id, isFirstPlay) { var flashvars = {}; flashvars.isFirstPlay = isFirstPlay; flashvars.localise = JCB.Common.constants.currentLocation; var params = {}; params.wmode = "opaque"; params.allowscriptaccess = "always"; var attributes = {}; attributes.id = id; swfobject.embedSWF(path, container, "100%", "100%", "9.0.0", false, flashvars, params, attributes); }, initNav: function () { $("#locationsClose").click(function () { $("#locationsContainer,  #locationsContainerFlash").animate({ height: 0 }, { duration: 750, easing: 'easeOutCubic' }).hide(0); $("#headerFlash, #navFlash, #logoBarFlash").animate({ top: 0 }, { duration: 750, easing: 'easeOutCubic' }); return false; }); $("#currentLocation").click(function () { $("#locationsContainer, #locationsContainerFlash").animate({ height: 160 }, { duration: 750, easing: 'easeOutCubic' }); $("#headerFlash, #navFlash, #logoBarFlash").animate({ top: 160 }, { duration: 750, easing: 'easeOutCubic' }); return false; }); }, setLocation: function (location, init) {
        JCB.Common.constants.currentLocation = location || JCB.Common.constants.defaultLocation; $("#locations a").each(function () {
            var elem = $(this); if (init) { elem.click(function () { JCB.Common.setLocation(elem.attr("rel"), false); }); }
            if (elem.attr("rel") == JCB.Common.constants.currentLocation) { elem.addClass("active"); $("#currentLocation").text(elem.attr("title")); }
            else
                elem.removeClass("active");
        });
    }, getCookie: function (name) {
        var start = document.cookie.indexOf(name + "="); var len = start + name.length + 1; if ((!start) && (name != document.cookie.substring(0, name.length))) { return null; }
        if (start == -1) return null; var end = document.cookie.indexOf(';', len); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end));
    }, setCookie: function (name, value, expires, path, domain, secure) {
        var today = new Date(); today.setTime(today.getTime()); if (expires) { expires = expires * 1000 * 60 * 60 * 24; }
        var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + '=' + escape(value) +
((expires) ? ';expires=' + expires_date.toGMTString() : '') +
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '') +
((secure) ? ';secure' : '');
    }, deleteCookie: function (name, path, domain) {
        if (getCookie(name)) document.cookie = name + '=' +
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '') + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    }, checkEmail: function (email) { var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (!filter.test(email)) return false; return true; } 
    }
})(); JCB.Flash = (function () {
    return { init: function (location, path) { JCB.Common.initScreen(); JCB.Common.setLocation(location, true); var hasPlayed = JCB.Common.getCookie("isFirstPlay") || "true"; JCB.Common.insertFlashContent(path, "flashPlaceholder", "flash", hasPlayed); JCB.Common.initNav(); if (location == "RU") return; Cufon.replace("H1, H2, H3"); Cufon.now(); }, transfer: function () {
        if (location.href.indexOf("preview-welcome.aspx") > 0)
            location.href = "/" + JCB.Common.constants.currentLocation.toLowerCase() + "/explore";
    }, introVideoFinished: function () { JCB.Common.setCookie("isFirstPlay", "false"); } 
    }
})(); function introVideoFinished() { JCB.Flash.introVideoFinished(); }
JCB.Content = (function () { return { init: function (location) { JCB.Common.initScreen(); JCB.Common.setLocation(location, true); JCB.Common.initNav(); if (location == "RU") return; Cufon.replace("H1, H2, H3"); Cufon.now(); } } })(); JCB.Contact = (function () {
    var requiredErrorMsg = ""; var generalErrorMsg = ""; var emailErrorMsg = ""; var agreeTermsElem = ""; var errorMsg = ""; function addBehaviour(callbackId, brochureRequestId) {
        $("#" + callbackId).change(function () {
            if (this.checked)
                $("#callbackMethod").fadeIn(); else
                $("#callbackMethod").fadeOut();
        }); $("#" + brochureRequestId).change(function () {
            if (this.checked)
                $("#brochureMethod").fadeIn(); else
                $("#brochureMethod").fadeOut();
        });
    }
    return { initForm: function (requiredMsg, generalMsg, emailMsg, callbackId, brochureRequestId, agreeTermsId) { requiredErrorMsg = requiredMsg; generalErrorMsg = generalMsg; emailErrorMsg = emailMsg; agreeTermsElem = agreeTermsId; addBehaviour(callbackId, brochureRequestId); }, validateForm: function (source, args) {
        errorMsg = ""; if (args.Value.length > 0) { args.IsValid = true; $("#" + source.controltovalidate).removeClass("highlightError"); } else { args.IsValid = false; errorMsg = requiredErrorMsg; $("#" + source.controltovalidate).addClass("highlightError"); }
        if (source.controltovalidate.toLowerCase().indexOf("email") > -1) {
            if (JCB.Common.checkEmail(args.Value)) { args.IsValid = true; $("#" + source.controltovalidate).removeClass("highlightError"); }
            else { args.IsValid = false; if (errorMsg.length == 0) errorMsg = emailErrorMsg; $("#" + source.controltovalidate).addClass("highlightError"); } 
        } 
    }, registerEvent: function (category, action, label) { _gaq.push(['_trackEvent', category, action, label]); }, validatePage: function () { $("#rightSection .errorMessage").html(""); if (!Page_ClientValidate()) { $("#rightSection .errorMessage").html(errorMsg); } } 
    }
})();
