function swapDealerResults(sValue) {
	hideAllRegions();
	
	if(sValue != "")
	{
	if (sValue == "QLDNT")
	{
		$("#regionQLDNT").show();
	}
	else
	   if (sValue == "WASA")
	   	{
	   		$("#regionWASA").show();
		}
		else
		  if (sValue == "NSWACT")
		 {
			$("#regionNSWACT").show();
		 }
		 else
		   if (sValue == "VICTAS")
		   {
		 	$("#regionVICTAS").show();
		   }
	}
	
	$("#dealerFlash a").removeClass("selected");
	$("#dealerFlash #map" + sValue + " a").addClass("selected");
}

function hideAllRegions()
{
	$("#regionQLDNT").hide();
	$("#regionWASA").hide();
	$("#regionNSWACT").hide();
	$("#regionVICTAS").hide();
	
}

function toggleUsRegions(bShow)
{
	if (bShow)
	{
		$("#overlayResults").show();
		$("#regionResults").hide();	
	}
	else
	{
		$("#overlayResults").hide();		
		$("#regionResults").show();
	}
}

function clearUSInputs()
{
	// set state and zip code to default
	$("input[@name='zip']").val("Enter ZIP code");
	$("select[@name='state']").val("");
}

$(document).ready(function() {
	hideAllRegions();
	// when dropdown changes, show new region and scroll to it
    $("select[@name='region']").change(function(e) {
		e.preventDefault();
				
		var sValue = $(this).val();
		swapDealerResults(sValue);
		clearUSInputs();		
    });
		
	// link click-- do swap and change select value
	$("#dealerFlash a").click(function(e) {
		e.preventDefault();
		var sId = this.href.match(/#(\w+)/)[1];
		swapDealerResults(sId);
		$("option[@value='" + sId + "']").get(0).selected = true;
		clearUSInputs();
	});
	
/*	if (window.parent && window.parent.sDealerLocatorMode != "US")
	{
		if($("select[@name='state']").val() == "" && $("input[@name='zip']").val().length >= 14)
		{
			toggleUsRegions(false);
		}
		else
		{
		toggleUsRegions(true);
		}
	}
	else
	{
		toggleUsRegions(true);
	}
	*/
	// when dropdown changes, clear zip and region
	$("select[@name='state']").change(function(e) {
		e.preventDefault();
		// set region and zip code to default
		sDealerLocatorMode = 'US';
		$("input[@name='zip']").val("Enter ZIP code");
		$("select[@name='region']").val("");
    });
	
		// when dropdown changes, clear state and region
	$("input[@name='zip']").click(function(e) {
		e.preventDefault();
		// set region and zip code to default
		sDealerLocatorMode = 'US';
		$("input[@name='zip']").val("");
		$("select[@name='state']").val("");
		$("select[@name='region']").val("");
    });
});





