// global variables
 var winRef = "";
function checkForNumeric(wField, wMessage, wFormOk) {
   if (! wFormOk) {
      return false;
   }	  
   if (wField.value.length > 0) {
      wStr = new String(wField.value);
      var stringMatchRE = /^(\d+)$/;
      var matchResult = wStr.match(stringMatchRE);
      if (matchResult == null) {
         alert(wMessage + " must be a number.");
		 wField.focus();
	     return false;
      }
   }
   return true;
}

function checkForSomething(wForm, wFormOk) {
   if (! wFormOk) {
      return false;
   }
   wFormOk = false;
 
   // loop through all the elements on the form
   for (i=0; i<wForm.elements.length; i++){
	  if (wForm.elements[i].name == "speciesProcessedAndOr") {
	     continue;
	  }
	  if (wForm.elements[i].name == "materialsPurchasedAndOr") {
	     continue;
	  }
	  if (wForm.elements[i].name == "productsSoldAndOr") {
	     continue;
	  }
	  if (wForm.elements[i].name == "sizeValueOper") {
	     continue;
	  }
	  if (wForm.elements[i].name == "Clear") {
	     continue;
	  }
	  if (wForm.elements[i].name == "speciesPurchasedAndOr") {
	     continue;
	  }
	  if (wForm.elements[i].name == "numEmployeesOper") {
	     continue;
	  }
	  if (wForm.elements[i].name == "totHardwoodLumberVolOper") {
	     continue;
	  }	 
	  if (wForm.elements[i].name == "totSoftwoodLumberVolOper") {
	     continue;
	  }	
	  // any form element that starts with "previous" is just a hidden field......
	  var stringMatchPreviousRE = /^(previous.*)$/;
      var matchResultPrevious = wForm.elements[i].name.match(stringMatchPreviousRE);
      if (matchResultPrevious != null) {
	     //alert ("continuing " + wForm.elements[i].name);
         continue;
      }	  
	  if (wForm.elements[i].name == "Submit") {
	     continue;
	  }
      //alert(wForm.elements[i].value);
	  if (wForm.elements[i].value.length > 0) {
	     if (wForm.elements[i].type == "checkbox") {
		    if (wForm.elements[i].checked) {
		       wFormOk = true;
			   //alert ("setting to true for a checkbox");
			}   
		 }  
		 else {	// not a checkbox 
		    //alert("type " + wForm.elements[i].type);
		    if (wForm.elements[i].type == "select-multiple") {
			   if (wForm.elements[i].selectedIndex > -1) {
			      //alert("setting for a select box");
				  wFormOk = true;
			   }
			}
			else { // not a checkbox or a select list     	  
	           //alert("setting to ok " + wForm.elements[i].name + " val: " + wForm.elements[i].value);
               wFormOk = true;
	        }
		 }		  
      }
   }
   // end for loop here	  
   
   if (! wFormOk) {
      alert("Please choose one or more search criteria.");
   }
   return wFormOk;
}

function checkMultiSelect (wSelBox, wPrevious) {
      
      wSelBox.focus();  // needed because ie does get the selectedIndex set upon onClick without focus() being called first.
   
      //alert('sel in cms ' + wSelBox.selectedIndex + ' prev ' + wPrevious.value ); 
	  var selCount = 0;
	  var lowestSelected = -1;
	  for (i = 0;	i < wSelBox.length; i++) {
         if (wSelBox.options[i].selected) {
		    if (selCount == 0) {
			   lowestSelected = i;
			}   
	        selCount++;
	     }
	  }	 		
	 
	  if (selCount == 1) {
	     if (wPrevious.value == wSelBox.selectedIndex) { 
	        wSelBox.selectedIndex = -1;
	     }		
	  } 
      wPrevious.value = wSelBox.selectedIndex;
}

function showHelp(targetWindow, pUrl) {
   if (winRef.closed) {
      winRef = "";
   }	  
   if (winRef != "") {
      //alert("closing");
      winRef.close();
   }	 
   //alert ("opening");
   winRef = window.open(pUrl, targetWindow, "width=600, height=350, resizable=yes, scrollbars=yes, left=10, top=10, screenX=10, screenY=10"); 
   //window.document.hiddenForm.winRef.value = winRef;
   winRef.focus(); 
   return false;
}