function Trim(str){
 if(str.charAt(0) == " "){
  str = str.slice(1);
  str = Trim(str); 
 }
 return str;
}

function doSimpleQuery(pageno) 
{  	
	var cql = "";
	if(document.form1.pagingType.value==0)
	{
		if(simpleQueryCheck(document.form1))
		{//校验通过
		//	alert("");
			cql = getSimpleCQL(document.form1);
			if(cql=="")
			{
				alert(document.form1.conInvalid.value);
			}
			else
			{
				document.form1.actionType.value="doSimpleQuery";
				document.form1.pageno.value=pageno;
				document.form1.query.value=cql;
				//alert("pageno="+document.form1.pageno.value);
				//alert("query="+document.form1.query.value);
				document.form1.action="doSimpleQuery.do";
				document.form1.submit();
			}
		}
	}
	else
	{
		document.form1.actionType.value="doSimpleQuery";
		document.form1.pageno.value=pageno;
		document.form1.action="doSimpleQuery.do";
		document.form1.submit();
	}
}

function simpleQueryCheck(form)
{
	if(Trim(form.condition.value)=="")
	{
		alert(form.conInvalid.value);
		return false;
	}
	else
	{
		//alert('Simple Query Condition Valid!');
		return true;
	}
}

function getSimpleCQL(form)
{
	keyAndMatching = form.indexkey.value;
	condition = form.condition.value;
	
	indexb = condition.indexOf("-");
	from = "";
	to = "";
	if(indexb <= -1)
	{
		from = condition;
		to = "";
	}
	else
	{
		from = condition.substring(0, indexb);
		to = condition.substring(indexb+1, condition.length);
	}
	
	//从keyAndMatching中拆分出key和matching
	index = keyAndMatching.indexOf("|");
	
	keyname = keyAndMatching.substring(0, index);
	matching = keyAndMatching.substring(index+1, keyAndMatching.length);
	condition = condition.replace("\"","&&;");
	condition = condition.replace("'","&&,");
	
	var cql = "";
	if(matching=="frt")
	{//前方一致
		//alert("");
		cql = keyname + "=" + "\"" + condition + "*" + "\"" ;  
	}
	if(matching=="ext")
	{//精确匹配
		//alert("");
		cql = keyname + "=" + "\"" + condition + "\"" ;  
	}
	if(matching=="inc")
	{//包含
	//	alert("");
		cql = keyname + "=" + "\"" + "*" + condition + "*" + "\"" ;  
	}
	if(matching=="lst")
	{//小于
		//alert("");
		cql = keyname + "<" + condition ;  
	}
	if(matching=="mot")
	{//大于
		//alert("");
		cql = keyname + ">" + condition ;  
	}
	if(matching=="leq")
	{//小于等于
		//alert("");
		cql = keyname + "<=" + condition ;  
	}
	if(matching=="meq")
	{//大于等于
		//alert("");
		cql = keyname + ">=" + condition ;  
	}
	if(matching=="equ")
	{//等于
		//alert("");
		cql = keyname + "=" + condition ;  
	}
	if(matching=="btw")
	{//介于之间
	//	alert("");
		cql = keyname + ">=" + from + " and " + keyname + "<=" + to ;  
	}

	cql = "(" + cql + ")";
	return cql;
}
function searchagain() {
  condition1 = document.all.condition1.value;
  if(Trim(condition1)=="") {
    return ;
  }
  cql = document.form1.query.value;
  againcql = getAgainCQL(document.all);
  cql += " and " + againcql 
  document.form1.query.value=cql;
  document.form1.action="doAdvanceQuery.do";
  document.form1.submit();

}
function doAdvanceQuery(pageno) 
{  
	var cql = "";
	if(document.form1.pagingType.value==0)
	{
		if(advanceQueryCheck(document.form1))
		{//校验通过
		//	alert("");
			cql = getAdvanceCQL(document.form1);
			if(cql=="")
			{
				alert(document.form1.nulInvalid.value);
			}
			else
			{
				document.form1.actionType.value="doAdvanceQuery";
				document.form1.pageno.value=pageno;
				document.form1.query.value=cql;
				//alert(document.form1.query.value);
				document.form1.action="doAdvanceQuery.do";
				document.form1.submit();
			}
		}
		else
		{
			alert(document.form1.conInvalid.value);
		}
	}
	else
	{
		document.form1.actionType.value="doAdvanceQuery";
		document.form1.pageno.value=pageno;
		document.form1.action="doAdvanceQuery.do";
		document.form1.submit();
	}
}

//校验，看输入对象的值是否为yyyy-yyyy
function isDateBtw(checktext){
	var datetime;
	var year1,year2;
	var gone;
	if(Trim(checktext.value)!=""){
		datetime = Trim(checktext.value);
		if(datetime.length==9){
			year1=datetime.substring(0,4);
			if(isNaN(year1)==true)
			{
				checktext.focus();
				return false;
			}
			gone=datetime.substring(4,5);
			if(gone!="-")
			{
				checktext.focus();
				return false;
			}
			year2=datetime.substring(5,9);
			if(isNaN(year2)==true)
			{
				checktext.focus();
				return false;
			}
		}else{
			checktext.focus();
			return false;
		}
	}else{
		return true;
	}
	return true;
}

function isYear(checktext){
	var datetime;
	var year1;
	if(Trim(checktext.value)!=""){
		datetime = Trim(checktext.value);
		if(datetime.length==4){
			year1=datetime.substring(0,4);
			if(isNaN(year1)==true)
			{
				checktext.focus();
				return false;
			}
		}else{
			checktext.focus();
			return false;
		}
	}else{
		return true;
	}
	return true;
}
function advanceQueryCheck(form)
{
	if(form.datematching5.value != "0")
	{//出版时间有限定时
		if(form.datematching5.value == "btw")
		{//出版时间限定为“介于之间”时
			if(!isDateBtw(form.condition5))
			{
				return false;
			}
		}
		else
		{
			if(!isYear(form.condition5))
			{
				return false;
			}
		}
	}
	
	return true;
}

function getAdvanceCQL(form)
{
	var cql = "";
	
	var str1 = "";
	condition1 = form.condition1.value;
	if(Trim(condition1)!="")
	{
		indexkey1 = form.indexkey1.value;
		listmatching1 = form.listmatching1.value;
		str1 = getACQL(indexkey1, listmatching1, condition1);
	}
	
	var str2 = "";
	condition2 = form.condition2.value;
	if(Trim(condition2)!="")
	{
		indexkey2 = form.indexkey2.value;
		listmatching2 = form.listmatching2.value;
		str2 = getACQL(indexkey2, listmatching2, condition2);
	}
	
	var str3 = "";
	condition3 = form.condition3.value;
	if(Trim(condition3)!="")
	{
		indexkey3 = form.indexkey3.value;
		listmatching3 = form.listmatching3.value;
		str3 = getACQL(indexkey3, listmatching3, condition3);
	}
	
	//alert("str1="+str1+";");
	//alert("str2="+str2+";");
	//alert("str3="+str3+";");
	
	//拼接第一部分
	var strPart1 = "";
	relation1 = form.relation1.value;
	relation2 = form.relation2.value;
	if(str1!="" & str2=="" & str3=="")
	{
		strPart1 = str1;
	}
	else if(str1=="" & str2!="" & str3=="")
	{
		strPart1 = str2;
	}
	else if(str1=="" & str2=="" & str3!="")
	{
		strPart1 = str3;
	}
	else if(str1!="" & str2!="" & str3=="")
	{
		strPart1 = str1 + " " + relation1 + " " + str2;
	}
	else if(str1!="" & str2=="" & str3!="")
	{
		strPart1 = str1 + " " + relation1 + " " + str3;
	}
	else if(str1=="" & str2!="" & str3!="")
	{
		strPart1 = str2 + " " + relation2 + " " + str3;
	}
	else if(str1!="" & str2!="" & str3!="")
	{
		strPart1 = "(" + str1 + " " + relation1 + " " + str2 + ")" + " " + relation2 + " " + str3;
	}
	
	if(strPart1!="")
	{
		strPart1 = "(" + strPart1 + ")";
		cql = " and " + strPart1;
	}

	condition4 = form.condition4.value;
	if(Trim(condition4)!="")
	{
		indexkey4 = form.indexkey4.value;
		matching4 = form.matching4.value;
		cql = cql + " and " + getACQL(indexkey4, matching4, condition4);
	}
	
	condition5 = form.condition5.value;
	if(form.datematching5.value != "0")
	{
		if(Trim(condition5)!="")
		{
			indexkey5 = form.indexkey5.value;
			datematching5 = form.datematching5.value;
			cql = cql + " and " + getACQL(indexkey5, datematching5, condition5);
		}
	}
	
	var strPart2 = "";
	if(form.condition6_1.checked & form.condition6_2.checked &  form.condition6_6.checked )
	{
		strPart2 = "";
	}
	else
	{
		if(form.condition6_1.checked)
		{
			indexkey6_1 = form.indexkey6_1.value;
			matching6_1 = form.matching6_1.value;
			condition6_1 = form.condition6_1.value;
			strPart2 = strPart2 + " or " + getACQL(indexkey6_1, matching6_1, condition6_1);
		}
		
		
		if(form.condition6_2.checked)
		{
			indexkey6_2 = form.indexkey6_2.value;
			matching6_2 = form.matching6_2.value;
			condition6_2 = form.condition6_2.value;
			strPart2 = strPart2 + " or " + getACQL(indexkey6_2, matching6_2, condition6_2);
		}
		
		
		
		
		
		if(form.condition6_6.checked)
		{
			indexkey6_6 = form.indexkey6_6.value;
			matching6_6 = form.matching6_6.value;
			condition6_6 = form.condition6_6.value;
			strPart2 = strPart2 + " or " + getACQL(indexkey6_6, matching6_6, condition6_6);
		}
		
		
	}
	
	if(strPart2!="")
	{
		strPart2 = "(" + strPart2.substring(4, strPart2.length) + ")";
		cql = cql + " and " + strPart2;
	}
	
/*	condition7 = form.condition7.value;
	if(Trim(condition7)!="")
	{
		indexkey7 = form.indexkey7.value;
		matching7 = form.matching7.value;
		cql = cql + " and " + getACQL(indexkey7, matching7, condition7);
	}
	
	condition8 = form.condition8.value;
	if(Trim(condition8)!="")
	{
		indexkey8 = form.indexkey8.value;
		matching8 = form.matching8.value;
		cql = cql + " and " + getACQL(indexkey8, matching8, condition8);
	} */
	
	if(cql!="")
	{
		cql = cql.substring(4, cql.length);
	}
	//alert(cql);
	return cql;
}
function getAgainCQL()
{
	var cql = "";
	
	var str1 = "";
	condition1 = document.all.condition1.value;
	indexkey1 = document.all.indexkey1.value;
	listmatching1 = document.all.listmatching1.value;
	cql = getACQL(indexkey1, listmatching1, condition1);
	return cql;
}
function getACQL(indexkey, matching, condition)
{
	indexb = condition.indexOf("-");
	from = "";
	to = "";
	if(indexb <= -1)
	{
		from = condition;
		to = "";
	}
	else
	{
		from = condition.substring(0, indexb);
		to = condition.substring(indexb+1, condition.length);
	}
	
	condition = condition.replace("\"","&&;");
	condition = condition.replace("'","&&,");
	
	
	var acql = "";
	if(matching=="frt")
	{//前方一致
		//alert("");
		
		acql = indexkey + "=" + "\"" + condition + "*" + "\"" ;  
	}
	if(matching=="ext")
	{//精确匹配
		//alert("");
		acql = indexkey + "=" + "\"" + condition + "\"" ;  
	}
	if(matching=="inc")
	{//包含
	
	    if(indexkey=="dc.identifier" || indexkey=="bath.issn" ||  indexkey=="bath.isbn" || indexkey=="calis.id" || indexkey=="calis.isrc")
		   acql = indexkey + "=" + "\"" + condition + "*" + "\"" ;  
	     else   
		  acql = indexkey + "=" + "\"" + "*" + condition + "*" + "\"" ;  
	}
	if(matching=="lst")
	{//小于
		//alert("");
		acql = indexkey + "<" + condition ;  
	}
	if(matching=="mot")
	{//大于
		//alert("");
		acql = indexkey + ">" + condition ;  
	}
	if(matching=="leq")
	{//小于等于
		//alert("");
		acql = indexkey + "<=" + condition ;  
	}
	if(matching=="meq")
	{//大于等于
		//alert("");
		acql = indexkey + ">=" + condition ;  
	}
	if(matching=="equ")
	{//等于
		//alert("");
		acql = indexkey + "=" + condition ;  
	}
	if(matching=="btw")
	{//介于之间
	//	alert("");
		acql = indexkey + ">=" + from + " and " + indexkey + "<=" + to ;  
	}

	return acql;
}

function switchToOtherBase(lang, queryType)
{
	document.form1.langBase.value=lang;
	
	if(queryType==0)
	{//简单检索
		doSimpleQuery(1);
	}
	else
	{//高级检索
		doAdvanceQuery(1);
	}
}
function sortagain()
{
 document.form1.sortkey.value=document.all.sortagainname.value; 
 doAdvanceQuery(1);	
}
function doShowDetails(recIndex, recTotal, fullTextType, dbselect,oid,sessionid)
{
	document.form1.action="showDetails.do?recIndex="+recIndex+"&recTotal="+recTotal+"&fullTextType="+fullTextType+"&dbselect="+dbselect;
	document.form1.submit();
}

function doShowDetails4MyBib(userid, id, fullTextType, index)
{
	document.form1.action="showDetails4MyBib.do?subact=gotoid&userid="+userid+"&id="+id+"&fullTextType="+fullTextType+"&index="+index;
	document.form1.submit();
}
				
function IsSelectAll()
{
	var checknum = 0;
	

	if(document.form1.idxCheckBox.length>=1)
	{
		//multi
		var index = 0;
		for(index=0; index<document.form1.idxCheckBox.length; index++)
		{
			//alert("index="+index);
			if(document.form1.idxCheckBox[index].checked)
			{
			   checknum ++;
			}
			//alert("checknum="+checknum);
		}
		//alert("--checknum="+checknum);
		if(checknum == document.form1.idxCheckBox.length) 
		{
			for(index=0 ; index < document.form1.idxCheckBox.length; index++)
		    	{
		    		//alert(index);
			    	document.form1.idxCheckBox[index].checked = false;
			}
		}
		else 
		{
			for(index=0 ; index < document.form1.idxCheckBox.length; index++)
		    	{
		    		//alert(index);
			    	document.form1.idxCheckBox[index].checked = true;
			}
		}
	}
	else
	{
		//single
		var index = 0;
		if(document.form1.idxCheckBox.checked) 
		{
			document.form1.idxCheckBox.checked = false;
		}
		else 
		{
			document.form1.idxCheckBox.checked = true;
		}
	}

}
				
function doscansearch(keyname, value, showval)
{

	
	document.form2.query.value = "(" + keyname + "=\"" + value + "\")";
	document.form2.startRecord.value = 1;
	document.form2.target = "";

	
		document.form2.actionType.value="doSimpleQuery";
		document.form2.pageno.value=1;
		document.form2.showqueryval.value = showval
		document.form2.action="doSimpleQuery.do";
		
		document.form2.submit();
	
}
function dosearch(keyname, value)
{
	document.form2.query.value = "(" + keyname + "=\"" + value + "\")";
	document.form2.startRecord.value = 1;
	document.form2.target = "";
	//document.form2.target = "dosearchWindow";
	//document.form2.targetName.value = "dosearchWindow";
	//document.form2.fromTree.value = "true";
	
	if(document.form2.queryType.value == 0)
	{
		//doSimpleQuery(1);
		document.form2.actionType.value="doSimpleQuery";
		document.form2.pageno.value=1;
		document.form2.action="doSimpleQuery.do";
		document.form2.submit();
	}
	else
	{
		//doAdvanceQuery(1);
		document.form2.actionType.value="doAdvanceQuery";
		document.form2.pageno.value=1;
		document.form2.action="doAdvanceQuery.do";
		document.form2.submit();
	}
	
	//document.form2.targetName.value = "";
	//document.form2.fromTree.value = "false";
}

function doSearch4Tree(keyname, value)

         
{
      if(keyname== "calis.scanrbClassification") {
         document.form2.query.value = "(" + keyname + "=\"" + value + "\")";
	document.form2.startRecord.value = 1;
	document.form2.target = "tree_main";
	document.form2.targetName.value = "tree_main";

	document.form2.actionType.value="doSimpleQuery";
	document.form2.pageno.value=1;
	document.form2.action="../doSimpleQuery.do?fromTree=true";
	document.form2.submit();
	document.form2.targetName.value = "";
	
      }else {
        
	
	value = value.substring(0,value.length-1)
	
	if(parent.opener.document.form1.indexkey1.value=="bath.localclassification")
	  parent.opener.document.form1.condition1.value = value 
	
	if(parent.opener.document.form1.indexkey2.value=="bath.localclassification")
	  parent.opener.document.form1.condition2.value = value 

	if(parent.opener.document.form1.indexkey3.value=="bath.localclassification")
	  parent.opener.document.form1.condition3.value = value   
	parent.close()  
      
      }  	
	
}

function doSearchInLangBase(langBase, keyname, value)
{
	document.form2.query.value = "(" + keyname + "=\"" + value + "\")";
	document.form2.startRecord.value = 1;
	document.form2.target = "";
	//document.form2.target = "dosearchWindow";
	//document.form2.targetName.value = "dosearchWindow";
	//document.form2.fromTree.value = "true";
	
	document.form2.langBase.value = langBase;
	document.form2.dbselect.value = langBase;
	
	if(document.form2.queryType.value == 0)
	{
		//doSimpleQuery(1);
		document.form2.actionType.value="doSimpleQuery";
		document.form2.pageno.value=1;
		document.form2.action="doSimpleQuery.do";
		document.form2.submit();
	}
	else
	{
		//doAdvanceQuery(1);
		document.form2.actionType.value="doAdvanceQuery";
		document.form2.pageno.value=1;
		document.form2.action="doAdvanceQuery.do";
		document.form2.submit();
	}
	
	//document.form2.targetName.value = "";
	//document.form2.fromTree.value = "false";
}
function doAdvanceSearchPage(langBase, dbselect) {
 document.form1.langBase.value = langBase;
 document.form1.dbselect.value = dbselect;
 document.form1.action="advanceSearch.do";
 document.form1.submit();
	
}
function doNewAdvanceSearchPage(langBase, dbselect) {
 document.form1.langBase.value = langBase
 document.form1.dbselect.value = dbselect
 document.form1.query.value = ""
 document.form1.action="advanceSearch.do"
 document.form1.submit();	
}

function doshowSearchPage(cqlstr) {

	document.form2.query.value = cqlstr;
	document.form2.action="advanceSearch.do";
	document.form2.submit();
	
}
function doSearch4MidPage(langBase, dbselect)
{
	document.form1.langBase.value = langBase;
	document.form1.dbselect.value = dbselect;
	
	if(document.form1.queryType.value == 0)
	{
		//doSimpleQuery(1);
		document.form1.actionType.value="doSimpleQuery";
		document.form1.pageno.value=1;
		document.form1.action="doSimpleQuery.do";
		document.form1.submit();
	}
	else
	{
		//doAdvanceQuery(1);
		document.form1.actionType.value="doAdvanceQuery";
		document.form1.pageno.value=1;
		document.form1.action="doAdvanceQuery.do";
		document.form1.submit();
	}
}

function doSearchInLangBase4MidPage(langBase)
{
	document.form1.langBase.value = langBase;
	document.form1.dbselect.value = langBase;
	
	if(document.form1.queryType.value == 0)
	{
		//doSimpleQuery(1);
		document.form1.actionType.value="doSimpleQuery";
		document.form1.pageno.value=1;
		document.form1.action="doSimpleQuery.do";
		document.form1.submit();
	}
	else
	{
		//doAdvanceQuery(1);
		document.form1.actionType.value="doAdvanceQuery";
		document.form1.pageno.value=1;
		document.form1.action="doAdvanceQuery.do";
		document.form1.submit();
	}
}

function outputRec(fromType, oid, oids, langBase)
{
	document.form2.targetName.value = "outputRecWindow";
	if(fromType=='fromResultFull')
	{
		document.form2.target = "outputRecWindow";
		document.form2.action="outputRecord.do?subact=enterpage&fromType="+fromType+"&oid="+oid+"&langBase="+langBase;
		document.form2.submit();
	}
	else if(fromType=='fromSimpleList')
	{
		document.form2.target = "outputRecWindow";
		document.form2.action="outputRecord.do?subact=enterpage&fromType="+fromType+"&oids="+oids+"&langBase="+langBase;
		document.form2.submit();
	}
	else if(fromType=='fromMyBibList')
	{
		document.form2.target = "outputRecWindow";
		document.form2.action="outputRecord.do?subact=enterpage&fromType="+fromType+"&oids="+oids+"&langBase="+langBase;
		document.form2.submit();
	}
	document.form2.targetName.value = "";
}

function checkOutput()
{
	var checknum = 0;
	var flag = 1;
	var oids = "";
	if(document.form1.idxCheckBox.length>=1)
	{//multi
		var index = 0;
		for(index=0; index<document.form1.idxCheckBox.length; index++)
		{
			if(document.form1.idxCheckBox[index].checked)
			{
			   checknum ++;
			   oids = oids + document.form1.idxCheckBox[index].value + "|";
			  
			}
		}
		if(checknum == 0)
		{
			flag = 0;
		}
		else
		{
			flag = 1;
		}
	}
	else
	{//single
		if(document.form1.idxCheckBox.checked) 
		{
			flag = 1;
			oids = oids + document.form1.idxCheckBox.value + "|";
		}
		else
		{
			flag = 0;
		}
	}
	
	
	if(flag == 0)
	{
		alert(document.form1.selInvalid.value);
		return oids;
	}
	else
	{
		return oids;
	}
}

function getLangBases()
{
	var checknum = 0;
	var flag = 1;
	var langBases = "";
	if(document.form1.idxCheckBox.length>=1)
	{//multi
		var index = 0;
		for(index=0; index<document.form1.idxCheckBox.length; index++)
		{
			if(document.form1.idxCheckBox[index].checked)
			{
			   checknum ++;
			   langBases = langBases + document.form1.langBases[index].value + "|";
			}
		}
		if(checknum == 0)
		{
			flag = 0;
		}
		else
		{
			flag = 1;
		}
	}
	else
	{//single
		if(document.form1.idxCheckBox.checked) 
		{
			flag = 1;
			langBases = langBases + document.form1.langBases.value + "|";
		}
		else
		{
			flag = 0;
		}
	}
	
	
	if(flag == 0)
	{
		alert(document.form1.selInvalid.value);
		return langBases;
	}
	else
	{
		return langBases;
	}
}

function doScan()
{
	if(doScanCheck(document.form1))
	{
		document.form1.resulttype.value="1";//1表示点击Scan按钮，非1表示点击上下翻页
		document.form1.action="scanResult.do?subact=doscan";
		document.form1.submit();
	}
}

function doScanCheck(form)
{
	if(Trim(form.termscan.value)=="")
	{
		alert(form.conInvalid.value);
		return false;
	}
	else
	{
		return true;
	}
}

function gotoScan(sid)
{
	document.form1.resulttype.value="0";//1表示点击Scan按钮，非1表示点击上下翻页
	document.form1.minsid.value=sid;
	document.form1.action="scanResult.do?subact=doscan";
	document.form1.submit();
}

function login()
{
	if(Trim(document.form1.userid.value)=="")
	{
		alert(document.form1.inputInvalid.value);
	}
	else
	{
		document.form1.action="login.do?subact=doLogin";
		document.form1.submit();
	}
}

function loginWinLogin()
{
	if(Trim(document.form1.loginPageUserid.value)=="")
	{
		alert(document.form1.inputInvalid.value);
	}
	else if(document.form1.loginPoint.value=="showMarc")
	{
		var recIndex = document.form1.recIndex.value;
		var recTotal = document.form1.recTotal.value;
		var fullTextType = document.form1.fullTextType.value;
		var dbselect = document.form1.dbselect.value;
		
		var userid = document.form1.loginPageUserid.value;
		var password = document.form1.loginPagePassword.value;
		
		var loginPoint = document.form1.loginPoint.value
		var passkey = document.form1.passkey.value
		opener.document.form1.action="login.do?subact=doLoginWinLogin&loginPoint="+loginPoint+"&loginPageUserid="+userid+"&loginPagePassword="+password+"&recIndex="+recIndex+"&recTotal="+recTotal+"&fullTextType="+fullTextType+"&dbselect="+dbselect+"&passkey="+passkey;
		opener.document.form1.submit();
		window.name="alertWin";
	}
	else
	{
		document.form1.action="login.do?subact=doLoginWinLogin";
		document.form1.submit();
	}
}
function doFlhhelp() {
  window.open("./classtree/flhhelp.html","newWin","width=600,height=600")

}

function gotoSearchHisIndex(toindex)
{
	document.form1.action="searchHis.do?subact=gotoindex&toindex="+toindex;
	document.form1.submit();
}

function getSearchResult(index)
{
	document.form1.action="searchHis.do?subact=getresult&index="+index;
	document.form1.submit();
}

function getSearchResultById(id)
{
	document.form1.action="searchHis.do?subact=getresultbyid&recid="+id;
	document.form1.submit();
}

function usersearchsave(hittotal, userid, saveType, index)
{
	document.form2.targetName.value = "searchSaveResultWindow";
	document.form2.target = "searchSaveResultWindow";
	document.form2.action = "userSearchSave.do?subact="+saveType+"&ss_hittotal="+hittotal+"&ss_userid="+userid+"&ss_index="+index;
	document.form2.submit();
	document.form2.targetName.value = "";
}

function mySchRuleGotoRec(recIndex)
{
	document.form1.action = "mySearchResult.do?subact=gotoRec&startindex="+recIndex;
	document.form1.submit();
}

function deleteMyQuery(startRexIndex, recId, msg)
{
	if(confirm(msg)) 
	{
		document.form1.action = "mySearchResult.do?subact=deleteRec&recid="+recId+"&startindex="+startRexIndex;
		document.form1.submit();
	}	
}

function add2MyBib(fromType, userid, oid, langBase)
{
	document.form2.targetName.value = "add2MyBibWindow";
	document.form2.target = "add2MyBibWindow";
	document.form2.action = "myBibliography.do?subact=addone&fromType="+fromType+"&userid="+userid+"&oid="+oid+"&langBase="+langBase;
	document.form2.submit();
	document.form2.targetName.value = "";
}

function addMore2MyBib(fromType, userid, langBase)
{
	var checknum = 0;
	var flag = 1;
	var oids = "";
	if(document.form1.idxCheckBox.length>=1)
	{//multi
		var index = 0;
		for(index=0; index<document.form1.idxCheckBox.length; index++)
		{
			if(document.form1.idxCheckBox[index].checked)
			{
			   checknum ++;
			   oids = oids + document.form1.idxCheckBox[index].value + "|";
			}
		}
		if(checknum == 0)
		{
			flag = 0;
		}
		else
		{
			flag = 1;
		}
	}
	else
	{//single
		if(document.form1.idxCheckBox.checked) 
		{
			flag = 1;
			oids = oids + document.form1.idxCheckBox.value + "|";
		}
		else
		{
			flag = 0;
		}
	}
	
	
	if(flag == 0)
	{
		alert(document.form1.selInvalid.value);
	}
	else
	{
		document.form2.targetName.value = "addMore2MyBibWindow";
		document.form2.target = "addMore2MyBibWindow";
		document.form2.action = "myBibliography.do?subact=addmore&fromType="+fromType+"&userid="+userid+"&langBase="+langBase+"&oids="+oids;
		document.form2.submit();
		document.form2.targetName.value = "";
	}
}

function gotoMyBib(index)
{
	document.form1.action = "myBibliography.do?subact=gotoRec&startindex="+index;
	document.form1.submit();
}

function deleteMyBib(startIndex, msg)
{
	var checknum = 0;
	var flag = 1;
	var ids = "";
	if(document.form1.idxCheckBox.length>=1)
	{//multi
		var index = 0;
		for(index=0; index<document.form1.idxCheckBox.length; index++)
		{
			if(document.form1.idxCheckBox[index].checked)
			{
			   checknum ++;
			   ids = ids + document.form1.idxCheckBox[index].value + "|" 
			}
		}
		if(checknum == 0)
		{
			flag = 0;
		}
		else
		{
			flag = 1;
		}
	}
	else
	{//single
		if(document.form1.idxCheckBox.checked) 
		{
			flag = 1;
			ids = ids + document.form1.idxCheckBox.value + "|";
		}
		else
		{
			flag = 0;
		}
	}
	
	if(flag == 0)
	{
		alert(document.form1.selInvalid.value);
	}
	else
	{
		if(confirm(msg)) 
		{
			document.form1.action = "myBibliography.do?subact=deleteSome&startIndex="+startIndex+"&ids="+ids;
			document.form1.submit();
		}
	}

}

function getholding(fromType, oid, langBase)
{
	document.form2.targetName.value = "showHoldingWindow";
	document.form2.target = "showHoldingWindow";
	document.form2.action = "showHolding.do?subact=enterpage&fromType4Holding="+fromType+"&oid4Holding="+oid+"&langBase4Holding="+langBase;
	document.form2.submit();
	document.form2.targetName.value = "";
}

function getCalisResource(fromType, oid, langBase)
{
	document.form2.targetName.value = "showResourceWindow";
	document.form2.target = "showResourceWindow";
	document.form2.action = "showResource.do?subact=enterpage&fromType4Resource="+fromType+"&oid4Resource="+oid+"&langBase4Resource="+langBase;
	document.form2.submit();
	document.form2.targetName.value = "";
}

function enterClassPage(type)
{
	//type可以为flh(分类号)和sklm(四库类目)
	document.form1.action = "classNumber.do?subact=enterpage&type="+type;
	document.form1.submit();
}

function enterLoginWin(loginPoint, a, b, c, d)
{
	//loginPoint = "saveQueryRule" or "add2MyBib" or "addOne2MyBib" or "showMarc"
	if(loginPoint == "saveQueryRule")
	{//a=hittotal, b=userid, c=saveType, d=index
		document.form2.targetName.value = "loginWin";
		document.form2.target = "loginWin";
		document.form2.action = "login.do?subact=enterLoginWin&loginPoint="+loginPoint+"&a="+a+"&b="+b+"&c="+c+"&d="+d;
		document.form2.submit();
		document.form2.targetName.value = "";
	}
	else if(loginPoint == "addOne2MyBib")
	{//a=fromType, b=userid, c=oid, d=langBase
		document.form2.targetName.value = "loginWin";
		document.form2.target = "loginWin";
		document.form2.action = "login.do?subact=enterLoginWin&loginPoint="+loginPoint+"&a="+a+"&b="+b+"&c="+c+"&d="+d;
		document.form2.submit();
		document.form2.targetName.value = "";
	}
	else if(loginPoint == "add2MyBib")
	{//a=fromType, b=userid, c=langBase
		var checknum = 0;
		var flag = 1;
		var oids = "";
		if(document.form1.idxCheckBox.length>=1)
		{//multi
			var index = 0;
			for(index=0; index<document.form1.idxCheckBox.length; index++)
			{
				if(document.form1.idxCheckBox[index].checked)
				{
				   checknum ++;
				   oids = oids + document.form1.idxCheckBox[index].value + "|";
				}
			}
			if(checknum == 0)
			{
				flag = 0;
			}
			else
			{
				flag = 1;
			}
		}
		else
		{//single
			if(document.form1.idxCheckBox.checked) 
			{
				flag = 1;
				oids = oids + document.form1.idxCheckBox.value + "|";
			}
			else
			{
				flag = 0;
			}
		}
		
		
		if(flag == 0)
		{
			alert(document.form1.selInvalid.value);
		}
		else
		{
			document.form2.targetName.value = "loginWin";
			document.form2.target = "loginWin";
			document.form2.action = "login.do?subact=enterLoginWin&loginPoint="+loginPoint+"&a="+a+"&b="+b+"&c="+c+"&d="+oids;
			document.form2.submit();
			document.form2.targetName.value = "";
		}
	}
	else if(loginPoint == "showMarc")
	{//a=recIndex, b=recTotal, c=fullTextType, d=dbselect
		document.form2.targetName.value = "loginWin";
		document.form2.target = "loginWin";
		document.form2.action = "login.do?subact=enterLoginWin&loginPoint="+loginPoint+"&a="+a+"&b="+b+"&c="+c+"&d="+d;
		document.form2.submit();
		document.form2.targetName.value = "";
	}
	
}
//function addMore2MyBib(fromType, userid, langBase)
//{
//	document.form2.target = "addMore2MyBibWindow";
//	document.form2.action = "myBibliography.do?subact=addmore&fromType="+fromType+"&userid="+userid+"&langBase="+langBase+"&oids="+oids;
//	document.form2.submit();
//}
//function usersearchsave(hittotal, userid, saveType, index)
//{
//	document.form2.target = "searchSaveResultWindow";
//	document.form2.action = "userSearchSave.do?subact="+saveType+"&ss_hittotal="+hittotal+"&ss_userid="+userid+"&ss_index="+index;
//	document.form2.submit();
//}
//function add2MyBib(fromType, userid, oid, langBase)
//{
//	document.form2.target = "add2MyBibWindow";
//	document.form2.action = "myBibliography.do?subact=addone&fromType="+fromType+"&userid="+userid+"&oid="+oid+"&langBase="+langBase;
//	document.form2.submit();
//}
//function doShowDetails(recIndex, recTotal, fullTextType, dbselect)
//{
//	document.form1.action="showDetails.do?recIndex="+recIndex+"&recTotal="+recTotal+"&fullTextType="+fullTextType+"&dbselect="+dbselect;
//	document.form1.submit();
//}

//--------------Wang Wei---------------
function register()
{
	//alert('haha');
	document.form1.action="addUser.do?subact=enroll";
	document.form1.submit();
}

function validateNewUserRegistration()
{
    email=document.form1.email.value;
    index=email.indexOf("@");
    flag=true;
    
    if(document.form1.userName.value=='')
    {
        flag=false;
        alert('UserName is required!');  
        document.form1.userName.focus();     
    }
    else if(document.form1.password.value!=document.form1.repassword.value)
    {
        flag=false;
        alert('Password you typed twice must be the same!');
        document.form1.password.focus();
    }
    else if(document.form1.email.value=='')
    {
        flag=false;
        alert('Email is required!');
        document.form1.email.focus();
    }
    else if((index==-1)||(index==0))
    {
        flag=false;
        alert('Email format wrong!');
        document.form1.email.focus();
    }
    
    
    if(flag==true)
    {
        register();
    }
}

function countryChanged()
{
    document.form1.action="addUser.do?subact=reselcountry&newcountry="+document.form1.country.value;
	document.form1.submit();
}

function provinceChanged()
{
    province=document.form1.province.value;
    country=document.form1.country.value;
    document.form1.action="addUser.do?subact=reselcountry&newcountry="+country+"&newprovince="+province;
	document.form1.submit();
}
function viewTOC(oid)
{
		document.form2.FounderOID.value =oid;
		document.form2.target = "ViewFounderDetailsWin";
		document.form2.action = "ShowFounderDetails.do?targetName=ViewFounderDetailsWin&subact=viewTOC&oid="+oid; 
		document.form2.submit();
}

function viewAbstract(oid)
{
		document.form2.FounderOID.value =oid;
		document.form2.target = "ViewFounderDetailsWin";
		document.form2.action = "ShowFounderDetails.do?targetName=ViewFounderDetailsWin&subact=viewAbstract&oid="+oid; 
		document.form2.submit();
}

function viewFullText(oid)
{
		document.form2.FounderOID.value =oid;
		document.form2.target = "ViewFounderDetailsWin";
		document.form2.action = "ShowFounderDetails.do?targetName=ViewFounderDetailsWin&subact=viewFullText&oid="+oid; 
		document.form2.submit();
}

function popwin(url,title)
{
	window.open(url,title);
}
//-------------end  



//-------------for resource scheduler from zhangyx-----2006,11
var openURLRequestMap = new Array();

function isIE(){
	//return (navigator.appName.indexOf("Netscape") >= 0 )
	return ( navigator.appName.indexOf("Microsoft") >= 0 );
}

function OpenURLRequest_addParam(key, value){
	var list = this.paramMap[key];
	if (list == null){
		this.paramMap[key] = list = new Array();
		var keys = this.paramMap.keys;
		keys[keys.length]= key;
	}
	list[list.length]=value;
}

function OpenURLRequest_renderURL()
{
	var rt = this.baseURL+"?";
	for (var i = 0; i < this.paramMap.keys.length; i++){
		var key = this.paramMap.keys[i];
		var list = this.paramMap[key];
		for (var j = 0; j < list.length; j++){
			//rt += key +"=" + encodeURIComponent(list[j])+"&";
			rt += key +"=" + (list[j])+"&";
		}
	}
	return rt;
}

function OpenURLRequest_send_1(isNewWindow){
	var cf = document.getElementById("form_openurl_" + this.id);
	var ah = document.getElementById("a_openurl_" + this.id);
	if (cf == null && this.baseURL.indexOf("?") < 0 && this.paramMap.keys.length > 0){
		cf = document.createElement("form");
		cf.action= this.baseURL;
		cf.method = this.httpMethod;
		if (isNewWindow){
			cf.target = this.id;
		}
		cf.setAttribute("accept-charset", this.charset);
		cf.setAttribute("id", "form_openurl_" + this.id);
		cf['accept-charset'] = this.charset;
		cf.style.visibility = "hidden";
		for (var i = 0; i < this.paramMap.keys.length; i++){
			var key = this.paramMap.keys[i];
			var list = this.paramMap[key];
			
			for (var j = 0; j < list.length; j++){
				var input = document.createElement("input");
				input.name = key;
				input.value = list[j];
				cf.appendChild(input);
			}
		}
		document.body.appendChild(cf);
	}else{
		ah = document.createElement("a");
		if (isNewWindow){
			ah.target=this.id;
		}
		if (this.paramMap.keys.length == 0){
			ah.href = this.baseURL;
		}else{
			ah.href=this.renderURL();
		}
		ah.setAttribute("id", "a_openurl_" + this.id);
		document.body.appendChild(ah);
	}
	var iecharset;
	if (isIE()){
			iecharset = document.charset;
			document.charset=this.charset;//tmp
	}
	if (cf != null){
		cf.submit();
	}else{
		ah.click();
	}
	if (isIE()){
		document.charset=iecharset;//restore to it
	}
}


function OpenURLRequest_send(){
	this.send_1(true);
}

function OpenURLRequest_IE_send(){
	var ifm = document.getElementById("frame_openurl_" + this.id);
	var cf;
	if (ifm == null){
		ifm = document.createElement("iframe");
		ifm.style.visibility = "hidden";
		ifm.document.write("<html><head>");
		ifm.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + this.charset +"\" />");
		ifm.document.write("</head><body></body></html>");
		cf = ifm.document.createElement("form");
		cf.action= this.baseURL;
		cf.method = this.httpMethod;
		cf.target = this.id;
		cf.setAttribute("accept-charset", this.charset);
		cf.setAttribute("id", "form_openurl_" + this.id);
		cf['accept-charset'] = this.charset;
		cf.style.visibility = "hidden";
		for (var i = 0; i < this.paramMap.keys.length; i++){
			var key = this.paramMap.keys[i];
			var list = this.paramMap[key];
			
			for (var j = 0; j < list.length; j++){
				var input = ifm.document.createElement("input");
				input.name = key;
				input.value = list[j];
				cf.appendChild(input);
			}
		}
		ifm.document.body.appendChild(cf);
		alert(ifm.document.body.innerHTML);
		document.body.appendChild(ifm);
	}else{
		cf = ifm.document.forms[0];
	}
	cf.submit();
}

function OpenURLRequest(id, baseURL, httpMethod, charset) {
	this.id = id;
	this.baseURL = baseURL;
	this.httpMethod = httpMethod;
	this.paramMap = new Array();
	this.paramMap.pro = 0;
	this.paramMap.keys = new Array();
	this.addParam = OpenURLRequest_addParam;
	this.renderURL = OpenURLRequest_renderURL;
	//this.send = isIE() ? OpenURLRequest_IE_send : OpenURLRequest_send;
	this.send = OpenURLRequest_send;
	this.send_1 = OpenURLRequest_send_1;
	if (charset == null)
		this.charset = "UTF-8";
	else
		this.charset = charset;
}
function rlsc_addParam(req, key, value){
	if (key == null || key.length == 0)
		return;
	req.addParam(key, value);
}

function rlsc_sendJArticleRequest(isNewWindow, rlsBaseURL, issn, eissn, journalTitle, articleTitle, volume,issue, startPage){
	var req = new OpenURLRequest(new Date().getTime(), rlsBaseURL, "get", "UTF-8");
	rlsc_addParam(req, "ver","OPENURL01CX");
	rlsc_addParam(req, "fmt", "journal");
	rlsc_addParam(req, "genre", "article");
	rlsc_addParam(req, "issn", issn);
	rlsc_addParam(req, "eissn", eissn);
	rlsc_addParam(req, "jtitle", journalTitle);
	rlsc_addParam(req, "atitle", articleTitle);
	rlsc_addParam(req, "volume", volume);
	rlsc_addParam(req, "issue", issue);
	rlsc_addParam(req, "spage", startPage);	
	req.send_1(isNewWindow);
}

function rlsc_sendJournalRequest(isNewWindow, rlsBaseURL, issn, eissn, journalTitle, volume,issue){
	var req = new OpenURLRequest(new Date().getTime(), rlsBaseURL, "get", "UTF-8");
	rlsc_addParam(req, "ver","OPENURL01CX");
	rlsc_addParam(req, "fmt", "journal");
	rlsc_addParam(req, "genre", "journal");
	rlsc_addParam(req, "issn", issn);
	rlsc_addParam(req, "eissn", eissn);
	rlsc_addParam(req, "jtitle", journalTitle);
	rlsc_addParam(req, "volume", volume);
	rlsc_addParam(req, "issue", issue);
	req.send_1(isNewWindow);
}

function rlsc_sendBookRequest(isNewWindow, rlsBaseURL, isbn, bookTitle){
	var req = new OpenURLRequest(new Date().getTime(), rlsBaseURL, "get", "UTF-8");
	rlsc_addParam(req, "ver","OPENURL01CX");
	rlsc_addParam(req, "fmt", "book");
	rlsc_addParam(req, "genre", "book");
	rlsc_addParam(req, "isbn", isbn);
	rlsc_addParam(req, "btitle", bookTitle);
	req.send_1(isNewWindow);
}



function rlsc_sendDCRequest(isNewWindow, rlsBaseURL, type, title, creator, date, contributor){
	var req = new OpenURLRequest(new Date().getTime(), rlsBaseURL, "get", "UTF-8");
	rlsc_addParam(req, "ver","OPENURL01CX");
	rlsc_addParam(req, "fmt", "dc");
	rlsc_addParam(req, "title", title);
	rlsc_addParam(req, "creator", creator);
	rlsc_addParam(req, "type", type);
	rlsc_addParam(req, "date", date);
	rlsc_addParam(req, "contributor", contributor);
	req.send_1(isNewWindow);
}

//-------------------------------------

