function isRegistryNumber(str) {
	str = str.replace(/^\s+/,'').replace(/\s+$/,'');

	if ((str.length < 7) || (str.length > 11)) return false;

	var dash1 = str.length - 5;
	var dash2 = str.length - 2;

	if ((str.charAt(dash1) == "-") && (str.charAt(dash2) == "-")) {
		return isNumber(str.substring(0,dash1) + str.substring(dash1+1,dash2) + str.charAt(str.length - 1));
	} else {
		return isNumber(str.substring(1));
	}
}

function isNumber(str) {
	var c;
	
	for (var i=0; i<str.length; i++) {
		c = str.charAt(i);
		if (isNaN(c)) return false;
	}
	
	return true;
}

function submitLiteQuery(form) {
  var wildChar = '*'; 
  if (form.QV1.value == "")
   {
      alert("Type search terms in the search box.");
      form.QV1.focus(); 
      return false;
   }
/*
   if (form.QV1.value.indexOf(wildChar) == 0)   {
        alert("This type of wildcard use is not supported. You can only use wildcard at the end of search characters");
        form.QV1.focus(); 
        return false;
   }
*/
   if (form.QV1.value.indexOf(wildChar) > 0 && form.QV1.value.length < 4) {
        alert("Please use 3 or more characters when using wildcard search");
        form.QV1.focus(); 
        return false;
   }
   // This is commented as 'contains' or 'ends with' search is not desired by NLM for now.
   /*if (form.QV1.value.indexOf(wildChar) == 0 && 
   	(form.QV1.value.lastIndexOf(wildChar) < 5 && form.QV1.value.lastIndexOf(wildChar) != 0) )
   {
      alert("Please enter at least 4 search characters");
      form.QV1.focus(); 
      return false;
   }*/

   form.QF1.value = isRegistryNumber(form.QV1.value)?"Number":"Name";
   form.QV1.value = form.QV1.value.toUpperCase().replace(/^\s+/,'').replace(/\s+$/,'');
   return true;
}
function executeSearch(qryForm) {
	var retValue = this.submitLiteQuery(qryForm);
	if (retValue) {
		 qryForm.submit();
	}
}
function clearValue(o) {
	o.value = '';
}
function transferTosearch(chemid) {
	document.search.superlistid.value = chemid;
	document.search.TRANSFER.value = true;
	document.search.submit();
}
function findSimilarStructures(chemid) {
	document.search.superlistid.value = chemid;
	document.search.actionHandle.value = 'similaritySearch';
	document.search.nextPage.value = 'jsp/chemidheavy/ChemidDataview.jsp';
	document.search.submit();
}
function findSalt(fileReference) {
        document.search.MOLFILE_REFERENCE.value = fileReference;
        document.search.QF10.value = "Flex";
        document.search.actionHandle.value = 'searchStructureSaltParent';
        document.search.nextPage.value = 'jsp/chemidheavy/ChemidDataview.jsp';
        document.search.submit();
}

function enlargeImage(sURL) {
	popitup(sURL, 535, 620);
}
