var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
function openMaskArea(maskId, editorId)
{
    positionEditor(editorId);
    var seCmsMask = document.getElementById(maskId);
    var seCmsEditor = document.getElementById(editorId);
    seCmsMask.style.display = "block";
    seCmsEditor.style.display = "block";
    if (!isIE6)
    {
        seCmsMask.style.position = "fixed";
        seCmsEditor.style.position = "fixed";
    }
    sizeMask();
    return false;
}

function positionEditor(editorId)
{
    var seCmsEditor = document.getElementById(editorId);
    var windowWidth = document.documentElement.clientWidth;
    var widthHalf = (windowWidth / 2) - 300;
    seCmsEditor.style.left = widthHalf + "px";
}

function sizeMask()
{
    var h = 0;
	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		h = window.innerHeight;
	}
    var seCmsMask = document.getElementById("seCmsMainMask");
    seCmsMask.style.height = h + "px";
    seCmsMask.style.opacity = .60;
    seCmsMask.style.filter = 'alpha(opacity= 60)';
}

function closeEditorWindow(maskId, editorId)
{
    var mask = document.getElementById(maskId);
    var editor = document.getElementById(editorId);
    mask.style.display = "none";
    editor.style.display = "none";
    return false;
}

function toggleBackgroundGraphic(image, id)
{
    var button = document.getElementById(id);
    button.style.background = "url(" + image + ")";
}

function toggleSaveGraphic(image, id)
{
    var button = document.getElementById(id);
    button.src = "url(" + image + ")";
}

function moveItem(id, hid, dir)
{
    var list = document.getElementById(id);   
    var hidden = document.getElementById(hid);
    var i = list.selectedIndex;
    var j = Math.max(Math.min(i + dir, list.options.length-1),0);
    var opt = list.options[i].text;
    list.options[i].text = list.options[j].text;
    list.options[j].text = opt;
    list.selectedIndex = j;
    hidden.value = "";
    for (var x = 0; x < list.options.length; x++)
    {
        hidden.value += list.options[x].text + ((x==list.options.length-1)?"":"|");
    }
}