function fetchSubCategory(site){

	var request = new Request.HTML({
		url: 'ajaxHandler.php',
		data: {
			Site: site,
			Method: 'getSubCat',
			Cat: $('category').get('value')
		},
		onSuccess: function(){
			$('subcategory').set('disabled',false);
		},
		update: $('subcategory')
	}).send();
}

function searchCategory(site){
	var cat = $('category').get('value').trim();
	var subcat = $('subcategory').get('value').trim();

	var url = 'http://' + site + "/indexes/suppliers-cat" + cat;

	if(cat.match(/^[a-y]$/) && subcat.match(/^[a-z]$/)){
		window.location = url + subcat + "-all.html";
	} else if (cat.match(/[a-y]/)){
		window.location = url +  "-all.html";
	}
}

function searchCompany(site){
	var url = 'http://' + site + "/news/";
	var ticker = $('cosearch_ticker').get('value');

	if(ticker.match(/[a-z]{3}/)){
		url += ticker + "/" + ticker + "000.html";;
		window.location = url;
	} else {
		alert("We are sorry but that company doesn't seem to exist in our database. Try typing less to let the autocomplete guess. ");
	}

}

// Overide Standard Autocompleter so we can pick up the company ticker
// When the selection is made
ProtalkAutocompleter = new Class({
	Extends: Autocompleter.Request.JSON,

	choiceSelect: function(choice) {
		if (choice) this.choiceOver(choice);
		this.setSelection(true);
		this.queryValue = false;
		this.hideChoices();
		$('cosearch_ticker').value = this.selected.inputTicker;
	}

	});
