﻿
Type.registerNamespace('PhotoSite');

PhotoSite.PopupMsgBox = function(id, clientID, rootURL)
{
    this.ID = id;
    this.ClientID = clientID;
    this.RootURL = rootURL;
}

PhotoSite.PopupMsgBox.prototype = {
    ID: null,
    ClientID: null,
    RootURL: null,

    Show: function(title, message, buttons, params) {
        document.getElementById(this.ID + '_pnlPopupMsgBoxButtons').innerHTML = '';
        document.getElementById(this.ID + '_pnlPopupMsgBoxTitle').innerHTML = title;
        document.getElementById(this.ID + '_pnlPopupMsgBoxText').innerHTML = message;

        var height = typeof(params) !== 'undefined' && typeof(params.Height) !== 'undefined' ? params.Height : 100;

        document.getElementById(this.ID + '_pnlPopupMsgBoxOuterContent').style.height = height + 'px';

        if (buttons != null) {
            for (var i = 0; i < buttons.length; i++) {
                var callback = buttons[i].Callback;
                var close = buttons[i].CloseOnClick;

                if (typeof (callback) === 'undefined') callback = null;
                if (typeof (close) === 'undefined') close = true;

                this.CreatePopupButton(buttons[i].Button, callback, close);
            }
        }
        showPopup(this.ClientID);
    },

    Hide: function() {
        hidePopup(this.ClientID);
    },

    CreatePopupButton: function(Name, Callback, Close) {
        var container = document.getElementById(this.ID + '_pnlPopupMsgBoxButtons');
        var root = this.RootURL + 'images/btns/';
        var link = document.createElement('a');
        var img = document.createElement('img');

        img.style.border = '0px';

        switch (Name.toLowerCase()) {
            case 'ok':
                img.src = root + 'btn_ok' + SR.LanguageSuffix + '.gif';
                break;
            case 'close':
                img.src = root + 'btn_close' + SR.LanguageSuffix + '.gif';
                break;
            case 'cancel':
                img.src = root + 'btn_cancel' + SR.LanguageSuffix + '.gif';
                break;
            case 'apply':
                img.src = root + 'btn_apply' + SR.LanguageSuffix + '.gif';
                break;
            case 'submit':
                img.src = root + 'btn_apply' + SR.LanguageSuffix + '.gif';
                break;
            case 'addtocart':
                img.src = root + 'btn_add_cart' + SR.LanguageSuffix + '.gif';
                break;
            case 'addandgotocart':
                img.src = root + 'btn_add_n_go_cart' + SR.LanguageSuffix + '.gif';
                break;
            case 'usecurrentphoto':
                img.src = root + 'btn_use_current_photo' + SR.LanguageSuffix + '.gif';
                break;
            default:
                return;
        }

        link.setAttribute('href', '#');
        link.oCallback = Callback;
        link.oClose = close;
        link.oParent = this;
        link.onclick = function() {
            if (this.oCallback != null) this.oCallback();
            if (this.oClose) this.oParent.Hide();
            return false;
        };
        link.appendChild(img);
        container.appendChild(link);
        container.appendChild(document.createTextNode(' '));
    }
};
