function purge(d) {
    var a = d.attributes, i, l, n; if (a) { l = a.length; for (i = 0; i < l; i += 1) { n = a[i].name; if (typeof d[n] === 'function') d[n] = null; } }
    a = d.childNodes; if (a) { l = a.length; for (i = 0; i < l; i += 1) purge(d.childNodes[i]); } 
}
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
var xmlNodeText = function(text, tag) { var m = text.match(new RegExp("<(" + tag + ")(?:\\s?[^>]*)>((?:\\s|\\S)*)<\/\\1>")); if (m && m[2]) return m[2]; else return null; }
function URLEncode(clearString) {
    var output = ''; var x = 0; clearString = clearString.toString(); var regex = /(^[a-zA-Z0-9_.]*)/; while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x)); if (match != null && match.length > 1 && match[1] != '') { output += match[1]; x += match[1].length; } else {
            if (clearString[x] == ' ')
                output += '+'; else { var charCode = clearString.charCodeAt(x); var hexVal = charCode.toString(16); output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase(); }
            x++;
        } 
    }
    return output;
}
function getFileExtension(filename) { f = filename.toLowerCase(); f = f.split("?")[0]; f = f.split("?")[0]; f = f.split("?")[0]; f = f.split("?")[0]; if (f.length == 0) return ""; var dot = f.lastIndexOf("."); if (dot == -1) return ""; var extension = f.substr(dot + 1, f.length); return extension; }
function replaceHtml(el, html) { var oldEl = (typeof el === "string" ? document.getElementById(el) : el); var newEl = oldEl.cloneNode(false); newEl.innerHTML = html; oldEl.parentNode.replaceChild(newEl, oldEl); return newEl; }; function validateAuMobile(str_phone) {
    var re = new RegExp(/^04\d{8}$/); if (!re.exec(str_phone)) { return false; }
    else
        return true;
}
function validateEmail(str_email) {
    var re = new RegExp(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/); if (!re.exec(str_email)) { return false; }
    else
        return true;
}
function validatePassword(str_password) {
    var re = new RegExp(/^[a-zA-Z0-9]{5,10}$/); if (!re.exec(str_password)) { return false; }
    else
        return true;
}
var DJgallery = { holderID: "#imageGallery", autorun: false, height: 310, width: 450, imagePath: "images/gallery/", imageArray: ["photo1.jpg", "photo2.jpg", "photo3.jpg"], imageCount: 0, currentPos: 0, useNumberTwo: true, init: function() { this.currentPos = 0; this.imageCount = this.imageArray.length; var html = "<img src='" + this.imagePath + this.imageArray[0] + "' id='DJGalleryImage1' height='" + this.height + "' width='" + this.width + "'><img src='" + this.imagePath + this.imageArray[0] + "' id='DJGalleryImage2' height='" + this.height + "' width='" + this.width + "'>"; html = html + "<div id='DJGalleryControls'><p>Photo <span id='DJGalleryCurrentPos'>1</span> of " + this.imageCount + "</p> <img src='/global/images/galleryPrev.png' alt='«' id='DJGalleryBackButton' /> <img alt='»' id='DJGalleryNextButton'  src='/global/images/galleryNext.png' /></div>"; jQuery(this.holderID).html(html); jQuery("#DJGalleryImage2").css("display", "block"); jQuery("#DJGalleryImage2").css("opacity", "0"); jQuery("#imageGallery").css("height", this.height + "px"); jQuery("#imageGallery").css("width", this.width + "px"); jQuery("#DJGalleryBackButton").click(function() { DJgallery.prev(); }); jQuery("#DJGalleryNextButton").click(function() { DJgallery.next(); }); jQuery("#DJGalleryImage1").click(function() { DJgallery.next(); }); jQuery("#DJGalleryImage2").click(function() { DJgallery.next(); }); }, go: function(move) {
    this.currentPos += move; if (this.currentPos == this.imageCount) this.currentPos = 0; if (this.currentPos == -1) this.currentPos = this.imageCount - 1; var currentImage = "#DJGalleryImage1"; var newImage = "#DJGalleryImage2"; if (!this.useNumberTwo) { currentImage = "#DJGalleryImage2"; newImage = "#DJGalleryImage1"; }
    jQuery(newImage).css("opacity", "0"); jQuery(currentImage).css("z-index", "400"); jQuery(newImage).css("z-index", "500"); jQuery("#DJGalleryControls").css("z-index", "600"); jQuery(newImage).attr("src", this.imagePath + this.imageArray[this.currentPos]); jQuery("#DJGalleryCurrentPos").html(this.currentPos + 1); this.useNumberTwo = !this.useNumberTwo; jQuery(newImage).animate({ opacity: 1 }, 250, null, function() { jQuery(currentImage).css("opacity", "0"); });
}, next: function() { this.go(1); }, prev: function() { this.go(-1); } 
}
function clickButton(e, buttonid) { var evt = e ? e : window.event; var bt = document.getElementById(buttonid); if (bt) { if (evt.keyCode == 13) { bt.click(); return false; } } }
var search = { delay: 550, qDefault: "Search...", last: this.qDefault, que: '', sForm: null, sInput: null, sResults: null, timeOut: null, init: function() { this.sForm = jQuery('#searchForm'); search.sInput = this.sForm.get()[0].q; search.sResults = jQuery('#liveSearch'); search.addEvents(); }, addEvents: function() { jQuery(search.sInput).click(function() { (this.value == search.qDefault) ? this.value = '' : a = 1; }); jQuery(search.sInput).blur(function() { (this.value == '') ? this.value = search.qDefault : a = 1; }); jQuery(search.sInput).keyup(function() { (this.value.length > 1) ? search.wait() : search.hide(); }); jQuery('#contentArea').click(function() { search.hide(); }); }, query: function(currentQ) {
    if (search.sInput.value.length == 0)
        return; search.show(); search.last = search.sInput.value; postVars = 'q=' + URLEncode(search.sInput.value) + '&ref=' + URLEncode(location.href); if (window.location.href.indexOf('https') >= 0)
        postVars = postVars + '&RequiresSecure=1'; jQuery.post("/search/scripts/ajax_search.aspx", postVars, search.drawResults);
}, show: function() { if (search.sResults.css('display') !== "block") { search.sResults.html("<img width='420' height='13' alt='' src='/global/images/search_top.png'/><div id='lsContent' class='overflow'><ul class='lsSpinner'><li /></ul></div><img width='420' height='13' alt='' src='/global/search/images/search_bottom.png' />"); search.sResults.css('display', 'block'); } }, hide: function() { search.sResults.css('display', 'none'); }, wait: function() {
    if (search.last == search.sInput.value.trim()) return false; search.que = URLEncode(search.sInput.value); var to = search.timeOut; if (to)
        clearTimeout(to); search.timeOut = setTimeout(search.check, search.delay);
}, check: function() { if (search.que == URLEncode(search.sInput.value)) search.query(); else { search.que = URLEncode(search.sInput.value); setTimeout(search.check, search.delay); } }, drawResults: function(o) { search.sResults.html(o); }, fail: function() { alert("failed read"); } 
}
var aTag, aHref, aTitle, mContainer, mWidth, mHeight, mClickOffArea, caroselCollection, objIdStr, ajaxCall, mTitle; var objHeight, objWidth; var mediaPanelController = { init: function() {
    if (window.jQuery) {
        var photos = jQuery("a[rel^='prettyOverlay'],a[rel^='prettyPhoto']"); photos.unbind(); if (photos.prettyPhoto) {
            photos.prettyPhoto
({ animationSpeed: 'normal', padding: 40, opacity: 0.50, showTitle: false, allowresize: true });
        } 
    }
    mPanel = jQuery("#mediaPanel"); mContainer = jQuery("#mContent"); mClickOffArea = jQuery('#contentArea'); mTitle = document.title; var mediaLinks = jQuery('a.media,area.media'); mediaLinks.unbind('click', this.addClick); mediaLinks.bind('click', this.addClick); if (window.location.hash) {
        var returnURL; var foundIndex = -1; var paramBits; var url = window.location.hash.split('#')[0]; var hashUrl = ('' + window.location).split('#')[1]; if (hashUrl != null && hashUrl.length > 0) {
            hashUrl = hashUrl.replace("[", "%5B").replace("]", "%5D"); hashUrl = hashUrl.replace(new RegExp(" ", "g"), "%20").toLowerCase(); mediaLinks.each(function(i) {
                if (media.fixpath(this.href).split('?')[0] == hashUrl.split('?')[0])
                { if (this.title) aTitle = this.title; aTag = jQuery(this); } 
            }); if (hashUrl.lastIndexOf('?') != -1) {
                paramBits = hashUrl.substring(hashUrl.lastIndexOf('?') + 1).split('&'); for (i in paramBits) {
                    var paramAndValue = paramBits[i].split('='); if (paramAndValue[0].toLowerCase() == 'returnurl')
                    { returnURL = 'returnURL=' + paramAndValue[1]; foundIndex = i; break; } 
                }
                if (foundIndex != -1)
                { paramBits.splice(foundIndex, 1); }
                hashUrl = hashUrl.substring(0, hashUrl.lastIndexOf('?') + 1) + paramBits.join('&');
            }
            if (aTag) {
                if (aTag.hasClass('secure')) {
                    var newHref; if (window.location.href.indexOf('https') < 0) {
                        if (window.location.href.indexOf('RequiresSecure') < 0) {
                            if (url.indexOf('?') < 0)
                            { window.location = url.replace('http://', 'https://') + '?RequiresSecure=1' + '#' + hashUrl; }
                            else
                            { window.location = url.replace('http://', 'https://') + '&RequiresSecure=1' + '#' + hashUrl; } 
                        }
                        else
                        { window.location = window.location.href.replace('http://', 'https://'); } 
                    }
                    else
                    { try { media.load(hashUrl, returnURL); } catch (e) { } } 
                }
                else
                { try { media.load(hashUrl, returnURL); } catch (e) { } } 
            }
            if (window.location.hash.split('flashhistory')[1] != null) {
                mediaLinks.each(function() {
                    aTag = jQuery(this); if (aTag.is('.auto'))
                    { media.load(media.fixpath(this.href)); } 
                });
            } 
        } 
    } 
}, addClick: function(e) {
    if (e.preventDefault)
        e.preventDefault(); aTag = jQuery(this); aTitle = aTag.attr('title'); aHref = media.fixpath(aTag.attr('href')); var returnURL; var foundIndex = -1; var paramBits; if (aHref.lastIndexOf('?') != -1) {
        paramBits = aHref.substring(aHref.lastIndexOf('?') + 1).split('&'); for (i in paramBits) {
            var paramAndValue = paramBits[i].split('='); if (paramAndValue[0].toLowerCase() == 'returnurl')
            { returnURL = 'returnURL=' + paramAndValue[1]; foundIndex = i; break; } 
        } 
    }
    var isSecure = aTag.hasClass('secure'); var inHttps = window.location.href.indexOf('https') >= 0; if (isSecure) {
        var newHref; if (!inHttps) {
            var url = window.location.href.split('#')[0]; if (paramBits)
                aHref = aHref.substring(0, aHref.lastIndexOf('?') + 1) + paramBits.join('&'); if (url.lastIndexOf('?') < 0) { url = url.replace('http://', 'https://') + '?RequiresSecure=1#' + aHref; }
            else { url = url.replace('http://', 'https://') + '&RequiresSecure=1#' + aHref; }
            window.location = url; this.href = 'javascript:void(0);';
        }
        else {
            if (foundIndex != -1)
            { paramBits.splice(foundIndex, 1); }
            if (paramBits)
                aHref = aHref.substring(0, aHref.lastIndexOf('?') + 1) + paramBits.join('&'); try { media.load(aHref, returnURL); } catch (e) { }
            if (!((getFileExtension(aHref) == "swf") || (aTag.hasClass('inline')) || (window.location.hash && window.location.hash.length > 0))) { location.href = '#' + aHref; } 
        } 
    }
    else if (aTag.attr('rel') == null || aTag.attr('rel') == '') {
        try { media.load(aHref, returnURL); } catch (e) { }
        if (!((getFileExtension(aHref) == "swf") || aTag.is('.inline') || (window.location.hash && window.location.hash.length > 1))) { location.href = '#' + aHref; } 
    }
    else {
        objIdStr = aTag.attr('rel'); jQuery("#" + objIdStr).html("<div style='position:absolute; top:50%;left:50%;z-index:999; margin:20px;'><img src='/global/images/spinner_darkGray.gif' /></div>" + jQuery("#" + objIdStr).html()); try { media.loadReplace(aHref); } catch (e) { }
        jQuery("a[rel], a[class*=on]").removeClass("on"); aTag.addClass('on');
    }
    return false;
}, load: function(strUrl, strPost) {
    mClickOffArea.unbind('click'); if (!strPost)
    { strPost = "isAjax=1&returnURL=" + location.href; }
    else
    { strPost += "&isAjax=1"; }
    if (aTag.is('.inline')) { mContainer = jQuery(aTag.children().get()[0]); if (mContainer.length == 0) return false; mHeight = mContainer.height(); mWidth = mContainer.width(); objHeight = mHeight; objWidth = mWidth; var newDiv = document.createElement("div"); aTag.replaceWith(newDiv); mContainer = jQuery(newDiv); mContainer.height(mHeight); mContainer.width(mWidth); mContainer.css("overflow", "hidden"); media.spin(); } else { objHeight = ""; objWidth = ""; media.show(); media.spin(); media.fixPosition(); }
    var ext = getFileExtension(strUrl); switch (ext) {
        case "jpg": case "gif": case "png": case "flv": case "swf": strPost += "&ext=" + ext + "&file=" + strUrl + "&h=" + objHeight + "&w=" + objWidth; if (aTitle)
                strPost += "&title=" + aTitle; if (aTag.is('.inline'))
                strPost += "&inline=1"; if (aTag) {
                var galleryTag = aTag.parent('*').parent('.gallery'); if (galleryTag.length > 0)
                { caroselCollection = galleryTag('a.media'); strPost += "&carousel=1"; } 
            }
            strUrl = "/global/templates/mediaTemplate.aspx"; break
        case "aspx": strPost += "&file=" + URLEncode(strUrl); strUrl = "/global/templates/codeTemplate.aspx"; break
        default: if (aTag.is('.inline') && aTag.is('[href^=/defencetv]')) {
                strPost += "&ext=" + ext + "&file=" + strUrl + "&h=" + objHeight + "&w=" + objWidth; if (aTitle)
                    strPost += "&title=" + aTitle; if (aTag.is('.inline'))
                    strPost += "&inline=1"; if (aTag) {
                    var galleryTag = aTag.parent('*').parent('.gallery'); if (galleryTag.length > 0)
                    { caroselCollection = galleryTag('a.media'); strPost += "&carousel=1"; } 
                }
                strUrl = "/global/templates/mediaTemplate.aspx";
            }
            break;
    }
    ajaxCall = jQuery.ajax({ type: "POST", url: strUrl, data: strPost, a: aTag, success: function(o) { var thisRef = this.a; setTimeout(function() { media.draw(o, thisRef) }, 2000); }, failure: media.fail });
}, loadReplace: function(strUrl, elementId) {
    if (elementId) objIdStr = elementId; jQuery.ajax({ type: "GET", url: strUrl, success: function(o) {
        media.drawReplace(o); try { } catch (e)
{ } 
    }, failure: function(msg) { media.failReplace(msg); try { if (aHref) aTag.attr('href', aHref); } catch (e) { } } 
    });
}, show: function() { window.scroll(0, 0); mPanel.css('display', 'block'); document.title = mTitle; }, hide: function(a) {
    mPanel.css('top', '-500'); mPanel.css('display', 'none'); if (window.location.hash) {
        var tempHref = ""; if (a.attr('href').split(window.location.protocol)[1] != null) { tempHref = window.location.protocol + "//" + window.location.host + window.location.port + window.location.href.split("#")[1]; } else { tempHref = window.location.href.split("#")[1]; }
        tempHref = tempHref.replace("[", "%5B").replace("]", "%5D"); tempHref = tempHref.replace(new RegExp(" ", "g"), "%20").toLowerCase(); if (media.fixpath(a.attr('href')) != tempHref.toLowerCase()) { this.href = location.href; } else { top.location.href = location.href.replace(/(.*)#.*/, "$1") + "#"; } 
    }
    jQuery("#mContent").html(""); mPanel = jQuery("#mediaPanel"); mContainer = jQuery("#mContent"); mClickOffArea.unbind('click'); document.title = mTitle;
}, draw: function(o, a) {
    mContainer = mContainer.html(o); try { var scriptTags = jQuery("mContent script").each(function() { if (this.innerHTML != null) { eval(this.innerHTML); } }); var objectTags = jQuery("#mContent object").each(function() { if (this.css('visibility') == 'hidden') { this.css('visibility') = 'visible'; } }); } catch (e) { }
    if (!a.is('.inline'))
    { mClickOffArea.click(function() { media.hide(a); }); jQuery("#mediaCloseButton").click(function() { media.hide(a); }); media.fixPosition(); media.show(); } else { }
    mContainer = jQuery("#mContent"); Cufon.refresh(); $('h2.mediaTitle, .mediaPanelRelated h2, .pagination p').css('text-indent', '0em'); updateSocialLinks();
}, drawReplace: function(o) { jQuery("#" + objIdStr).html(o); media.init(); Cufon.refresh(); $('h2.mediaTitle, .mediaPanelRelated h2, .pagination p').css('text-indent', '0em'); updateSocialLinks(); }, fail: function(msg) { mContainer.html("<b>Load failed</b><p>Please try again.</p><br>"); }, failReplace: function(msg) { jQuery("#" + objIdStr).html("<b>Load failed</b><p>Please try again.</p><br>"); }, spin: function() { mContainer.html("<img src='/global/images/spinner_grey.gif' class='spinner' align='absmiddle'>"); }, fixpath: function(u) { regx = new RegExp(window.location.protocol + "\/\/" + window.location.host); var url = u.replace(regx, ""); url = url.replace("[", "%5B").replace("]", "%5D"); return url.replace(new RegExp(" ", "g"), "%20").toLowerCase(); }, fixPosition: function() { mWidth = mContainer.width() + 30; mHeight = mPanel.height(); mPanel.width(mWidth); cWidth = jQuery(window).width(); cHeight = window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight; newWidth = (cWidth / 2) - (mWidth / 2); newWidth = (newWidth < 0) ? 0 : newWidth; newHeight = (cHeight / 2) - (mHeight / 2); newHeight = (newHeight < 0) ? 0 : newHeight; mPanel.css('left', newWidth + "px"); mPanel.css('top', (newHeight + 50) + "px"); } 
}
var messagePanel, messageContainer, messageWidth, messageHeight, messageClickOffArea; function ShowMessage(strMessage) { CreateMessage("<div class=\"GlobalMessageBox\">" + strMessage + "</div>"); }
function ShowErrorMessage(strMessage) { CreateMessage("<div class=\"GlobalErrorMessageBox\">" + strMessage + "</div>"); }
function ShowSuccessMessage(strMessage) { CreateMessage("<div class=\"GlobalSuccessMessageBox\">" + strMessage + "</div>"); }
function CreateMessage(_message) { messagePanel = jQuery("#mediaPanel"); messageContainer = jQuery("#mContent"); messageClickOffArea = jQuery('#contentArea'); objHeight = messageContainer.height(); objWidth = messageContainer.width(); var buttons = "<div id=\"mediaCloseButton\" style=\"float:right;cursor:pointer;margin-top:0;margin-right:0;\"><img src=\"/global/images/close_button.png\" alt=\"\" width=\"13px\" height=\"12px\"/></div>"; var o = buttons + _message; aTag = jQuery(this); messageContainer.html(o); messageClickOffArea.click(function() { messagePanel.css('top', '-500'); messagePanel.css('display', 'none'); }); jQuery("#mediaCloseButton").click(function() { messagePanel.css('top', '-500'); messagePanel.css('display', 'none'); }); messagePanel.show(); fixPosition(messageContainer, messagePanel); }
function fixPosition(messageContainer, messagePanel) { mWidth = messageContainer.width() + 30; mHeight = messagePanel.height(); messagePanel.width(mWidth); cWidth = jQuery(window).width(); cHeight = window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight; newWidth = (cWidth / 2) - (mWidth / 2); newWidth = (newWidth < 0) ? 0 : newWidth; newHeight = (cHeight / 2) - (mHeight / 2); newHeight = (newHeight < 0) ? 0 : newHeight; messagePanel.css('left', newWidth + "px"); messagePanel.css('top', (newHeight + 50) + "px"); }
if (typeof media != "undefined") { for (prop in mediaPanelController) { if (typeof mediaPanelController[prop] == "function") { media[prop] = mediaPanelController[prop]; } } }
else { media = mediaPanelController; }
window.onresize = function() { media.fixPosition(); }
var mplayercentre_aTag, mplayercentre_aTitle, mplayercentre_mContainer
var mplayercentre_mClickOffArea, mplayercentre_mTitle; var mplayercentre_mPanel; var mediaPlayerCentre = { init: function() { mplayercentre_mPanel = jQuery("#mediaCentrePanel"); mplayercentre_mContainer = jQuery("#mediaCentreContent"); mplayercentre_mClickOffArea = jQuery('#blackOut'); mplayercentre_mTitle = document.title; var mediaLinks = jQuery('a.mediaPlayerCentre,area.mediaPlayerCentre'); mediaLinks.unbind('click', this.addClick); mediaLinks.bind('click', this.addClick); }, addClick: function(e) {
    if (e.preventDefault)
        e.preventDefault(); mplayercentre_aTag = jQuery(this); mplayercentre_aTitle = mplayercentre_aTag.attr('title'); var aHref = mediaPlayerCentre.fixpath(mplayercentre_aTag.attr('href')); try { mediaPlayerCentre.load(aHref, ""); }
    catch (e) { alert(e.number + ': ' + e.description); }
    return false;
}, load: function(aHref, strPost) {
    mplayercentre_mClickOffArea.unbind('click'); if (!strPost)
    { strPost = "isAjax=1&returnURL=" + location.href; }
    else
    { strPost += "&isAjax=1"; }
    var objHeight = ""; var objWidth = ""; mediaPlayerCentre.show(); mediaPlayerCentre.spin(); mediaPlayerCentre.blackOut(); mediaPlayerCentre.fixPosition(); strPost += "&aHref=" + aHref + "&h=" + objHeight + "&w=" + objWidth; if (mplayercentre_aTitle)
        strPost += "&title=" + mplayercentre_aTitle; strUrl = "/global/templates/mediaPlayerTemplate.aspx"; jQuery.ajax({ type: "POST", url: strUrl, data: strPost, a: mplayercentre_aTag, success: function(o) { var thisRef = this.a; setTimeout(function() { mediaPlayerCentre.draw(o, thisRef) }, 2000); }, failure: mediaPlayerCentre.fail });
}, show: function() { mplayercentre_mPanel.css('display', 'block'); updateSocialLinks(); }, hide: function(a) { mplayercentre_mPanel.css('top', '-500'); mplayercentre_mPanel.css('display', 'none'); $('#blackOut').remove(); $("#floMediaCentrePlayer").remove(); jQuery("#mediaCenterContent").html(""); mplayercentre_mClickOffArea.unbind('click'); window.onresize = function() { media.fixPosition(); } }, draw: function(o, a) {
    mplayercentre_mContainer = mplayercentre_mContainer.html(o); try { var scriptTags = jQuery("#mediaCentreContent script").each(function() { if (this.innerHTML != null) { eval(this.innerHTML); } }); }
    catch (e)
{ }
    if (!a.is('.inline'))
    { mplayercentre_mClickOffArea.click(function() { mediaPlayerCentre.hide(a); }); jQuery("#mediaCentreCloseButton").click(function() { mediaPlayerCentre.hide(a); $('#blackOut').remove(); }); jQuery("#blackOut").click(function() { mediaPlayerCentre.hide(a); $('#blackOut').remove(); }); mediaPlayerCentre.fixPosition(); mediaPlayerCentre.show(); } else { }
    mplayercentre_mContainer = jQuery("#mediaCentreContent"); jQuery(document).ready(function() { media.init(); Cufon.refresh(); $('h2.mediaTitle, .mediaPanelRelated h2, .pagination p').css('text-indent', '0em'); updateSocialLinks(); window.onresize = function() { mediaPlayerCentre.fixPosition(); } });
}, fail: function(msg) { mplayercentre_mContainer.html("<b>Load failed</b><p>Please try again.</p><br>"); }, spin: function() { mplayercentre_mContainer.html("<img src='/global/images/spinner_darkGray.gif' class='spinnerMedia' align='absmiddle'>"); }, blackOut: function() { $('body').append('<div id="blackOut"></div>'); }, fixpath: function(u) { regx = new RegExp(window.location.protocol + "\/\/" + window.location.host); var url = u.replace(regx, ""); url = url.replace("[", "%5B").replace("]", "%5D"); return url.replace(new RegExp(" ", "g"), "%20").toLowerCase(); }, fixPosition: function() { var mWidth_cc = mplayercentre_mContainer.width(); var mHeight_cc = mplayercentre_mPanel.height(); mplayercentre_mPanel.width(mWidth_cc); var cWidth_cc = jQuery(window).width(); var cHeight_cc = window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight; var newWidth_cc = (cWidth_cc / 2) - (mWidth_cc / 2); newWidth_cc = (newWidth_cc < 0) ? 0 : newWidth_cc; var newHeight_cc = (cHeight_cc / 2) - (mHeight_cc / 2); newHeight_cc = (newHeight_cc < 0) ? 0 : newHeight_cc; mplayercentre_mPanel.css('left', newWidth_cc + "px"); mplayercentre_mPanel.css('top', (newHeight_cc) + "px"); } 
}
var divReplaceID_mediaPlayerCentrePanel = "channelVideos"; function loadVideos(searchUrl, strQueryString, sReplaceID) {
    divReplaceID_mediaPlayerCentrePanel = sReplaceID; if (window.jQuery) {
        jQuery("#" + sReplaceID).html("<div style='position:relative;z-index:999; background-color:#fff; margin:20px;'><img src='/global/images/spinner_white.gif' /> Loading...</div>" + jQuery("#" + sReplaceID).html()); var url = searchUrl + (strQueryString != "" ? "?" + strQueryString : ""); if (window.location.href.indexOf('https') >= 0)
            url = url + '&RequiresSecure=1'; jQuery.ajax({ type: "GET", url: url, success: showVideoResults, failure: showVideErrors });
    } 
}
function showVideoResults(o) {
    var resultObj = jQuery("#" + divReplaceID_mediaPlayerCentrePanel); if (resultObj) {
        resultObj.html(o)
        jQuery(document).ready(function()
        { media.init(); Cufon.refresh(); $('h2.mediaTitle, .mediaPanelRelated h2, .pagination p').css('text-indent', '0em'); updateSocialLinks(); });
    } 
}
function showVideErrors(o) {
    var resultObj = jQuery("#" + divReplaceID_mediaPlayerCentrePanel); if (resultObj)
    { resultObj.html("<div style='color:red;'>Cannot load channel videos.</div>"); } 
}
var _fullVideoWidth = 850; var _fullVideoHeight = 500; var _originalVideoWidth = 550; var _originalVideoHeight = 330; function showHideVideoToFull(isFull, lnkFullId, lnkDetailId, divVideoObj, divDetail) {
    var videoObj = $("#floMediaCentrePlayer")
    if (videoObj) {
        if (isFull)
        { $('.mediaCentrePanelVideo object').css({ 'height': _fullVideoHeight, 'width': _fullVideoWidth }); $("#" + divDetail).hide(); $("#" + lnkDetailId).show("slow"); $("#" + lnkFullId).hide(); }
        else
        { $('.mediaCentrePanelVideo object').css({ 'height': _originalVideoHeight, 'width': _originalVideoWidth }); $("#" + divDetail).show(); $("#" + lnkDetailId).hide(); $("#" + lnkFullId).show(); } 
    }
    mediaPlayerCentre.show();
}
var mc_videoVar_lnkFullId; var mc_videoVar_lnkDetailId; var mc_videoVar_divVideoObj; var mc_videoVar_divDetail; function mc_enlargePlayer() { showHideVideoToFull(true, mc_videoVar_lnkFullId, mc_videoVar_lnkDetailId, mc_videoVar_divVideoObj, mc_videoVar_divDetail); }
function mc_shrinkPlayer() { showHideVideoToFull(false, mc_videoVar_lnkFullId, mc_videoVar_lnkDetailId, mc_videoVar_divVideoObj, mc_videoVar_divDetail); }
function updateSocialLinks() { var pageURL = window.location; var pageTitle = document.title; $('.addthis_toolbox a').each(function(i) { if ($(this).attr('rel').length) { var socialType = $(this).attr('rel'); $(this).attr('href', 'http://www.addthis.com/bookmark.php?pub=&v=250&source=tbx-250&tt=0&s=' + socialType + '&url=' + pageURL + '&title=' + pageTitle + '&content=&sms_ss=1&lng=en'); } }); }
var RatePageControl = function() {
    var ratePageWithValue = function(rating, url) { jQuery('div.beforeRate').fadeOut(function() { jQuery.ajax({ type: "POST", url: '/global/ratePage/RatePage.aspx?rating=' + rating + '&ratedPageUrl=' + url, success: function(data) { var fbLink = jQuery('div.ratePage a.feedbackLink'); fbLink.attr('href', fbLink.attr('href') + data); jQuery('div.afterRate').fadeIn(); }, error: function(data) { jQuery('div.beforeRate').fadeIn(); } }); }); }
    var init = function() {
        jQuery('div.ratePage a.yesLink').click(function(e) {
            var url = jQuery(this).attr('href'); url = url.substring(url.indexOf("ratedPageUrl=") + 13); ratePageWithValue('yes', url); if (e.preventDefault)
                e.preventDefault; return false;
        }); jQuery('div.ratePage a.noLink').click(function(e) {
            var url = jQuery(this).attr('href'); url = url.substring(url.indexOf("ratedPageUrl=" + 13)); ratePageWithValue('no', url); if (e.preventDefault)
                e.preventDefault; return false;
        })
    } (); return {};
}
var interval; var keepAlive = { start: function(time)
{ clearInterval(interval); interval = setInterval("keepAlive.query();", time); }, query: function() { jQuery.post('/global/keepalive.aspx'); }, stop: function()
{ clearInterval(interval); }
}

// Be defensive and ensure that jQuery is available
var enableRMCForm = false;
if (typeof jQuery !== 'undefined') {
    $(function () {
        if (enableRMCForm && $('.enable-rmc-fasttrack').length) {

            $('a[href*="global/forms/apply/default.aspx"]').each(function () {

                var $t = $(this);

                // Update href to point at fast track RMC Officer form.
                $t.attr("href", "/global/forms/JobEnquiries/RMCOfficerEnquiry.aspx?RequiresSecure=1");

                // Remove the "secure" class as it forces a redirection across to https if
                // the current page was not requested under SSL. This step is optional, and
                // is included only to provide consistency with the existing RMC fast track
                // user flow, which served the form via http
                //$t.removeClass("secure");
            });
        }
    });
}

