//
function setVisitorID(randomvisitornumber) {
	var expirydate = new Date()
	//var randomvisitornumber=Math.floor(Math.random()*100000001) ;
	//alert(randomvisitornumber) ;
	expirydate.setTime(expirydate.getTime() + (180*24*60*60*1000));
	if (isNaN(readCookie('visitor_id')) || readCookie('visitor_id') == 1 || !readCookie('visitor_id')) {
		//var randomvisitornumber=Math.floor(Math.random()*100000001) ;
		//document.cookie = "visitor_id=" + escape(randomvisitornumber) + "; expires=" + expirydate.toGMTString() + ";";
	}
	document.cookie = "visitor_id=" + escape(randomvisitornumber) + "; expires=" + expirydate.toGMTString() + ";";
}

// This is called by clicking to add product to notepad - stores the product index key in $_POST field then submits notepad form
function addNotepad(idx_key) {
	//setcookies() ;
	document.forms.notepad.notepad_add_products_index_key.value = idx_key ;
	document.forms.notepad.submit() ;
}

// This is called by clicking to remove product from notepad - stores the product index key in $_POST field then submits notepad form
function removeNotepad(idx_key) {
	//setcookies() ;
	document.forms.notepad.notepad_remove_products_index_key.value = idx_key ;
	document.forms.notepad.submit() ;
}

// This is called by clicking the main notepad link - sets the form field to Y then submits the form
function viewNotepad(doviewnotepad) {
	// If going to view notepad, remove the search settings (Y), but retain them if going back to browing (N)
	if (doviewnotepad == 'Y') {
		document.forms.searchform.categories0_index_key.value = 'all' ;
		document.forms.searchform.categories1_index_key.value = 'all' ;
		document.forms.searchform.manufacturers_index_key.value = 'all' ;
		document.forms.searchform.brands_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' ;
	}
	// When this cookie is set to Y, only products within the notepad (and meeting search conditions) are displayed
	document.forms.searchform.view_notepad.value = doviewnotepad ;
	searchformsubmit() ;
}

// This function stores all the cookies
function setcookies() {
	var expirydate = new Date()
	expirydate.setTime(expirydate.getTime() + (180*24*60*60*1000));
	document.cookie = "categories0_index_key=" + escape(document.forms.searchform.categories0_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "categories1_index_key=" + escape(document.forms.searchform.categories1_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "manufacturers_index_key=" + escape(document.forms.searchform.manufacturers_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "brands_index_key=" + escape(document.forms.searchform.brands_index_key.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "keywords=" + escape(document.forms.searchform.keywords.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "minprice=" + escape(document.forms.searchform.minprice.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "maxprice=" + escape(document.forms.searchform.maxprice.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "searchoffers=" + escape(document.forms.searchform.searchoffers.checked) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "products_per_page=" + escape(document.forms.searchform.products_per_page.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "reference_seq=" + escape(document.forms.searchform.reference_seq.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "price_seq=" + escape(document.forms.searchform.price_seq.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "sort_field=" + escape(document.forms.searchform.sort_field.value) + "; expires=" + expirydate.toGMTString() + ";";
	document.cookie = "view_notepad=" + escape(document.forms.searchform.view_notepad.value) + "; expires=" + expirydate.toGMTString() + ";";
}

   //function preventBack(){window.history.forward();} 

  //  setTimeout("preventBack()", 0); 

//    window.onunload=function(){null}; 
