Array.prototype.unique=function()
{
	var a={};
	for(var i=0;i<this.length;i++)
	{
	if(typeof a[this[i]]=="undefined")
	a[this[i]]=1;
	}
	this.length=0;
	for(var i in a)
	this[this.length]=i;
	return this;
}


function goPage(number){
	document.getElementById('page').value = number;
	document.getElementById('pageDivision').submit();
}
function sortRs(){
	document.getElementById('hiddenSort').value = document.getElementById('sortBy').value;
	document.getElementById('pageDivision').submit();
}

function sortValue(value){
	document.getElementById('hiddenSort').value = value
	document.getElementById('pageDivision').submit();
}

function chushi(i){
	document.getElementById('copyrightCenter').className = 'current';
	document.getElementById("searchForm").style.display="block";
	init_search(i);
}
function init_search(e){
	var link = document.getElementById('link'+e);
	//	if(link.className == 'current')return;
	var search = document.getElementById('searchForm');
	for(var i=1; i<5; i++){
		document.getElementById('link'+i).className='nn';
	}
	for(var i = 4 ; i >0  ; i--){
		var rankSelect = document.getElementById('rank'+i);
		if(rankSelect.value != -1){
			getNextRank('rank'+i);
			break;
		}
	}
	document.getElementById('link'+e).className='current';
	document.getElementById('writingSearchKeys').style.display='none';
	document.getElementById('entrustSearchKeys').style.display='none';
	document.getElementById('cooperationSearchKeys').style.display='none';
	document.getElementById('publishSearchKeys').style.display='none';
	if(e == '1'){
		search.action = '/copyright/writing/index.php';
		document.getElementById('writingSearchKeys').style.display='block';
	}
	if(e == '2'){
		search.action = '/copyright/entrust_compose/index.php';
		document.getElementById('entrustSearchKeys').style.display='block';
	}
	if(e == '3'){
		search.action = '/copyright/cooperation/index.php';
		document.getElementById('cooperationSearchKeys').style.display='block';
	}
	if(e == '4'){
		search.action = '/copyright/publish/index.php';
		document.getElementById('publishSearchKeys').style.display='block';
	}

}
function changeUrl(e){
	var link = document.getElementById('link'+e);
	if(link.className == 'current')return;
	var search = document.getElementById('searchForm');
	for(var i=1; i<5; i++){
		document.getElementById('link'+i).className='';
	}
	document.getElementById('link'+e).className='current';
	document.getElementById('writingSearchKeys').style.display='none';
	document.getElementById('entrustSearchKeys').style.display='none';
	document.getElementById('cooperationSearchKeys').style.display='none';
	document.getElementById('publishSearchKeys').style.display='none';
	if(e == '1'){
		search.action = '/copyright/writing/index.php';
		document.getElementById('writingSearchKeys').style.display='block';
	}
	if(e == '2'){
		search.action = '/copyright/entrust_compose/index.php';
		document.getElementById('entrustSearchKeys').style.display='block';
	}
	if(e == '3'){
		search.action = '/copyright/cooperation/index.php';
		document.getElementById('cooperationSearchKeys').style.display='block';
	}
	if(e == '4'){
		search.action = '/copyright/publish/index.php';
		document.getElementById('publishSearchKeys').style.display='block';
	}
	document.getElementById('rank1').selectedIndex = 0;
	for(var i = 2 ; i < 5 ; i++){
		var sele = document.getElementById('rank'+i);
		resetSelect(sele);
	}
	document.getElementById('advCopyrightSearchDiv').style.display='none';
	document.getElementById('advEntrustSearchDiv').style.display='none';
	document.getElementById('advPublishSearchDiv').style.display='none';
	var advSearchLink = document.getElementById('advSearchLink');
	toNormalSearch(advSearchLink);
}
function show(e){
	//	alert(document.getElementById('link1'));
	for(var i=1; i<5; i++){
		document.getElementById('link'+i).className='';
		document.getElementById("form"+i).style.display="none";
	}
	document.getElementById('link'+e).className='current';
	document.getElementById("form"+e).style.display="block";
}
var xmlHttp;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	}else{
		xmlHttp = new XMLHttpRequest();
	}
}
function getNextRank(sele){
	var select = document.getElementById(sele);
	createXMLHttpRequest();
	xmlHttp.open('GET',"/copyright/get_next_rank.php?" + select.id + '=' + select.value,true);
	xmlHttp.onreadystatechange = showNextRank;
	xmlHttp.send(null);
}
function showNextRank(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status ==200){
			var xmlDoc = xmlHttp.responseXML;
			var item = xmlDoc.getElementsByTagName('rank');
			var rank_class = item[0].textContent || item[0].text;
			var nextRank = document.getElementById('rank'+rank_class);
			var n2 = document.getElementById('rank'+(rank_class-(-1)));
			var n3 = document.getElementById('rank'+(rank_class-(-2)));
			resetSelect(nextRank);
			if(n2)resetSelect(n2);
			if(n3)resetSelect(n3);
			var ops = xmlDoc.getElementsByTagName('option');
			for(var i = 0 ; i < ops.length ; i++){
				var value = ops[i].getAttribute('value');
				var text = ops[i].text || ops[i].textContent;
				var newOption = new Option(text,value);
				nextRank.options[nextRank.options.length] = newOption;
			}
			getCopyright('rank'+(rank_class-1));
		}else{
			alert(xmlHttp.responseText);
		}
	}
}
function resetSelect(sele){
	sele.innerHTML = '';
	var op = new Option('--请选择--','-1');
	sele.options[0] = op;
}
function setSelect(select_id,value){
	//	alert(value);
	var select = document.getElementById(select_id);
	for(var i = 0 ; i < select.options.length ; i++){
		if(select.options[i].value == value){
			select.options[i].selected = true;
		}
	}
}
function toAdvanceSearch(advLink){
	advLink.innerHTML = '关闭高级搜索';
	advLink.onclick = function(){toNormalSearch(advLink);};
	for(var i = 1 ; i < 5 ; i++){
		var link = document.getElementById('link'+i);
		if(link.className=='current' && i == 1){
			var advSearchDiv = document.getElementById('advCopyrightSearchDiv');
			advSearchDiv.style.display = 'block';
		}
		if(link.className=='current' && i == 2){
			var advSearchDiv = document.getElementById('advEntrustSearchDiv');
			advSearchDiv.style.display = 'block';
		}
		if(link.className=='current' && i == 3){
			var advSearchDiv = document.getElementById('advEntrustSearchDiv');
			advSearchDiv.style.display = 'block';
		}
		if(link.className=='current' && i == 4){
			var advSearchDiv = document.getElementById('advPublishSearchDiv');
			advSearchDiv.style.display = 'block';
		}

	}
}
function toNormalSearch(advLink){
	advLink.innerHTML = '高级搜索';
	advLink.onclick = function(){toAdvanceSearch(advLink);}
	for(var i = 1 ; i < 5 ; i++){
		var link = document.getElementById('link'+i);
		if(link.className=='current' && i == 1){
			var advSearchDiv = document.getElementById('advCopyrightSearchDiv');
			advSearchDiv.style.display = 'none';
		}
		if(link.className=='current' && i == 2){
			var advSearchDiv = document.getElementById('advEntrustSearchDiv');
			advSearchDiv.style.display = 'none';
		}
		if(link.className=='current' && i == 3){
			var advSearchDiv = document.getElementById('advEntrustSearchDiv');
			advSearchDiv.style.display = 'none';
		}
		if(link.className=='current' && i == 4){
			var advSearchDiv = document.getElementById('advPublishSearchDiv');
			advSearchDiv.style.display = 'none';
		}
		document.getElementById('copyright').selectedIndex = 0;
		document.getElementById('tradeType').selectedIndex = 0;
		document.getElementById('major').value = '';
		document.getElementById('area').selectedIndex = 0 ;
		document.getElementById('degree').selectedIndex = 0;
		document.getElementById('defaultWorkType').checked = true;
	}
}
function getCopyright(rankId){
	var rank = document.getElementById(rankId).value;
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = showCopyright;
	xmlHttp.open("GET",'/copyright/get_copyright.php?'+rankId+'='+rank);
	xmlHttp.send(null);
}
function showCopyright(){
	if(xmlHttp.readyState == 4){
		xmlDoc = xmlHttp.responseXML;
		ops = xmlDoc.getElementsByTagName('content');
		var sele = document.getElementById('copyright');
		sele.innerHTML = '';
		sele.options[0] = new Option('--请选择--',-1);
		var tmp = new Array();
		for(var i = 0 ; i < ops.length ; i++){
			var text = ops[i].text || ops[i].textContent;
			text = text.substr(0,text.indexOf('权')+1);
			tmp[i] = text;
		}
		ops = tmp.unique();
		for(var i = 0 ; i < ops.length ; i++){
			option = new Option(ops[i],ops[i]);
			sele.options[sele.options.length] = option;
		}
	}
}

