/*
		search.js
*/

// Variables for global use
var subCatManager;

// Submit from the search button under the categories criterion
function submitResult(){
	var mainCatValue = $('main_cat').getSelected().getProperty('value');
	var selCategory = new String('?title=');
	if (mainCatValue != 0) {
		selCategory += $('main_cat').getSelected().getProperty('text');
	}
	//alert ("-->" + selCategory.replace(" ", "_") + "<--");
	document.searchfrm.action="result-product.php" + selCategory.replace(/ /g, '_');
	document.searchfrm.submit();
}

// Get the list of subcategories and update the field when the Main Category changes
function getSubCategories() {
	var main_cat = $('main_cat').getSelected()[0].getProperty('value');
	subCatManager.setOptions({data: {'main_cat' : main_cat}}).send();
	return true;
}

// Script to run when the DOM is loaded and ready
window.addEvent('domready', function() {

	// Populate the sub-category list
	subCatManager = new Request({
		method: 'post',
		url: 'includes/form_getSubCat.php',
		data: { 'main_cat' : 0
		},
		onSuccess : function (responseText) {
			$('sub_cat').set('html', responseText);
		}
	});
});