/* (c) 2007-2009 Kampyle Ltd. All rights reserved */
function DlgLoadCode(url)
{
	var ax = new XHConn();

    var f = function(server)
    {
    	eval(server.responseText);
		
		var list_available = document.getElementById('list-available');
		var list_order = document.getElementById('list-in-order');
		
		if(list_available && available)
		{
			for(i in available)
			{
				option = document.createElement('OPTION');
				option.text = available[i];
				list_available.options.add(option);
			}
		}
		
		if(list_order && order)
		{
			for(i in order)
			{
				option = document.createElement('OPTION');
				option.text = order[i];
				list_order.options.add(option);
			}
		}
    }
    ax.connect(url, 'get', '', f);
}

function DlgListItemUp(list_id)
{
	var list = document.getElementById(list_id);
	if(list.selectedIndex > 0)
	{
		var tmp = list.options[list.selectedIndex - 1].text;
		list.options[list.selectedIndex - 1].text = list.options[list.selectedIndex].text;
		list.options[list.selectedIndex].text = tmp;
		list.selectedIndex = list.selectedIndex - 1;
	}
}

function DlgListItemDown(list_id)
{
	var list = document.getElementById(list_id);
	
	if(list.selectedIndex < list.length - 1)
	{
		var tmp = list.options[list.selectedIndex + 1].text;
		list.options[list.selectedIndex + 1].text = list.options[list.selectedIndex].text;
		list.options[list.selectedIndex].text = tmp;
		list.selectedIndex = list.selectedIndex + 1;
	}
}

function DlgSwapItem(source_id, dest_id)
{
	var source = document.getElementById(source_id);
	var dest = document.getElementById(dest_id);
	
	if(source && dest)
	{
		for(var i = 0; i < source.length; i++)
		{
			if(source.options[i].selected)
			{
				option = document.createElement('OPTION');
				option.text = source.options[i].text; 
				dest.options.add(option);
			}
		}

		for(i = source.length - 1; i >= 0; i--)
		{
			if(source.options[i].selected)
			{
				source.remove(i);
			}
		}
	}
}
