/*--------------------------------------------------------------------------
 * OkCancelDialog 1.0
 * Version d.d. 17/7/2007
 * 
 * Requires
 * - prototype 1.5.0
 * - window 1.2 (http://www.xilinus.com/)
 *--------------------------------------------------------------------------*/

OkCancelDialog = Class.create();
OkCancelDialog.prototype = {
    initialize: function(windowDiv) {
        this.windowDiv   = windowDiv;
        this.createWindow();
        this.initButtonsHTML();
    },
    createWindow: function() {
	    this.windowDiv.style['display'] = 'none';
	},
	open: function() {
	    new Insertion.Bottom(this.windowDiv, '<div id="dialogButtonBar"/>');
	    new Insertion.Top('dialogButtonBar', this.dialogButtonsHTML);

        $('dialogOk').onclick        = this.onButtonOk.bindAsEventListener(this);
        $('dialogCancel').onclick    = this.onButtonCancel.bindAsEventListener(this);

        this.windowDiv.style.display = 'block';
	},	
	close: function() {
	    $('dialogButtonBar').remove(true);
	    this.windowDiv.style['display'] = 'none';
	},
	initButtonsHTML: function() {
		this.dialogButtonsHTML = '<a id="dialogOk"     href="#" class="button">Ok</a>'+
	    	 			         '<a id="dialogCancel" href="#" class="button">Cancel</a>';
	},
	onButtonOk: function() {
	    var closeWindow = true;
	    if (this.onOkCallback != null)
	        closeWindow = this.onOkCallback();
	    if (closeWindow)
	        this.close();
	},
	onButtonCancel: function() {
	    if(this.onCancelCallback != null) {
	        this.onCancelCallback();
	    }
        this.close();
	},
	setCallbackHandler: function(onOk, onCancel) {
	    this.onOkCallback = onOk;
	    this.onCancelCallback = onCancel;
	}
}