(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
$(function(){
   $(window).hashchange(function(){$('input,textarea').not('input[type="radio"],input[type="checkbox"],:hidden, :button, :submit,:reset').val('');
$('input[type="radio"], input[type="checkbox"], select').removeAttr('checked').removeAttr('selected');

    });
    $(window).hashchange();//Windowロード時に実行
});

jQuery(function($) {
	
	$("#120,#200").click(function() {
	$("#d1,#h1").attr("disabled", false);
	$("#d4,#d5,#g").attr("disabled", true);
	$("#d1,#h1").fadeIn("slow");
	$("#d4,#d5,#g").fadeOut("slow");
	});
	
	$("#120,#150").click(function() {
	$("#a").attr("disabled", true);
	$("#a").fadeOut("slow");
	});
	
	$("#200").click(function() {
	$("#a").attr("disabled", false);
	$("#a").fadeIn("slow");
	});
	
	$("#150").click(function() {
	$("#h1,#d4,#d5,#g").attr("disabled", true);
	$("#d1").attr("disabled", false);
	$("#h1,#d4,#d5,#g").fadeOut("slow");
	$("#d1").fadeIn("slow");
	});	
	
	$("#300,#500").click(function() {
	$("#d4,#d5,#a,#g").attr("disabled", false);
	$("#d1,#h1").attr("disabled", true);
	$("#d4,#d5,#a,#g").fadeIn("slow");
	$("#d1,#h1").fadeOut("slow");
	});

});


function search_db(){
		  
  	var model = $("input[name=model]:checked").val();
  	var height = $("input[name=height]:checked").val();
	var width = $("input[name=width]:checked").val();
	var depth = $("input[name=depth]:checked").val();
	var step = $("select[name=step]").val();
	var type = $("input[name=type]:checked").val();
	switch(type){
		case "0" : type_a="s";break;
		case "1" : type_a="a";break;
	}
	var color = $("input[name=color]:checked").val();
	var color_a
	switch(color){
		case "0" : color_a="s";break;
		case "1" : color_a="g";break;
	}
	var size_c = $("input[name=height]:checked").attr("id")+$("input[name=width]:checked").attr("id")+"_";
	var size_d = $("input[name=height]:checked").attr("id")+$("input[name=depth]:checked").attr("id")+"_";
	var sel_size ="高さ"+height+"×横幅"+width+"×奥行"+depth;
	var price_cm;
	
	if(height==null || width==null || depth==null || step==null|| model==null|| type==null|| color==null){
		alert("項目を全て入力して下さい");
	}else{

	$("#est_result_w").fadeOut(50);
		
		$("#sel_step").html(step+"段");
		
		switch(type){
			case "0":$("#sel_type").html("単体");type_a="s";break
			case "1":$("#sel_type").html("増連");type_a="a";break
		}
		
		switch(color){
			case "0":$("#sel_col").html("グレー");break
			case "1":$("#sel_col").html("グリーン");break
		}
	var img_link;
	  	switch(model){
	  	case "120":
		img_link = model + "h" + height + "w" + width + "d450.jpg";
		$("#tentou a").attr("href","http://www.taiyou-outlet.com/user_data/tentou_op120.php");
		$("#caster a").attr("href","http://www.taiyou-outlet.com/user_data/caster120.php");
		$("#adjust a").attr("href","http://www.taiyou-outlet.com/user_data/adjust120.php");
		$("#rakka a").attr("href","http://www.taiyou-outlet.com/user_data/uc.php");break;
		break;
	  	case "150":img_link = model + "h" + height + "w" + width + "d450.jpg";
		$("#tentou a").attr("href","http://www.taiyou-outlet.com/user_data/uc.php");
		$("#caster a").attr("href","http://www.taiyou-outlet.com/user_data/uc.php");
		$("#adjust a").attr("href","http://www.taiyou-outlet.com/user_data/uc.php");
		$("#rakka a").attr("href","http://www.taiyou-outlet.com/user_data/uc.php");break;
	  	case "200":img_link = model + "h" + height + "w" + width + "d450"+ type_a +".jpg";
		$("#tentou a").attr("href","http://www.taiyou-outlet.com/user_data/tentou_op200.php");
		$("#caster a").attr("href","http://www.taiyou-outlet.com/user_data/caster200.php");
		$("#adjust a").attr("href","http://www.taiyou-outlet.com/user_data/adjust200.php");
		$("#rakka a").attr("href","http://www.taiyou-outlet.com/user_data/rakkaboushi.php");break;
	  	case "300":
	  	case "500":img_link = "300h" + height + "w" + width + "d600"+ type_a + color_a +".jpg";
		$("#tentou a").attr("href","http://www.taiyou-outlet.com/user_data/tentou_op300.php");
		$("#caster a").attr("href","http://www.taiyou-outlet.com/user_data/caster300.php");
		$("#adjust a").attr("href","http://www.taiyou-outlet.com/user_data/adjust200.php");
		$("#rakka a").attr("href","http://www.taiyou-outlet.com/user_data/rakkaboushi.php");break;
	  	}
		
	
	$("#sel_si").html(sel_size);	
	$.getJSON(
		"../js/ajax.php",
		{                                                       
	        "model": model,            
	        "height": height,            
	        "width": width,         
	        "depth": depth,
	        "step": step,
			"type": type,
			"color": color
    	},
		function(data,status){
			
				var img_link2="<a href='../products/detail.php?product_id=" + data[0].product_id + "'><img width='150' height='150' src='../upload/save_image/"+img_link+"'</a>";
				$("#res_img").html(img_link2);
				$("#mod_img").attr("src","../user_data/packages/default/img/estimate/"+model+".png");
				$("#product_link").attr("href","../products/detail.php?product_id="+data[0].product_id);
				$("#size_link").attr("href","http://www.taiyou-outlet.com/user_data/packages/default/img/sizepic/"+model+size_c+type_a+"_"+step+".gif");
				$("#size_link_d").attr("href","http://www.taiyou-outlet.com/user_data/packages/default/img/sizepic/"+model+size_d+step+".gif");
				$("#price_f").html(addFigure(data[0].price02)+"円");
				$("#product_id").attr("value",data[0].product_id);
				$("#product_class_id").attr("value",data[0].product_class_id);
			  	$("#classcategory_id1").attr("value",step);
			  	$("#classcategory_id2").attr("value",color);
				$("#form_est").attr("action","../products/detail.php?product_id="+data[0].product_class_id);
				$("#est_result_w").fadeIn("slow");
			
                });
	}
}



function cart_in(){
	
	var qua_now=$("#quantity").val();
	
	if(qua_now==null){
		alert("購入数を入力して下さい");
	}else{
	$("#form_est").submit();
	tb_remove();
	}
}

function cart_in2(){
	alert(1);
		$("#cart_area").load("../frontparts/bloc/cart.php");

}

function addFigure(str) {

　var num = new String(str).replace(/,/g, "");

　while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));

　return num;

}
