/* Minification failed. Returning unminified contents.
(5,4): run-time error CSS1031: Expected selector, found '('
(5,4): run-time error CSS1025: Expected comma or open brace, found '('
(9,8): run-time error CSS1031: Expected selector, found '='
(9,8): run-time error CSS1025: Expected comma or open brace, found '='
(11,4): run-time error CSS1031: Expected selector, found '('
(11,4): run-time error CSS1025: Expected comma or open brace, found '('
(76,25): run-time error CSS1031: Expected selector, found '='
(76,25): run-time error CSS1025: Expected comma or open brace, found '='
(89,1): run-time error CSS1019: Unexpected token, found '('
(89,11): run-time error CSS1031: Expected selector, found '('
(89,11): run-time error CSS1025: Expected comma or open brace, found '('
(116,2): run-time error CSS1019: Unexpected token, found '('
(116,9): run-time error CSS1031: Expected selector, found ')'
(116,9): run-time error CSS1025: Expected comma or open brace, found ')'
(118,1): run-time error CSS1019: Unexpected token, found '$'
(118,16): run-time error CSS1031: Expected selector, found '='
(118,16): run-time error CSS1025: Expected comma or open brace, found '='
 */

//CR Common Js

//requires jQuery
if (typeof jQuery === 'undefined') {
    throw new Error('this requires jQuery');
}

var cr = cr || {};

if (cr.common === undefined) {

    cr.common = (function ($) {
        'use strict';
        /*-----------------------------------------*/
        //  init
        /*-----------------------------------------*/
        log("core-init");

        var siteAbbreviation = "cr-cal";

        /*-----------------------------------------*/
        //  internal functions
        /*-----------------------------------------*/

        /*-----------------------------------------*/
        //  private functions
        /*-----------------------------------------*/
        function log(message) {
            if (console && console.log) {
                console.log(message);
            }
        }

        function noCacheParameter() {
            var d = new Date();
            return d.getTime();
        }

        function saveLocalStorage(name, obj) {
            localStorage.setItem("{0}-{1}-local-storage".format(siteAbbreviation, name), JSON.stringify(obj));
        }

        function getLocalStorage(name) {
            var objString = localStorage.getItem("{0}-{1}-local-storage".format(siteAbbreviation, name));
            if (objString && objString.length > 0) {
                return JSON.parse(objString);
            }
            return undefined;
        }

        function isValidEmailAddress(emailAddress) {
            var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
            return pattern.test(emailAddress);
        };


        /*-----------------------------------------*/
        //  public functions
        /*-----------------------------------------*/
        return {
            log: log,
            noCacheParameter: noCacheParameter,
            saveLocalStorage: saveLocalStorage,
            getLocalStorage: getLocalStorage,
            isValidEmailAddress: isValidEmailAddress
        };

    })(jQuery);
}


/*-----------------------------------------*/
//  Global Extention Methods
/*-----------------------------------------*/
String.prototype.format = String.prototype.format = function () {
    var s = this,
        i = arguments.length;

    while (i--) {
        s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
    }
    return s;
};


// adds .naturalWidth() and .naturalHeight() methods to jQuery
// for retreaving a normalized naturalWidth and naturalHeight.
(function ($) {
    var
        props = ['Width', 'Height'],
        prop;

    while (prop = props.pop()) {
        (function (natural, prop) {
            $.fn[natural] = (natural in new Image()) ?
                function () {
                    return this[0][natural];
                } :
                function () {
                    var
                        node = this[0],
                        img,
                        value;

                    if (node.tagName.toLowerCase() === 'img') {
                        img = new Image();
                        img.src = node.src,
                            value = img[prop];
                    }

                    return value;
                };
        }('natural' + prop, prop.toLowerCase()));
    }
}(jQuery));

$.fn.outerHTML = function () {

    // IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning
    return (!this.length) ? this : (this[0].outerHTML || (
      function (el) {
          var div = document.createElement('div');
          div.appendChild(el.cloneNode(true));
          var contents = div.innerHTML;
          div = null;
          return contents;
      })(this[0]));

}

