dojo.require("dijit._Calendar");
dojo.require("dojo.date.locale");

dojo.require("dojo.parser"); // scan page for widgets
jmaki.namespace("jmaki.widgets.dojo.dijit.calendar");

/**
 * @constructor
*/
jmaki.widgets.dojo.dijit.calendar.Widget = function(wargs) {

    var _this = this;
    var container = document.getElementById(wargs.uuid);
    
    this.wrapper = new dijit._Calendar({}, container);
  
    var topic = "/dojo/dijit/calendar";	

    if (wargs.value) {
        var date = new Date(wargs.value);
	this.wrapper.setDate(date);
    }
    
    if ( wargs.publish) {
        topic = wargs.publish;
    }
     
    this.getValue = function() {
        return  _this.wrapper.getValue().replace(/-/g, '/');
    }

   this.datepickerEvent = function(date) {
        jmaki.publish(topic, {id: wargs.uuid, wargs: wargs, value:date});
    }


    dojo.connect(_this.wrapper, "onValueChanged", _this, "datepickerEvent" );    


}
