$(document).ready(function () {
	
	$('#advancedSearch').click(function(){
		
		if ($('#extraSearchOptions').css('display') == 'none'){
			$('#advancedSearch img').attr('src', '/images/small-minus-ms.gif');
		} else {
			$('#advancedSearch img').attr('src', '/images/small-plus-ms.gif')
		}
		$('#extraSearchOptions').slideToggle(700, 'easeOutExpo');
	});
	

	$('.lowerRads').click(function(){
		$(this).children("input:radio").attr("checked",true);
		$("input[name='SortBy']").parent().removeClass('lowerRadSelected');
		$("input[name='SortBy']:checked").parent().addClass('lowerRadSelected');
		
	});
	
	$('#searchLink').click(function(){
		SubmitQueryForm();
	});
	
	$('#frmSearch select').change(function(){
		if($(this).attr('id') == 'ManufacturerId'){
			clearmodel();
			showCustomer(true);
		} else {
			showCustomer(true);
		}
	});
	
	$('.searchType').click(function(){
		
		checkVal = $(this).attr('id');
		var currentClasses = $(this).attr('class');
		if(currentClasses.indexOf('searchTypeSelected') > -1){
			$(this).removeClass('searchTypeSelected');
			checkVal = "None";
		} else {
			$('.searchType').removeClass('searchTypeSelected');
			$(this).addClass('searchTypeSelected')
		}
		
		if(checkVal == "New"){
			$("select[name='ConditionId']").val('2');
			$("select[name='BodyTypeId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "Used"){
			$("select[name='ConditionId']").val('1');
			$("select[name='BodyTypeId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "Vans"){
			$("select[name='BodyTypeId']").val('1');
			$("select[name='ConditionId']").val('-1');
			showCustomer(true);
		}
		if(checkVal == "None"){
			$("select[name='BodyTypeId']").val('-1');
			$("select[name='ConditionId']").val('-1');
			showCustomer(true);
		}
	});
	
	$('#frmSearch select[name=Branch]').change(function(){
		if($(this).val() == "All"){
			showCustomer(true,164,-1);
			$('#frmSearch input[name=DealerGroupId]').val('164');
			$('#frmSearch input[name=DealerId]').val('-1');
		}
		
		if($(this).val() == "Chislehurst"){
			showCustomer(true,-1,166);
			$('#frmSearch input[name=DealerGroupId]').val('-1');
			$('#frmSearch input[name=DealerId]').val('166');
		}
		
		if($(this).val() == "Edenbridge"){
			showCustomer(true,-1,167);
			$('#frmSearch input[name=DealerGroupId]').val('-1');
			$('#frmSearch input[name=DealerId]').val('167');
		}
		
		if($(this).val() == "Sevenoaks"){
			showCustomer(true,-1,165);
			$('#frmSearch input[name=DealerGroupId]').val('-1');
			$('#frmSearch input[name=DealerId]').val('165');
		}
	});
	
	showCustomer(true,164,-1);

});
