// CHOICE 
//create a namespace 
YAHOO.namespace("qw.choice")

//create a new object for this module:
YAHOO.qw.choice.inDialog = function(){

	//Some shortcuts to use in our example:
	var Event = YAHOO.util.Event, Dom = YAHOO.util.Dom, lang = YAHOO.lang;
	
	return {
		
		init: function()
		{
		
			// Instantiate the Dialog
			this.dialog = new YAHOO.widget.Dialog("yui-choice-panel", {
				
				height: "100px",
				fixedcenter: true,
				visible: false,
				close: false,
				constraintoviewport: true,
				buttons: [{
					text: "Ok",
					handler: function(){
						this.cancel();
						onChoiceSet($F('yui-select'),this.op);
					},
					isDefault: true
				}, {
					text: "Cancel",
					handler: function(){
						this.cancel();
						onChoiceCancel(this.op);
					}
				}]
			});
				
			this.show = function(op)
			{
				this.dialog.op = op;
				var choices = op.choices.sub("choose:","").split(",");
				dlg = $('yui-choice');
				dlg.update("");
				e = new Element("select",{"id":"yui-select"});
				this.dialog.selection = e;
				dlg.insert({
					bottom: e
				})
				choices.each(function(ch){
					o = new Element("option",{value:ch});
					o.update(ch);
					e.insert({bottom:o})
					});
				
				e.observe("change",function(e)
					{
						onChoiceChange($F('yui-select'),op)
					});
				this.dialog.show();
			}
			
			// We're all set up with our Dialog's configurations. Now, render the Dialog 
			
			this.dialog.render(); 
		}
		
		
	}

}()

YAHOO.util.Event.onDOMReady(YAHOO.qw.choice.inDialog.init, YAHOO.qw.choice.inDialog, true); 


function doChoiceDialog(op)
{
	YAHOO.qw.choice.inDialog.show(op);
}

function onChoiceSet(value,op)
{
	qwCommit(op,value);
}

function onChoiceChange(value,op)
{
	qwSet(op,value);
}

function onChoiceCancel(op)
{
	qwSet(op,op.value);
}


	