﻿//This file contains functionality which appears at the top of the document as all Document ready functionality is placed at the bottom of the HTML document
var Header = {

    Default: (function () {

        function init() {
            window.onload = Header.OnLoadMgr.RunOnLoad;
            //Should be called if at least one contour form is on the page
        }

        return {
            init: init
        }
    })(),


    OnLoadMgr: (function () {

        var LoadInitList = [];

        function AddFunction(func) {
            LoadInitList.push(func);
        }

        function RunOnLoad() {
            for (x = 0; x < LoadInitList.length; x++) {
                var tmpFunc = new Function(LoadInitList[x]);
                tmpFunc();
            }
        }

        return {
            AddFunction: AddFunction,
            LoadInitList: LoadInitList,
            RunOnLoad: RunOnLoad
        }

    })(),

    DocReadyMgr: (function () {

        var ReadyInitList = [];

        function AddFunction(func) {
            ReadyInitList.push(func);
        }

        function Run() {
            for (x = 0; x < ReadyInitList.length; x++) {
                var tmpFunc = new Function(ReadyInitList[x]);
                tmpFunc();
            }
        }

        return {
            AddFunction: AddFunction,
            ReadyInitList: ReadyInitList,
            Run: Run
        }

    })(),

   
    
   Utility: (function () {

        function setBodyClass(body, classToAdd) {
            var bodyClass = body.className;
            body.className = bodyClass === '' ? classToAdd : bodyClass += ' ' + classToAdd;
        }

        function scriptWrite(scriptSrc) {
            var script = document.createElement("script");
            script.type = "text/javascript";
            script.src = scriptSrc;
            document.getElementsByTagName("head")[0].appendChild(script);
        }

        return {
            setBodyClass: setBodyClass,
            scriptWrite: scriptWrite
        }
    })(),

    Html5: (function () {
        // "<script>var elm = document.getElementById('{0}'); elm.setAttribute('type','{1}'); elm.setAttribute('placeholder','{2}')</script>";
        function ConvertInput(id, type, placeholder) {
            var input = document.getElementById(id);
            try {
                input.setAttribute('type', type);
                input.setAttribute('placeholder', placeholder);
            } catch (err) {
            }
        }
        return { ConvertInput: ConvertInput }
    })()
}

/***** Cookies Management ********************************************/
var CookieManager = {
    create: function (name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },
    read: function (name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return '';
    },
    erase: function (name) {
        Data.CookieManager.create(name, "", -1);
    }
}

Header.Default.init();
