function keyEvt(event, btn)
{
	if (event && event.keyCode == 13)
		document.getElementById(btn).focus();
	else
		return true;
}

function noenter()
{
	return !(window.event && window.event.keyCode == 13);
}

function close_msg(which)
{
	if(which != 'ok' && which != 'warn' && which != 'error')
		which = 'ok';
	obj = document.getElementById(which + '_msg');
	if(!obj) return;
	obj.style.display = 'none';
	obj.style.height=0;
}

function createTasks0(index)
{
	var obj = document.getElementsByName('tasks')[0];
	eval(ajax.response);
}

function createTasks1(index)
{
	var obj = document.getElementsByName('tasks')[1];
	eval(ajax.response);
}

function addDependencies(index)
{
	if(!index) index=0;
	var tObj = document.getElementsByName('tasks')[index];
	if(tObj.options.length == 0)
		return;

	var dObj = document.getElementsByName('dtype')[index];
	var obj = document.getElementsByName('dependencies[]')[index];

	var newTxt = dObj.options[dObj.selectedIndex].text + ' -> ' + tObj.options[tObj.selectedIndex].text;
	var newVal = tObj.options[tObj.selectedIndex].value + ',' + dObj.options[dObj.selectedIndex].value;

    for(x = 0; x < obj.options.length; x++)
	{
		var items = obj.options[x].value.split(',');
		if(tObj.options[tObj.selectedIndex].value == items[0])
			return;
	}

	obj.options[obj.options.length] = new Option(newTxt, newVal);

	var tmpTextArray = new Array();
	for(i = 0; i < obj.options.length; i++)
	{
		tmpTextArray.push(obj.options[i].text + '___' + obj.options[i].value);
	}
	tmpTextArray.sort();

	for(i = 0; i < tmpTextArray.length; i++)
	{
		var items = tmpTextArray[i].split('___');
		obj.options[i] = new Option(items[0], items[1]);
	}
}

function delDependencies(index)
{
	if(!index) index=0;
	var obj = document.getElementsByName('dependencies[]')[index];
    for(i = 0; i < obj.options.length; i++)
	{
		if(obj.options[i].selected)
		{
			obj.options[i].selected = false;
			obj.options[i] = null;
			//obj.options.length--;
			i--;
		}
	}
}

function createUploadRow()
{
	newnode = document.getElementById('uploadRowHidden').firstChild.cloneNode(true);
	document.getElementById('uploadRow').appendChild(newnode);
}

function removeUploadRow()
{
	obj = document.getElementById('uploadRow');
	if(obj.childNodes.length > 1 && obj.lastChild)
		obj.removeChild(obj.lastChild);
}
