/* Copyright 2009 Palm, Inc.  All rights reserved. */

var BirthdayPickerAssistant = Class.create({
	initialize:function(controller, callback, model){
		this.controller = controller;
		this.callback = callback;
		this.model = model;
		model.birthdayDate = Utilities.localDateToDate(model.birthday);
		if(!model.birthdayDate) model.birthdayDate =new Date();
	},
	
	setup:function(widget){
		this.widget = widget;
		this.controller.setupWidget("BirthdayPicker", {modelProperty:"birthdayDate"}, this.model);
		this.controller.listen("BirthdayPicker", Mojo.Event.propertyChange, this.birthdayChanged.bind(this));
		this.controller.listen("DonePickingBirthday", Mojo.Event.tap, this.finish.bind(this));
		this.controller.listen("ClearBirthday", Mojo.Event.tap, this.clearBirthday.bind(this));
		this.controller.listen("CancelBirthday", Mojo.Event.tap, this.cancel.bind(this));
	},
	
	birthdayChanged:function(e){
		this.model.birthday = Utilities.dateToLocalDate(this.model.birthdayDate)
	},
	
	clearBirthday:function(){
		this.callback(0);
		this.widget.mojo.close();
	},
	  
  finish: function(){
    this.callback(this.model.birthdayDate);
    this.widget.mojo.close();
  },
  
  cancel:function(){
  	this.widget.mojo.close();
  }
})
