﻿

function Messagebox(message, option) {
    option = $j.extend({
		title: 'Information',
        showOK: true,
        showCancel: false,
        okHandler: null,
        cancelHandler: null
    }, option);

	var okText = option.okText;
	var cancelText = option.cancelText;
	
    var msgbox = 
    $j('<div class="dialog" style="display:none;">'+
        '<h2>'+ message + '</h2>' +
    '</div>');
	
	option = $j.extend({
		messagebox: msgbox
	}, option);
	
	var buttons = {};
    if(option.showOK == true)
    {
		buttons = $j.extend({
			'OK' : function(){
				if(option.okHandler){
					option.okHandler(option);
				}else{
					msgbox.removeDialog();
				}
			}
		}, buttons);
    }
    if (option.showCancel == true) {
        buttons = $j.extend({
			'Cancel' : function(){
				if(option.cancelHandler){
					option.cancelHandler(option);
				}else{
					msgbox.removeDialog();
				}
			}
		}, buttons);
    }
    $j('body').append(msgbox);
    msgbox.dialog({
        draggable: true,
        autoOpen: false,
        resizable: false,
        modal: true,
        width: 450,
        height: 150,
		'buttons': buttons,
		title: option.title
    }).parent().appendTo($j("form:first"));
    msgbox.openDialog();
}

function SetDefaultButton(panelID, buttonID) {
	$j('#'+panelID+' :text').keypress(
        function(e) {
			var btnID = buttonID;
            if (e.which == 13) {
                $j('#' + btnID).click();
            }
        });
    }
    
function trimAll(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}
