/**
* @author       Dan Beam (dan.beam@ticketmaster.com)
* @name         tm/og.js
* @fileOverview Container for London 2012 JS (behind root TM namespace)
*/

/** @namespace TM */
// set up global namespace (TM is the same as window.TM)
if (!("TM" in window)) { TM = {}; }

/** @module OG */
// set up module namespace
if (!("OG" in TM)) { TM.OG = {}; }

/**
* TM.OG.Util
* @submodule    TM.OG.Util
* @description  Utility object for random functions
* @usage        TM.OG.Util.doSomething([args]);
* @usage        var util = TM.OG.Util; util.doSomething([args]);
* @static
*/
TM.OG.Util = {
    /** 
    * TM.OG.Util.escapeHTMl
    * @description   Duplicating Prototype's String.prototype.escapeHTML function
    * @param         {string} str - string to escape
    */
    'escapeHTML' : function (str) {
        if ('string' !== typeof str) { throw 'TM.OG.Util.escapeHTML requires a string as an argument'; }
        return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
    },

    /** 
    * TM.OG.Util.stripTags
    * @description   Duplicating Prototype's String.prototype.stripTags function
    * @param         {string} str - string to strip tags from
    */
    'stripTags' : function (str) {
        if ('string' !== typeof str) { throw 'TM.OG.Util.stripTags requires a string as an argument'; }
        return str.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
    },

    /** 
    * TM.OG.Util.stripScripts
    * @description   Duplicating Prototype's String.prototype.stripScripts function
    * @param         {string} str - string to clean
    */
    'stripScripts' : function (str) {
        if ('string' !== typeof str) { throw 'TM.OG.Util.stripScripts requires a string as an argument'; }
        return str.replace(new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'img'), '');
    },

    /** 
    * TM.OG.Util.getUrlParam
    * @description   retrieves a param value from the url querystring
    * @param         {string} str - param to get value for
    */
    'getUrlParam' : function (str) {
        if ('string' !== typeof str) { throw 'TM.OG.Util.getUrlParam requires a string as an argument'; }
        var results = new RegExp('[\\?&]' + str + '=([^&#]*)').exec(window.location.href);
        if (!results) { return ''; }
        return results[1] || '';
    }
};

