function setMultipleValuesStartDate(y,m,d) {
	document.unifindSearch.searchStartDate_year.value=y;
	document.unifindSearch.searchStartDate_month.selectedIndex=m-1;
	for (var i=0; i<document.unifindSearch.searchStartDate_day.options.length; i++) {
		if (document.unifindSearch.searchStartDate_day.options[i].value==d) { document.unifindSearch.searchStartDate_day.selectedIndex=i; }
	}
	document.unifindSearch.searchEndDate_year.value=y;
	document.unifindSearch.searchEndDate_month.selectedIndex=m-1;
	for (var i=0; i<document.unifindSearch.searchEndDate_day.options.length; i++) {
		if (document.unifindSearch.searchEndDate_day.options[i].value==d) { document.unifindSearch.searchEndDate_day.selectedIndex=i; }
	}
}
function setMultipleValuesEndDate(y,m,d) {
	document.unifindSearch.searchEndDate_year.value=y;
	document.unifindSearch.searchEndDate_month.selectedIndex=m-1;
	for (var i=0; i<document.unifindSearch.searchEndDate_day.options.length; i++) {
		if (document.unifindSearch.searchEndDate_day.options[i].value==d) { document.unifindSearch.searchEndDate_day.selectedIndex=i; }
	}
}

function getDateString(y_obj,m_obj,d_obj) {
	var y = y_obj.options[y_obj.selectedIndex].value;
	var m = m_obj.options[m_obj.selectedIndex].value;
	var d = d_obj.options[d_obj.selectedIndex].value;
	if (y=="" || m=="") { return null; }
	if (d=="") { d=1; }
	return str= y+'-'+m+'-'+d;
	}

function searchAdvanced() {
  document.unifindSearch.searchType.value = 'advanced';
  document.unifindSearch.action = "searchAdvanced.asp";
  document.unifindSearch.submit();
}
function gotoPage(type,stat,total,start) {
  document.unifindSearch.searchType.value = type;
  document.unifindSearch.Stat.value = stat;
  document.unifindSearch.Total.value = total;
  document.unifindSearch.Start.value = start;
  document.unifindSearch.submit();
}

function sortBy(sort, type, stat, total, start) {
  document.unifindSearch.searchType.value = type;
  document.unifindSearch.Stat.value = stat;
  document.unifindSearch.Total.value = total;
  document.unifindSearch.Start.value = start;
  document.unifindSearch.BRank.value = sort;
  document.unifindSearch.submit();
}

function spellingResubmit(query,type) {
  document.unifindSearch.Query.value = query;
  document.unifindSearch.searchType.value = type;
  document.unifindSearch.Stat.value = 'resubmit';
  document.unifindSearch.submit();
}

	
function enableDate(state) {
  if (state) { state=false; } else { state=true; }
  document.unifindSearch.searchStartDate_year.disabled = state;
  document.unifindSearch.searchStartDate_month.disabled = state;
  document.unifindSearch.searchStartDate_day.disabled = state;
  document.unifindSearch.searchEndDate_year.disabled = state;
  document.unifindSearch.searchEndDate_month.disabled = state;
  document.unifindSearch.searchEndDate_day.disabled = state;
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}


function validateForm(form) {
	if (form.Query.value.length < 4) {
		alert("You have either not entered a search string or it is less than the required 4 characters.  Please revise your query before continuing.");
		form.Query.focus();
		return false;
	}
	if (form.Filter3Field.checked == true) {
		if (!isDate(form.searchStartDate_day.options[form.searchStartDate_day.selectedIndex].value, form.searchStartDate_month.options[form.searchStartDate_month.selectedIndex].value, form.searchStartDate_year.options[form.searchStartDate_year.selectedIndex].value)) { 
			alert("You have entered an invalid starting date range.  Please modify it now."); 
			form.searchStartDate_month.focus();
			return false;
		}
		if (!isDate(form.searchEndDate_day.options[form.searchEndDate_day.selectedIndex].value, form.searchEndDate_month.options[form.searchEndDate_month.selectedIndex].value, form.searchEndDate_year.options[form.searchEndDate_year.selectedIndex].value)) { 
			alert("You have entered an invalid ending date range.  Please modify it now."); 
			form.searchEndDate_month.focus();
			return false;
		}
	    startDate = new Date(form.searchStartDate_year.options[form.searchStartDate_year.selectedIndex].value,form.searchStartDate_month.options[form.searchStartDate_month.selectedIndex].value-1,form.searchStartDate_day.options[form.searchStartDate_day.selectedIndex].value)
	    endDate = new Date(form.searchEndDate_year.options[form.searchEndDate_year.selectedIndex].value,form.searchEndDate_month.options[form.searchEndDate_month.selectedIndex].value-1,form.searchEndDate_day.options[form.searchEndDate_day.selectedIndex].value)
	    if (endDate < startDate) {
	      alert("The ending range must be the same or after the starting range.  Please modify it now.");
  		  form.searchStartDate_month.focus();
	      return false;
	    }
	}
	return true;
}
  
function openWindow(objPage, popW, popH, bScroll) {
  var w = 450, h = 340;
  if (document.all) {
    /* the following is only available after onLoad */
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  } else if (document.layers) {
    w = window.innerWidth;
    h = window.innerHeight;
  }
  var leftPos = (w-popW)/2, topPos = (h-popH)/2;
  if (!window.windowRef) {
    // has not yet been defined
    windowRef = window.open(objPage,'popup','toolbar=0,scrollbars='+bScroll+',location=0,statusbar=0,menubar=0,resizable=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
  } else {
    // has been defined
    if (!windowRef.closed) {
      // still open
      windowRef.focus();
    } else {
      windowRef = window.open(objPage,'popup','toolbar=0,scrollbars='+bScroll+',location=0,statusbar=0,menubar=0,resizable=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
    }
  }
}