// JavaScript Document: QuoteRequest page scripts.

$(document).ready(function() {

	// Apply initialization scripts before manipulating tabs.
	//
	// transform the multiselect control into a multiselect dropdown.
  /*$("#RecyclingTypes").multiSelect({
		noneSelected: 'Vad* (Vad vill du ha hjälp med?)',
		oneOrMoreSelected: '*'
	});*/

	// bind to the textarea control
	$('#Description').click(function() {
		// clear text.
		$(this).val('');
		$(this).removeClass('grey-text');
		// unbind the click event.
		$(this).unbind('click');
	});

	// AJAX for County dropdown.
	$('#County').change(function() {
		var countyId = $(this).val();
		if(countyId=='') {
			$('#Municipality').val(''); // set the appropriate Municipality value in the drop-down.
			return; // Ignore the first option: "---- Select County ---" has value=""
		}

		$.ajax({
			url: '/modules/ajax/getmunicipalitysincounty/',
			data: {county_id: countyId},
			dataType: 'json',
			success: function(data) {
				// populate #Municipality drop-down.
				var options = '<option value="">--- Kommun ---</option>';

	      for(var key in data) {
	      	var value = data[key];
	      	options += '<option value="' + key + '">' + value + '</option>';
	      }

	      $('#Municipality').html(options);
			},
			error: function(xhr, textStatus, errorThrown) {
				alert('Ajax Failed!');
			}
		});
	});

	// bind events and hide tabs.
	//

	$("#tab1-next").click(function() {
		// validate of tab1 form controls
		if(validate_QRF_tab1()) {
			$('#tab1').css('display', 'none');
			$('#tab2').css('display', 'block');
		}
	}); //#tab1-next

	$('#tab2-back').click(function() {
		$('#tab2').css('display', 'none');
		$('#tab1').css('display', 'block');
	}); //#tab2-back

	// validations on form submit.
	$("#Submit").click(function() {
		return validate_QuoteRequestForm();
	});

	// hide all tabs.
	$('#tab2').css('display', 'none');
	$('#tab1').css('display', 'block');

	//TODO: make the banner visible
});

