//
//Check whether a required field is empty
//If empty return true
//otherwise, return false
//
function FieldEmpty(inputStr)
{
  if (inputStr == null || inputStr.length == 0)
    return true
  else
    return false
}

function SubmitSearchString(thisForm,checkSearchType)
{
    var cleanSearchString
    var searchType
    
    if (checkSearchType)
    {
        for (var i=0; i<thisForm.searchtype.length; i++)
        {
            if (thisForm.searchtype[i].checked)
            {
                searchType = thisForm.searchtype[i].value
                break
            }
        }
    }else
    {
        searchType = "keyword"
    }
    
    thisForm.titles.value="no"
    cleanSearchString = thisForm.search.value.replace(/\s+/g,"+")
    cleanSearchString = cleanSearchString.replace(/<+/g,"")
    cleanSearchString = cleanSearchString.replace(/>+/g,"")
    cleanSearchString = cleanSearchString.replace(/\(+/g,"")
    cleanSearchString = cleanSearchString.replace(/\)+/g,"")
    thisForm.action = searchUrlBase + "search=" + searchType + ";" + cleanSearchString;
    thisForm.submit()
}

function GoAdvSearch(theFormName)
{
	var numForms = document.forms.length
	var thisForm
	var bSubmit = true

	for (var i=0;i<numForms;i++)
	{
		thisForm = document.forms[i]
		if (thisForm.name == 'searchform1' &&
		    theFormName == 'searchform1' &&
		    !FieldEmpty(thisForm.search.value) &&
		    thisForm.search.value != 'Enter Search')
		{
		    SubmitSearchString(thisForm,true)
		    return
		}else
		{
		    if (thisForm.name == 'searchform3' &&
	            theFormName == 'searchform3' &&
	            !FieldEmpty(thisForm.search.value))
	        {
	            SubmitSearchString(thisForm,false)
	            return
		    }
		}
	}
	alert("Sorry, you must specify a search string.")
}

function CheckBlankSearch(theFormName)
{
	var numForms = document.forms.length
	var thisForm

	for (var i=0;i<numForms;i++)
	{
		thisForm = document.forms[i]
		if (thisForm.name == 'searchform1' &&
		    theFormName == 'searchform1' &&
		    !FieldEmpty(thisForm.search.value))
		{
		    return true
		}
	}
    alert("Sorry, you must specify a search string.")
    return false
}