$(document).ready(function(){
	 if ($.browser.mozilla) {
	      $("#q").keypress(checkForEnter);
	  } else {
	      $("#q").keydown(checkForEnter);
	  }
});

function ShowAreas(lnk)
{
	if(lnk.innerHTML=='Show All Areas')
	{
		$(".pickAreas p").show('slow');
		lnk.innerHTML='Hide Areas';
	}
	else
	{
		$(".pickAreas p.h").hide('slow');
		lnk.innerHTML='Show All Areas';
	}
	
	return false;
}

//http://www.mredkj.com/javascript/nfbasic.html
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

$(function(){
		$(".pickAreas input").change(function(){
			if ($(this).is(":checked")) {
				$("#specificMls").attr("checked", "checked");
				$("#allMls").removeAttr("checked");
			}
		});
	});
	
	$(function(){
		$("#allMls").change(function(){
			if ($(this).is(":checked")) {
				$("#specificMls").removeAttr("checked");
				$(".pickAreas input").removeAttr("checked");
			}
		});
	});
	
	$(function(){
		$(".pickTypes input").change(function(){
			if ($(this).is(":checked")) {
				$("#specificTypes").attr("checked", "checked");
				$("#allTypes").removeAttr("checked");
			}
		});
	});
	
	$(function(){
		$("#allTypes").change(function(){
			if ($(this).is(":checked")) {
				$("#specificTypes").removeAttr("checked");
				$(".pickTypes input").removeAttr("checked");
			}
		});
	});
		
	function checkForEnter(event) {
  	 if (event.keyCode == 13) {
      PostForm('frmSearch');
  	 }
	} 
	
	function PostForm(form)
	{
		if($('#q').val().indexOf('Search') != -1)
			$('#q').val('');
		
		$('#' + form).submit();
	}