$(document).ready(function() {
	 	loadMfg();
		$("select#Mfg").change(loadModel).throbber("change", {parent: "#throbber", image: "img/ajax-loader.gif"});
		function loadMfg() {
			document.tsel.Mfg.disabled = true;
			$.getJSON('/cfmx/web/aviattiresel/components/tiresel.cfc',
				{method: "getMfg",
				 returnformat: "json"},  function(data) {
					$("select#Mfg").removeOption(/./);
					$.each(data.DATA, function(i,item){
						$("select#Mfg").addOption(item[0], item[0]); //loop over the JSON dataset
					});
					//select first option in the list
					$("select#Mfg option:first").attr("selected","selected");
					loadModel();
					document.tsel.Mfg.disabled = false;
				 });
		}
		function loadModel() {
			document.tsel.Model.disabled = true;
			var manufg = $("select#Mfg").val();
		    $.getJSON('/cfmx/web/aviattiresel/components/tiresel.cfc',
			{method: "getModel",
			 mfg: manufg,
			 returnformat: "json"},  function(data) {
				$("select#Model").removeOption(/./); 
				$.each(data.DATA, function(i,item){
					$("select#Model").addOption(item[0], item[0]);
				});
				//select first option in the list
				$("select#Model option:first").attr("selected","selected");
			 });
			 if (document.tsel.Mfg.selectedIndex > 0)
			 {
			 	document.tsel.Model.disabled = false;
			 }
		}
	});
	function validate()
	{
		if ( document.tsel.Mfg.selectedIndex == 0 )
		{
			alert ( "Please select a manufacturer." );
			return false;
		}
		
		else if ( document.tsel.Model.selectedIndex == 0 )
		{
			alert ( "Please select a model." );
			return false;
		}
		
		else {return true;}

	}