var downLinks = new Array();
var downNum = 0;
var downLimit = 0;		// 下载链接类型:0为直接链接,1为防盗链接
var o_links;
function initLinks()
{

	if (downLinks.length==0){
		downLinks.push(new Array("下载点1", ""));
	}
	
	o_links = document.getElementById("dLinks");
	for(var i=0; i<downLinks.length; i++){
		var arr = downLinks[i];
		createLink(arr[0], arr[1], arr[2]);
	}

//	alert("B");
	
}

function createLink(dName, dUrl, dLimit)
{
	var cid = downNum;
	var o_link = document.createElement("DIV");
	o_link.innerHTML = " 名称 ";
	var o_input = document.createElement("INPUT");
	var o_item;
	o_input.type = "text";
	o_input.name = "dn"+ cid;
	o_input.size = "20";
	o_input.maxLength = "20";
	o_input.value = dName;
//	o_input.onclick=alertname;
	o_link.appendChild(o_input);
	
	o_span = document.createElement("SPAN");
	o_span.innerHTML = "　地址 ";
	o_link.appendChild(o_span);
	
	o_input = document.createElement("INPUT");
	o_input.name = "du"+ cid;
	o_input.id = "du"+ cid;
	o_input.type = "text";
	o_input.size = "30";
	o_input.maxLength = "255";
	o_input.value = dUrl;
	o_link.appendChild(o_input);
	
	o_span = document.createElement("SPAN");
	o_span.innerHTML = "　";
	o_link.appendChild(o_span);
	
	o_input = document.createElement("SELECT");
	o_input.name = "dl"+ cid;
	o_item = document.createElement("OPTION");
	o_item.value = "0";
	o_item.innerText = "直接链接";
	o_item.text = "直接链接";	//firefox
	o_input.appendChild(o_item);
	o_item = document.createElement("OPTION");
	o_item.value = "1";
	o_item.innerText = "防盗链接";
	o_item.text = "防盗链接";
	o_input.appendChild(o_item);
	o_input.selectedIndex = dLimit==null ? downLimit : dLimit;
	o_link.appendChild(o_input);
	
	if(cid>0){
		o_span = document.createElement("SPAN");
		o_span.innerHTML = "　<a href=\"javascript:deleteLink("+ cid +")\">删除</a>";
		o_link.appendChild(o_span);
	}
	
	o_links.appendChild(o_link);
	
	downNum++;
}

function addLink()
{
	createLink("下载点"+(downNum+1),"", downLimit);
}

function deleteLink(n)
{
	o_links.removeChild(o_links.childNodes[n]);
	downNum--;
	if (n<downNum){
		for(var i=n; i<downNum; i++){
			var o_link = o_links.childNodes[i];
		//	alert(o_link.childNodes.length);
			o_link.childNodes[1].name = "dn"+ i;
			o_link.childNodes[3].name = "du"+ i;
			o_link.childNodes[5].name = "dl"+ i;
			o_link.childNodes[6].innerHTML = "　<a href=\"javascript:deleteLink("+ i +")\">删除</a>";
		}
	}
}

/*
function alertname(){
	alert(window.event.srcElement.name);
}
*/