
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}



function highlightLinks(linkName) {
	
   var linkList = document.getElementById("navigation").getElementsByTagName("a");
   for (i = 0; i < linkList.length; i++) {
      linkList[i].className = "";
      
     // alert(linkList[i].text + ' ' + link);
      if (linkList[i].name == linkName)
    	 linkList[i].className = "current";
   }
 //  obj.className = "current";
}


function  popupwithname(url,winname) {
	var newwindow  = window.open( url,winname,'location=0,statusbar=1,width=525,height=300');

	if ( window.focus )
		{ newwindow.focus(); }
	//return newwindow;
}

function  popup(url) {
	var newwindow  = window.open( url,'Publication','location=0,statusbar=1,width=525,height=300');

	if ( window.focus )
		{ newwindow.focus(); }
	//return newwindow;
}
function  popupBibTex(url) {
	var newwindow = window.open( url,'Publication','location=0,statusbar=1,scrollbars=1,width=600,height=200');
	if ( window.focus )
		{ newwindow.focus(); }
//	return newwindow;
}

function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete ?")) {
    document.location = delUrl;
  }
}

function confirmDeleteCategory(delUrl) {
  if (confirm("Deleting this category will delete all publications in this category !!!!\n"
  			   + "Are you sure you want to delete ?")) {
    document.location = delUrl;
  }
}



function addAuthor(){

	authorSrc = document.forms[0].authorSrc;
	author = document.forms[0].author;
    moveSelectedOptions(authorSrc,author);

}

function removeAuthor(){
	authorSrc = document.forms[0].authorSrc;
	author = document.forms[0].author;
    moveSelectedOptions(author,authorSrc);
	sortSelect(authorSrc);
}

function removeAllAuthor(){
	author = document.forms[0].author;
	authorSrc = document.forms[0].authorSrc;
	moveAllOptions(author,authorSrc);
	sortSelect(authorSrc);
}

function moveUpAuthor(){
	author = document.forms[0].author;
	moveOptionUp(author);
}

function moveDownAuthor(){
	author = document.forms[0].author;
	moveOptionDown(author);

}
// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		if (!hasOptions(obj)) { return; }
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			unSelectMatchingOptions(from,regex);
			}
		}
	// Move them over
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
			to.options[index] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		//sortSelect(from);
		//sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	if (!hasOptions(from)) { return; }
	if (from.type=="select-one") {
		from.options[from.selectedIndex] = null;
		}
	else {
		for (var i=(from.options.length-1); i>=0; i--) { 
			var o=from.options[i]; 
			if (o.selected) { 
				from.options[i] = null; 
				} 
			}
		}
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
}







function setViewBy(){
	if(document.forms[0].currentViewBy.value=='0')
		document.forms[0].viewBy[0].checked = true;
	else if(document.forms[0].currentViewBy.value=='1')
		document.forms[0].viewBy[1].checked = true;
	else if(document.forms[0].currentViewBy.value=='2')
		document.forms[0].viewBy[2].checked = true;	
	else if(document.forms[0].currentViewBy.value=='3'){
		document.forms[0].viewBy[3].checked = true;	
		document.forms[0].otherlink.disabled = false;	
	}	
	if (document.forms[0].link.value == ""){
		if(document.forms[0].viewBy[1].checked == true){
			document.forms[0].viewBy[2].checked = true;// change to nolink if the link is blank
		}
		document.forms[0].viewBy[1].disabled = true;
	}else {
		document.forms[0].viewBy[1].disabled = false;
	}
	
}
function  disableAbstract() {

	document.forms[0].abstractPub.readOnly = true;
	document.forms[0].file1.disabled = true;
	document.forms[0].file2.disabled = true;
	document.forms[0].file3.disabled = true;
}
function  enableAbstract() {

	document.forms[0].abstractPub.readOnly = false;
	document.forms[0].file1.disabled = false;
	document.forms[0].file2.disabled = false;
	document.forms[0].file3.disabled = false;
}

function validateAddAuthorForm() {
  var  valid = true;
  DWRUtil.setValue("firstname-error", ""); 
  DWRUtil.setValue("lastname-error", "");
  if ( DWRUtil.getValue("firstname")=="") {
  	DWRUtil.setValue("firstname-error", "Please enter firstname");
	valid = false;
  }
  if ( DWRUtil.getValue("lastname")=="") {
  	DWRUtil.setValue("lastname-error", "Please enter lastname");
  	valid = false;
  }
  return valid;
}

function validateAddPubForm() {
 	  var  valid = true;
	  var  validAdd = true;
	  var alertText = "";
	  DWRUtil.setValue("title-error", "");
	  DWRUtil.setValue("author-error", "");
	  DWRUtil.setValue("otherlink-error", "");
 	  //DWRUtil.setValue("category-error", "");
	  if(DWRUtil.getValue("preprintfile") != ""){
		  if (confirm("You did not upload the preprint file. Do you want to go back to upload the file ?")==true){
		  	valid = false;
		  	validAdd = false;
		  }
		 
	  }
	  if(DWRUtil.getValue("file1") != ""){
		  if (confirm("You did not add the additional file. Do you want to go back to add the file ?")==true){
		  	valid = false;
		  	validAdd = false;
		  }
		 
	  }
 	  
 	  if(DWRUtil.getValue("link2") != ""){
		  if (confirm("You did not add the additional link. Do you want to go back to add  the link ?")==true){
		  	valid = false;
		  	validAdd = false;
		  }
		 
	  }
	  if ( DWRUtil.getValue("title")=="") {
	  	DWRUtil.setValue("title-error", "Please enter title");
		if (alertText != "") alertText = alertText + ",";
	  	alertText = alertText + " title";	  	
		valid = false;
	  }	
	  if (DWRUtil.getValue("pubtype")=="-1"){
	  	DWRUtil.setValue("pubtype-error", "Please select publication type");
	  	if (alertText != "") alertText = alertText + ",";
	  	alertText = alertText + " publication type";  	
		valid = false;
	  } else if(DWRUtil.getValue("pubtype")=="1") { // for journal
	  	  DWRUtil.setValue("journal-error", "");
		  if (DWRUtil.getValue("journal")=="-1"){
		  	DWRUtil.setValue("journal-error", "Please select Journal");
		  	if (alertText != "") alertText = alertText + ",";
		  	alertText = alertText + " journal";
	   	 	valid = false;
	  	  }
	  }else if(DWRUtil.getValue("pubtype")=="3" || DWRUtil.getValue("pubtype")=="4") { // for conference
		  DWRUtil.setValue("conference-error", "");
		  if (DWRUtil.getValue("conference")=="-1"){
		  	DWRUtil.setValue("conference-error", "Please select conference");
		  	if (alertText != "") alertText = alertText + ",";
		  	alertText = alertText + " conference";
	   	 	valid = false;
	  	  }
	  }else if(DWRUtil.getValue("pubtype")=="2") { // for thesis
	 	  DWRUtil.setValue("thesistype-error", "");
	 	  DWRUtil.setValue("university-error", "");
		  if (DWRUtil.getValue("thesistype")=="-1"){
		  	DWRUtil.setValue("thesistype-error", "Please select thesis type");
		  	if (alertText != "") alertText = alertText + ",";
		  	alertText = alertText + " thesis type";	
	   	 	valid = false;
	  	  }
	  	  if (DWRUtil.getValue("university")=="-1"){
		  	DWRUtil.setValue("university-error", "Please select university");
		  	if (alertText != "") alertText = alertText + ",";
		  	alertText = alertText + " university";		  	
	   	 	valid = false;
	  	  }
	  }
	  
	  if (DWRUtil.getValue("pubtype")=="1" || DWRUtil.getValue("pubtype")=="2"
	 	   || DWRUtil.getValue("pubtype")=="3" || DWRUtil.getValue("pubtype")=="4"
	 	   || DWRUtil.getValue("pubtype")=="5" || DWRUtil.getValue("pubtype")=="6"){
	 	   DWRUtil.setValue("year-error", "");
	 	   if (DWRUtil.getValue("year")==""){
		 	    DWRUtil.setValue("year-error", "Please enter year");
			  	if (alertText != "") alertText = alertText + ",";
			  	alertText = alertText + " year";	
		   	 	valid = false;
	 	   }
	  }
	  author = document.forms[0].author;
	 
	  if (author.length == 0) {
	  	DWRUtil.setValue("author-error", "Please select author");
		if (alertText != "") alertText = alertText + ",";
		  	alertText = alertText + " author";		  
	  	valid = false;
	  }
	  if ( DWRUtil.getValue("viewBy")=="3" &&  DWRUtil.getValue("otherlink")=="") {
	  	DWRUtil.setValue("otherlink-error", "Please enter link");
		if (alertText != "") alertText = alertText + ",";
	  	alertText = alertText + " other link";	  	
		valid = false;
	  }	
	  if (valid)
	  	selectAllOptions(author);
	  else {
	  	if (validAdd){
	  		alert("Please complete the following information: \n" + alertText);
	  	}
	  }
	  return valid;
}

function validateAddCategoryForm(){
  var  valid = true;
  DWRUtil.setValue("name-error", ""); 
  if ( DWRUtil.getValue("name")=="") {
  	DWRUtil.setValue("name-error", "Please enter name");
	valid = false;
  }
  return valid;
}

function clikedEditForm(id, db_id){
	var table = document.getElementById("tbledit");
	var row = table.rows[id];
	var cell = row.cells[1];
	var name = cell.firstChild.nodeValue;
	DWRUtil.setValue("id",db_id);	
	DWRUtil.setValue("name",name);
}

function clikedEditBibTextForm(id, db_id){
	var table = document.getElementById("tbledit");
	var row = table.rows[id];
	var cell = row.cells[1];
	var cell2 = row.cells[2];
	var cell3 = row.cells[3];
	var specialtext = cell.firstChild.nodeValue;
	var replacetext = cell2.firstChild.nodeValue;
	var replacetextforkey = cell3.firstChild.nodeValue;
	
	DWRUtil.setValue("id",db_id);	
	DWRUtil.setValue("specialtext",specialtext);
	DWRUtil.setValue("replacetext",replacetext);
	DWRUtil.setValue("replacetextforkey",replacetextforkey);
}


function goToAddPub(){
	//alert('jey');
	pubtype = document.forms[0].pubtype.value;
	window.location = "addpub.jsp?type=" + pubtype;
}

function submitDeleteFile(fileIndex){
	author = document.forms[0].author;
	selectAllOptions(author);
	document.forms[0].deleteFileIndex.value = fileIndex;
	document.forms[0].chkDeleteFileClick.value = true;
	document.forms[0].submit();
}


function checksubmittedButton(submitMode){
	author = document.forms[0].author;
	selectAllOptions(author);
	document.forms[0].chkMode.value = submitMode;
	document.forms[0].submit();
}
function submitDelete(dIndex,submitMode){
	author = document.forms[0].author;
	selectAllOptions(author);
	document.forms[0].chkMode.value = submitMode;
	document.forms[0].deleteIndex.value = dIndex;
	document.forms[0].submit();
}

function validateAddAdditionalFile(submitMode){
	var  valid = true;
	DWRUtil.setValue("descfile-error", ""); 
 	 if ( DWRUtil.getValue("descfile")=="") {
  		DWRUtil.setValue("descfile-error", "Please enter description");
		valid = false;
  	}
  	if (valid==true){
  		checksubmittedButton(submitMode);
  	}
}

function validateAddAdditionalLink(submitMode){
	var  valid = true;
	DWRUtil.setValue("desclink-error", ""); 
	DWRUtil.setValue("link2-error", ""); 
 	if ( DWRUtil.getValue("desclink")=="") {
  		DWRUtil.setValue("desclink-error", "Please enter description");
		valid = false;
  	}
  	if ( DWRUtil.getValue("link2")=="") {
  		DWRUtil.setValue("link2-error", "Please enter link");
		valid = false;
  	}
  	if (valid==true){
  		checksubmittedButton(submitMode);
  	}else 
  		return valid;
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}

function validatBibtextForm(){
	var  valid = true;
	DWRUtil.setValue("bibtext-error", ""); 
 	if ( DWRUtil.getValue("replacetext")=="") {
  		DWRUtil.setValue("bibtext-error", "Please enter replacing characters");
		valid = false;
  	}
  	if ( DWRUtil.getValue("specialtext")=="") {
  		DWRUtil.setValue("bibtext-error", "Please enter special characters");
		valid = false;
  	}
	return valid;
}

function validatAddBibtextForm(){
	var  valid = true;
	DWRUtil.setValue("addbibtext-error", ""); 
 	if ( DWRUtil.getValue("addreplacetext")=="") {
  		DWRUtil.setValue("addbibtext-error", "Please enter replacing characters");
		valid = false;
  	}
  	if ( DWRUtil.getValue("addspecialtext")=="") {
  		DWRUtil.setValue("addbibtext-error", "Please enter special characters");
		valid = false;
  	}
	return valid;
}

function submitFilter(){
	order = "";
	year = "";
	searchtype = "";
	searchauthor = "";
	searchkeyword = "";
	if (document.forms[0].order.length > 3){
		DWRUtil.setValue("order-error", "Please do not select more than three \"order by\"");
		return false;
	}
		
	for (i = 0; i <  document.forms[0].order.length; i++) {
	 	order = order + "&order=" + document.forms[0].order.options[i].value;
	}
	for (i = 0; i <  document.forms[0].year.length; i++) {
		if ( document.forms[0].year.options[i].selected)
	 		year = year + "&year=" + document.forms[0].year.options[i].value;
	}
	for (i = 0; i <  document.forms[0].author.length; i++) {
		if ( document.forms[0].author.options[i].selected)
	 		searchauthor = searchauthor + "&author=" + document.forms[0].author.options[i].value;
	}
	for (i = 0; i <  document.forms[0].keyword.length; i++) {
		if ( document.forms[0].keyword.options[i].selected)
	 		searchkeyword = searchkeyword + "&keyword=" + document.forms[0].keyword.options[i].value;
	}
	for (i = 0; i <  document.forms[0].pubtype.length; i++) {
		if ( document.forms[0].pubtype.options[i].selected)
	 		searchtype = searchtype + "&pubtype=" + document.forms[0].pubtype.options[i].value;
	}
	
	url = "submitfilter.jsp?"+order+year+searchtype+searchauthor+searchkeyword;
	//window.open( url,'Publication','location=0,statusbar=1,scrollbars=1,width=970,height=800');
	window.location = url;
}



function submitKeyword(){
	searchkeyword = "";
	for (i = 0; i <  document.forms[0].keyword.length; i++) {
		if ( document.forms[0].keyword.options[i].selected)
	 		searchkeyword = searchkeyword + "&keyword=" + document.forms[0].keyword.options[i].value;
	}
	url = "submitfilter.jsp?"+searchkeyword + "&order=keyword";
	//window.open( url,'Spiral_Publication','location=0,statusbar=1,scrollbars=1,width=970,height=800');
	window.location = url;
}

function checkMultipleSelect(selectBoxName){

	var selectNum = 0;
	var selectBox = document.getElementById(selectBoxName);
	for (i = 0; i <  selectBox.length; i++) {
		if ( selectBox.options[i].selected)
	 		selectNum++;
	}
	
	if (selectNum>1){
		removeOpition(selectBoxName);
	}else{
		enableOption(selectBoxName);
	}
	
	
}

function enableOption(optionName){
	
 	var selectBox = document.forms[0].orderSrc;
	var isexist = false;
	for (i=0; i<selectBox.length; i++) {

		if (selectBox.options[i].value == optionName) {
		  //  alert('test');
	   		//selectBox.options[i].disabled = '';
	   		isexist = true;
    	}
    	
    }
    if (isexist == false){
     	selectBox.options[selectBox.length] = new Option(optionName,optionName);
    }
    
    
}

function removeOpition(optionName){
	var selectBox = document.forms[0].order;
	var selectBoxSrc = document.forms[0].orderSrc;
 	for (i=0; i<selectBox.length; i++) {

	    if (selectBox.options[i].value == optionName) {
	    	//selectBox.options[i] = null;
	    	//selectBoxSrc.options[selectBoxSrc.length] = new Option(optionName,optionName);
	    	
    		selectBox.remove(i);
    
    	}
    }
    
    selectBox = document.forms[0].orderSrc;
    for (i=0; i<selectBox.length; i++) {

	    if (selectBox.options[i].value == optionName) {
    		selectBox.remove(i);
    	//	selectBox.options[i].disabled = 'disabled';
    	}
    }

}

function popupSearchBibTex(url){
	var newwindow = window.open( url,'Publication','location=0,statusbar=1,scrollbars=1,width=600,height=600');
	if ( window.focus )
		{ newwindow.focus(); }
	//return newwindow;
}

function setInputFileWidth(){
	var browser ='';
	if (browser == ''){
		if (navigator.appName.indexOf('Microsoft') != -1)
			browser = 'IE'
		else if (navigator.appName.indexOf('Netscape') != -1)
			browser = 'Netscape'
		else browser = 'IE';
	}
	
    if (screen.width>=1600){
	    if (browser == 'IE'){
          document.forms[0].preprintfile.size = 81;
          document.forms[0].file1.size = 81;
        }else {
          document.forms[0].preprintfile.size = 80;
          document.forms[0].file1.size = 80;      
        }
    }else{
        if (browser == 'IE'){
          document.forms[0].preprintfile.size = 108;
          document.forms[0].file1.size = 108;
        }else {
          document.forms[0].preprintfile.size = 109;
          document.forms[0].file1.size = 109;   
        }

    }
 }
 
function checkLinkToPublisher() {
	
	if (document.forms[0].link.value == ""){
		if(document.forms[0].viewBy[1].checked == true){
			document.forms[0].viewBy[2].checked = true;
		}
		document.forms[0].viewBy[1].disabled = true;
	}else{
		
		document.forms[0].viewBy[1].disabled = false;			
	}
}

var strToAppear = "";
var strSubmitted = "submitted for publication";
function addToAppear(){
	removeToAppear();
	removeSubmitted();
	var strNoteBt = document.forms[0].note.value;
	document.forms[0].note.value = strToAppear + strNoteBt;
}


function removeToAppear(){
	var strNoteBt = document.forms[0].note.value;
	var strlength = strNoteBt.length ;
	if (strlength >= strToAppear.length){
		if(strNoteBt.substring(0,strToAppear.length)== strToAppear){
			document.forms[0].note.value = strNoteBt.substring(strToAppear.length,strlength);
		}
	}
}

function addSubmitted(){
	removeSubmitted();
	removeToAppear();
	var strNoteBt = document.forms[0].note.value;
	document.forms[0].note.value =   strSubmitted+ strNoteBt;
}

function removeSubmitted(){
	var strNoteBt = document.forms[0].note.value;
	var strlength = strNoteBt.length ;
	if (strlength >= strSubmitted.length){
		if(strNoteBt.substring(0,strSubmitted.length)==strSubmitted){
			document.forms[0].note.value = strNoteBt.substring(strSubmitted.length,strlength);
		}
	}
}

function enableOtherlinkText(){
	document.forms[0].otherlink.disabled = false; 
}

function disableOtherlinkText(){
	document.forms[0].otherlink.value = ""; 
	document.forms[0].otherlink.disabled = true; 
}

function redirectPage(url){
	window.location = url;
}

/* 
function checkChagePubType(){s
	author = document.forms[0].author;
	selectAllOptions(author);
	document.forms[0].chkChangePubTypeClick.value = true;
	document.forms[0].submit();
}

function checkAddLink(){
	author = document.forms[0].author;
	selectAllOptions(author);
	document.forms[0].chkAddLinkClick.value = true;
	document.forms[0].submit();
}
function checkAddPubflie(){
	author = document.forms[0].author;
	document.forms[0].chkAddFileClick.value = true;
	selectAllOptions(author);
}

function checkAddInfo(){
	author = document.forms[0].author;
	document.forms[0].chkAddInfoClick.value = true;
	selectAllOptions(author);
}


 */
