String.prototype.trim = function() {
	// skip leading and trailing whitespace and return everything in between
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
} 
function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}
function formatURL(value){
	if (value.substr(0,7) != "http://"){
		value = "http://" + value;
	}
	return value;
}
top.SubmitForm=function(theForm){
        //var theForm = document.all.theForm;
	var bSaveOK=true;
	var sBadFields=""
	var els=theForm.elements;
	var foundChecked=false;

	if(theForm.exhibit_title.value.trim()=="" && theForm.frexhibit_title.value.trim()=="")
	{
		bSaveOK=false;
		sBadFields+="> The Title of Exhibit \n"
	}
	else if(theForm.exhibit_title.value.trim()=="")
	{
		theForm.exhibit_title.value=theForm.frexhibit_title.value;
	}
	else if(theForm.frexhibit_title.value.trim()=="")
	{
		theForm.frexhibit_title.value=theForm.exhibit_title.value;
	}

	if(theForm.url.value.trim()=="" && theForm.frurl.value.trim()=="")
	{
		bSaveOK=false;
		sBadFields+="> URL \n"
	}
	else if(theForm.url.value.trim()=="")
	{
		theForm.url.value=theForm.frurl.value;
	}
	else if(theForm.frurl.value.trim()=="")
	{
		theForm.frurl.value=theForm.url.value;
	}

	if(theForm.contributors.value.trim()=="" && theForm.frcontributors.value.trim()=="")
	{
		/* nothing for now */
	}
	else if(theForm.contributors.value.trim()=="")
	{
		theForm.contributors.value=theForm.frcontributors.value;
	}
	else if(theForm.frcontributors.value.trim()=="")
	{
		theForm.frcontributors.value=theForm.contributors.value;
	}

	if(theForm.date_coverage.value.trim()=="" && theForm.frdate_coverage.value.trim()=="")
	{
		/* nothing to see here */
	}
	else if(theForm.date_coverage.value.trim()=="")
	{
		theForm.date_coverage.value=theForm.frdate_coverage.value;
	}
	else if(theForm.frdate_coverage.value.trim()=="")
	{
		theForm.frdate_coverage.value=theForm.date_coverage.value;
	}

	if(theForm.description.value.trim()=="" && theForm.frdescription.value.trim()=="")
	{
		bSaveOK=false;
		sBadFields+="> Description \n"		
	}
	else if(theForm.description.value.trim()=="")
	{
		theForm.description.value=theForm.frdescription.value;
	}
	else if(theForm.frdescription.value.trim()=="")
	{
		theForm.frdescription.value=theForm.description.value;
	}

	if(theForm.education_desc.value.trim()=="" && theForm.freducation_desc.value.trim()=="")
	{
		/* nothing to see here */
	}
	else if(theForm.education_desc.value.trim()=="")
	{
		theForm.education_desc.value=theForm.freducation_desc.value;
	}
	else if(theForm.freducation_desc.value.trim()=="")
	{
		theForm.freducation_desc.value=theForm.education_desc.value;
	}

	if(theForm.rights.value.trim()=="" && theForm.frrights.value.trim()=="")
	{
		/* nothing to see here */
	}
	else if(theForm.rights.value.trim()=="")
	{
		theForm.rights.value=theForm.frrights.value;
	}
	else if(theForm.frrights.value.trim()=="")
	{
		theForm.frrights.value=theForm.rights.value;
	}

	if(theForm.otherlanguage.value.trim()=="" && theForm.frotherlanguage.value.trim()=="")
	{
		/* nothing to see here */
	}
	else if(theForm.otherlanguage.value.trim()=="")
	{
		theForm.otherlanguage.value=theForm.frotherlanguage.value;
	}
	else if(theForm.frotherlanguage.value.trim()=="")
	{
		theForm.frotherlanguage.value=theForm.otherlanguage.value;
	}

	if(bSaveOK)
	{
	  theForm.frurl.value = formatURL(theForm.frurl.value);
	  theForm.url.value = formatURL(theForm.url.value);
	  theForm.action="search.asp";
	  theForm.submit();
	}
	else
	{
		alert("Invalid Record.\nPlease correct the following:\n" + sBadFields);
	}
}
