
function orgOnHandle() {

	//if (document.forms[0].BATBOOL.value != "") {
	//	document.forms[0].BATTerm4.value = document.forms[0].BATTerm1.value + " not " + document.forms[0].BATBOOL.value;
	//	}
	for (LoopID=1; LoopID <= 4; LoopID++) { 
		if (document.organization.elements[LoopID].name == "BATTerm1.Attribute") {
			if (document.organization.elements[LoopID].selectedIndex == "0" && document.organization.elements[LoopID].value == "BAT.BooleanExpr"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) { 
					if (document.organization.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.organization.BATTerm1.value = replaceChars(document.organization.BATTerm1.value);
						document.organization.elements[LoopID2].value = "Structure.Word List";
						document.organization.BATTerm1.value = setOr(trim(document.organization.BATTerm1.value));
					}
				}
			}
			if (document.organization.elements[LoopID].selectedIndex == "1"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) { 
					if (document.organization.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.organization.elements[LoopID2].value = "";
					}
				}
			}
			if (document.organization.elements[LoopID].selectedIndex == "2"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) { 
					if (document.organization.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.organization.BATTerm1.value = replaceChars(document.organization.BATTerm1.value);
						document.organization.elements[LoopID2].value = "";
					}
				}
			}
		}
	}
}

function proOnHandle() {


	
	//if (document.products.Combine.checked == true){
	//	document.products.BATQuery.value = "ProductAdvancedSearch";
	//	}
	//else if (document.products.Combine.checked == false){
		document.products.BATQuery.value = "ProductAdvancedWOSort";
	//}

	var CurrentDate = new Date();
	var CurrentDateMonth = (CurrentDate.getMonth()+1);
	var CurrentDateYear = CurrentDate.getFullYear();
	var CurrentDay = CurrentDate.getDate();


	  var ToMonth = document.products.ToMonth.selectedIndex;
	  var ToDay = document.products.ToDay.selectedIndex;
	  var ToYear = document.products.ToYear.value;
	  if (ToYear == ""){
		ToYear = CurrentDateYear;
	  }
	  if (ToMonth == ""){
		if (CurrentDateMonth < 10) {
				CurrentDateMonth = "0" + CurrentDateMonth;
			}
		document.products.ToMonth.options[ToMonth].value = CurrentDateMonth;
	  }
	  if (ToDay == ""){
		if (CurrentDay < 10) {
				CurrentDay = "0" + CurrentDay;
			}
		document.products.ToDay.options[ToDay].value = CurrentDay;
	  }
	  if (document.products.ToYear.value == "" && document.products.ToMonth.selectedIndex == "0" && document.products.ToDay.selectedIndex == "0"){
			document.products.BATTerm6.value = "";
	  }
	  else {
		document.products.BATTerm6.value = document.products.ToMonth.options[ToMonth].value + document.products.ToDay.options[ToDay].value + ToYear;
		//document.products.BATTerm6.value = ToYear + document.products.ToMonth.options[ToMonth].value + document.products.ToDay.options[ToDay].value;
		document.products.BATTerm14.value = ToYear + document.products.ToMonth.options[ToMonth].value + document.products.ToDay.options[ToDay].value;
	  }

	  var FromMonth = document.products.FromMonth.selectedIndex;
	  var FromDay = document.products.FromDay.selectedIndex;
	  var FromYear = document.products.FromYear.value;
	  if (FromYear == ""){
		FromYear = CurrentDateYear;
	  }
	  if (FromMonth == ""){
		document.products.FromMonth.options[FromMonth].value = CurrentDateMonth;
	  }
	  if (FromDay == ""){
		document.products.FromDay.options[FromDay].value = CurrentDay;
	  }
	  if (document.products.FromYear.value == "" && document.products.FromMonth.selectedIndex == "0" && document.products.FromDay.selectedIndex == "0"){
			document.products.BATTerm5.value = "";
	  }
	  else {
		 //document.products.BATTerm5.value = FromYear + document.products.FromMonth.options[FromMonth].value + document.products.FromDay.options[FromDay].value;		
		 document.products.BATTerm13.value = FromYear + document.products.FromMonth.options[FromMonth].value + document.products.FromDay.options[FromDay].value;
		
		document.products.BATTerm5.value = document.products.FromMonth.options[FromMonth].value + document.products.FromDay.options[FromDay].value + FromYear;		
		//document.products.BATTerm13.value = document.products.FromMonth.options[FromMonth].value + document.products.FromDay.options[FromDay].value + FromYear;		
		
		
		}
		
	  if (document.products.BATTerm12.options[0].selected == true) {
		document.products.BATTerm5.value = "";
		document.products.BATTerm6.value = "";
	  }else
	  {
		document.products.BATTerm13.value = "";
		document.products.BATTerm14.value = "";
	  
	  }
	  	  

	  for (LoopID=1; LoopID <= 9; LoopID++) {
		if (document.products.elements[LoopID].name == "BATTerm1.Attribute") {
			if (document.products.elements[LoopID].selectedIndex == "0" && document.products.elements[LoopID].value == "BAT.BooleanExpr"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.products.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.products.BATTerm1.value = replaceChars(document.products.BATTerm1.value);
						document.products.elements[LoopID2].value = "Structure.Word List";
						document.products.BATTerm1.value = setOr(trim(document.products.BATTerm1.value));
					}
				}
			}
			if (document.products.elements[LoopID].selectedIndex == "1"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.products.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.products.elements[LoopID2].value = "";
					}
				}
			}
			if (document.products.elements[LoopID].selectedIndex == "2"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.products.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.products.BATTerm1.value = replaceChars(document.products.BATTerm1.value);
						document.products.elements[LoopID2].value = "";
					}
				}
			}
		}
	}
}

	function replaceChars(entry) {
		out = " and"; // replace this
		add = ""; // with this
		temp = "" + entry; // temporary holder

		while (temp.indexOf(out)>-1) {
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add +
			temp.substring((pos + out.length), temp.length));
			}
		document.SOFO.BATTerm1.value = temp;
		}

function eveOnHandle() {

	//if (document.events.Combine.checked == true){
	//	document.events.BATQuery.value = "EventsAdvancedSearch";
	//	}
	//else {
		document.events.BATQuery.value = "EventsAdvancedSearchWOSort";
	//}

	var CurrentDate = new Date();
	var CurrentDateMonth = (CurrentDate.getMonth()+1);
	var CurrentDateYear = CurrentDate.getFullYear();
	var CurrentDay = CurrentDate.getDate();

	var ToMonth = document.events.ToMonth.selectedIndex;
	var ToDay = document.events.ToDay.selectedIndex;
	var ToYear = document.events.ToYear.value;
	 if (ToYear == ""){
			ToYear = CurrentDateYear;
		  }
		  if (ToMonth == ""){
			if (CurrentDateMonth < 10) {
					CurrentDateMonth = "0" + CurrentDateMonth;
				}
			document.events.ToMonth.options[ToMonth].value = CurrentDateMonth;
		  }
		  if (ToDay == ""){
			if (CurrentDay < 10) {
					CurrentDay = "0" + CurrentDay;
				}
			document.events.ToDay.options[ToDay].value = CurrentDay;
		  }
		 if (document.events.ToYear.value == "" && document.events.ToMonth.selectedIndex == "0" && document.events.ToDay.selectedIndex == "0"){
				document.events.BATTerm6.value = "";
				document.events.BATTerm11.value = "";
		  }
		  else {
			document.events.BATTerm6.value = ToYear + document.events.ToMonth.options[ToMonth].value + document.events.ToDay.options[ToDay].value;
			document.events.BATTerm11.value = ToYear + document.events.ToMonth.options[ToMonth].value + document.events.ToDay.options[ToDay].value;
		 }



	var FromMonth = document.events.FromMonth.selectedIndex;
	var FromDay = document.events.FromDay.selectedIndex;
	var FromYear = document.events.FromYear.value;
	if (FromYear == ""){
			FromYear = CurrentDateYear;
		  }
		  if (FromMonth == ""){
			document.events.FromMonth.options[FromMonth].value = CurrentDateMonth;
		  }
		  if (FromDay == ""){
			document.events.FromDay.options[FromDay].value = CurrentDay;
		  }
		 if (document.events.FromYear.value == "" && document.events.FromMonth.selectedIndex == "0" && document.events.FromDay.selectedIndex == "0"){
				document.events.BATTerm5.value = "";
				document.events.BATTerm4.value = "";
		  }
		  else {
			document.events.BATTerm5.value = FromYear + document.events.FromMonth.options[FromMonth].value + document.events.FromDay.options[FromDay].value;
			document.events.BATTerm4.value = FromYear + document.events.FromMonth.options[FromMonth].value + document.events.FromDay.options[FromDay].value;
		}
	for (LoopID=1; LoopID <= 4; LoopID++) {
		if (document.events.elements[LoopID].name == "BATTerm1.Attribute") {
			if (document.events.elements[LoopID].selectedIndex == "0" && document.events.elements[LoopID].value == "BAT.BooleanExpr"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.events.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.events.BATTerm1.value = replaceChars(document.events.BATTerm1.value);
						document.events.elements[LoopID2].value = "Structure.Word List";
						document.events.BATTerm1.value = setOr(trim(document.events.BATTerm1.value));
					}
				}
			}
			if (document.events.elements[LoopID].selectedIndex == "1"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.events.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.events.elements[LoopID2].value = "";
					}
				}
			}
			if (document.events.elements[LoopID].selectedIndex == "2"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.events.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.events.BATTerm1.value = replaceChars(document.events.BATTerm1.value);
						document.events.elements[LoopID2].value = "";
					}
				}
			}
		}
	}
	if (document.events.BATTerm9.options[0].selected == true){
		document.events.BATTerm5.value ="";
		document.events.BATTerm6.value ="";
	}
}

function resOnHandle() {

	  var CurrentDate = new Date();
	  var CurrentDateMonth = (CurrentDate.getMonth()+1);
	  var CurrentDateYear = CurrentDate.getFullYear();
	  var CurrentDay = CurrentDate.getDate();

	  var ToMonth = document.researchers.ToMonth.selectedIndex;
	  var ToDay = document.researchers.ToDay.selectedIndex;
	  var ToYear = document.researchers.ToYear.value;

	  if (ToYear == ""){
		ToYear = CurrentDateYear;
	  }
	  if (ToMonth == ""){
		if (CurrentDateMonth < 10) {
				CurrentDateMonth = "0" + CurrentDateMonth;
			}
		document.researchers.ToMonth.options[ToMonth].value = CurrentDateMonth;
	  }
	  if (ToDay == ""){
		if (CurrentDay < 10) {
				CurrentDay = "0" + CurrentDay;
			}
		document.researchers.ToDay.options[ToDay].value = CurrentDay;
	  }
	  if (document.researchers.ToYear.value == "" && document.researchers.ToMonth.selectedIndex == "0" && document.researchers.ToDay.selectedIndex == "0"){
			document.researchers.BATTerm6.value = "";
	  }
	  else{
		document.researchers.BATTerm6.value = ToYear + document.researchers.ToMonth.options[ToMonth].value + document.researchers.ToDay.options[ToDay].value;
		}

	  var FromMonth = document.researchers.FromMonth.selectedIndex;
	  var FromDay = document.researchers.FromDay.selectedIndex;
	  var FromYear = document.researchers.FromYear.value;
	  if (FromYear == ""){
		FromYear = CurrentDateYear;
	  }
	  if (FromMonth == ""){
		document.researchers.FromMonth.options[FromMonth].value = CurrentDateMonth;
	  }
	  if (FromDay == ""){
		document.researchers.FromDay.options[FromDay].value = CurrentDay;
	  }
	  if (document.researchers.FromYear.value == "" && document.researchers.FromMonth.selectedIndex == "0" && document.researchers.FromDay.selectedIndex == "0"){
			document.researchers.BATTerm5.value = "";
	  }
	  else {
		document.researchers.BATTerm5.value = FromYear + document.researchers.FromMonth.options[FromMonth].value + document.researchers.FromDay.options[FromDay].value;
	}
	for (LoopID=1; LoopID <= 10; LoopID++) {
		if (document.researchers.elements[LoopID].name == "BATTerm1.Attribute") {
			if (document.researchers.elements[LoopID].selectedIndex == "0" && document.researchers.elements[LoopID].value == "BAT.BooleanExpr"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.researchers.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.researchers.BATTerm1.value = replaceChars(document.researchers.BATTerm1.value);
						document.researchers.elements[LoopID2].value = "Structure.Word List";
						document.researchers.BATTerm1.value = setOr(trim(document.researchers.BATTerm1.value));
					}
				}
			}
			if (document.researchers.elements[LoopID].selectedIndex == "1"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.researchers.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.researchers.elements[LoopID2].value = "";
					}
				}
			}
			if (document.researchers.elements[LoopID].selectedIndex == "2"){
				for (LoopID2=0; LoopID2 <= 0; LoopID2++) {
					if (document.researchers.elements[LoopID2].name == "BATTerm1.Attribute") {
						document.researchers.BATTerm1.value = replaceChars(document.researchers.BATTerm1.value);
						document.researchers.elements[LoopID2].value = "";
					}
				}
			}
		}
	}
}

function replaceChars(entry) {
	out = " and"; // replace this
	add = ""; // with this
	temp = "" + entry; // temporary holder
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function SetQuery(value){
	var lreturn = "ProductAdvancedWOSort";
	if (value == true){
		lreturn = "ProductAdvancedSearch";
	}
	return lreturn;
}

function setOr(str) {
	var n = str;
	var lReturn = "";
	var catchvalue = 0;
	while(n.indexOf(" ") >= 0) {
		lReturn += n.substring(0,n.indexOf(" ")) + " and ";
		n = n.substring(n.indexOf(" ")+1,n.length);
		catchvalue++;
	}
	lReturn += n;
	return lReturn;
}

function trim(str) {
	n = str;
	while(n.charAt(0)==' ')
		n=n.substring(1,n.length)
	while(n.charAt(n.length-1)==' ')
		n=n.substring(0,n.length-1)
	return n;
}

function showLocations()
{
	locationsWindow = window.open ("../Locations.htm", "mylocations","location=1,status=0,scrollbars=1, width=620,height=500");
} 

function showLocationsAdmin()
{
	locationsAdminWindow = window.open ("../LocationsAdmin.htm", "mylocationsadmin","location=1,status=0,scrollbars=1, width=620,height=500");
} 

function clearlist() {
	document.products.BATTerm8.value="";
}

function clearadminlist() {
	document.products.BATTerm10.value="";
}

function AllAcademic(pSetting) {
	if (pSetting == true) {
		for (i=0; i<=25; i++)
			document.products.BATDBList[i].checked = document.products.AllAcademicCB.checked == true;
	}
	else {
   				document.products.AllAcademicCB.checked = false;
	}
}

function eveAllAcademic(pSetting) {
	if (pSetting == true) {
		for (i=0; i<=3; i++)
			document.events.BATDBList[i].checked = document.events.AllAcademicCB.checked == true;
	}
	else {
   				document.events.AllAcademicCB.checked = false;
	}
}


function resAllAcademic(pSetting) {
	if (pSetting == true) {
		for (i=0; i<=1; i++)
			document.researchers.BATDBList[i].checked = document.researchers.AllAcademicCB.checked == true;
	}
	else {
   				document.researchers.AllAcademicCB.checked = false;
	}
}