window.onload = function () {
	drop_down_list_prov();
}

function inline_results(form,o) {
		var r=check_form(document.search_form);

		if (r)
		{
			$('#search_panel').hide();
			$('#content_panel').hide();
			$('#loading_content').show();
			var p=$('#province').val();
			var c=$('#city').val();
			var ca=get_checkbox_value(document.search_form);
			var url=base_url+'main/ajaxsearch';

			//alert("Inline\nProv: "+p+"\nCity: "+c+"\nCategory: "+ca);
			if (o==null)
			{
				o=0;
			}
			$.post(url, { prov: p, city: c, cat: ca, offset: o },
				function(mydata){
				$("#content_panel").html(mydata);
				$('#loading_content').hide();
				$('#content_panel').show();
			});
		}
}

function show_business(id) {

	$('#search_panel').hide();
	$('#content_panel').hide();
	$('#loading_content').show();
	var url=base_url+'main/show_business';

	$.post(url, { bid: id },
		function(mydata){
		$("#content_panel").html(mydata);
		$('#loading_content').hide();
		$('#content_panel').show();
	});

}

function check_form(form)
{
		// Check for checkbox data!
		var city=form.city.value;
		var prov=form.province.value;
		var c=0;
		with(form) {
			ln=checkbox_categories.length;
			if(ln>1) {
				for(var i=0;i<ln;i++) {
					if (checkbox_categories[i].checked)	{
						c=checkbox_categories[i].value;
						break;
					}
				}
			}
			else {
				c=checkbox_categories.value;
			}
		}
		if (c==0) {
			$("#dialog").html("<p>Could you please select a Category.</p>");
			$("#dialog").dialog("open");
			return false;
		}
		return true;
}

function get_checkbox_value(form) {
	var ln=document.search_form.checkbox_categories.length;
	var cvalue=false;
	with(form) {
		if (ln>1)
		{
			for (var i=0; i<ln; i++)
			{
				if (checkbox_categories[i].checked)
				{
					cvalue=checkbox_categories[i].value;
					break;
				}
			}
		}
		else {
			cvalue=checkbox_categories.value;
		}
	}
	return cvalue;
}