﻿ModalTracking = Class.create({
    initialize: function () {
        // if s hasn't been created, we make an empty one
        if (typeof (window.s) == 'undefined') { s = {} }
        // creating an instance of s so we can track multiple events on the page
        this.s = s;
    },
    getPageUrl: function () {
        return window.location.protocol + "//" + window.location.hostname + "/register";
    },
    getPageTitle: function () {
        return $$('title')[0].innerHTML;
    },
    getSection: function () {
        return this.getPageUrl().replace('http://', '').split('/')[1];
    },
    ModalDialogOpen: function () {
        // this is going to be one time override for site catalyst implementation
        // as modal dialog appearence need to be tracked
        this.clearValues();
        this.s.pageName = "Starz: Register";
        this.s.pageURL = this.getPageUrl();
        this.s.prop1 = this.getPageUrl();
        this.s.t();
    },
    clearValues: function () {
        // get an object reflection to get all the properties
        var props = this.getSObjectProperties();
        for (var i in props) {
            this.s[props[i]] = "";
        }
        var props = this.getSObjectEVars();
        for (var i in props) {
            this.s[props[i]] = "";
        }
        var props = this.getSObjectEvents();
        for (var i in props) {
            this.s[props[i]] = "";
        }
    },
    getSObjectProperties: function () {
        var props = new Array();
        for (var sProp in this.s) {
            if (sProp.search(/prop/i) >= 0) {
                if (typeof (this.s[sProp]) != "function") {
                    props[props.length] = sProp;
                }
            }
        }
        return props;
    },
    getSObjectEVars: function () {
        var props = new Array();
        for (var sProp in this.s) {
            if (sProp.search(/evar/i) >= 0) {
                if (typeof (this.s[sProp]) != "function") {
                    props[props.length] = sProp;
                }
            }
        }
        return props;
    },
    getSObjectEvents: function () {
        var props = new Array();
        for (var sProp in this.s) {
            if (sProp.search(/event/i) >= 0) {
                if (typeof (this.s[sProp]) != "function") {
                    props[props.length] = sProp;
                }
            }
        }
        return props;
    }

});

ModalTracking.init = function () {};
Event.observe(window, 'load', ModalTracking.init);

