function showWaitDialog() {
    Ext.MessageBox.show({
        msg: 'Saving your data, please wait...',
        progressText: 'Saving...',
        width:300,
        wait:true,
        waitConfig: {interval:200}
        //icon:'ext-mb-download' //custom class in msg-box.html
//            animEl: id
    });
}

function closeWaitDialog() {
    Ext.MessageBox.hide();
    Ext.MessageBox.alert('Done', 'Data saved!');
}

var winPanel;

function showExtPopup(url, title, width) {
    winPanel = Ext.getCmp('panelWindowId');
    var divId = "dialog-box-extjs";
    Ext.Ajax.request({
        url:url,
        success:function(response, option) {
            if (!winPanel) {
                winPanel = new Ext.Window({
                    title:title, //Title of the Window
                    id: 'panelWindowId', //ID of the Window Panel
                    autoHeight:true,
                    closeAction:'hide',
                    width:width, //Width of the Window
                    resizable: true, //Resize of the Window, if false - it cannot be resized
                    closable: true, //Hide close button of the Window
                    modal: true, //When modal:true it make the window modal and mask everything behind it when displayed
                    contentEl: divId,
                    constrain : true
                });
            } else {
                winPanel.setTitle(title);
                winPanel.setWidth(width);
            }
            jQuery('#' + divId).html(response.responseText);
            winPanel.show();
        },
        params:{ajax:true,ajaxDate:new Date()}
    });
}

function showExtPopupInDiv(url, title, width, divId) {
    var panelId = 'panelWindowId1';
    winPanel = Ext.getCmp(panelId);
    Ext.Ajax.request({
        url:url,
        params:{ajax:true,ajaxDate:new Date(),panelId:panelId},
        success:function(response, option) {
            if (!winPanel) {
                winPanel = new Ext.Window({
                    title:title, //Title of the Window
                    id: 'panelWindowId1', //ID of the Window Panel
                    autoHeight:true,
                    closeAction:'hide',
                    width:width, //Width of the Window
                    resizable: true, //Resize of the Window, if false - it cannot be resized
                    closable: true, //Hide close button of the Window
                    modal: true, //When modal:true it make the window modal and mask everything behind it when displayed
                    contentEl: divId,
                    constrain : true
                });
            } else {
                winPanel.setTitle(title);
                winPanel.setWidth(width);
            }
            jQuery('#' + divId).html(response.responseText);
            setTimeout(function(){
                winPanel.show();
            },1000);

        }
    });
}

function closePopup() {
    var winPanel = Ext.getCmp('panelWindowId');
    if (winPanel) {
        winPanel.hide();
    }
}

function adjustPopup(title) {
    var winPanel = Ext.getCmp('panelWindowId');
    if (winPanel) {
        winPanel.setTitle(title);
    }
}
function calendar(defaultDate) {
    dateField = new Ext.form.DateField({
        id:'date_value',
        name:'date_value',
        applyTo:'date_value',
        allowBlank:false
    });
    var date = new Date(defaultDate);
    dateField.setValue(date);
}

function createHtmlEditor(id, renderTo, width, height, defaultValue) {
    Ext.QuickTips.init();
    var htmlEditor = new Ext.form.HtmlEditor({
        renderTo:renderTo,
        id:id,
        name:renderTo,
        height: height,
        width: width,
        frame: true,
        layout: 'fit',
        required:true
    });
    htmlEditor.setValue(defaultValue);
}

function createSelectFileButton(applyTo, title, issueId, divId, attachmentDirDiv) {
    var attachmentDir = attachmentDirDiv ? $("#attachmentDir", attachmentDirDiv).val() : $("#attachmentDir").val();
    var button = new Ext.Button({
        text:title,
        width:100,
        renderTo:applyTo,
        listeners:{
            click:function(button, e) {
                var attachWindowUrl = createUrl('util', 'attachFilePopup') + '/' + issueId + '?attachmentDir=' + attachmentDir;
                showExtPopupInDiv(attachWindowUrl, 'Attach File', 950, divId)
            }
        }
    });
}

function closePopupPanel(panelId) {
    var winPanel;
    if (panelId) {
        winPanel = Ext.getCmp(panelId);
        if (winPanel) {
            winPanel.hide();
        }
    } else {
        winPanel = Ext.getCmp('panelWindowId');
        if (winPanel) {
            winPanel.hide();
        }
    }
}


