word=",a,is,an,are,we,have,has,he,she,it,or,and,not,go,when,they,its,his,him,her,where,what,why,who,the,am,"
specialword="!,@,#,$,%,^,&,*,(,),<,>,[,],{,},+,-,*,/,?,\""

function advsearchcheck(obj) {

author=obj.author.value
while (author.indexOf(" ") == 0) {
author=author.substr(1,author.length-1)
}
while (author.substr(author.length-1,1)==" ") {
author=author.substr(0,author.length-1)
}

authorinit=obj.authorinit.value
while (authorinit.indexOf(" ") == 0) {
authorinit=authorinit.substr(1,authorinit.length-1)
}
while (authorinit.substr(authorinit.length-1,1)==" ") {
author=authorinit.substr(0,authorinit.length-1)
}

title=obj.title.value
while (title.indexOf(" ") == 0) {
title=title.substr(1,title.length-1)
}
while (title.substr(title.length-1,1)==" ") {
title=title.substr(0,title.length-1)
}

key_abstract=document.forms[1].elements[3].value
//key_abstract=obj.abstract.value
while (key_abstract.indexOf(" ") == 0) {
key_abstract=key_abstract.substr(1,key_abstract.length-1)
}
while (key_abstract.substr(key_abstract.length-1,1)==" ") {
key_abstract=key_abstract.substr(0,key_abstract.length-1)
}

article=obj.article.value
while (article.indexOf(" ") == 0) {
article=article.substr(1,article.length-1)
}
while (article.substr(article.length-1,1)==" ") {
article=article.substr(0,article.length-1)
}

lengthcount=0
if ((author != "") && (author.length <=1)) {lengthcount=lengthcount+1}
if ((title != "") && (title.length <=1)) {lengthcount=lengthcount+1}
if ((key_abstract != "") && (key_abstract.length <=1)) {lengthcount=lengthcount+1}
if ((article != "") && (article.length <=1)) {lengthcount=lengthcount+1}
if (lengthcount != 0) {alert("Keyword must at least 2 characters.");return false}


//----------------- check special character for Advsearch
lengthcount=0
//if ((author != "") && (author.indexOf("'") > -1)) {lengthcount=lengthcount+1}
//if ((authorinit != "") && (authorinit.indexOf("'") > -1)) {lengthcount=lengthcount+1}
//if ((title != "") && (title.indexOf("'") > -1)) {lengthcount=lengthcount+1}
//if ((key_abstract != "") && (key_abstract.indexOf("'") > -1)) {lengthcount=lengthcount+1}
//if ((article != "") && (article.indexOf("'") > -1)) {lengthcount=lengthcount+1}
//if (lengthcount != 0) {alert("Keyword can not contain special character.");return false}
spc=specialword.split(",")
if (author != "") {
	for (s=0;s<spc.length;s++) {
		if (author.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}

if (authorinit != "") {
	for (s=0;s<spc.length;s++) {
		if (authorinit.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}

if (title != "") {
	for (s=0;s<spc.length;s++) {
		if (title.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}

if (key_abstract != "") {
	for (s=0;s<spc.length;s++) {
		if (key_abstract.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}

if (article != "") {
	for (s=0;s<spc.length;s++) {
		if (article.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}

if (lengthcount != 0) {alert("Keyword can not contain special character.");return false}
//----------------  check special character for Advsearch End

key1=author
key2=title
key3=key_abstract
key4=article
akey=""
keycount=0

if (keycount==0) {
key=","+key1+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key1}
}

if (keycount==0) {
key=","+key2+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key2}
}

if (keycount==0) {
key=","+key3+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key3}
}

if (keycount==0) {
key=","+key4+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key4}
}

if (keycount != 0) {alert("Keyword '"+akey+"' \nis not accepted.");return false}

count=0
if (author != "") {count=count+1}
if (authorinit != "") {count=count+1}
if (title != "") {count=count+1}
if (key_abstract != "") {count=count+1}
if (article != "") {count=count+1}
if (count==0) {alert("Please input search keyword.");return false}

if (lengthcount+keycount==0 || count !=0) {return true}
}


function refinesearchcheck(obj) {

varKey=obj.varKey.value

while (varKey.indexOf(" ") == 0) {
varKey=varKey.substr(1,varKey.length-1)
}
while (varKey.substr(varKey.length-1,1)==" ") {
varKey=varKey.substr(0,varKey.length-1)
}

lengthcount=0
if ((varKey != "") && (varKey.length <=1)) {lengthcount=lengthcount+1}
if (lengthcount != 0) {alert("Keyword must at least 2 characters.");return false}

lengthcount=0
//if ((varKey != "") && (varKey.indexOf("'") > -1)) {lengthcount=lengthcount+1}
if (varKey != "") {
	spc=specialword.split(",")
	for (s=0;s<spc.length;s++) {
		if (varKey.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}	
if (lengthcount != 0) {alert("Keyword can not contain special character.");return false}

key2=varKey
akey=""
keycount=0
if (keycount==0) {
key=","+key2+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key2}
if (keycount != 0) {alert("Keyword '"+akey+"' \nis not accepted.");return false}
}

err=""
if (obj.varName.value == "") {err=err+" - select field type\n"}
if (varKey == "") {err=err+" - input keyword\n"}
if (err!= "")  {alert("Please complete following information :\n\n"+err);return false}
if (lengthcount+keycount==0 || err =="") {return true}
}


function simplesearchcheck(obj) {
keyword=obj.keyword.value
while (keyword.indexOf(" ") == 0) {
keyword=keyword.substr(1,keyword.length-1)
}
while (keyword.substr(keyword.length-1,1)==" ") {
keyword=keyword.substr(0,keyword.length-1)
}

lengthcount=0
if ((keyword != "") && (keyword.length <=1)) {lengthcount=lengthcount+1}
if (lengthcount != 0) {alert("Keyword must at least 2 characters.");return false}

lengthcount=0
//if ((keyword != "") && (keyword.indexOf("'") > -1)) {lengthcount=lengthcount+1}
if (keyword != "") {
	spc=specialword.split(",")
	for (s=0;s<spc.length;s++) {
		if (keyword.indexOf(spc[s]) > -1) {
			lengthcount=lengthcount+1
		}
	}
}	
if (lengthcount != 0) {alert("Keyword can not contain special character.");return false}

key2=keyword
akey=""
keycount=0
if (keycount==0) {
key=","+key2+","
pos=word.indexOf(key)
if (pos != -1) {keycount=keycount+1;akey=key2}
if (keycount != 0) {alert("Keyword '"+akey+"' \nis not accepted.");return false}
}

err=""
if (keyword == "") {alert("Please input search keyword.");err="error";return false}
if (lengthcount+keycount==0 || err =="") {return true}
}


function retrievecheck(obj) {
checkcount=0
ttlid=obj.ttlid.value-1
for (i=0;i<=ttlid;i++) {
	if (ttlid==0) {
		if (obj.selectid.checked == true) {checkcount=checkcount+1}
		}else{
		if (obj.selectid[i].checked == true) {checkcount=checkcount+1}
	}
}
if (checkcount==0)  {alert("Please select item.");return false}else{return true}
}


function authorinfo(id) {
window.open ("authorinfo.asp?id="+id,"info","width=400,height=300,scrollbars=yes,resizable=yes,top=50,left=50")
}

function showhide(divId) {
d = document.getElementById(divId)
if (d.style.visibility=="visible") {
d.style.visibility="hidden"
d.style.display="none"
document.printform.authorinfo.value="hidden"
}else{
d.style.visibility="visible"
d.style.display=""
document.printform.authorinfo.value="visible"
}
}
//function authorinfotest() {
//	if (authorlayer.style.visibility=="hidden") {
//	authorlayer.style.width="400px"
//	authorlayer.style.height="100px"
//	authorlayer.style.visibility="visible"
//	authorlayer.style.overflow="visible"
//	} else {
//	authorlayer.style.width="0px"
//	authorlayer.style.height="0px"
//	authorlayer.style.visibility="hidden"
//	}
//}