// This is called when the Reference button is clicked. Indicates to sort by reference, in the appropriate order
function sortreference(sort_order) {
	document.forms.searchform.reference_seq.value = sort_order ;
	document.forms.searchform.sort_field.value = "R" ;
	searchformsubmit() ;
}

// This is called when the Price button is clicked. Indicates to sort by price, in the appropriate order
function sortprice(sort_order) {
	document.forms.searchform.price_seq.value = sort_order ;
	document.forms.searchform.sort_field.value = "P" ;
	setpage(1) ;	// if changing the sort order, then always go back to page one
	searchformsubmit() ;
}

// This is called by clicking main search button (and if auto-submit is on) - always reset page to 1. Goes on to set cookies then submit form
function searchbrand() {
	document.forms.searchform.categories0_index_key.value = 'all' ;
	document.forms.searchform.categories1_index_key.value = 'all' ;
	document.forms.searchform.keywords.value = '' ;
	document.forms.searchform.minprice.value = '' ;
	document.forms.searchform.maxprice.value = '' ;
	document.forms.searchform.searchoffers.value = '0' ;
	setpage(1) ;	
}

// This is called by clicking main search button (and if auto-submit is on) - always reset page to 1. Goes on to set cookies then submit form
function searchoptions() {
	setpage(1) ;	
}

// This function Stores the requested page number, then soes on to set cookies and submit the form
function setpage(page_no) {
	document.forms.searchform.page_no.value = page_no ;
	searchformsubmit() ;
}

// This function stores the cookies and carries out the actual submission of the form
function searchformsubmit() {
	setcookies() ;
	document.forms.searchform.submit() ;
}

// This function stores the cookies and carries out the actual submission of the form
function view_option(formname) {
	//setcookies() ;
	//alert(formname + ' - ' + document.forms[formname].index_key.options[document.forms[formname].index_key.selectedIndex].value) ;
	//alert(formname + ' - ' + document.forms[formname].index_key.value + ' - ' + document.forms[formname].index_key.selectedIndex) ;
	document.forms[formname].action = 'view-product.php?index=' + document.forms[formname].index_key.value ;
	document.forms[formname].submit() ;
}

function clearSearchResults(subcat) {
	document.getElementById("search_results").style.display="none" ;
	document.getElementById("search_results_clock").style.display="inline" ;
	document.getElementById(subcat).style.display="none" ;
}
