$(function() {

	var oldClass = $("input.autocomplete").attr("class"),
		newClass, c, t, location, name,
		warning = $("<p id='warning'>Vul een postcode, plaats en/of naam in.</p>");

	$("div.location-widget div:eq(1)").prepend(warning.hide());

	$("div.location-widget select").change(function() {

		warning.hide();

		newClass = "textfield ";
		c = $.classToObject(oldClass);
		t = $.queryToObject(c.url);
		t["careproviderId"] = $(this).val();
		c.url = $.objectToQuery(t);
		newClass += $.objectToClass(c);

		$("input.autocomplete").attr("class", newClass);

		location = $("input.textfield")[0].value.length;
		name = $("input.textfield")[1].value.length;

		if (location <= 0) {
			if (name < 4) {
				$.getJSON("/zorgverleners/services/totalresult.svc/getcareprovidertotalcount?careproviderid=" + ($(this).val() || 0), function(data) {
					if (parseInt(data.d) > 999) {
						warning.fadeIn("slow");
					}
				});
			}
		}
	});

});