/** 
 * -----------------------------------------------------------
 *  return dimensions of a block
 *
 * -----------------------------------------------------------
 */
function getDimensions(element) {
    element = document.getElementById(element);
    if (element.clientWidth && element.clientHeight) {
        return {width: element.clientWidth, height: element.clientHeight};
    }
    var els = element.style;
    var originalVisibility = els.visibility;
    var originalPosition = els.position;
    var originalDisplay = els.display;
    els.visibility = 'hidden';
    els.position = 'absolute';
    els.display = 'block';
    var originalWidth = element.clientWidth;
    var originalHeight = element.clientHeight;
    els.display = originalDisplay;
    els.position = originalPosition;
    els.visibility = originalVisibility;
    return {width: originalWidth, height: originalHeight};
}
/** 
 * -----------------------------------------------------------
 * build an element block
 *
 * -----------------------------------------------------------
 */
function buildCalendarElement(data)
{
    if (data.type == undefined) return;

    var obj = document.createElement(data.type);
    if (data.name != undefined) {
        var newAttr = document.createAttribute("name")
        newAttr.value = "localSearch"
        obj.setAttributeNode(newAttr);
    }

    if (data.id != undefined) {
        obj.id = data.id;
    }
    if (data.ftype != undefined) {
        obj.type = data.ftype;
    }
    if (data.text != undefined) {
        obj.innerHTML = data.text;
    }
    if (data.className != undefined) {
        obj.className = data.className;
    }
    if (data.size != undefined) {
        obj.size = data.size;
    }

    return obj;
}
/** 
 * -----------------------------------------------------------
 *  load a javascript json request
 *
 * -----------------------------------------------------------
 */
function loadCalendarJSON(url)    
{
    url += '&noCacheIE=' + (new Date()).getTime();

    var headID = document.getElementsByTagName("head")[0];         
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = url;
    headID.appendChild(newScript);
}
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
function okWidget(init, containerId, name) {
    this.initialize(init, containerId, name);
};
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
function _CSAT(init, containerId, name) { 
    this.initialize(init, containerId, name);
}
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
function eCalendar(init, containerId, name) {
    this.initialize(init, containerId, name);
}
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
_CSAT.prototype = {
    /** Variables declaration */
    name                : "_csat",
    containerId         : "_csatListing",
       
    calendarId          : "",           /** calendar group id in wimgo            */
    venueId             : "",           /** venue id in wimgo                     */
    zips                : "",           /** zip code to search for                */
    distance            : 0,            /** distance from zip code or venue       */
    partnerId           : "",           /** wimgo partner id                      */
    sdate               : "",
    smonth              : "",
    monthsAhead         : 0,
    daysAhead           : 0,

    /** Style Information */
    eventClass          : "event",
    maxTitleLength      : 250,           /** maximum length of title               */

    
    counter             : 1, /** internal use only */
    data                : null,

    /** Don't change anything below this line */

    calendarListURL : "http://wimgo.com/ajax/okla365/eventList.php?", 
    detailEventURL  : "http://wimgo.com/events/", 

    initialize: function (init, containerId, name)
    {
        if(typeof(containerId) != 'undefined')          { this.containerId      = containerId;              }
        if(typeof(name) != 'undefined')                 { this.name             = name;                     }

        if(typeof(init.monthsAhead) != 'undefined')     { this.monthsAhed       = init.monthsAhead;         }
        if(typeof(init.daysAhead) != 'undefined')       { this.daysAhead         = init.daysAhead;           }
        if(typeof(init.calendarId) != 'undefined')      { this.calendarId       = init.calendarId;          }
        if(typeof(init.venueId) != 'undefined')         { this.venueId          = init.venueId;             }
        if(typeof(init.zips) != 'undefined')            { this.zips             = init.zips;                }
        if(typeof(init.partnerId) != 'undefined')       { this.partnerId        = init.partnerId;           }
        if(typeof(init.distance) != 'undefined')        { this.distance         = init.distance;            }
        if(typeof(init.eventClass) != 'undefined')      { this.eventClass       = init.eventClass;          }
        if(typeof(init.maxTitleLength) != 'undefined')  { this.maxTitleLength   = init.maxTitleLength;      }
        if(typeof(init.calendarListURL) != 'undefined') { this.calendarListURL  = init.calendarListURL;     }
        if(typeof(init.detailEventURL) != 'undefined')  { this.detailEventURL   = init.detailEventURL;      }
    },
    loadMonth: function(search) 
    {
        var url =  this.calendarListURL;
        
            var sdate = sdate || escape(this.sdate);

            url += "sdate="         + sdate;
        //url += "sdate="         + escape(this.sdate);
        url += "&smonth="       + escape(this.smonth);
        url += "&calendarId="   + escape(this.calendarId);
        url += "&venue_id="     + escape(this.venueId);
        url += "&zips="         + escape(this.zips);
        url += "&distance="     + escape(this.distance);
        url += "&monthsAhead="  + escape(this.monthsAhead);
        url += "&daysAhead="  + escape(this.daysAhead);
        if (search != undefined) {
            url += "&search=" + escape(search);
        }
        if (this.partnerId.length) {
            url += "&partner_id=" + escape(this.partnerId);
        }
        url += "&callBack="+this.name+'.display';

        loadCalendarJSON(url); 

        return false;
    },
    eventDetails: function(blockId, eventListId) 
    {
        document.getElementById(blockId).style.display = (document.getElementById(blockId).style.display == 'block') ? 'none' : 'block';
    },
    buildHTML: function (eventListId, id, title, description, date, happens, venue, address, city, zip)
    {
        var blockId = '_eventDetails' + this.counter++; 
        var html = "";
        html += "<div class='title'>";
        html += "<a href='javascript: void(0);' "
        html += " onClick=\""+this.name+".eventDetails('"+blockId+"',"+eventListId+");\"";
        html += " title='"+title+"'>";
        html += title.substr(0,this.maxTitleLength)
          if (title.length > this.maxTitleLength) {
                html += "...";
          }
        html += "</a>"
        html += "</div>"
        html += "<span class='date'>" + date;
        if (happens.length) {
            html += " | Happens: " + happens;
        }
        html += "</span><br />";
        html += "<span class='venue'>"+venue+",  "+city+"</span>";
        html += "<div id='"+blockId+"' class='description' style='display: none'>";
        html += description;
        html += "&nbsp; <a class='moreinfo' href='"+this.detailEventURL+id+"/' target='_blank'>More details</a>"
        html += "</div>";
        return html;
    },
    display: function(data) 
    {
        this.data = data;
        var container = document.getElementById(this.containerId);
        if (container == undefined) {
            alert("Event list container ("+this.containerId+") not found.");
            return false;
        }

        while (container.firstChild) 
        {
            container.removeChild(container.firstChild);
        }

        if (data.events.length == 0) {
            html = 'There are no events found.'
            container.appendChild(buildCalendarElement({"type": "div", "text" : html, "className":this.eventClass}));
        }
        for(var i=0; i < data.events.length; i++)
        {
            var html = this.buildHTML(
                                        i,
                                        data.events[i].id, 
                                        data.events[i].title,  
                                        data.events[i].description,    
                                        data.events[i].date,    
                                        data.events[i].happens,    
                                        data.events[i].venue,
                                        data.events[i].address,
                                        data.events[i].city,
                                        data.events[i].zip
                                );
            container.appendChild(buildCalendarElement({"type": "div", "text" : html, "className":this.eventClass}));
        }
        
    }
}
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
okWidget.prototype = {
    containerId : "_okWidgetId",
    name        : "_okWidget",
    _CSAT       : "",
    title       : "Calendar",
    searchable  : false,
    calClass    : false,
    initialize: function(init, containerId, name) 
    {
        if(typeof(containerId) != 'undefined')      { this.containerId      = containerId;  }
        if(typeof(name) != 'undefined')             { this.name             = name;         }

        if(typeof(init.title) != 'undefined')       { this.title        = init.title;       }
        if(typeof(init.searchable) != 'undefined')  { this.searchable   = init.searchable;  }
        if(typeof(init.calClass) != 'undefined')    { this.calClass     = init.calClass;    }

        this._CSAT  = new _CSAT(init, this.containerId + "Listings", this.name+"._CSAT" );
        this.buildCalendar();
        this._CSAT.loadMonth();
    },
    buildCalendar: function()
    {
        var searchString = ""
        var container = document.getElementById(this.containerId);
        if (container == undefined) {
            alert("okWidget ID not found.");
            return false;
        }
        while (container.firstChild) 
        {
            container.removeChild(container.firstChild);
        }
        var calDiv = buildCalendarElement({"type" : "div", "className" : this.calClass});
        container.appendChild(calDiv);

        if (this.title.length) {
            calDiv.appendChild(buildCalendarElement({"type" : "div", "className" : "header", "text" : this.title }));
        }
        if (this.searchable) {
            var calSearch = buildCalendarElement({"type" : "div", "className":"search"});
            var myForm = buildCalendarElement({"type" : "form", "id":"Form"+this.name});
            myForm.onsubmit = function() {
                try 
                {
                    if (this.localSearch == undefined) {
                        searchString = this.elements[0].value;
                    } else {
                        searchString = this.localSearch.value
                    }
                    listings = this.id.replace(/Form/, "") + "._CSAT.loadMonth('"+searchString+"');"
                    eval(listings);
                } catch (e) { 
                    alert(e);
                }
            
                return false;
            }

            var myLocalSearch = buildCalendarElement({"type":"input", "ftype":"text", "name" : "localSearch", "size" : "15", "id":"localSearch"})
            myForm.appendChild(myLocalSearch);
            myForm.appendChild(buildCalendarElement({"type":"input", "ftype":"submit", "className":"search_button", "value":"Search" }));
            calSearch.appendChild(myForm);
            calDiv.appendChild(calSearch);
        }
        calDiv.appendChild(buildCalendarElement({"type" : "div", "id":this.containerId+"Listings", "className":"eventListing"}));
    }
}

/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
eCalendar.prototype = {
    /**
     *  @method initialiaze constructor
     */
    name            : '_eCalendar',
    id              : '_eCalendarId',
    eventId         : 0,
    monthsAhead     : 11,
    markedDayClass  : 'cal_day_events',
    selectedDayClass: 'cal_day_selected',
    normalClass    	: 'cal_day_normal',
    fadedClass	    : 'cal_day_faded',
    months          : new Array(),
    calendarURL     : "http://wimgo.com/ajax/okla365/calendarCreate.php",

    /**
     *
     */
    initialize: function(init, containerId, name) 
    {
        if(typeof(containerId) != 'undefined')          { this.containerId      = containerId;          }
        if(typeof(name) != 'undefined')                 { this.name             = name;                 }

        if(typeof(name) != 'undefined')                 { this.name             = name;                 }
        if(typeof(init.id) != 'undefined')              { this.id               = init.id;              }
        if(typeof(init.eventId) != 'undefined')         { this.eventId          = init.eventId;         }
        if(typeof(init.monthsAhead) != 'undefined')     { this.monthsAhed       = init.monthsAhead;     }
        if(typeof(init.markedDayClass) != 'undefined')  { this.markedDayClass   = init.markedDayClass;  }
        if(typeof(init.selectedDayClass) != 'undefined'){ this.selectedDayClass = init.selectedDayClass;}
        if(typeof(init.normalClass) != 'undefined')     { this.normalClass      = init.normalClass;     }
        if(typeof(init.fadedClass) != 'undefined')      { this.fadedClass       = init.fadedClass;      }
        if(typeof(init.calendarURL) != 'undefined')     { this.calendarURL       = init.calendarURL;    }

        this.click  	    	= false;

        this.dimensions         = {};
        this.calWidth           = 0;
        this.scrollAnim	    	= { time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null };
        this.currLoc	    	= 0;
        this.dayIds		        = new Array();

        this.options            = {};

        var html = "<div>";
        html += "<div class='week_button_holder'>";
        html += "<div class='week_buttons'>";
/*        html += "<div class='week1_button' id='week1_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
        html += "<div class='week2_button' id='week2_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
        html += "<div class='week3_button' id='week3_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
        html += "<div class='week4_button' id='week4_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
        html += "<div class='week5_button' id='week5_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
        html += "<div class='week6_button' id='week6_"+this.containerId+"'><img title='View events happening this week.' src='http://static.newsok.biz/sites/wimgo/images/week_button.gif' border='0' /></div>";
*/        html += "</div>";
        html += "</div>";
        html += "<div id='calControls'>";
        html += "<div id='calControlsHolder'>";
        html += "<input type='button' id='ecalPrevButton' class='prevButton' title='Previous Month' onclick='"+this.name+".prevMonth()' />";
        html += "<input type='button' id='ecalNextButton' class='nextButton' title='Next Month' onclick='"+this.name+".nextMonth()' /><br style='clear:both' />";
        html += "</div>";
        html += "</div>";
        html += "<div class='ecal' id='"+this.containerId+"MonthView'>";
        html += "<div id='"+this.containerId+"Container'></div>";
        html += "</div>";
        html += "</div>";
        document.getElementById(this.containerId).innerHTML = html;
        this.load();
    },
    /**
     *
     */
    dayShiftClick: function(id, e) 
    { 
        return true;
    },
    /**
     *
     */
    dayRightClick: function(id, e) 
    { 
        return true;
    },
    /**
     *
     */
    dayClick: function(id, e) 
    { 
        return true;
    },
    /**
     *
     */
    monthClick: function(month)
    {
    },
    setWidth: function() {
        this.dimensions  	= getDimensions(this.containerId+"MonthView");
        this.calWidth       = this.dimensions.width;
    },
    /**
     *  @method scrollH
     */
    scrollH: function(delta) 
    {
        this.click = true;

        if (this.scrollAnim.timer != null) {
            clearInterval(this.scrollAnim.timer);
            this.scrollAnim.timer = null;
        }
        
        this.scrollAnim.time = 0;
        this.scrollAnim.begin = document.getElementById(this.containerId+"MonthView").scrollLeft;
        this.scrollAnim.change = delta;
        this.scrollAnim.duration = 25;
        this.scrollAnim.element = document.getElementById(this.containerId+"MonthView");
            
    	mySelf	= this;
        if ((this.scrollAnim.change + this.scrollAnim.begin) >= 0) {
            this.scrollAnim.timer = setInterval(function() { mySelf.scroll()}, 10);
        }
    },
    /**
     *  @method scroll
     */
    scroll: function() 
    {
        if (this.scrollAnim.time > this.scrollAnim.duration) {
            clearInterval(this.scrollAnim.timer);
            this.scrollAnim.timer = null;
            this.click = false;
        } else {
            move = this.sineInOut(this.scrollAnim.time, this.scrollAnim.begin, this.scrollAnim.change, this.scrollAnim.duration);
            this.scrollAnim.element.scrollLeft = move;
            this.scrollAnim.time++; 
        }
    },
    /**
     *  @method scroll
     */
    sineInOut: function(t, b, c, d) 
    {
        return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
    },
    /**
     *  @method load
     */
    load: function(month, year, id) 
    {
        var url = "";
        if (month == undefined) month = 0;
        if (year == undefined) year = 0;
        if (id == undefined) id = 0;
        if (this.eventId) {
            url = this.calendarURL + '?&monthsAhead='+this.monthsAhead+'&event_id='+this.eventId;
        } else {
            url = this.calendarURL + '?&monthsAhead='+this.monthsAhead+'&id='+id+'&month='+month+"&year="+year;
        }
        url += "&callBack="+this.name+".loadCalendar"
        loadCalendarJSON(url);
    },
    /**
     *  @method createDay
     */
    createDay: function(day) 
    {
        var className   = null;
        var myself      = this;

        var id = this.getDayID(day.day,day.month,day.year, day.inMonth);
    
        if (day.inMonth == 0) {
            className = this.fadedClass;
        } else {
            if (day.events) {
                className = this.markedDayClass
            } else {
                className = this.normalClass;
            }
        }

        var obj = buildCalendarElement({"type": "div", 'id': id, "className": className});
        obj.onclick = function(e) { 
            if (!e) {
                e = window.event;
            }

            if (e.shiftKey) {
                return myself.dayShiftClick(id,e); 
            }
            return myself.dayClick(id); 
        };
        obj.oncontextmenu = function(e) { 
            if (!e) {
                e = window.event;
            }
            return myself.dayRightClick(id, e); 
        };
        obj.appendChild(buildCalendarElement({"type": "p", "text": day.day}));

    
        return obj;
    },
    /**
     *  @method loadCalendar JSON callBack function
     */
    loadCalendar: function(data) 
    {
        var container = document.getElementById(this.containerId + 'Container');
    	if (container == undefined) {
            alert("Calendar Container ID not found.");
            return false;
        }
        while (container.firstChild) {
            container.removeChild(container.firstChild);
        }

        var content = buildCalendarElement({"type": "div", "className": 'ecalContent', 'id': this.containerId+"Content"});
        container.appendChild(content);

        for(var i=0; i<data.months.length; i++) {
            var monthId = document.getElementById(this.containerId + data.months[i].id);
            if (monthId == undefined)  {
                monthId = buildCalendarElement({"type": "div", 'className': "month"});

            } else {
                while (monthId.firstChild) {
                    monthId.removeChild(monthId.firstChild);
                }
            }

            dcal = buildCalendarElement({"type": "div", "className": 'dcal'});

            this.loadMonth(data.months[i], dcal);

            monthId.appendChild(dcal);
            content.appendChild(monthId);
        }
    },
    /**
     *  @method loadMonth
     */
    loadMonth: function(data, monthId) 
    {

        /* append month */
        var h1 = document.createElement("h1");

        this.months[this.months.length] = data.month + " " + data.year;

        html = "<a href='javascript: void(0);' onClick=\""+this.name+".monthClick('"+data.month+" "+data.year+"');\">"+data.month+"</a>";
        h1.appendChild(buildCalendarElement({"type": "div", "text": html, "className": 'name'}));
        /* append year */
        h1.appendChild(buildCalendarElement({"type": "div", "text": data.year, "className": 'year'}));

        monthId.appendChild(h1);
    
        containerDiv = buildCalendarElement({"type": "div", "className": 'daysContainer'});
        monthId.appendChild(containerDiv);
    
        pDiv = buildCalendarElement({"type": "div", "className": 'positionContainer'});
    
        var div = buildCalendarElement({"type": "div", "className": 'cal'});

        div.appendChild(buildCalendarElement({"type": "div", "text" : 'S', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'M', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'T', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'W', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'T', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'F', "className": 'wday'}));
        div.appendChild(buildCalendarElement({"type": "div", "text" : 'S', "className": 'wday'}));
        pDiv.appendChild(div);
    
        for (var i = 0; i < data.weeks.length && i < 6; i++) {
            var obj = buildCalendarElement({"type": "div", "className": 'cal'});
    
            for (var j = 0; j < data.weeks[i].length; j++) {
                    var day = this.createDay(data.weeks[i][j])
                    obj.appendChild(day);
                    if(j==0){
                        var img = document.createElement('img');
                        img.setAttribute('src','http://static.newsok.biz/sites/wimgo/images/week_button.gif');
                        img.setAttribute('border','0');
                        img.setAttribute('width','11');
                        img.setAttribute('height','38');
                        img.className = 'weekButton';
                        
                        var a = document.createElement('a');
                        a.setAttribute('href',"javascript:void(0);");
                        a.setAttribute('onclick',"");
                        a.className = 'weekBtnLink';
                        
                        a.appendChild(img);
                        day.appendChild(a);
                    }
            }
    
                pDiv.appendChild(obj);
        }
        containerDiv.appendChild(pDiv);
    },
    /**
     *  @method swapImages
     */
    swapImages: function() 
    {
        document.getElementById('ecalPrevButton').className = (this.currLoc > 0) ? "prevButton" : "prevButtonFaded";
        document.getElementById('ecalNextButton').className = (this.currLoc < this.monthsAhead) ? "nextButton" : "nextButtonFaded";
    },
    /**
     *  @method nextMonth
     */
    nextMonth: function(id) 
    {
        if (!this.click && (this.currLoc < this.monthsAhead)) {
            if (this.calWidth == 0) {
                this.setWidth();
            }
            this.scrollH(this.calWidth);
            this.currLoc++;
            this.monthClick(this.months[this.currLoc]);
            this.swapImages();
        }
    },
    /**
     *  @method prevMonth
     */
    prevMonth: function(id) 
    {
        if (!this.click && (this.currLoc > 0)) {
            if (this.calWidth == 0) {
                this.setWidth();
            }
            this.scrollH(-1*this.calWidth);
            this.currLoc--;
            this.monthClick(this.months[this.currLoc]);
            this.swapImages();
        }
    },
    getDayID: function(day, month, year, inMonth) {
    	return this.containerId+'_'+day+'_'+month+'_'+year+'_'+inMonth;
    },
    clearDates: function() {
        var day = '';
        var dayID = '';
        for (var i = 0; i < this.dayIds.length; i++) {
                if (document.getElementById(this.dayIds[i])) {
                    document.getElementById(this.dayIds[i]).className = this.normalClass;
                }
        }
    },
    markDates: function(dates, className) 
    {
        if (typeof(className) == 'undefined') className = this.markedDayClass;

        this.clearDates();
        var dayID = '';
        this.dayIds = new Array();
        for(i=0; i < dates.length; i++) {
            var a = dates[i].sdate.split('-');
            var year    = parseInt(a[0], 10); // cast to int
            var month   = parseInt(a[1], 10); // cast to int
            var day     = parseInt(a[2], 10); // cast to int
            dayID = this.getDayID(day, month, year, 1);
            if (document.getElementById(dayID) != undefined) {
                document.getElementById(dayID).className = className
            }

            // set days that were marked in array, to be cleared later if needed //
            this.dayIds[this.dayIds.length] = dayID;
        }
    }
}
/** 
 * -----------------------------------------------------------
 *
 *
 * -----------------------------------------------------------
 */
function buildEventCalendar(divId, init, advert)
{
   if(advert == null) {
        advert=true;
    } else if(advert == false) {
        advert=false;
    } else {
        //if advert is ANYTHING else other than false then it is true, capish?
        advert = true;
    }

 var html = "";

    if(typeof(divId) == 'undefined') { 
        alert("Need div id of calendar container.");
        return;
    }

    var calDiv = document.getElementById(divId);
    var ord = Math.random()*10000000000000000;
    var ad = "<a href='http://ad.doubleclick.net/jump/okp.wimgosatellites/;sz=300x250;ord=" + ord + "?' target='_blank'><img src='http://ad.doubleclick.net/ad/okp.wimgosatellites/;sz=300x250;ord=" + ord + "?' width='300' height='250' border='0' alt=''></a>";
    //var ad = "<a href='http://promos.newsok.com/adclick.php?n=a2f2a004' target='_blank'><img src='http://promos.newsok.com/adview.php?what=zone:1254&amp;n=a2f2a004' border='0' alt=''></a>";

    html  = "<div id='wimgoSatelliteEmbed'>";
    html += "    <div id='wimgoSatellite'>";
    html += "        <div id='header_graphics'>";
    html += "           <div class='topLeft'></div>";
    html += "           <div class='topRight'></div>";
    html += "        </div>";
    html += "        <div id='wimgo_columnB'>";
    html += "            <div class='rightRail_container'><div id='wimgoCalendar'></div></div>";
    if(advert){
        html += "            <div id='wimgoAdContainer' class='rightRail_container'><div id='wimgoAdZone'>"+ad+"</div></div>";
    }
    html += "        </div>";
    html += "        <div id='wimgoListings'>";
    html += "        </div>";
    html += "        <div class='clear'></div>";
    html += "        <div id='footer_graphics'>";
    html += "           <div class='bottomLeft'></div>";
    html += "           <div class='bottomRight'></div>";
    html += "        </div>";
    html += "        <div class='clear'></div>";
    html += "   </div>";
    html += "   <div class='wimgo_credits'>Powered by <a href='http://wimgo.com/'>wimgo.com</a></div>";
    html += "</div>";

    calDiv.innerHTML = html;

    _okWidget1               = new okWidget(init, "wimgoListings", "_okWidget1");
    _myCal                   = new eCalendar({}, 'wimgoCalendar', '_myCal');
    
    _okWidget1._CSAT.eventDetails = function(blockId, eventListId)
    {
        if (document.getElementById(blockId).style.display == 'block') {
            document.getElementById(blockId).style.display = 'none';
            _myCal.clearDates();
        } else {
            document.getElementById(blockId).style.display = 'block';
            _myCal.markDates(this.data.events[eventListId].dates);
        }
    }

    _myCal.dayClick = function (id, e)
    {
        this.clearDates();
        var dt = id.replace(this.containerId +"_", '');
        var a = dt.split("_");
        var day = parseInt(a[0], 10);
        var month = parseInt(a[1], 10);
        var year = parseInt(a[2], 10);
        dates = new Array();
        dates[dates.length] = { "sdate": year+"-"+month+"-"+day  }
        this.markDates(dates, this.selectedDayClass);

        _okWidget1._CSAT.sdate = year + '-' + month + '-' +day
        _okWidget1._CSAT.loadMonth(null,_okWidget1._CSAT.sdate);
    }
    _myCal.monthClick = function (monthId)
    {
        this.clearDates();
        _okWidget1._CSAT.sdate = ''
        _okWidget1._CSAT.smonth = monthId
        _okWidget1._CSAT.loadMonth(_okWidget1._CSAT.sdate);
    }
    
}
