Type.registerNamespace('msWeb');

/* Begin PresenterEditor */
msWeb.PresenterEditor = function(element)
{
    msWeb.PresenterEditor.initializeBase(this, [element]);

    this.listBoxPresentersId = null;
    this.inputPresenters = null;
    this.imageMoveUp = null;
    this.imageMoveDown = null;
    this.imageDelete = null;
    this.useDataChangeValidator = null;
    this.listBoxPresenters = null;
}

msWeb.PresenterEditor.prototype =
{
    initialize: function()
    {
        $addHandler(this.imageMoveUp, 'click', Function.createDelegate(this, this.MoveUp));
        $addHandler(this.imageMoveDown, 'click', Function.createDelegate(this, this.MoveDown));
        $addHandler(this.imageDelete, 'click', Function.createDelegate(this, this.Delete));
        msWeb.PresenterEditor.callBaseMethod(this, 'initialize');
    },

    dispose: function()
    {
        $clearHandlers(this.imageMoveUp);
        $clearHandlers(this.imageMoveDown);
        $clearHandlers(this.imageDelete);
        msWeb.PresenterEditor.callBaseMethod(this, 'dispose');
    },

    get_listBoxPresentersId: function()
    {
        return this.listBoxPresentersId;
    },

    set_listBoxPresentersId: function(value)
    {
        this.listBoxPresentersId = value;
    },

    get_inputPresenters: function()
    {
        return this.inputPresenters;
    },

    set_inputPresenters: function(value)
    {
        this.inputPresenters = value;
    },

    get_imageMoveUp: function()
    {
        return this.imageMoveUp;
    },

    set_imageMoveUp: function(value)
    {
        this.imageMoveUp = value;
    },

    get_imageMoveDown: function()
    {
        return this.imageMoveDown;
    },

    set_imageMoveDown: function(value)
    {
        this.imageMoveDown = value;
    },

    get_imageDelete: function()
    {
        return this.imageDelete;
    },

    set_imageDelete: function(value)
    {
        this.imageDelete = value;
    },

    get_useDataChangeValidator: function()
    {
        return this.useDataChangeValidator;
    },

    set_useDataChangeValidator: function(value)
    {
        this.useDataChangeValidator = value;
    },

    SetHiddenInput: function()
    {
        var ids = '';

        this.listBoxPresenters = $get(this.listBoxPresentersId);

        for (var i = 0; i < this.listBoxPresenters.options.length; i++)
        {
            if (i == 0)
            {
                this.listBoxPresenters.options[i].style.color = 'black';
            }
            else
            {
                this.listBoxPresenters.options[i].style.color = 'Gray';
            }

            ids += this.listBoxPresenters.options[i].value + '|';
        }

        this.inputPresenters.value = ids;
    },

    MoveUp: function()
    {
        var i;
        this.listBoxPresenters = $get(this.listBoxPresentersId);

        if (this.listBoxPresenters.options.length < 2)
        {
            return;
        }

        for (i = 0; i < this.listBoxPresenters.options.length; i++)
        {
            if (this.listBoxPresenters.options[i].selected)
            {
                break;
            }
        }

        if (i == 0)
        {
            return;
        }
        else
        {
            var topItem = document.createElement('option');
            topItem.text = this.listBoxPresenters.options[i - 1].text;
            topItem.value = this.listBoxPresenters.options[i - 1].value;

            var bottomItem = document.createElement('option');
            bottomItem.text = this.listBoxPresenters.options[i].text;
            bottomItem.value = this.listBoxPresenters.options[i].value;
            bottomItem.selected = true;

            this.listBoxPresenters.options[i - 1] = bottomItem;
            this.listBoxPresenters.options[i] = topItem;
        }

        this.SetHiddenInput();
    },

    MoveDown: function()
    {
        var i;
        this.listBoxPresenters = $get(this.listBoxPresentersId);

        if (this.listBoxPresenters.options.length < 2)
        {
            return;
        }

        for (i = 0; i < this.listBoxPresenters.options.length; i++)
        {
            if (this.listBoxPresenters.options[i].selected)
            {
                break;
            }
        }

        if (i == this.listBoxPresenters.options.length - 1)
        {
            return;
        }
        else
        {
            var bottomItem = document.createElement('option');
            bottomItem.text = this.listBoxPresenters.options[i + 1].text;
            bottomItem.value = this.listBoxPresenters.options[i + 1].value;

            var topItem = document.createElement('option');
            topItem.text = this.listBoxPresenters.options[i].text;
            topItem.value = this.listBoxPresenters.options[i].value;
            topItem.selected = true;

            this.listBoxPresenters.options[i + 1] = topItem;
            this.listBoxPresenters.options[i] = bottomItem;
        }

        this.SetHiddenInput();
    },

    Delete: function()
    {
        var i;
        this.listBoxPresenters = $get(this.listBoxPresentersId);

        for (i = 0; i < this.listBoxPresenters.options.length; i++)
        {
            if (this.listBoxPresenters.options[i].selected)
            {
                break;
            }
        }

        this.listBoxPresenters.options[i] = null;
        this.SetHiddenInput();

        if (this.useDataChangeValidator)
        {
            SetPageDirty();
        }
    },

    ValidatePresenters: function(source, args)
    {
        this.listBoxPresenters = $get(this.listBoxPresentersId);
        args.isValid = this.listBoxPresenters.options.length > 0;
    }
}
msWeb.PresenterEditor.registerClass('msWeb.PresenterEditor', Sys.UI.Control);
/* End PresenterEditor */

/* Begin SingleFileUpload */
msWeb.SingleFileUpload = function(element)
{
	msWeb.SingleFileUpload.initializeBase(this, [element]);
	this.iFrameId = null;
	this.fileUpload = null;
}

msWeb.SingleFileUpload.prototype =
{
	initialize: function()
	{
		msWeb.SingleFileUpload.callBaseMethod(this, 'initialize');
	},

	dispose: function()
	{
		msWeb.SingleFileUpload.callBaseMethod(this, 'dispose');
	},

	get_iFrameId: function()
	{
		return this.iFrameId;
	},

	set_iFrameId: function(value)
	{
		this.iFrameId = value;
	},

	IsFileSelected: function()
	{
		try
		{
			return $get('fileUpload', window.frames[this.iFrameId].document).Content.SingleFileUpload.FileSelected;
		}
		catch (ex)
		{
			return false;
		}
	},

	StartUpload: function()
	{
		try
		{
			$get('fileUpload', window.frames[this.iFrameId].document).Content.SingleFileUpload.StartUpload();
		}
		catch (ex)
		{
		}
	},

	OpenFileDialog: function()
	{
		Sys.Debug.trace('openfiledialog');
		try
		{
			$get('fileUpload', window.frames[this.iFrameId].document).Content.SingleFileUpload.OpenFileDialog();
		}
		catch (ex)
		{
		}
	}
}
msWeb.SingleFileUpload.registerClass('msWeb.SingleFileUpload', Sys.UI.Control);
/* End SingleFileUpload */

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();