 
 function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

function printArtist(first, last) {

      if(first) {
	  	first = first.trim();
		last = last.trim();
	     document.write(first + ' ' + last);
      } else {
	     document.write(last.trim());
	  }

   }

	function SubmitSort(sortForm, searchType) {
	   
		if(!sortForm.ascDesc) {
			sortForm.innerHTML += '<input type="hidden" name="ascDesc" value="DESC">';
		} else if(sortForm.ascDesc.value == "DESC") {
		    sortForm.ascDesc.value = "ASC";
		} else {
		    sortForm.ascDesc.value = "DESC";
		}
		
		
		if(sortForm.sort) {
		   sortForm.sort.value = searchType;
		}
		if(sortForm.format) {
			sortForm.format.value = '';
		}
		//alert(sortForm.ascDesc.value);
		sortForm.submit();
	}
	
	function SubmitFormat(sortForm, format) {
		if(!sortForm.format) {
			sortForm.innerHTML += '<input type="hidden" name="format" value="' + format + '">';
		} else {
			sortForm.format.value = format;
		}
		
		if(sortForm.next.value) {
		  sortForm.next.value = 0;
		}
		if(sortForm.prev.value) {
		   sortForm.prev.value = 0;
		}
		if(sortForm.start.value) {
		   sortForm.start.value = 0;
		}
		if(sortForm.end.value) {
		   sortForm.end.value = 0;
		}
		
		sortForm.submit();
		return true;
	}
	
	function artistSearch(searchForm, artistFirst, artistLast) {
		searchForm.artistFirst.value = artistFirst;
		searchForm.artistLast.value = artistLast;
		searchForm.submit();
	}
	
	function browseBy(browseForm, letter) {
		if(browseForm.next) {
			browseForm.next.value = 0;
		}
		if(browseForm.prev) {
			browseForm.prev.value = 0;
		}
		if(browseForm.start) {
			browseForm.start.value = 0;
		}
		if(browseForm.end) {
			browseForm.end.value = 1;
		}
		browseForm.browseBy.value = letter;
		browseForm.submit();
	}
	
	function changeMaxResults(sortForm, newMaxResults, start, curSort) {
	
		if(sortForm.maxResults) {
		   sortForm.maxResults.value = newMaxResults;
		} else {
			sortForm.innerHTML += '<input type="hidden" name="maxResults" value="' + newMaxResults + '">';
		}
		
		
		//if(sortForm.ascDesc) {
		//   sortForm.ascDesc.value = curSort;
		//}
		//if(sortForm.start) {
		//	sortForm.start.value = start;
		//}
		//if(sortForm.end) {
		//	sortForm.end.value = newMaxResults;
		//}
		
		sortForm.submit();
	}
	
	function nextSearchPage(searchForm) {
		//alert("Search Form");
		if(searchForm.prev) {
			searchForm.prev.value = 0;
		}
		
		if(!searchForm.next) {
		   searchForm.innerHTML += '<input type="hidden" name="next" value="1">';
		} else {
			searchForm.next.value = "1";
		}
		
		searchForm.submit();
	}
	
	function prevSearchPage(searchForm) {
		if(searchForm.next) {
			searchForm.next.value = 0;
		}
		
		if(!searchForm.prev) {
		   searchForm.innerHTML += '<input type="hidden" name="prev" value="1">';
		} else {
		   searchForm.prev.value = "1";
		}
		
		searchForm.submit();
	}
	
	function inventoryNoSearch(searchForm, InventoryNo) {
		//alert("HOORAY!");
		if(searchForm.keywords) {
			searchForm.keywords.value = InventoryNo
		}
		
		searchForm.submit();
	}
	
	function randomCoolSearch(searchForm, category, days, price, sort, format) {
		if(searchForm.category) {
			searchForm.category.value = category;
		}
		
		if(searchForm.addedSince && ! is_empty(days)) {
				searchForm.addedSince.value = days;
		}
		
		if(searchForm.price && ! is_empty(price)) {
				searchForm.price.value = price;
				searchForm.sort.value = "price";
				searchForm.searchType.value = "price";
				if(searchForm.ascDesc) {
					searchForm.ascDesc.value = "DESC";
				}
			
		}
		
		if(!is_empty(sort)) {
			if(sort == "date") {
				if(searchForm.ascDesc) {
					searchForm.ascDesc.value = "DESC";
				}
			}
			searchForm.sort.value = sort;
		}
		
		if(!is_empty(format)) {
			searchForm.format.value = format;
		}
		
		searchForm.submit();
	}
	
	function is_empty(str) {
		if(str == "" || str == null) {
			return true
		}
	}
	
	function wantListPopUp(invId) {
		var wantList = "/wantlistAdd.php?invId=" + invId;
		var NewWindow = window.open(wantList,'WantList','width=250,height=300,scrollbars=no');
		if(NewWindow.focus) 
			NewWindow.focus();
	}
	
	function pop_global(freeship){
		freeship = window.open("freeship_pop.html", "displayWindow", "width=325,height=375,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=no");
	}