

/* EMBEDHELPER */
/**
* Copyright (c) 2009 James Padolsey
* -------------------------------------------------------
* Dual licensed under the MIT and GPL licenses.
*    - http://www.opensource.org/licenses/mit-license.php
*    - http://www.gnu.org/copyleft/gpl.html
*/
var embedHelper = (
	function() {
	    var a = (
				function() {
				    var b = document.getElementsByTagName("script");
				    return b[b.length - 1];
				}
			)();

	    return {
	        getConfig: function(g) {
	            var b = a.innerHTML,
				d = {},
				c = Array.prototype.slice.call(arguments);
	            try {
	                d = (new Function("return " + b.replace(/\n|\r/g, "")))();
	            } catch (f) { }
	            c.push(d);
	            return this.merge.apply(this, c);
	        },
	        merge: function(g, f) {
	            if (typeof g !== "object") {
	                g = {};
	            }
	            for (var e in f) {
	                if (!f.hasOwnProperty || f.hasOwnProperty(e)) {
	                    var b = f[e];
	                    if (typeof b === "object") {
	                        g[e] = this.merge(g[e], b);
	                        continue;
	                    }
	                    g[e] = b;
	                }
	            }

	            for (var d = 2, c = arguments.length; d < c; d++) {
	                this.merge(g, arguments[d]);
	            }
	            return g;
	        },
	        insert: function(e) {
	            if (e.nodeName && !e.length) {
	                return a.parentNode.insertBefore(e, a);
	            }
	            if (typeof e === "string") {
	                var c = document.createElement("div");
	                c.innerHTML = e;
	                e = c.childNodes;
	            }
	            for (var d = 0, b = e.length || 0; d < b; ++d) {
	                this.insert(e[d]);
	            }
	            return this;
	        },
	        scriptRef: a
	    }
	}
)();
/* ----------- */

/* Widget code */

(function() {
    var siteAddr = "";
    var requestStr = "";
    var userOptions = embedHelper.getConfig({});

    if (typeof (widgetBuilder) == "undefined") {
        widgetBuilder = {};
    }

    var makeRequestStr = function() {
        requestStr = "";
        if (userOptions.hasOwnProperty("siteAddr")) {
            siteAddr = userOptions["siteAddr"];
        };
        if (userOptions.hasOwnProperty("ucColumns")) {
            requestStr += "ucColumns=" + userOptions["ucColumns"] + "&";
        };
        if (typeof (userOptions["ucEntityId"]) !== "undefined") {
            requestStr += "ucEntityId=" + userOptions["ucEntityId"] + "&";
        };
        if (typeof (userOptions["ucEntityJoin"]) !== "undefined") {
            requestStr += "ucEntityJoin=" + userOptions["ucEntityJoin"] + "&";
        };
        if (typeof (userOptions["ucInitialViewSetting"]) !== "undefined") {
            requestStr += "ucInitialViewSetting=" + userOptions["ucInitialViewSetting"] + "&";
        };
        if (typeof (userOptions["ucIsExpandable"]) !== "undefined") {
            requestStr += "ucIsExpandable=" + userOptions["ucIsExpandable"] + "&";
        };
        if (typeof (userOptions["ucIsPageable"]) !== "undefined") {
            requestStr += "ucIsPageable=" + userOptions["ucIsPageable"] + "&";
        };
        if (typeof (userOptions["ucItemEndDate"]) !== "undefined") {
            requestStr += "ucItemEndDate=" + userOptions["ucItemEndDate"] + "&";
        };
        if (typeof (userOptions["ucItemStartDate"]) !== "undefined") {
            requestStr += "ucItemStartDate=" + userOptions["ucItemStartDate"] + "&";
        };
        if (typeof (userOptions["ucResultFormat"]) !== "undefined") {
            requestStr += "ucResultFormat=" + userOptions["ucResultFormat"] + "&";
        };
        if (typeof (userOptions["ucResultLimit"]) !== "undefined") {
            requestStr += "ucResultLimit=" + userOptions["ucResultLimit"] + "&";
        };
        if (typeof (userOptions["ucResultList"]) !== "undefined") {
            requestStr += "ucResultList=" + userOptions["ucResultList"] + "&";
        };
        if (typeof (userOptions["ucSelection"]) !== "undefined") {
            requestStr += "ucSelection=" + userOptions["ucSelection"] + "&";
        };
        if (typeof (userOptions["ucTemplate"]) !== "undefined") {
            requestStr += "ucTemplate=" + userOptions["ucTemplate"] + "&";
        };
        if (typeof (userOptions["ucTitle"]) !== "undefined") {
            requestStr += "ucTitle=" + userOptions["ucTitle"] + "&";
        };
        if (typeof (userOptions["ucViewAllLink"]) !== "undefined") {
            requestStr += "ucViewAllLink=" + userOptions["ucViewAllLink"] + "&";
        };
        if (typeof (userOptions["ucViewAllStr"]) !== "undefined") {
            requestStr += "ucViewAllStr=" + userOptions["ucViewAllStr"] + "&";
        };
        if (typeof (userOptions["ucViewLessStr"]) !== "undefined") {
            requestStr += "ucViewLessStr=" + userOptions["ucViewLessStr"] + "&";
        };
    };

    embedHelper.insert("<div id='calendar7Day'><ul id='calendar7Day_Days'></ul><div id='ppz'>&nbsp;</div></div>");

    makeRequestStr();

    jQuery.ajax({
        url: siteAddr + 'userControls/Calendar7Day/results.aspx?' + requestStr,
        dataType: "jsonp",
        jsonpCallbackString: "resultCBFN",
        success: function(data) {
            jQuery("#ppz").html(data);
        }
    });

    jQuery(document).ready(function($) {
    
        var buildCalendar = function() {
            var i, currDay, sb, fs, startdate;
            var days = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
            currDay = new Date();
            sb = "";
            for (i = 0; i < 7; i++) {            
                fs = ['<li month="',
					    currDay.getMonth(),
					    '" day="',
					    currDay.getDate(),
					    '" year="',
					    currDay.getFullYear(),
					    '"><span class="calendar7Day_DayLetter">',
					    days[currDay.getDay()],
					    '</span><span class="calendar7Day_DayNumber">',
					    currDay.getDate(),
					    '</span></li>'].join("");
                sb += fs;
                currDay.setDate(currDay.getDate() + 1);
            }

            jQuery("#calendar7Day_Days").html(sb);
             


            jQuery('#calendar7Day li').each(function(i) {
                var $this = $(this);
                var selYear = Number($this.attr('year'));
                var selMonth = Number($this.attr('month'));
                var selDay = Number($this.attr('day'));
                $this.click(function(e) {
                    e.preventDefault();
                    getCalWidgetResults(selYear, selMonth, selDay);
                    jQuery('#calendar7Day li.selected').removeClass('selected');
                    $this.addClass('selected');
                });
            });
            jQuery('#calendar7Day li:first').click();
        };

        var getCalWidgetResults = function(selYear, selMonth, selDay) {


            userOptions["ucItemStartDate"] = selYear + '-' + (selMonth + 1) + '-' + selDay;
            userOptions["ucItemEndDate"] = userOptions["ucItemStartDate"];

            makeRequestStr();
            jQuery.ajax({
                url: siteAddr + 'userControls/Calendar7Day/results.aspx?' + requestStr,
                dataType: "jsonp",
                jsonpCallbackString: "resultCBFN",
                success: function(data) {
                    jQuery("#ppz").html(data);
                }
            });
        };

        buildCalendar();

    });

})();

var resultCBFN = function(data) {    
    jQuery("#ppz").html(data);
};