﻿var Cowi = Cowi || {};

Cowi.Dn.Utils = {

    /**
    * Loads a number of javascript scripts by adding them to the head tag.
    * This function does not guarantee that the script has loaded when the function returns.
    * @param <array> scripts: an array of script paths
    */
    loadScripts: function (scripts) {
        var head = document.getElementsByTagName("head")[0];

        for (var i = 0; i < scripts.length; i++) {
            var script = scripts[i];

            var s = document.createElement("script");
            s.type = "text/javascript";
            s.src = script;
            s.async = true;

            head.appendChild(s);
        }
    },

    /**
    * Retrieve a parameter from an url
    */
    getParameterFromUrl: function (param) {
        param = param.toLowerCase();
        param = param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + param + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href.toLowerCase());
        if (results == null)
            return "";
        else
            return results[1];
    }
}
