/* $Id: common.js 32014 2010-07-21 01:12:58Z mmohta $ */

if (typeof(v6js_init_common) == 'undefined') {
    var v6js_init_common = true;

    // :NOTE: Entire content of common.js is only loaded if not previously done

var original_class          = null;
var original_class_obj      = new Object();
var wizard                  = null;
var document_root           = '';
var virtual_root            = '';
var package_root            = '';
var virtual_package_root    = '';
var package_alias           = null;
var old_package             = '';
var debug_mode              = false;
var conn_type               = null;
var debug_window            = null;
var debug_messages          = '';
var debug_timer             = false;
var package_alias_array     = new Array;
var wiz_audio               = null;
var blocked_popup_msg       = 'It appears your request has been stopped by a pop-up blocker, please disable your pop-up blocker and try again.';
var tracking                = false;
var is_corporate            = false;

// Javascript Constants
var NBSP        = '&nbsp;';
var CR          = "\r";
var CRLF        = "\r\n";
var SF_DD_DELIM = ',';

var EXISTING = 1;
var ADDED    = 2;
var DELETED  = 3;
var HIDDEN   = 4;


//=============================================================
// Define Browse Vars
// -Gecko-
//  ns          firefox / webkit / other gecko based (any version)
//  fx_ver      firefox version (major & minor as float)
//  fx1         firefox 1
//  fx2         firefox 2
//  fx3         firefox 3
//
// -Microsoft-
//  ie          all IE versions
//  ie5         IE 5.x
//  aboveIE5    IE 6.0+ (incl. IE7)
//  ie7         IE 7.x
//=============================================================

var ie       = (navigator.appVersion.indexOf('MSIE')    != -1)                    ? true : false;
var ns       = ((typeof(document.all) == 'undefined') && document.getElementById) ? true : false;
var ie5      = (navigator.appVersion.indexOf('MSIE 5.') != -1)                    ? true : false;
var ie6      = (navigator.appVersion.indexOf('MSIE 6.') != -1)                    ? true : false;
var ie7      = (navigator.appVersion.indexOf('MSIE 7.') != -1)                    ? true : false;
var ie8      = (navigator.appVersion.indexOf('MSIE 8.') != -1)                    ? true : false;
var aboveIE5 = (!ie5 && !ns)                                                      ? true : false;

// detect firefox version
if (ns && typeof navigator != 'undefined') {
    var fx_ver = 0;
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
        fx_ver = new Number(RegExp.$1);
    }
    var fx1 = fx_ver >= 1 && fx_ver <= 2 ? true : false;
    var fx2 = fx_ver >= 2 && fx_ver <= 3 ? true : false;
    var fx3 = fx_ver >= 3 && fx_ver <= 4 ? true : false;
}

//=============================================================



// custom alert box vars
var alert_timeout_id = 0;
var alert_mozopacity = 0;

var debug_window  = null;
var debug_counter = 0;


// Add utility functions to prototypes

String.prototype.strip = function() {
    return(this.replace(/[\f\n\r\t\v]/g,''));
}


String.prototype.trim = function(c, n) {
    if (!c) {
        c = '\\s';
    }

    n = parseInt(n);

    var r1 = new RegExp('^' + c + '*');
    var r2 = new RegExp(c + '*$');

    var value = this.replace(r1, '').replace(r2, '');

    if ((n > 0) && (value.length > n)) {
        value = value.slice(0, n) + '...';
    }

    return value;
};


String.prototype.entityTags = function() {
    a = this.replace(/>/, '&gt;');
    return a.replace(/</, '&lt;');
};


if (typeof Element != 'undefined' && Element.prototype && document.createRange) {
   Element.prototype.__defineGetter__(
     'innerText',
     function () {
       var range = document.createRange();
       range.selectNodeContents(this);
       return range.toString();
     }
   );
   Element.prototype.__defineSetter__(
     'innerText',
     function (text) {
       var range = document.createRange();
       range.selectNodeContents(this);
       range.deleteContents();
       this.appendChild(document.createTextNode(text));
     }
   );
}


Date.prototype.fromISO = function(s) {
    var tmp = s.split(' ');
    date = tmp[0].split('-');
    time = tmp[1].split(':');
    this.setDate(1);
    this.setFullYear(parseInt(date[0], 10));
    this.setMonth(parseInt(date[1], 10) - 1);
    this.setDate(parseInt(date[2], 10));
    this.setHours(parseInt(time[0], 10));
    this.setMinutes(parseInt(time[1], 10));

    return this;
}


Date.prototype.toISO = function() {
    return this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate() + ' ' + this.getHours() + ':' + this.getMinutes() + ':' + this.getSeconds();
}


Date.prototype.toShort = function(use_time, use_seconds) {
    var s = this.getDate() + '/' + (this.getMonth() + 1) + '/' + this.getFullYear();
    if (use_time) {
        var mins = '' + this.getMinutes();
        if (mins.length < 2) {
            mins = '0' + mins;
        }
        s += ' ' + this.getHours() + ':' + mins;
        if (use_seconds) {
            var secs = '' + this.getSeconds();
            if (secs.length < 2) {
                secs = '0' + secs;
            }
            s += ':' + secs;
        }
    }
    return s;
}


/**
 * Utility functions
 *
 */

function bindEvent(object, type, func) {
    var capture = (arguments.length > 3) ? arguments[3] : true;
    if (ie) {
        object.attachEvent('on' + type, func);
    } else {
        object.addEventListener(type, func, capture);
    }
}


function cancelEvent(event) {
    if (ie) {
        window.event.cancelBubble = true;
    } else {
        event.stopPropagation();
    }
}


function popupsBlocked() {
 var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
 if(mine)
    return false;
 else
     mine.close();
     return true;
}


/*
 * Standard Page Set functions
 * These get called on every page to pass php vars and info into js
 */

function setIsCorporate(corp_flag) {
    is_corporate = corp_flag;
}

function setDebugMode(mode) {
    debug_mode = getBoolVal(mode);
    if (!debug_mode) {
        window.onerror = handleError;
    }
}

function setDocumentRoot(path) {
    document_root = path;
}

function setVirtualRoot(path) {
    virtual_root = path;
}

function setPackage(alias) {
    package_alias = alias;
    package_root = document_root + '/' + package_alias;
    virtual_package_root = virtual_root + '/' + package_alias;
}

function addPackageAlias(pkg, alias) {
    package_alias_array[pkg] = alias;
}

function setPackageAliasByPackage(pkg) {
    old_package = getPackage();
    if(typeof(package_alias_array[pkg]) != 'undefined') {
        setPackage(package_alias_array[pkg]);
        return true;
    } else {
        alert('Sorry, you dont have access to perform this function.');
        return false;
    }
}


function showPopupCampaignHelp(e, context) {
    owin = openWindow(e, '/em/campaign/help.php?context=' + context, 700, 400);
}

function showPopupBackupHelp(e, context) {
    owin = openWindow(e, '/em/backup/help.php?context=' + context, 700, 400);
}


/*
 * Get & Is Functions
 */

function getObjectFromEvent(e) {
    if(typeof(e.srcElement) == 'undefined') {
        return e.target;
    } else {
        return e.srcElement;
    }
}

function isCorporate() {
    return is_corporate;
}

function getPackageAlias(pkg) {
    return package_alias_array[pkg];
}

function getPackage() {
    return package_alias;
}

function restorePackage() {
    return setPackage(old_package);
}

function getPackageRoot() {
    return package_root;
}





/*
 * changeClass functions (used for rollovers) etc.
 */

function changeClass(obj, class_name) {
    original_class      = obj.className;
    original_class_obj  = obj;
    obj.className       = class_name;
    obj.onmouseout      = restoreClass;

}

function restoreClass(e) {
    if((typeof(original_class_obj) != 'undefined') && (typeof(original_class_obj.className) != 'undefined')) {
        original_class_obj.className = original_class;
        setStat('');
    }
}

function overButton(e, obj){
    if(!obj) {
        if(typeof(e.srcElement) == 'undefined') {
            obj = e.currentTarget;
        } else {
            obj = e.srcElement;
        }
    }
    strValue = obj.value;
    if( obj.className == "formButton" ){
        changeClass(obj, "formButtonOver");
        setStat(strValue);
    }
}



/*
 * Generic Page functions
 * These get called on nearly every page
 */

function isNotPopupWindow() {
    return (((typeof(window.opener) == 'undefined') || (window.opener == null)) && (parent.location.href == window.location.href));
}

function trackMe(idle) {

    if (isNotPopupWindow()) {
        if(document.body && document.body.style && (typeof(document.body.style.behavior) != 'undefined')) {
            document.body.style.behavior = "url(#default#clientCaps)";
            conn_type = document.body.connectionType;
        } else {
            conn_type = 'unknown';
        }
        var now       = new Date();
        var offset    = now.getTimezoneOffset();
        var now_time  = now.getTime();

        //Make track me hit.
        if (typeof(xmlhttpCall) != 'undefined') {
            xmlhttpCall("GET", processTrackMeResponse, document_root + '/main/track.php?sr=' + screen.width + 'x' + screen.height + '&ct=' + conn_type + '&to=' + offset + '&t=' + now_time + '&idle=' + idle);
        } else if (typeof(APP.XHR) != 'undefined') {
            APP.XHR.request(
                document_root + '/main/track.php',
                'GET',
                {
                'sr':   screen.width+'x'+screen.height,
                'ct':   conn_type,
                'to':   offset,
                't':    now_time,
                'idle': idle
                },
                false, false, false, false, true);
        }

        if(idle)  {
            // Track again in 180 seconds.
            setTimeout('trackMe(true)', 180000);
        }
    }
}

function setTracking() {
    setTimeout('trackMe(true)', 180000);
}

function processTrackMeResponse(m) {
    // m is the raw system notification message, or empty if no message is available
    if (m) {
        var notification = '';
        try {
            notification = eval(m);
        } catch (e) {
            // bad response
        }
        showSystemNotification(notification);
    }
}

function handleError(desc, page, line)  {
    var bit  = '&';
    var sURL = document_root + '/assets/js_error.php?';
        sURL += 'desc=' + escape(desc) + bit
        sURL += 'page=' + escape(page) + bit
        sURL += 'line=' + escape(line) + bit
        sURL += 'useragent=' + escape(navigator.userAgent) + bit;

    var img = new Image();
        img.src = sURL;

    return true;
}





/*
 * Misc functions and Util Functions
 */

function goUrl(sUrl){
    location.href = sUrl;
}

function convertFontSizeToPixels(size) {
    size = parseInt(size);
    var pixels_list = [11, 11, 13, 16, 18, 24, 32, 48];
    return (typeof(pixels_list[size]) != 'undefined' ? pixels_list[size] : 13) + 'px';
}

function getWindowDimensions(dont_detect_overflow) {
    var viewport_width = -1, viewport_height = -1, viewport_offset_x = -1, viewport_offset_y = -1;

    if (window.innerWidth) {

        // Non-MSIE browsers; take 16px off in Fx for scrollbars if appropriate
        viewport_width = window.innerWidth;
        viewport_height = window.innerHeight;
        if (!dont_detect_overflow) {
            viewport_width -= ((document.body && document.body.offsetHeight && document.body.offsetHeight > window.innerHeight) ? 16 : 0);
            viewport_height -= ((document.body && document.body.offsetWidth && document.body.offsetWidth > window.innerWidth) ? 16 : 0);
        }
        viewport_offset_x = self.pageXOffset;
        viewport_offset_y = self.pageYOffset;

    } else if (document.documentElement && document.documentElement.clientWidth) {

        // MSIE6/7 Standards-compliant

        viewport_width = document.documentElement.clientWidth;
        viewport_height = document.documentElement.clientHeight;
        viewport_offset_x = document.documentElement.scrollLeft;
        viewport_offset_y = document.documentElement.scrollTop;

    } else if (document.body) {

        // Other MSIE versions (including MSIE6/7 Quirks mode)

        viewport_width = document.body.clientWidth;
        viewport_height = document.body.clientHeight;
        viewport_offset_x = document.body.scrollLeft;
        viewport_offset_y = document.body.scrollTop;
    }

    var return_values = {
        width: viewport_width,
        height: viewport_height,
        offset_x: viewport_offset_x,
        offset_y: viewport_offset_y
    };

    return return_values;
}



function showTip(event, text, fake_param, pos_x, pos_y) {

    if(pos_x && pos_y) {
        // no idea why these are backwards, but it doesnt matter:
        var cell_left   = pos_y;
        var cell_top    = pos_x;

        var cell_width  = 0;
        var cell_height = 0;
    } else {
        var cell = getObjectFromEvent(event).parentNode;
        var cell_top = findPosY(cell), cell_left = findPosX(cell);
        var cell_width = cell.offsetWidth, cell_height = cell.offsetHeight;
    }

    var ttip = document.getElementById('tooltip');
    if (!ttip) {
        ttip = document.createElement('div');
        ttip.id = 'tooltip';
        ttip.style.position = 'absolute';
        ttip.style.top = '339px';
        ttip.style.right = 'auto';
        ttip.style.left = '215px';
        ttip.style.display = 'none';
        ttip.className = 'ttip';
        document.body.appendChild(ttip);
    }

    ttip.style.zIndex = '60000';
    ttip.style.display = '';
    ttip.style.top     = cell_top + cell_height + 10;
    ttip.style.right   = 'auto';
    ttip.style.left    = cell_left + 4;
    ttip.innerHTML     = text;

    // Reposition/break up tooltip if it stretches offpage and/or offscreen
    //   :NOTE: The tooltip element's container box width is different cross-browser:
    //     - IE's bounding width (right edge) is the rightmost edge of the current viewport (e.g. 1000 + 42).
    //     - Fx's however is the rightmost "edge" of the window.innerWidth itself (e.g. 1000).
    //   But their left edges are both the leftmost point of the page, so use that to calculate right edges.


    // Get the inner viewport width (excluding scrollbars) and horizontal scroll position
    var viewport_dimensions = getWindowDimensions();
    var viewport_width = viewport_dimensions.width, viewport_offset_x = viewport_dimensions.offset_x;

    // First pass - over right edge of document, line up tooltip right edge with document right edge (all with a 4px gap)
    var tooltip_right_edge = ttip.offsetLeft + ttip.offsetWidth, viewport_right_edge = viewport_width + viewport_offset_x, tooltip_width = ttip.offsetWidth;

    if (viewport_right_edge > 0 && tooltip_right_edge > viewport_right_edge - 4) {
        ttip.style.left = cell_left + cell_width - tooltip_width - 4;
    }

    // Second pass - over right edge of viewport, line up tooltip right edge with viewport right edge (all with a 4px gap)
    tooltip_right_edge = ttip.offsetLeft + ttip.offsetWidth;

    if (viewport_right_edge > 0 && tooltip_right_edge > viewport_right_edge - 4) {
        ttip.style.left = viewport_right_edge - tooltip_width - 4;
    }

    // :NOTE: Could do further repositioning/splitting attempts here,
    // e.g. to ensure left edge isn't beyond left viewport edge,
    // or that the tooltip isn't wider than the viewport itself,
    // but these cases shouldn't happen very often at all :-P
}



function hideTip() {
    //document.getElementById("tooltip").style.visibility="hidden";
    document.getElementById("tooltip").style.display = 'none';
}

function openerReload() {
    opener.location=opener.location;
}

function setStat( txt ){
    window.status = '';
    window.status = txt;
    return true;
}

function copytoClipboard(field) {
    //field.focus();
    //field.select();

    if (ie){
        therange=field.createTextRange();
        therange.execCommand("Copy");

        if (window.clipboardData.getData("Text")) {
            alert('Text has been copied to the Clipboard');
        }
    } else {
        alert('Sorry, your browser does not support "Copy to Clipboard"');
    }
}


function canPrint() {
    var isMac = navigator.userAgent.indexOf("Mac");
    var isIE  = navigator.userAgent.indexOf("MSIE");

    if((isMac != -1) && (isIE != -1)) {
        return false;
    } else {
        return true;
    }
}

function doPrint() {
    if(canPrint()) {
        print();
    } else {
        alert("Press 'APPLE + P' to print.");
    }
}

function insertCard(drop_id, fld_name){
    if (document.getElementsByName(fld_name)) {
        card = document.getElementById('ins_' + drop_id);
        fld  = document.getElementsByName(fld_name);
        fld  = fld[0];
        fld.focus();
        card = card[card.selectedIndex].value;

        fld.caretPos = (ie) ? document.selection.createRange().duplicate() : window.getSelection();

        if (fld.createTextRange && fld.caretPos) {
            var caretPos = fld.caretPos;
            selectedtext = caretPos.text;
            caretPos.text = card;
        } else if (fld.selectionStart || fld.selectionStart == '0') {
            var startPos = fld.selectionStart;
            var endPos = fld.selectionEnd;
            fld.value = fld.value.substring(0, startPos) + card + fld.value.substring(endPos, fld.value.length);
        }else  {
            fld.value = fld.value + ' ' + card;
        }
    }

    fld.focus();
}

function insertCardMultiple(identifier) {
    var wild_dd = document.getElementById(identifier + '_wilds');
    var txt = wild_dd[wild_dd.selectedIndex].value;

    if (txt) {
        fld = document.getElementById(identifier);
        fld.focus();
        fld.caretPos = (ie) ? document.selection.createRange().duplicate() : window.getSelection();

        if (fld.createTextRange && fld.caretPos) {
            var caretPos = fld.caretPos;
            selectedtext = caretPos.text;
            caretPos.text = txt;
        } else if (fld.selectionStart || fld.selectionStart == '0') {
            var startPos = fld.selectionStart;
            var endPos = fld.selectionEnd;
            fld.value = fld.value.substring(0, startPos) + txt + fld.value.substring(endPos, fld.value.length);
        }else  {
            fld.value = fld.value + ' ' + txt;
        }
    }
}

function getBoolVal(str){
    if(typeof(str) != 'undefined') {
        if(typeof(str) == 'boolean') {
            return str;
        } else {
            str = str.toString();
            return (str.toLowerCase() == "true" || str == "1" || str == "yes");
        }
    } else {
        return false;
    }
}

function openWindow(e, url, width, height, attrs, optional_name, use_parent) {
    ah = screen.availHeight - 30;
    aw = screen.availWidth - 10;

    xc = (aw - width) / 2;
    yc = (ah - height) / 2;

    //Make up a window name based on the URL.
    window_name = optional_name ? optional_name : url.replace(/[^a-z]*/gi,'');

    if (ie) {
        //Status=yes is forced for SP2 compatibility.
        attrs += ',status=yes,location=no';
    }

    //Status=yes is forced for SP2 compatibility.
    attrs = attrs ? ',' + attrs : '';

    if (use_parent && window.opener){
        w = window.opener.open(url, window_name, 'width='+width+',height='+height+',left='+xc+',top='+yc+attrs);
    } else {
        w = window.open(url, window_name, 'width='+width+',height='+height+',left='+xc+',top='+yc+attrs);
    }

    //Test that it worked!
    if(!w) {
        alert(blocked_popup_msg);
    } else {
        if (width < 600 || height < 600 || attrs.match(/location=no|resize=no/gi)) {
            initPopupWindow(w);
        } else {
            w.focus();
        }
    }

    return w;
}

// tells a popup window to scale to fit its contents after loading
function initPopupWindow(my_window) {
    try{
        if (!my_window.run_popup_init) {        // only run once
            my_window.run_popup_init = true;
            var on_popup_init = function() {};
            if (typeof my_window.onload == 'function') {
                on_popup_init = my_window.onload;
            }
            my_window.onload = function() {
                // get window contents size
                var setw = (typeof my_window.innerWidth == 'undefined' ? my_window.document.body.clientWidth : my_window.innerWidth);
                var seth = (typeof my_window.innerHeight == 'undefined' ? my_window.document.body.clientHeight : my_window.innerHeight);

                // attempt setting window to contents size...
                my_window.resizeTo(setw, seth);

                // ...calculate difference between desired size and resultant size (browsers decide differently what to scale)...
                var diffw = setw - (typeof my_window.innerWidth == 'undefined' ? my_window.document.body.clientWidth : my_window.innerWidth);
                var diffh = seth - (typeof my_window.innerHeight == 'undefined' ? my_window.document.body.clientHeight : my_window.innerHeight);

                // ...and resize finally, respecting these browser-specific peculiarities
                return my_window.resizeTo(setw + diffw, seth + diffh);

                on_popup_init();
                my_window.focus();      // focus *after* resizing to prevent windows jumping so visibly
            };
        }
        // Note: If the init function has already run we still need to focus the window.
        //       Also, the above is not foolproof. If a page loads quickly the
        //       onload function is added after the onload event has fired.
        my_window.focus();
    }catch(e){
        // IE7 fails setting the above properties for child windows in other domains
    }
}


function getQueryString(qs_key) {
   var qs_tmp = location.search.substring(1);
   var i = qs_tmp.toLowerCase().indexOf(qs_key.toLowerCase() + '=');

   if (i >= 0) {
      qs_tmp = qs_tmp.substring(qs_key.length + i + 1);
      i = qs_tmp.indexOf('&');
      return unescape(qs_tmp = qs_tmp.substring(0, (i >= 0) ? i : qs_tmp.length));
   }

   return false;
}



function fixCurrentUrlInHref(href_value) {
    if (ie && href_value) {
        // first replace about:blank, which is also appended sometimes
        href_value = href_value.replace('about:blank', '');
        if ((href_value.indexOf('#') != -1) || (href_value.indexOf('%%') != -1)) {
            // there is an anchor, so look for current page in href value
            var current_url = document.location.href;
            if (href_value.indexOf(current_url) != -1) {
                // the current query string is part of the href value -> was probably added by IE, so strip it out
                href_value = href_value.replace(current_url, '');
            }
            // and to make sure, in case only the query string was added by IE
            var pos = current_url.lastIndexOf('/') + 1;
            var query_string = current_url.slice(pos, current_url.length);
            if (href_value.indexOf(query_string) != -1) {
                href_value = href_value.replace(query_string, '');
            }
        }
        return href_value;
    }
    return href_value;
}



function getHref(obj) {
    var href = getAttributePercSafe(obj, 'href');
    if (ie) {
        href = fixCurrentUrlInHref(href);
    }
    return href;
}

function getSrc(obj) {
    return getAttributePercSafe(obj, 'src');
}

function setSrc(obj, value) {
    setAttributePercSafe(obj, 'src', value);
}

function getAttributePercSafe(obj, attribute) {
    // This uses outerHTML and Regex to grab an attribute that might have problems with % symbols
    // in it - primarily HREF attributes in <A> tags and SRC attributes in <IMG> tags.
    // This was done because the current wildcards format (%%) breaks in IE7. It does not affect Gecko based browsers.
    // due to a documented chosen "behaviour" by Microsoft
    // Read http://channel9.msdn.com/wiki/default.aspx/Channel9.InternetExplorer7Beta2PreviewBugs for more info
    if (ie7 || ie8) {
        var regexp = new RegExp (attribute + '[\s]*=[\s]*"[^\n"]*"');
        var url_match = regexp.exec(obj.outerHTML);
        if (url_match) {
            var url = decodeHtmlEntities(url_match[0].replace(attribute + '="','').replace('"',''));
            // only use getAttribute() if URL is NOT a wildcard, AND if the URL
            // is NOT a mailto link then it can't contain the @ symbol
            if (url.indexOf('%%') == -1 && (url.indexOf('@') == -1 || url.indexOf('mailto:')) >= 0) {
                // no wildcard, no not a mailto link, no @ symbol -> return the
                // normal getAttribute()
                url = obj.getAttribute(attribute);
            }
        } else {
            var url = '';
        }
    } else {
        url = obj.getAttribute(attribute);
    }
    return url;
}

function setAttributePercSafe(obj, attribute, value) {
    // the reverse functionality to getAttributePercSafe()
    if (ie7 || ie8) {
        var regexp = new RegExp (attribute + '[\s]*=[\s]*"[^\n"]*"');
        obj.outerHTML = obj.outerHTML.replace(RegExp, attribute + '="' + value + '"');
    } else {
        obj.setAttribute(attribute, value);
    }
}

// Used for C&RW emails
function getAbsoluteUrl(url) {
    if (url.substring(0, 1) == '/') {
        url = document_root + url;
    }

    return url;
}





/*
 * HTML Entities decoder function
 */

function decodeHtmlEntities (str) {
    // This function exists because  we may need to add more htmlentities in the
    // future that do not get decoded by IE in URI's.

    // Add new entries to the array if needed in format below:
    // html_entities[1] = new Array('&tilde;','~');
    // Currently ampersands (&amp;) are the only known entities needed to be
    // decoded.

    var html_entities = new Array();
    html_entities[0] = new Array(/&amp;/g, '&');
    for (i=0; i < html_entities.length; i++) {
        str = str.replace(html_entities[i][0],html_entities[i][1]);
    }

    return str;
}



// converts special HTML characters into entities, for escaping attributes, innerHTML etc
function encodeHtmlEntities(text_str) {
    text_str = text_str.toString();
    text_str = text_str.replace(/&/g, '&amp;');
    text_str = text_str.replace(/\"/g, '&quot;');
    text_str = text_str.replace(/</g, '&lt;');
    text_str = text_str.replace(/>/g, '&gt;');
    text_str = text_str.replace(/\xa0/g, '&nbsp;');
    return text_str;
}


/*
 * Help Function
 */

function showHelp(e) {
    openWindow(e, document_root + '/help/index.php?pkg=' + package_alias, 716,510, 'status=yes,scrollbars=yes', 'uihelp');
}

function showHelpPage(e, page) {
    openWindow(e, document_root + '/help/' + page + '&pkg=' + package_alias, 716,510, 'status=yes,scrollbars=yes', 'uihelp');
}

function showKnowledgeCentre(e) {
    var url = document_root + '/kc/app/';
    if (arguments.length) {
        if (typeof arguments[1] != 'undefined') {
            url += arguments[1];
        }
    }
    var xSize = getCookie('KC_WinSizeX'), ySize = getCookie('KC_WinSizeY');
    xSize = (xSize == null || typeof xSize == 'undefined' || xSize == 'undefined' ? 950 : xSize);
    ySize = (ySize == null || typeof ySize == 'undefined' || ySize == 'undefined' ? 740 : ySize);

    openWindow(e, url, xSize, ySize, 'status=yes, scrollbars=yes, resizable= yes', 'kc_app');
}

function redirectKc(redirect_url) {
    var dialog = JQ('<div>').attr('id', 'kc_redirection_dialog').html('<font color="#000000">Please click OK to open Knowledge Centre in a new window.</font>');
    dialog.appendTo(JQ(document.body));

    dialog.dialog({
        autoOpen:  true,
        title:     'Knowledge Centre',
        width:     325,
        minHeight: 100,
        modal:     true,
        resizable: false,
        draggable: false,
        bgiframe:  true,
        open:      function() {
                       JQ(document.body).css('overflow', 'hidden');
                   },
        close:     function() {
                       JQ(document.body).css('overflow', '');
                   },
        buttons: {
            'OK':     function(e) {
                          showKnowledgeCentre(e, redirect_url);
                          document.location = document.location.protocol + '//' + document.location.hostname + document.location.pathname;
                          JQ(this).dialog('close');
                      },
            'Cancel': function() {
                          JQ(this).dialog('close');
                      }
        }
    });
}



/*
 * Form Functions
 */

function setSelection(val,objSelect){
    for( i=0; i<objSelect.length; i++ ){
        if( objSelect.options[i].value == val ){
            objSelect.options[i].selected = true;
        }
    }
}

function setTick(val,objSelect){
    for( i=0; i<objSelect.length; i++ ){
        if( objSelect[i].value == val ){
            objSelect[i].checked = true;
        }
    }
}


function updateCheckboxes(oChkBox){

    if (oChkBox) {

        // Update Mandatory fields
        if (oChkBox.name == 'cb_is_trial'){
             if (!oChkBox.checked){

                var mandatory_icon = '<img src="/assets/images/mandatory.gif" align="top" alt="(Required Field)" title="Required Field" />';

                document.getElementById("comp_addr").setAttribute('mandatory',true);
                document.getElementById("comp_addr").setAttribute('sf_title','Company Address');
                document.getElementById("mand_comp_addr").innerHTML = mandatory_icon;

                document.getElementById("comp_suburb").setAttribute('mandatory',true);
                document.getElementById("comp_suburb").setAttribute('sf_title','Suburb');
                document.getElementById("mand_comp_suburb").innerHTML = mandatory_icon;

                document.getElementById("comp_state").setAttribute('mandatory',true);
                document.getElementById("comp_state").setAttribute('sf_title','State');
                document.getElementById("mand_comp_state").innerHTML = mandatory_icon;

                document.getElementById("comp_zip").setAttribute('mandatory',true);
                document.getElementById("comp_zip").setAttribute('sf_title','Zip/Post Code');
                document.getElementById("mand_comp_zip").innerHTML = mandatory_icon;

             } else {

                document.getElementById("comp_addr").setAttribute('mandatory',false);
                document.getElementById("comp_suburb").setAttribute('mandatory',false);
                document.getElementById("comp_state").setAttribute('mandatory',false);
                document.getElementById("comp_zip").setAttribute('mandatory',false);

                document.getElementById("mand_comp_addr").innerHTML = '';
                document.getElementById("mand_comp_suburb").innerHTML = '';
                document.getElementById("mand_comp_state").innerHTML = '';
                document.getElementById("mand_comp_zip").innerHTML = '';
             }
        }

        checked_items = new Array();
        var hidden_fld  = eval('oChkBox.form.' + oChkBox.name.substr(3,oChkBox.name.length));
        var items   = eval("oChkBox.form." + oChkBox.name);
        if(items.length) {
            for( i=0; i<items.length; i++ ){
                if( items[i].checked ){
                    checked_items[checked_items.length] = items[i].value;
                }
            }
            hidden_fld.value = checked_items.join(',');
        } else {
            if (items.checked) {
                hidden_fld.value = items.value;
            } else {
                hidden_fld.value = '';
            }
        }
    }
}



function dblClickRadio() {
    if (document.getElementById('default_button')) {
        document.getElementById('default_button').click();
    }
}





/*
 * Javascript Array Functions, these are used for sb
 */
function array_unique(array_in) {
    unique_array = new Array();
    for (id in array_in) {
        if (typeof(array_in[id]) == 'function') continue;
        if(!in_array(array_in[id], unique_array)) {
            unique_array[unique_array.length] = array_in[id];
        }
    }
    return unique_array;
}

function in_array(needle, haystack) {
    for (key in haystack) {
        if (typeof(haystack[key]) == 'function') continue;
        if(haystack[key] == needle) {
            return true;
        }
    }
    return false;
}


/*
 * Image Manager Functions
 */

var temp_max_width  = null;
var temp_max_height = null;
var temp_image      = null;
var temp_onchange   = null;
var used_for        = null;
var used_for_obj    = null;

function openImageManager(use_wysiwyg, used_for_type, doc_obj, restrict_ui){

    if (!restrict_ui && restrict_ui !=0) {
        if (use_wysiwyg) {
            restrict_ui = 0;
        } else {
            restrict_ui = 1;
        }
    }

    if (use_wysiwyg) {
        wysiwyg_image_dialog = false;
    }
    // Use by Generate Form only
    // :TODO: Remove this.
    if (openImageManager.arguments.length == 2) {
        if(typeof(openImageManager.arguments[1]) == 'object') {
            temp_max_width  = (openImageManager.arguments[1]['max_width'])?openImageManager.arguments[1]['max_width']:null;
            temp_max_height = (openImageManager.arguments[1]['max_height'])?openImageManager.arguments[1]['max_height']:null;
            temp_image      = openImageManager.arguments[1]['which_img'];
            temp_onchange   = (openImageManager.arguments[1]['onchange']) ? openImageManager.arguments[1]['onchange']:null;
        }
    } else {
        used_for        = used_for_type;
        used_for_obj    = doc_obj;
    }

    if (opener && opener.name == 'kc_app') {
        var owin = window.open(package_root + '../../../em/file_manager.php?r='+ restrict_ui +'&w=' + use_wysiwyg, 'img_manager', 'width=680,height=480');
    } else {
        var owin = window.open(package_root + '/file_manager.php?r='+ restrict_ui +'&w=' + use_wysiwyg, 'img_manager', 'width=680,height=480');
    }

    if ((typeof(event) != "undefined") && (event != null)) {
        return owin;
    } else {
        // No event, use window.open
        if (owin && typeof(owin) != 'undefined') {
            initPopupWindow(owin);
            return owin;
        } else {
            // Popup got blocked
            alert(blocked_popup_msg);
            return false;
        }
    }
}


function openAutoFill(){
    var link_uri = $('em_wfs_sub_item_list').value;
    if (!fromWFS) {
        // strips apart the web form style field, and pulls out the database id
        var db_id = link_uri.split('/')[3].replace('.html','');
    } else {
        var match = /(?:\?|&(?:amp;)?)db=([0-9]+)/.exec(link_uri);
        var db_id = null;
        if (match && match[1]) {
            db_id = match[1];
        }
    }
    var adb   = /(?:\?|&(?:amp;)?)adb_id=(\d+)/.exec(linkUrl);

    adb_id = (typeof(adb) == 'object' && adb != null && adb.length == 2 ? adb[1] : 0);
    // if the event isn't a valid event blank the variable
    if ((typeof(event) == "undefined") || (event == null)) {
        event = '';
    }

    if(ie){
        var modalObject = new Object();
        modalObject.linkUrl = linkUrl;
        modalObject.fromWFS = fromWFS || 0;
        query_string = window.showModalDialog("/em/message/email/wizard/autofill.php?db_id="+db_id+'&adb='+adb_id, modalObject, "dialogWidth:550px;dialogHeight:400px");
    } else {
        owin = openWindow(event,'/em/message/email/wizard/autofill.php?db_id='+db_id+'&adb='+adb_id,550,400,'','auto_fill');
        return owin;
    }
}

/* -----------As far as i got - goofy ----------- */


function previewEmail(e, email_id) {
    if(setPackageAliasByPackage('em')) {
        if(email_id) {
            var owin = openWindow(e, package_root + '/preview.php?id=' + email_id,600,430);
        } else {
            alert('Please select an Email');
        }
        restorePackage();
    }
}


function validateEmail(addr) {
    if(_e_r.test(addr)) {
        return true;
    } else {
        return false;
    }
}






//
// Function to display the popup help window.
//


function centerAlertBox() {
    var alert_box = document.getElementById('alert_box');
    if (alert_box) {
        var t = (document.body.offsetHeight / 2) - 160;
        var l = (document.body.offsetWidth / 2) - (parseInt(alert_box.style.width) / 2);
        alert_box.style.top = t;
        alert_box.style.left = l;
        alert_box.style.display    = '';
        alert_box.style.visibility = '';
    }
}


function displaySystemNotice() {
    noticeDiv = document.getElementById("_systemNoticeDiv");
    if(!noticeDiv) {
        // no error
        return;
    }
    iframe = document.getElementById("_systemNoticeIframe");
    if(!iframe) {
        fudgeaframe("_systemNoticeIframe");
        iframe = document.getElementById("_systemNoticeIframe");
    }
    if(!iframe) {
        alert('An error occured and the system was unable to create a window to display the related information');
        return;
    }

    noticeDiv.style.position = 'absolute';
    noticeDiv.style.display = '';
    iframe.style.display = '';

    var docwidth = document.body.offsetWidth;

    leftPos = (docwidth / 2) - (noticeDiv.offsetWidth / 2);
    topPos  = 120;


    noticeDiv.style.top     = topPos;
    noticeDiv.style.left    = leftPos;

    iframe.style.top = topPos;
    iframe.style.left = leftPos;
    iframe.style.border=20;

    // rct = noticeDiv.getClientRects();

    // the -3 is for the dropshadow
    iframe.style.width = noticeDiv.offsetWidth - 3;
    iframe.style.height = noticeDiv.offsetHeight - 3;
    iframe.style.zIndex = 1;
    noticeDiv.style.zIndex = 2;
}


function fudgeaframe(name) {
    if(!name) {
        name = "FUDGEFRAME";
    }

    var iframe = document.createElement('IFRAME');
    iframe.id = name;
    iframe.style.display = "none";
    iframe.style.position = "absolute";
    iframe.style.border = 0;
    iframe.width = 0;
    iframe.height = 0;
    iframe.src = "/assets/blank.html";

    document.body.appendChild(iframe);
}

function closeHelpOptions(e, table_id) {
    iframe = document.getElementById("FUDGEFRAME");
    options_layer = document.getElementById(table_id);
    options_layer.style.display  = "none";
    iframe.style.display = "none";
}

function showHelpOptions(e, table_id) {
    iframe = document.getElementById("FUDGEFRAME");
    options_layer = document.getElementById(table_id);
    if(!iframe) {
        fudgeaframe();
        iframe = document.getElementById("FUDGEFRAME");
    }
    if(!iframe) return;
    if(!e.srcElement) {
        obj = e.currentTarget;
    } else {
        obj = e.srcElement;
    }

    leftPos =  obj.offsetLeft;
    topPos  =  obj.offsetTop;

    while ((obj = obj.offsetParent) != null) {
        leftPos += obj.offsetLeft;
        topPos  += obj.offsetTop;
    }

    if(options_layer.style.display == '') {
        closeHelpOptions(e, table_id);
    } else {
        options_layer.style.display = '';
        iframe.style.display = '';

        options_layer.style.top     = topPos+20;
        options_layer.style.left    = (leftPos-164);

        iframe.style.top = topPos+20;
        iframe.style.left = leftPos-164;

        rct = options_layer.getClientRects();

        // the -3 is for the dropshadow
        iframe.width = rct[0].right - rct[0].left - 3;
        iframe.height = rct[0].bottom - rct[0].top - 3;
        iframe.style.zIndex = 1;
        options_layer.style.zIndex = 2;
    }

}

function posthref(url, target, postform) {
    var url_break = url.indexOf('?');
    var getdata = '';
    if (url_break != -1) {
        getdata = url.substr(url_break + 1);
    }

    var href_data_ok = (url.length < 1024 || url_break == -1 || getdata.length == 0);

    if (!postform && href_data_ok) {
        // small url or no get vars and not explicitly posting a form
        if (target) {
            window.open(url, target);
        } else {
            location.href = url;
        }
    } else {
        // long url or explicitly posting a form
        var page = href_data_ok ? url : url.substr(0,url_break);

        var use_fake_form = !postform;
        var doc = null;

        if (use_fake_form) {
            // make form here
            postform = document.createElement("FORM");
            postform.method = "POST";
            postform.style.display = "none";
            doc = document;
        } else {
            doc = postform.ownerDocument;
        }

        postform.action = page;
        if (target) {
            postform.target = target;
        }

        if (!href_data_ok) {
            var fakegetinput = doc.createElement("INPUT");
            fakegetinput.name = "__v6_fg";
            fakegetinput.value = getdata;
            fakegetinput.type = "hidden";
            postform.appendChild(fakegetinput);
        }

        if (use_fake_form) {
            document.body.appendChild(postform);
        }
        postform.submit();
    }
}

location.posthref = posthref;


function closeMessageBubble() {
    page_msg_bubble.hide();
    if (ie) {
        page_msg_bubble.info_bubble.detachEvent('onmousedown', closeMessageBubble,false);
    } else {
        page_msg_bubble.info_bubble.removeEventListener('mousedown',  closeMessageBubble, false);
    }
}


function checkForPageMessage() {
    if (msg_img = document.getElementById('ui_page_message')) {

        msg_span = document.getElementById('ui_page_message_span');

        page_msg_bubble.setMessage(msg_img.getAttribute('message'));
        page_msg_bubble.setObjectToDisplayFrom(msg_img);
        page_msg_bubble.setPointerVerticalDirection(BOTTOM, (arguments.length > 0 ? arguments[0] : true));
        page_msg_bubble.setAutoScroll(false);

        if (ie) {
            page_msg_bubble.info_bubble.attachEvent('onclick', closeMessageBubble);
        } else {
            page_msg_bubble.info_bubble.addEventListener('mousedown',  closeMessageBubble, false);
        }

        msg_span.innerHTML = msg_img.getAttribute('message').entityTags();

        // disply the bubble in half a seccond
        setTimeout('page_msg_bubble.display();', 500);

        // Close the bubble
        setTimeout("closeMessageBubble()", 3000);
    }
}






var drag_obj = new Object();


/*
 * startDraging();
 *
 * This function handles the onmousemove event and actualy moves the element around the page.
 *
 */

function startDraging(e) {
    // Now lets work out where the mouse is on the screen
    if (ie) {
        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
    } else {
        x = e.clientX + window.scrollX;
        y = e.clientY + window.scrollY;
    }

    move_x = (drag_obj.element_start_x  + x - drag_obj.cursor_start_x);
    move_y = (drag_obj.element_start_y  + y - drag_obj.cursor_start_y);

    // Lets move the item to that position
    drag_obj.element.style.left = move_x;
    drag_obj.element.style.top  = move_y;

    if (drag_obj.hidden_iframe) {
        drag_obj.hidden_iframe.style.display    = '';
        drag_obj.hidden_iframe.style.width      = drag_obj.element.clientWidth;
        drag_obj.hidden_iframe.style.height     = drag_obj.element.clientHeight;
        drag_obj.hidden_iframe.style.left       = move_x + 'px';
        drag_obj.hidden_iframe.style.top        = move_y + 'px';
    }

    if (ie) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    } else {
        e.preventDefault();
    }

}


/*
 * endDrag();
 *
 * This function gets called on mouse release and kills all draging.
 */

function endDrag(e) {

    // For if the bubble is hanging from the object thats being moved we need to move the bubble aswell.
    if (wizard && wizard.in_progress) {
        if (wizard.info_bubble && !wizard.info_bubble.can_drag) {
            wizard.info_bubble.reposition(true);
        }
    }

    // Lets turn off the events now they've let their mouse up.
    if (ie) {
        document.detachEvent("onmousemove", startDraging);
        document.detachEvent("onmouseup",   endDrag);
    } else {
        document.removeEventListener("mousemove", startDraging,   true);
        document.removeEventListener("mouseup",   endDrag, true);
    }

}

/*
 * beginDrag();
 *
 * This basicly just sets up drag_obj and page events to handle the drag.
 *
 */

function beginDrag(e, id, iframe_id) {

    // Get the object that fired the event
    if (id) {
        drag_obj.element = document.getElementById(id);
    } else {
        drag_obj.element = getObjectFromEvent(e);
    }

    // Lets also keep track of that iframe which lives under it so we can move it aswell.
    if (iframe_id && !ie5) {
        drag_obj.hidden_iframe = document.getElementById(iframe_id);
    }

    // Check it wasnt a text node
    if (drag_obj.element.nodeType == 3) {
        drag_obj = drag_obj.parentNode;
    }

    // Now lets work out where the mouse is on the screen
    if (ie) {
        x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
        y = window.event.clientY + document.documentElement.scrollTop  + document.body.scrollTop;
    } else {
        x = e.clientX + window.scrollX;
        y = e.clientY + window.scrollY;
    }

    // Lets keep ahold of the original posision
    drag_obj.cursor_start_x  = x;
    drag_obj.cursor_start_y  = y;
    drag_obj.element_start_x = parseInt(drag_obj.element.style.left, 10);
    drag_obj.element_start_y = parseInt(drag_obj.element.style.top,  10);


    // Now we have all the details we need we can attach some events to the document.
    if (ie) {
        document.attachEvent("onmousemove", startDraging);
        document.attachEvent("onmouseup",   endDrag);

        window.event.cancelBubble = true;
        window.event.returnValue = false;
    } else {
        document.addEventListener("mousemove", startDraging,   true);
        document.addEventListener("mouseup",   endDrag, true);
        e.preventDefault();
    }

}



/* Gets a value from a cookie */
function getCookieValue(name) {
    var c = document.cookie;
    var prefix = name + "=";
    var start = c.indexOf("; " + prefix);

    if (start == -1) {
        start = c.indexOf(prefix);
        if (start != 0) {
            return null;
        }
    } else {
        start += 2;
    }

    var end = c.indexOf(";", start);

    if (end == -1) {
        end = c.length;
    }

    return c.substring(start + prefix.length, end);
}




//http://tech.irt.org/articles/js064/index.htm
if (typeof(getCookie) == 'undefined') {
    function getCookie(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));
    }
}

if (typeof(setCookie) == 'undefined') {
    function setCookie(name, value, expires, path, domain, secure) {
        document.cookie = name + '=' + escape(value) +
            (typeof(expires) != 'undefined' && expires ? ';expires=Sun 01-Jan-2030 00:00:00 UTC' : '') +
            (typeof(path)    != 'undefined' && path    ? ';path=' + path                         : '') +
            (typeof(domain)  != 'undefined' && domain  ? ';domain=' + domain                     : '') +
            (typeof(secure)  != 'undefined' && secure  ? ';secure'                               : '');
    }
}

if (typeof(deleteCookie) == 'undefined') {
    function deleteCookie(name,path,domain) {
        if (getCookie(name)) document.cookie = name + "=" +
            ( (path) ? ";path=" + path : "") +
            ( (domain) ? ";domain=" + domain : "") +
            ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}


/*
 * findPosX()
 */
function findPosX(obj,include_scroll) {
    var curleft = 0;
    if (obj != null) {
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft
                obj = obj.offsetParent;

            }
        } else if (obj.x) {
            curleft += obj.x;
        }
        if (include_scroll) {
            curleft = curleft-obj.scrollLeft;
        }
    }

    return curleft;
}


/*
 * findPosY()
 */
function findPosY(obj,include_scroll) {
    var curtop = 0;

    if (obj != null) {
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        } else if (obj.y) {
            curtop += obj.y;
        }

        if (include_scroll) {
            curtop = curtop-obj.scrollTop;
        }
    }

    return curtop;
}

/*
 * getModalDialogWindowHeight()
 */

function getModalDialogWindowHeight(height) {
    if (ie7) {
        var estimated_total_chrome_elements_height = 45;
        return height-estimated_total_chrome_elements_height + 'px';
    } else if (ie8) {
        var estimated_total_chrome_elements_height = 60;
        return height-estimated_total_chrome_elements_height + 'px';
    } else    {
        return height + 'px';
    }
}

/*
 * getModalDialogWindowWidth()
 */

function getModalDialogWindowWidth(width) {
    if (ie7) {
        var estimated_total_chrome_elements_width = 4;
        return width-estimated_total_chrome_elements_width + 'px';
    } else {
        return width + 'px';
    }
}

/*
 * startWizard();
 */

function startWizard(wizard_to_start, step_to_start_at) {

    if (!step_to_start_at) {
        step_to_start_at = 0;
    }

    setCookie('wizard_mode', wizard_to_start, null, '/');
    setCookie('wizard_step', step_to_start_at, null, '/');

    location.href = 'wizard_begin.php';
}


function checkWizard(cmd, obj, e) {

    // netscape window.event hack
    if (typeof(window.event) == 'undefined' && e) {
        window.event = e;
    }

    if (wizard) {
        if (wizard.in_progress) {

            if ((obj) && (obj.id == steps[(wizard.current_step-1)].id)) {
                // BB-3249
                // check if this is now the last step, bit of a :SHONK: as the
                // final step of 33 is hard coded, will need to change if steps
                // change in the future
                if (steps[wizard.current_step - 1].next_step == 33) {
                    // wizard is complete so we'll modify the url
                    if (/^location\.href/.test(cmd)) {
                        // replace so we can let the dashboard know
                        var regExp = new RegExp('^(location\.href=[\'"]*[\\w\\d:\/\.]*)([\'"]*)');
                        cmd = cmd.replace(regExp, '$1?wc=1$2');
                    }
                }

                // they clicked a menu which was available to be clicked while in the wizard
                eval(cmd);
            }  else {
                // They clicked someth8ing that wasnt available in the wizard
                wizard.confirmLeave(cmd);
            }
        } else {
            eval(cmd);
        }
    } else {
        eval(cmd);
    }
}





function moveSelectOption(field_name) {

    if ((arguments.length == 3) && (arguments[2] == 'transfer')) {

        var from_sel = document.getElementById(arguments[0]);
        var to_sel = document.getElementById(arguments[1]);

        for (i=0; i < from_sel.options.length; i++) {
            var current = from_sel.options[i];
            if (current.selected) {
                to_sel.options[to_sel.length] = new Option(current.text,current.value);
                from_sel.options[i] = null;
                i--;
            }
        }

        if (typeof(window.updateHidden) != 'undefined') {
            updateHidden();
        }

    } else if (arguments.length == 2) {

        var to = arguments[1];

        osel = document.getElementById(field_name);
        swap_index  = osel.selectedIndex + ((to == 'up') ? -1 : 1);

        if ((osel.selectedIndex >= 0) && (swap_index < osel.options.length && swap_index >= 0)) {

            current     = osel[osel.selectedIndex];
            to_swap     = osel[swap_index];
            var parent  = current.parentNode;
            var swaped  = parent.replaceChild(current, to_swap);

            parent.insertBefore(swaped, (to=='up') ? current.nextSibling : current);
        }

        if (typeof(window.updateHidden) != 'undefined') {
            updateHidden();
        }

    }

}



function selectAllDropdownOptions(dropdown) {
    if (dropdown) {
        for (var i = 0; i < dropdown.options.length; i++) {
            dropdown[i].selected = true;
        }
    }

}


function delayedConfirm(e, seconds, q, url, w, h, msg_type, form_name, disable_button, send_inputs, c_width, c_height, callback_function) {
    if (!msg_type) {
        msg_type = 'warning';
    }

    // BB-4834: Add a callback function to use it in the load event of the /main/confirm.php page
    var cb_function = '';
    if (typeof callback_function != 'undefined') {
        cb_function = '&cb=' + callback_function;
    }
    return win = openWindow(e, '/main/confirm.php?q='+ escape(q) +'&w='+w+'&h='+h+'&s='+seconds+'&u='+escape(url)+'&type='+escape(msg_type)+'&o='+form_name+'&p='+(send_inputs ? 1 : 0)+cb_function, c_width ? c_width : 360, c_height ? c_height : 176);
}

function delayedConfirmOk(e, url, w, h, form_name, disable_button, post_this_form_variables) {
    if (disable_button && opener.document.getElementById(disable_button)) {
        opener.document.getElementById(disable_button).disabled = true;
    }

    if (url == 'sms' || url == 'post') {
        if (form_name != '' && opener.document.forms[form_name]) {
            opener.document.forms[form_name].submit();
        } else {
            opener.document.forms[0].submit();
        }
    } else if (url == 'func') {
        eval(form_name);
    } else {
        if (post_this_form_variables != undefined && post_this_form_variables) {
            var submit_form = document.getElementById('confirm_submit_form');
            if (!window.opener.name) {
                window.opener.name = "confirm_submit_target";
            }
            if (window.opener['posthref_variables']) {
                var url_break = (url.indexOf('?') != -1) ? '&' : '?';
                url = url + url_break + window.opener['posthref_variables'];
            }
            window.opener.posthref(url, window.opener.name, submit_form);
        } else if (url) {
            if (w == 0 && h == 0) {
                // BB-3639 When we need to pass long values in variables through the URL to perform an action
                // we should use "posthref" instead of "location.href". E.g: when deleting contacts from a database
                // and the user select around 1000 records to delete.
                if (window.opener['posthref_variables']) {
                    var url_break = (url.indexOf('?') != -1) ? '&' : '?';
                    window.opener.posthref(url + url_break + window.opener['posthref_variables']);
                } else {
                    window.opener.location.href = url;
                }
            } else {
                win = opener.openWindow(e, url, w, h);
                win.focus;
            }
        }
        // else do nothing, just close this window
    }

    window.close();
}

function closeWindowRefreshOpener(msg) {

    var url_obj = new Url(opener.location.href);
    url_obj.setVar('msg', escape(msg));
    opener.location.href = url_obj.getUrl();
    opener.focus();
    window.close();
}

function launchAdvancedSearch(e, script){
    var win = openWindow(e,package_root + '/' + script,650,450);
    return win;
}
function clearAdvancedSearch(e, caller) {
    document.location = package_root + '/' + caller;
}


function updateKickoutCountdown(diff_seconds) {

    var no_kickout_bar = false;

    if (window.parent && window.parent.frames) {
        for (var i = 0, frame; frame = window.parent.frames[i]; i ++) {
            if (frame == window) {
                no_kickout_bar = true;
            }
        }
    }

    if (window.opener && typeof window.opener != 'undefined') {
        no_kickout_bar = true;
    }

    if (no_kickout_bar) {
        document.getElementById('kickout_timer_background').style.display = 'none';
        document.getElementById('kickout_timer_text').style.display = 'none';
        return;
    }

    if (diff_seconds < 0) {
        document.location = document_root + '/logout.php';
    }

    var seconds = diff_seconds % 60;
    var tmp_minutes = Math.floor(diff_seconds / 60);
    var minutes = tmp_minutes % 60;
    var hours = Math.floor(tmp_minutes / 60);
    var s = (hours > 0 ? hours + ' hours, ' : '') + (minutes > 0 ? minutes + ' minutes, ' : '') + (seconds < 10 ? '0' + seconds : seconds) + ' seconds';

    if (ie) {
        var div = document.getElementById('kickout_timer_background');
        div.parentNode.removeChild(div);
        document.body.appendChild(div);
        /*
        div = document.createElement('div');
        div.style.backgroundColor = '#336600';
        div.style.width = '100%';
        document.body.appendChild(div);
        */
        // div.style.width = document.body.clientWidth;
    }

    var div = document.getElementById('kickout_timer_text_time');
    div.innerHTML = s;
    diff_seconds -= 1;
    setTimeout('updateKickoutCountdown(' + diff_seconds + ')', 1000);
}


function showSystemNotification(message) {
    var no_message_bar = false;

    if (!message) {
        return;
    }

    if (window.parent && window.parent.frames) {
        for (var i = 0, frame; frame = window.parent.frames[i]; i ++) {
            if (frame == window) {
                no_message_bar = true;
            }
        }
    }

    if (window.opener && typeof window.opener != 'undefined') {
        no_message_bar = true;
    }

    if (no_message_bar) {
        if (document.getElementById('notification_bar')) {
            document.getElementById('notification_bar').style.display = 'none';
        }
        return;
    } else {
        if (!document.getElementById('notification_bar')) {
            var bar = document.createElement('div');
            bar.id = 'notification_bar';
            bar.title = 'Click to dismiss';
            var text = document.createElement('span');
            text.id = 'notification_text';
            bar.appendChild(text);
            if (ie) {
                bar.className = 'ie6';  // add fixed positioning hacks with css expressions
            }
            bar.onclick = function(e) {
                this.style.display = 'none';
            };
            document.body.appendChild(bar);
        }
        document.getElementById('notification_bar').style.display = 'block';
    }

    if (ie) {
        var div = document.getElementById('notification_bar');
        div.parentNode.removeChild(div);
        document.body.appendChild(div);
    }

    var div = document.getElementById('notification_text');
    div.innerHTML = '<img alt="Information" align="absmiddle" src="' + document_root + '/assets/images/info.gif" /> ' + message;
}

/*
 * repositionDisableDivs()
 *
 * This gets called when the window is resized and goes through all disable_div objects
 * and updates there position on the page.
 */

// Keep all objects in an array so they can be repositioned when the window is resized
var v6_disable_divs = new Array();



function repositionDisableDivs() {
    for (var i = 0; i < v6_disable_divs.length; i ++) {
        var a = true;
        if (arguments.length && (arguments[0] instanceof Array) && arguments[0].length) {
            for (var j = 0, dd_id; dd_id = arguments[0][j]; j ++) {
                if (dd_id == v6_disable_divs[i].id) {
                    a = false;
                    break;
                }
            }
        }
        if (a) {
            v6_disable_divs[i].positionDiv();
        }
    }
}




function showHideProgressIndicators() {
    if (typeof ProgressIndicators != 'undefined') {
        ProgressIndicators.showHide();
    }
}



function showHideSliders() {
    if (typeof Sliders != 'undefined') {
        Sliders.showHide();
    }
}



// Prevents users from having to click twice on flash objects to enable them
// See http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/activating_activex.asp
function activateObjectElements() {
    if (ie) {
        // Yes, modifying an OBJECT's outerHTML prevents the user
        // from having to click to enable the object
        objects = document.getElementsByTagName("object");
        for (i=0; i < objects.length; i++) {
            objects[i].outerHTML = objects[i].outerHTML;
        }
    }
}

function getRealPos(el,which) {
    iPos = 0
    while (el != null) {
        if(el.style.overflow == 'scroll' || el.style.overflowX == 'scroll' || el.style.overflowY == 'scroll'){
            iPos -= el['scroll'+ which];
        }
        iPos += el["offset" + which];
        el = el.offsetParent;
    }
    return iPos
}

function passwordStrength(str, uname) {
    if (!str || typeof(str) == 'undefined' || str.length < 8) {
        if (str.length == 0) {
            return {strength: 0, error: 1, text: '&nbsp;'};
        }
        return {strength: 0, error: 1, text: 'The password is not long enough'};
    } else {
        var length = str.length;

        //check for a couple of bad passwords:
        if (uname && str.toLowerCase() == uname.toLowerCase()) {
            return{strength: 0, error:4, text: 'Password cannot be the same as your Username'};
        }
        if (str.toLowerCase() == 'password') {
            return {strength: 0, error: 3, text: 'Password is too common'};
        }

        //see if there are 3 consecutive chars (or more) and fail!
        var consecutives = str.match(/(.)\1{2}/g);
        if (consecutives) {
            return {strength: 0, error: 2, text: 'Too many consecutive characters'};
        }

        //count the number of numerics
        var numbers = str.match(/\d/g);
        if (numbers) {
            numbers = numbers.length
        } else {
            var numbers = 0;
        }

        //count the number of uppercase chars
        var uppers = str.match(/[A-Z]/g);
        if (uppers) {
            uppers = uppers.length
        } else {
            var uppers = 0;
        }

        //count the number of non-alhpa-num chars
        var others = str.match(/[^A-z0-9]/g);
        if (others) {
            others = others.length
        } else {
            var others = 0;
        }

        //and weigh them all up.
        if (others > 1 || (uppers > 1 && numbers > 1)) {
            //strongest
            return {strength: 5, error: 0, text: 'Strongest'};
        } else if ((uppers > 0 && numbers > 0) || length > 14) {
            //very strong
            return {strength: 4, error: 0, text: 'Very Strong'};
        } else if (uppers > 0 || numbers > 2 || length > 9) {
            //strong
            return {strength: 3, error: 0, text: 'Strong'};
        } else if (numbers > 1) {
            //good
            return {strength: 2, error: 0, text: 'Fair'};
        }
        //fair
        return {strength: 1, error: 0, text: 'Weak'};
    }
}


function switch_debug_mode(mode) {
    if (mode == 1) {
        xmlhttpCall('POST', refreshPage, '/xmlhttp/switch_debug_mode.php?debug_mode=on');
    } else {
        xmlhttpCall('POST', refreshPage, '/xmlhttp/switch_debug_mode.php?debug_mode=off');
    }
}

function refreshPage(response) {
    this.location.reload(true);
}

// Works in the same manner as Date.parse() - returns a UNIX timestamp.
Date.parseTimestamp = Date.prototype.parseTimestamp = function (stamp_date_val) {
    //first make sure we have a datetime string
    if (stamp_date_val.match(/^\d{4}\-\d{2}\-\d{2}$/)) {             // no time!
        stamp_date_val += ' 00:00:00';
    }
    if (stamp_date_val.match(/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}$/)) { // no seconds!
        stamp_date_val += ':00';
    }
    var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts = stamp_date_val.replace(regex, '$1 $2 $3 $4 $5 $6').split(' ');
    var d = new Date(parts[0], Number(parts[1])-1, parts[2], parts[3], parts[4], parts[5]);
    return d.getTime();
}


// Provide compatibility on pages also using the Prototype JS library;
//   access jQuery via the "JQ" object, and Prototype as usual with "$"
function initJQ() {
    if (typeof(jQuery) != 'undefined' && !JQ) {
        JQ = jQuery.noConflict();
    }
}

if (typeof(JQ) == 'undefined') {
    var JQ = false;
}



// Context Sensitive Help

var ContextHelp = {
    window_obj: false,
    wrapper_obj: false,
    button_obj: false,
    ie_button_obj: false,
    timer_obj: false,
    over_start_init: false,
    out_start_init: false,
    ignore_click: false,
    ignore_click_timer_obj: false,
    ie6_iframe: false,

    stopEvent: function(e) {
        var target_obj = false;

        if (typeof(e) == 'object') {
            if (typeof(e.stopPropagation) != 'undefined') {
                e.stopPropagation();
                target_obj = e.target;
            } else {
                target_obj = e;
            }
        }

        if (typeof(event) != 'undefined' && typeof(event.cancelBubble) != 'undefined') {
            event.cancelBubble = true;
            target_obj = event.srcElement;
        }

        return target_obj;
    },

    init: function() {
        ContextHelp.wrapper_obj = document.getElementById('cshelp_outer');

        if (ContextHelp.wrapper_obj) {
            ContextHelp.button_obj = ContextHelp.wrapper_obj.getElementsByTagName('h3')[0];

            if (ie) {
                ContextHelp.ie_button_obj = ContextHelp.button_obj;
                ContextHelp.button_obj = document.getElementById('cshelp_inner');
            }

            ContextHelp.wrapper_obj.onmouseover = ContextHelp.overStart;
            ContextHelp.wrapper_obj.onmouseout = ContextHelp.outStart;
            ContextHelp.button_obj.onclick = ContextHelp.clickButton;

            var help_items = ContextHelp.wrapper_obj.getElementsByTagName('a'), help_itemsc = help_items.length;

            for (var i = 0; i < help_itemsc; i++) {
                help_items[i].onclick = ContextHelp.follow;
            }

            if (ie) {
                ContextHelp.button_obj.onmouseover = ContextHelp.overButtonIE;
                ContextHelp.button_obj.onmouseout = ContextHelp.outButtonIE;
                help_items = document.getElementById('cshelp_lists').getElementsByTagName('ul');
                help_itemsc = help_items.length;

                for (i = 0; i < help_itemsc; i++) {
                    help_items[i].getElementsByTagName('li')[0].className = 'first';
                }

                if (!ie7) {
                    ContextHelp.ie6_iframe = document.getElementById('cshelp_iframe');

                    if (!ContextHelp.ie6_iframe) {
                        fudgeaframe('cshelp_iframe');
                        ContextHelp.ie6_iframe = document.getElementById('cshelp_iframe');
                    }
                }
            }

            if (in_array('notify', ContextHelp.wrapper_obj.className.split(' '))) {
                ContextHelp.notify.start();
            }
        }
    },

    shown: function() {
        return in_array('show', ContextHelp.wrapper_obj.className.split(' '));
    },

    overButtonIE: function(e) {
        ContextHelp.ie_button_obj.className = 'over';
    },

    outButtonIE: function(e) {
        ContextHelp.ie_button_obj.className = '';
    },

    overStart: function(e) {
        var target_obj = ContextHelp.stopEvent(e);

        if (ContextHelp.shown()) {
            if (ContextHelp.out_start_init) {
                ContextHelp.out_start_init = false;
                window.clearInterval(ContextHelp.timer_obj);
            }
        } else if (!ContextHelp.over_start_init) {
            ContextHelp.timer_obj = window.setInterval(ContextHelp.overAction, 250);
            ContextHelp.over_start_init = true;
        }
    },

    overAction: function() {
        if (ContextHelp.over_start_init && !ContextHelp.out_start_init) {
            ContextHelp.over_start_init = false;
            window.clearInterval(ContextHelp.timer_obj);
            if (!ContextHelp.shown()) {
                ContextHelp.showList();
            }
            ContextHelp.ignore_click = true;
            ContextHelp.ignore_click_timer_obj = window.setInterval(ContextHelp.allowClick, 750);
        }
    },

    clickButton: function(e) {
        var target_obj = ContextHelp.stopEvent(e);

        if (!ContextHelp.ignore_click) {
            if (ContextHelp.shown()) {
                ContextHelp.hideList();
            } else {
                ContextHelp.showList();
            }
        }
    },

    allowClick: function() {
        ContextHelp.ignore_click = false;
        window.clearInterval(ContextHelp.ignore_click_timer_obj);
    },

    outStart:function(e) {
        var target_obj = ContextHelp.stopEvent(e);

        if (!ContextHelp.shown()) {
            if (ContextHelp.over_start_init) {
                ContextHelp.over_start_init = false;
                window.clearInterval(ContextHelp.timer_obj);
            }
        } else if (!ContextHelp.out_start_init) {
            ContextHelp.timer_obj = window.setInterval(ContextHelp.outAction, 500);
            ContextHelp.out_start_init = true;
        }
    },

    outAction: function() {
        if (ContextHelp.out_start_init && !ContextHelp.over_start_init) {
            ContextHelp.out_start_init = false;
            window.clearInterval(ContextHelp.timer_obj);
            ContextHelp.timer_obj = false;
            ContextHelp.hideList();
        }
    },

    showList: function() {
        if (ContextHelp.ie6_iframe && ContextHelp.ie6_iframe.clientWidth == 0) {
            var lists_obj = document.getElementById('cshelp_lists');
            lists_obj.style.visibility = 'hidden';
            ContextHelp.ie6_iframe.style.backgroundColor = '#fff';
        }

        ContextHelp.wrapper_obj.className += ' show';
        ContextHelp.wrapper_obj.className = ContextHelp.wrapper_obj.className.trim();

        if (ContextHelp.ie6_iframe) {
            ContextHelp.ie6_iframe.style.display = 'block';

            if (ContextHelp.ie6_iframe.clientWidth == 0) {
                ContextHelp.ie6_iframe.style.left = findPosX(lists_obj) + 'px';
                ContextHelp.ie6_iframe.style.top = findPosY(lists_obj) + 'px';
                ContextHelp.ie6_iframe.style.width = (lists_obj.clientWidth + 2) + 'px';
                ContextHelp.ie6_iframe.style.height = (lists_obj.clientHeight + 2) + 'px';
                lists_obj.style.visibility = 'visible';
                ContextHelp.ie6_iframe.style.zIndex = 1;
            }
        }

        var a_els = ContextHelp.wrapper_obj.getElementsByTagName('A');

        if (a_els.length > 0 && typeof(a_els[0].focus) != 'undefined') {
            a_els[0].focus();
            a_els[0].blur();
        }

        var tracker_img = new Image();
        var tracker_url = document_root + '/main/contexthelp_usage.php?page_uri=' + encodeURIComponent(location.pathname) + '&t=d';
        tracker_url += '&nc=' + (new Date().getTime());
        tracker_img.src = tracker_url;
    },

    hideList: function() {
        if (ContextHelp.ie6_iframe) {
            ContextHelp.ie6_iframe.style.display = 'none';
        }

        ContextHelp.wrapper_obj.className = ContextHelp.wrapper_obj.className.replace(/show/g, '').trim();
    },

    follow: function(e_or_href) {
        var target_href = '';

        if (typeof(e_or_href) == 'string') {
            target_href = e_or_href;
            e_or_href = null;
        } else {
            var target_obj = ContextHelp.stopEvent(e_or_href);

            if (typeof(target_obj) == 'object' && typeof(target_obj.blur) != 'undefined') {
                target_obj.blur();
            }

            while (typeof(target_obj) == 'object' && target_obj.tagName.toLowerCase() != 'a') {
                target_obj = target_obj.parentNode;
            }

            if (typeof(target_obj) == 'object') {
                target_href = getHref(target_obj);

                if (typeof(e_or_href) == 'undefined' || (typeof(e_or_href.tagName) != 'undefined' && e_or_href.tagName != '')) {
                    e_or_href = null;
                }
            }
        }

        if (ContextHelp.timer_obj) {
            window.clearInterval(ContextHelp.timer_obj);
            ContextHelp.timer_obj = false;
        }

        if (ContextHelp.wrapper_obj) {
            ContextHelp.hideList();
        }

        if (target_href) {
            target_href = document_root + '/main/contexthelp_usage.php?url=' + encodeURIComponent(target_href) + '&t=o';
            if (target_obj && target_obj.id && target_obj.id == 'kc') {
                showKnowledgeCentre(e_or_href);
                return false;
            }
            var item_id = (target_obj.id ? target_obj.id.replace('cshelp_item_', '') : 0);
            target_href += '&page_uri=' + encodeURIComponent(location.pathname) + '&item_id=' + encodeURIComponent(item_id);
            target_href += '&nc=' + (new Date().getTime());
            openWindow(e_or_href, target_href, 760, 570, 'resize=no,toolbars=no,scrollbars=no', 'ContextHelp', false);
        } else {
            alert('An error occurred attempting to show the selected help item. Please try again later.');
        }

        return false;
    },

    notify: {
        initial_value: 221,
        current_value: 0,
        current_cycle: 0,
        max_cycles: 3,
        inc: 3,
        delay: 3,
        min: 153,
        max: 238,
        timer_obj: null,

        start: function() {
            ContextHelp.notify.current_value = ContextHelp.notify.initial_value;
            ContextHelp.notify.timer_obj = window.setInterval(ContextHelp.notify.cycle, ContextHelp.notify.delay);
        },

        cycle: function() {
            if (isNaN(ContextHelp.notify.current_value)) {
                window.clearInterval(ContextHelp.notify.timer_obj);
                return false;
            }

            ContextHelp.notify.current_value += ContextHelp.notify.inc;

            if (ContextHelp.notify.inc > 0) {
                if (ContextHelp.notify.current_value >= ContextHelp.notify.max) {
                    ContextHelp.notify.inc = -ContextHelp.notify.inc;
                    ContextHelp.notify.current_value = ContextHelp.notify.max;
                } else if (ContextHelp.notify.current_value >= ContextHelp.notify.initial_value && ContextHelp.notify.current_cycle >= ContextHelp.notify.max_cycles) {
                    ContextHelp.notify.current_value = ContextHelp.notify.initial_value;
                    window.clearInterval(ContextHelp.notify.timer_obj);
                    ContextHelp.notify.timer_obj = false;
                }
            } else {
                if (ContextHelp.notify.current_value <= ContextHelp.notify.min) {
                    ContextHelp.notify.inc = -ContextHelp.notify.inc;
                    ContextHelp.notify.current_value = ContextHelp.notify.min;
                    ContextHelp.notify.current_cycle++;
                }
            }

            if (ContextHelp.notify.timer_obj) {
                ContextHelp.button_obj.style.borderColor = 'rgb(' + ContextHelp.notify.current_value + ', ' + ContextHelp.notify.current_value + ', ' + ContextHelp.notify.current_value + ')';
            } else {
                ContextHelp.button_obj.style.borderColor = '';
            }
        }
    }
};



// Notification box handler/animator

var UINotifier = {
    display_obj:    false,
    timer_obj:      false,
    target_height:  false,
    current_height: false,

    startTimer: function() {
        UINotifier.clearTimer();
        UINotifier.timer_obj = window.setTimeout(UINotifier.takeStep, 28);
    },

    clearTimer: function() {
        if (UINotifier.timer_obj) {
            window.clearTimeout(UINotifier.timer_obj);
            UINotifier.timer_obj = false;
        }
    },

    takeStep: function() {
        UINotifier.current_height           = Math.min(UINotifier.current_height + 3, UINotifier.target_height);
        UINotifier.display_obj.style.height = UINotifier.current_height + 'px';
        var opacity_value = UINotifier.current_height / UINotifier.target_height;

        if (UINotifier.current_height < UINotifier.target_height) {
            UINotifier.startTimer();
        } else {
            opacity_value = 0.9999999999;
        }

        UINotifier.display_obj.style.MozOpacity = opacity_value;
        UINotifier.display_obj.style.opacity    = opacity_value;
        UINotifier.display_obj.style.filter     = 'Alpha(style=0, opacity=' + (opacity_value * 100) + ')';
    },

    position: function() {
        // :TODO:
        var top  = 0;
        var left = 0;

        if (ie) {
            left = document.body.clientWidth  - 320;
            top  = document.body.clientHeight - 105;
        } else {
            left = window.innerWidth  - 350;
            top  = window.innerHeight - 80;
        }

        UINotifier.display_obj.style.top  = top  + 'px';
        UINotifier.display_obj.style.left = left + 'px';
    },

    init: function() {
        UINotifier.display_obj = document.getElementById('notification_box');

        if (UINotifier.display_obj) {
//            UINotifier.position();    // :TODO: get it right
            UINotifier.target_height                = UINotifier.display_obj.offsetHeight || UINotifier.display_obj.clientHeight;
            UINotifier.current_height               = 0;
            UINotifier.display_obj.style.height     = '0px';
            UINotifier.display_obj.style.visibility = 'visible';
            UINotifier.startTimer();
            event_handler.addMethod(ONUNLOAD, 'UINotifier.unload()');
        }
    },

    unload: function() {
        UINotifier.target_height = null;
        UINotifier.timer_obj     = null;
        UINotifier.display_obj   = null;
    }
}

if (typeof(event_handler) != 'undefined' && event_handler) {
    event_handler.addMethod(ONLOAD, 'UINotifier.init()');
}


    // :NOTE: Entire content of common.js is now loaded, and won't be asked for again

}
