function be2Alert(dialogDivId, title, message, button, callback, onShowFunc, containerId) {
    if (dialogDivId == '' || dialogDivId == null)
        dialogDivId = "alert";
    if (containerId == '' || containerId == null)
        containerId = 'confirmModalContainer';
    jQuery('#' + dialogDivId).modal({close:false,overlayId:'confirmModalOverlay',containerId:containerId,effect:true,onClose:function(dialog) {
        if (jQuery.isFunction(callback)) {
            callback.apply();
        }
        jQuery.modal.close();
    },onShow:function(dialog) {
        if (jQuery.isFunction(onShowFunc)) {
            onShowFunc.apply();
        }
        if (button != '')
            jQuery('#bOk').html(button);
        var decodedMessage = decodeMessage(message);
        dialog.data.find('.message').append(decodedMessage);
        dialog.data.find('.title').append(title);
    },onClose:function(dialog) {
        if (jQuery.isFunction(callback)) {
            callback.apply();
        }
    }});
}
function be2Confirm(requestURL, title, formID, httpParams, message, buttons, onShowFunc, callback)
{
    jQuery('#confirm').modal({close:false,overlayId:'confirmModalOverlay',containerId:'confirmModalContainer',effect:true,onShow:function(dialog) {
        if (jQuery.isFunction(onShowFunc)) {
            onShowFunc.apply();
        }
        dialog.data.find('.message').append(message);
        dialog.data.find('.title').append(title);
        jQuery('#bYes').click(function() {
            if (isNaN(formID))
                httpParams = jQuery("#" + formID).serialize();
            if (isNaN(requestURL)) {
                jQuery.get(requestURL, httpParams);
            }
            if (jQuery.isFunction(callback)) {
                if (callback.apply())
                    jQuery.modal.close();
            }
            else
                jQuery.modal.close();
        });
        if (isNaN(buttons[0]))
        {
            jQuery('#bYes').html(buttons[0]);
        }
        if (isNaN(buttons[1])) {
            jQuery('#bNo').html(buttons[1]);
        }
    },onClose:function() {
        jQuery('#confirmModalOverlay').fadeOut("slow");
        jQuery('#confirmModalContainer').slideUp("fast");
        jQuery('#confirm').slideUp("fast");
        this.opts.onClose = null;
        this.close();
    }});
}
function decodeMessage(inString) {
    var inStringLength = inString.length;
    var outString = "";
    for (i = 0; i < inStringLength; i++) {
        var isEntity = false;
        if (inString.substr(i, 2) == "&#") {
            for (j = 1; j <= 5; j++) {
                if (inString.substr(i + 2 + j, 1) == ";") {
                    var temp = inString.substr(i + 2, j);
                    temp = Math.ceil(temp);
                    if (!isNaN(temp)) {
                        outString += String.fromCharCode(temp);
                        i += 2 + j;
                        isEntity = true;
                    }
                    break
                }
            }
        }
        if (!isEntity) {
            outString += inString.substr(i, 1);
        }
    }
    return outString;
}
function alertHelp(id) {
    jQuery('#' + id).dialog('open');
}
function alertConfirm(id) {
    jQuery('#' + id).dialog('open');
}
function loadBox(boxId) {
    var btns = {'Close':function() {
        jQuery(this).dialog('close');
    }}
    loadDialog(boxId, btns);
}
function loadConfirm(boxId) {
    var btns = {'Ok':function() {
        jQuery(this).dialog('close');
    },'Cancel':function() {
        jQuery(this).dialog('close');
    }}
    loadDialog(boxId, btns);
}
function loadDialog(boxId, btns) {
    destroyRemainingBox(boxId);
    jQuery('#' + boxId).dialog({appendToElement:document.body,autoOpen: true,close:function() {
        jQuery("select").show();
        jQuery('#' + this.id + '_container').removeShadow();
    },open:function() {
        jQuery("select").hide();
        jQuery('#' + this.id + '_container').dropShadow({left:3,top:5,opacity:0.8,blur:2});
    },buttons:btns});
}
function loadDialogCallbacked(boxId, btns, callback, className, dialogWidth, onShow, hideSelect) {
    destroyRemainingBox(boxId);
    jQuery('#' + boxId).dialog({dialogClass:className,width:dialogWidth,appendToElement:document.body,close:function() {
        jQuery("select").show();
        if(jQuery.isFunction(callback))
            callback();
        jQuery('#' + this.id + '_container').removeShadow();
    },open:function() {
        if (hideSelect){
            jQuery("select").hide();
        }
        if(jQuery.isFunction(onShow))
            onShow();
        jQuery('#' + this.id + '_container').dropShadow({left:3,top:5,opacity:0.8,blur:2});
    },buttons:btns});
}
function loadDialogArrowed(boxId, btns, pos) {
    destroyRemainingBox(boxId)
    jQuery('#' + boxId).dialog({appendToElement:document.body,dialogClass:'red',modal:false,width:250,arrow:'show',close:function() {
        jQuery('#' + this.id + '_container').removeShadow();
        jQuery("select").show();
    },open:function() {
        jQuery("select").hide();
        moveToPos(boxId + '_container', pos);
        jQuery('#' + this.id + '_container').dropShadow({left:3,top:5,opacity:0.8,blur:2});
    },buttons:btns});
}
function moveToPos(boxId, pos) {
    document.getElementById(boxId).style.top = document.getElementById(pos).offsetTop - 25;
    document.getElementById(boxId).style.left = document.getElementById(pos).offsetLeft + 40;
}
function destroyRemainingBox(boxId) {
    if (box = document.getElementById(boxId + '_container')) {
        document.body.removeChild(box);
    }
}

//preparing for any modal dialog(confirm)
function prepareConfirmDialog(boxId, buttons, callback, className, dialogWidth, onShow, title, message, ajaxURL, formID, httpParams, onClose) {
    createPoput(boxId);

    //    destroyRemainingBox(boxId);
    jQuery('#' + boxId).dialog({modal:true,width:dialogWidth,dialogClass:className,close:function() {
        jQuery('#' + this.id + '_container').removeShadow();
        jQuery("select").show();
        if (jQuery.isFunction(onClose))
            onClose.apply();
    },open:function() {
        jQuery("select").hide();
        if (jQuery.isFunction(onShow))
            onShow();
        jQuery('#' + this.id + '_container').dropShadow({left:3,top:5,opacity:0.8,blur:2});
    }});
    if (message) {
        jQuery("#" + boxId + '_msg').html(decodeMessage(message));
    }
    if (title)
        jQuery("#" + boxId).dialog('option', 'title', title);
    if (isNaN(formID))
        httpParams = jQuery("#" + formID).serialize();
    jQuery('#bYes').click(function() {
        if (isNaN(formID))
            httpParams = jQuery("#" + formID).serialize();
        if (isNaN(ajaxURL)) {
            jQuery.get(ajaxURL, httpParams);
        }
        if (jQuery.isFunction(callback)) {
            if (callback.apply())
                jQuery("#" + boxId).dialog('close');
        }
        else
            jQuery("#" + boxId).dialog('close');
    });
    jQuery('#bNo').click(function() {
        jQuery("#" + boxId).dialog('close');
        });
    if (isNaN(buttons[0]))
    {
        jQuery('#bYes').html(buttons[0]);
    }
    if (isNaN(buttons[1])) {
        jQuery('#bNo').html(buttons[1]);
    }
}

var boxParentEl = null;
var confirmBoxHTML = null;
var alertBoxHTML = null;
function createPoput(boxId) {
    if (boxParentEl == null) {
        boxParentEl = document.getElementById(boxId).parentNode;
    }

    if (boxId == "confirm") {
        if (confirmBoxHTML == null) {
            confirmBoxHTML = document.getElementById(boxId).innerHTML;
        }
        destroyPoput(boxId);

        var divEl = document.createElement("DIV");
        divEl.id = boxId;
        divEl.className = "clearfix";
        divEl.style.display = "none";
        divEl.innerHTML = confirmBoxHTML;
        boxParentEl.appendChild(divEl);
    } else if (boxId == "alert") {
        if (alertBoxHTML == null) {
            alertBoxHTML = document.getElementById(boxId).innerHTML;
        }
        destroyPoput(boxId);

        var divEl = document.createElement("DIV");
        divEl.id = boxId;
        divEl.className = "clearfix";
        divEl.style.display = "none";
        divEl.innerHTML = alertBoxHTML;
        boxParentEl.appendChild(divEl);
    }
    return boxId;
}

function destroyPoput(boxId) {
    var el = document.getElementById(boxId);
    if (el != null) {
        var parentEl = el.parentNode;
        parentEl.removeChild(el);
    }
}