function downTypeChange( type, did)
{
	var link = "module.php?mod=download&action=downtypechange&channelid="+channelid;
	AJAX.request( link,
	{
		method		: 'post',
		parameters	: 'type='+type+'&id='+did,
		onComplete	: function(json)
		{
			createNewTable(did, json);
		}
	});
}

function createNewTable( id, json)
{
	if( json.status == 200)
	{
		var obj = $('down_table');
		while( obj.rows[1].id != 'urlsitem')
		{
			obj.deleteRow(1);
		}
		var _tr ;
		obj = $('Tabs0');
		_tr = obj.insertRow(1);
		var _td = _tr.insertCell(0);
			_td.className = "tablerowl";
			_td.width = "10%";
		var _td = _tr.insertCell(1);
			_td.className = "tablerow";
			_td.width = "90%";
			_td.innerHTML = "<input type=\"button\" class='f-text' value=\"下载地址添加\" name=\"addoption\" onClick=\"AddItem();\"> <input type=button value=\"下载模式转换\" onclick=\"downTypeChange(0, "+id+");\" disabled>";
		for( var i=0; i<json.message.length; i++)
		{
			_tr = obj.insertRow(i+2);
			var _td = _tr.insertCell(0);
				_td.className = "tablerowl";
				_td.width = "10%";
				_td.innerHTML = "<font color=red>下载地址</font>";
			var _td = _tr.insertCell(1);
				_td.className = "tablerow";
				_td.width = "90%";
				_td.innerHTML = "<input type=\"text\" class='f-text'  id=\"url_name_"+json.message[i].selfid+"\" size=\"15\" maxlength=\"30\" value=\"下载地址"+(i+1)+"\">";
				_td.innerHTML+= " <input type=\"text\" class='f-text'  id=\"urls_"+json.message[i].selfid+"\" size=\"40\" maxlength=\"255\" value=\""+json.message[i].urls+"\">";				
				_td.innerHTML+= " <input onclick=\"save('editurl',"+json.message[i].selfid+",0);\" value='保存修改' type='button'> <input onclick=\"save('deleteurl',"+json.message[i].selfid+",this.parentNode.parentNode.rowIndex);\" value='删除此行' type='button' class='f-button'>";
		}
		$('type').value = 0;
	}
	else
	{
		alert("wrong");
	}
}

function save( action,id,rows)
{
	var url_name = '';
	var link = '';
	if( action=='editurl'){
		urls       = encodeURIComponent($("urls_"+id).value) ;
		url_name   = $("url_name_"+id).value;
		link   = "system.php?sys=module&mod="+mod+"&channelid="+channelid+"&action=ajax&action_do="+action+"&urls="+urls+"&id="+id;
	}
	if( action=='deleteurl'){
		if(!makeSure()) return false;
		link = "system.php?sys=module&mod="+mod+"&channelid="+channelid+"&action=ajax&action_do="+action+"&id="+id;
	}
	if(link == '') return alert("error");
	var A = arguments;
	if(A.length == 4){
		A[3].disabled = true;
	}
	AJAX.request( link,
	{
		method		: 'post',
		parameters	: 'url_name=' + encodeURIComponent(url_name),
		onComplete	: function( json){
			var json = evaljson(json);
			if(A.length == 4){
				A[3].disabled = false;
			}
			if( json[0]==1){
				if( action=='editurl'){
					alert( lang[json[1]]);
				}else{
					var myTable = $("down_table");
					myTable.deleteRow( rows);
				}
			}else{
				alert(lang[json[1]]);
			}
		}
	});
}
var autoIndex = 1;
function AddItem()
{
	autoIndex++;
	var index = $('urlsitem').rowIndex;
	var _tr   = $('down_table').insertRow( index);
	var a     = _tr.insertCell(0);
      		a.className = "tablerowl";
		a.innerHTML = "下载地址";
	var b = _tr.insertCell(1);
      		b.className = "tablerow";
		b.innerHTML = "<input name=\"url_name[]\" type=\"text\" class='f-text'  size=\"15\" maxlength=\"30\" value=\"下载地址"+index+"\">&nbsp;<input  class='f-text' name=\"urls[]\" id=\"urls_modify_"+autoIndex+"\" type=\"text\" size=\"40\" maxlength=\"255\" value=\"\"><input type=\"button\" class=\"f-button\" value=\"上传\" onClick=\"qmeCms.dialogView.iframe('上传文件','module.php?mod=download&action=upload&id=urls_modify_"+autoIndex+"&channelid="+channelid+"&file_type=file',{type:'abs'});\"><input class=\"f-button\" type=button onclick=\"SelectBrowse('"+config.url+"admin/images/browse.html?type=file&channelid="+channelid+"&callback=getBrowseSoft','urls_modify_"+autoIndex+"',550,360);\" value=\"浏览\"><input class=\"f-button\" type=\"button\" value=\"删除\" onclick=\"$('down_table').deleteRow(this.parentNode.parentNode.rowIndex)\">";
}
function doCheck()
{
	if (document.myform.cid.value=='0'){
		alert('指定的栏目不允许添加文章！只允许在其子栏目中添加文章。');
		return false;
	}
	if (document.myform.subject.value=="") {
		alert("请输入标题！");
		return false;
	}
	if (document.myform.size.value=="") {
		alert("请输入大小！");
		return false;
	}
	qmeCms.dialogView.form('操作提示','', {width:400})
	$('submit').disabled = true;
}
