
var dfMakerOptionTag    = '<option value="" class="menu_option">メーカー選択</option>';
var dfModelOptionTag    = '<option value="" class="menu_option">車種選択</option>';
var dfCategoryOptionTag = '<option value="" class="menu_option">カテゴリー選択</option>';

function send(){
	
  if(document.form1.keyword.value !="")
  {document.form1.action="list.php";}else{document.form1.action="model.php";}
  if(document.form1.maker_id.value=="" && document.form1.keyword.value==""){return false;}
  
}


$(function(){
	
	$("#select_menu__maker_select").change( function () {
		
		objMaker = $(this).children("option:selected");
		
		$.ajax({
			   type: "GET",
			   url: "res_pulldown_menu.php",
			   data: "mkid="+objMaker.attr("value"),
			   success: function(html){
					html = dfModelOptionTag+html;
					$("#select_menu__model_select").html(html);
			   }
		});
		
		$("#select_menu__category_select").html(dfCategoryOptionTag);
		
	});
	
	$("#select_menu__model_select").change( function () {
		
		objMaker = $("#select_menu__maker_select").children("option:selected");
		objModel = $("#select_menu__model_select").children("option:selected");
		
		$.ajax({
			   type: "GET",
			   url: "res_pulldown_menu.php",
			   data: "mkid="+objMaker.attr("value")+"&"+"moid="+objModel.attr("value"),
			   success: function(html){
					html = dfCategoryOptionTag+html;
					$("#select_menu__category_select").html(html);
			   }
		});
		
	});
	
	$("#select_menu__category_select").change( function () {

		objMaker = $("#select_menu__maker_select").children("option:selected");
		objModel = $("#select_menu__model_select").children("option:selected");
		objCategory = $("#select_menu__category_select").children("option:selected");
		
	});
	
	$("#form_menu_submit").click( function () {
		
		objMaker = $("#select_menu__maker_select").children("option:selected");
		objModel = $("#select_menu__model_select").children("option:selected");
		objCategory = $("#select_menu__category_select").children("option:selected");
		
		makerId = objMaker.attr("value");
		modelId = objModel.attr("value");
		categeoryId = objCategory.attr("value");
		
		if(makerId && modelId && categeoryId){
			//list.php?model_id=430&cat_id=1&view=titlepic
			//url = "list.php?model_id="+modelId+"&cat_id="+categeoryId;
			url = "list.php";
		} else if(makerId && modelId){
			//category.php?model_id=430
			//url = "category.php?model_id="+modelId;
			url = "category.php";
		} else if(makerId){
			//url = "model.php?maker_id="+makerId;
			url = "model.php";
		} else {
			url = "";
		}
		
		if(url){
			$("#form_menu_model").attr({action:url});
			$("#form_menu_model").submit();
		}
		
	});

	$("#select_menu__maker_select").change( function () {
		
		objMaker = $(this).children("option:selected");
		
		$.ajax({
			   type: "GET",
			   url: "res_pulldown_menu.php",
			   data: "mkid="+objMaker.attr("value"),
			   success: function(html){
					html = dfModelOptionTag+html;
					$("#select_menu__model_select").html(html);
			   }
		});
		
		$("#select_menu__category_select").html(dfCategoryOptionTag);
		
	});
	
	$("#direct_menu_bt").click( function () {
		
		if($("#direct_menu_value").attr("value") > 0){
			
			$("#form_direct_menu").submit();
			
		}
		
	});
	
	/*
	$("#img_thumb_0").click( function () {
		
		img = $("#img_thumb_0").attr("src");
		title = $("#img_thumb_0").attr("alt");
		
		$.prettyPhoto.open(img,title,'');
		
	});
	*/
	
	
});



