
$(document).ready( function() {


/* Check if user has pressed back button on browser, to make sure the correct AJAX call is made */
var currentUrl = document.location.href;
var currentUrlElements = currentUrl.split('#');


if( currentUrlElements.length > 1 )
{
	if ( currentUrlElements[1].length > 3)
	{
		var sPostal = currentUrlElements[1];
		getDealers(sPostal);
	}
}

$('#locator').click(

	function()
	{
		var sPostal = $('#postal').attr('value');
		getDealers(sPostal);
	}

);

checkWebshopButton();
getOfferteForm();

} );


function getDealers(sPostal)
{
	if(sPostal)
	{
		sPostal = sPostal.replace(' ','');
	}
	else
	{
		sPostal = false;
	}





	if(sPostal.length != 6)
	{
		alert('Dit is geen juiste postcode!');
		$('#postal').focus();
	}
	else
	{
		$('#postal').attr({value: sPostal});
		$('#locator').attr({value: 'Een moment geduld', disabled: true});
		$('#dealers').load('/locator.php?postal='+sPostal,function() { $('#locator').attr({value: 'Zoek uw specialist', disabled: false}); } );
	}

}
