﻿/*************************************************
* Go Dialog popup 
* Version 1.1
* Show dialog Popup, alert, confirm, auto hide popup
* Created in 01/04/2010
* Modified in 24/05/2011
* Author by thetoan.cao (Cao The Toan)
* Website http://my.go.vn
* Demo http://www.go.vn/dev/#Popup
**************************************************/
// quy chuan style cho the button
function applyStyleButtonTag() {
   // $('#ui-bt-f0 .ui-bt-bg-f').addClass('ui-bt-center-bg-gray');
}
//$.fn.extend({
var MediaVersion = 9.11;
var GoDialogAlertId = "GoDialogAlert", GoDialogConfirmId = "GoDialogConfirm";
var GoDialog = new function () {
    this.Init = function () {
        var staticURL = 'http://static.gox.vn/media/';
        var head = document.getElementsByTagName('head')[0];
        var link = document.createElement('link');
        link.rel = 'stylesheet';
        link.type = 'text/css';
        link.href = staticURL + 'homepage/css/jquery-ui-1.7.2.custom.css';
        head.appendChild(link);
        if (typeof jQuery == "undefined") {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = staticURL + 'homepage/js/jquery-1.3.2.min.js';
            head.appendChild(script);
        }
        if (typeof jQuery.ui == "undefined") {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = staticURL + 'homepage/js/jquery.ui.all.js?v=' + MediaVersion;
            head.appendChild(script);
        }
        var strDialog = '';
        if (!document.getElementById(GoDialogAlertId)) {
            strDialog += '<div id="' + GoDialogAlertId + '" title="Thông báo" style="display:none;">';
            //strDialog += '<img src="' + staticURL + 'homepage/images/logo_popup.jpg" style="float:left; padding-right:5px;" alt="logo" width="66px"  />';
            strDialog += '<span id="' + GoDialogAlertId + 'Content" class="ml10 mt10 fl"></span>';
            strDialog += '</div>';
        }
        if (!document.getElementById(GoDialogConfirmId)) {
            strDialog += '<div id="' + GoDialogConfirmId + '" title="Xác nhận" style="display:none;">';
           // strDialog += '<div style="float:left; padding-right:5px;"><img src="' + staticURL + 'homepage/images/logo_popup.jpg" style="width="66px"" alt="logo" /></div>';
            strDialog += '<span id="' + GoDialogConfirmId + 'Content" class="ml10 mt10 fl"></span>';
            strDialog += '</div>';
        }
        document.write(strDialog);
    }
    this.Waiting = function (content) {
        $("#" + GoDialogAlertId + "Content").html(content);
        $("#" + GoDialogAlertId).dialog({
            autoOpen: true,
            modal: true,
            resizable: false,
            buttons: {
                'Đóng': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            },
            open: function (event, ui) {
                applyStyleButtonTag();
            }
        });
    }
    this.HideWaiting = function () {
        $("#" + GoDialogAlertId).dialog('close');
    }
    this.Alert = function (content, callback, params) {
        $("#" + GoDialogAlertId + "Content").html(content);
        $("#" + GoDialogAlertId).dialog({
            autoOpen: true,
            modal: true,
            resizable: false,
            buttons: {
                'Đóng': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                if (typeof callback == 'function') {
                    callback(params);
                }
                $(this).dialog("destroy");
            }
        });
    }
    this.AlertThenHide = function (content, callback, params, time) {
        $("#" + GoDialogAlertId + "Content").html(content);
        $("#" + GoDialogAlertId).dialog({
            autoOpen: true,
            modal: true,
            resizable: false,
            buttons: {
                'Đóng': function () {
                    $(this).dialog('close');
                }
            },
            close: function () {
                if (typeof callback == 'function') {
                    callback(params);
                }
                $(this).dialog("destroy");
            }
        });
        setTimeout(function () { $("#" + GoDialogAlertId).dialog('close') }, time);
    }
    // hien thi dialog thong bao
    this.Confirm = function (title, content, callback, params) {
        $("#" + GoDialogConfirmId + "Content").html(content);
        $("#" + GoDialogConfirmId).dialog({
            autoOpen: true,
            modal: true,
            title: title,
            resizable: false,
            buttons: {
                'Bỏ qua': function () {
                    $(this).dialog('close');
                    return;
                },
                'Đồng ý': function () {
                    if (typeof callback == 'function') {
                        callback(params);
                    }
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            }

        });
    }
    // hien thi dialog thong bao
    this.ConfirmTwoButton = function (title, content, callback, params, callback2, params2) {
        $("#" + GoDialogConfirmId + "Content").html(content);
        $("#" + GoDialogConfirmId).dialog({
            autoOpen: true,
            modal: true,
            title: title,
            resizable: false,
            buttons: {
                'Bỏ qua': function () {
                    if (typeof callback2 == 'function') {
                        callback2(params2);
                    }
                    $(this).dialog('close');
                    return;
                },
                'Đồng ý': function () {
                    if (typeof callback == 'function') {
                        callback(params);
                    }
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            }

        });
    }
    this.ConfirmParam = function (param) {
        if (typeof (param) !== Array) return;
        $("#" + GoDialogConfirmId + "Content").html(param.content);
        $("#" + GoDialogConfirmId).dialog({
            autoOpen: true,
            modal: true,
            title: param.title,
            resizable: false,
            buttons: {
                'Hủy bỏ': function () {
                    $(this).dialog('close');
                    return;
                },
                'Đồng ý': function () {
                    if (typeof param.callback == 'function') {
                        param.callback(param.params);
                    }
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            }
        });
    }

    this.HideAlert = function () {
        $('#' + GoDialogAlertId).dialog('close');
    }
    this.HideAlertTimeout = function (time) {
        setTimeout(function () {
            $('#' + GoDialogAlertId).dialog('close');
        }, time);
    }

    // hien thi popup dialog
    this.Popup = function (selector, title) {

        $(selector).dialog({
            autoOpen: true,
            title: title,
            modal: true,
            resizable: false,
            width: 600,
            //height:500,

            close: function () {
                $(this).dialog("destroy");
            }
        });
    }

    this.PopupElement = function (selector, title, callback, params) {

        $(selector).dialog({
            autoOpen: true,
            title: title,
            modal: true,
            resizable: false,
            width: 360,
            //height:500,
            buttons: {
                'Hủy bỏ': function () {
                    $(this).dialog('close');
                    return;
                },
                'Đồng ý': function () {
                    if (typeof callback == 'function') {
                        callback(params);
                    }
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            }
        });
    }
    this.PopupElementNameButtonWidth = function (selector, title, callback, params, btok, btcancel, width) {

        $(selector).dialog({
            autoOpen: true,
            title: title,
            modal: true,
            resizable: false,
            width: width,
            //height:500,
            buttons: {
                btcancel: function () {
                    $(this).dialog('close');
                    return;
                },
                btok: function () {
                    if (typeof callback == 'function') {
                        callback(params);
                    }
                    $(this).dialog('close');
                }
            },
            close: function () {
                $(this).dialog("destroy");
            }
        });
    }
}
try { GoDialog.Init(); }
catch (e) { }
