$(document).ready(function() {
	var href = location.href;
	var pos = href.lastIndexOf("/");
	href = href.substring(pos+1,href.length)
	href = href.replace(".html","");
	
	var posown = location.href.lastIndexOf("/owner/");
	
	if (posown > 0) {
	 // 関連表
  var mtx = {12 : 164, 8: 162, 6 : 164, 10 : 340, 4 : 140, 11 : 402};
  href = mtx[href];
	}
	if(is_exist(href)){
		redrew_detail_view(href);
	}
	else {
 	var href = location.href;
 	if (href.match(/company\.html/)) {
   var mm = href.split("/");
   try {
    if (is_exist(mm[4])) {
     redrew_detail_view(mm[4]);
    }
   } catch (e) {}
 	}
	}
});


function add_fc_from_detail(fid,idmark){
	if(fid){
		add_fid(fid,idmark);
		redrew_detail_view(fid);
		GB_FORM();
	}
}

function add_fc_from_detail_big(fid,idmark){
 no_dialog = true;
	if(fid){
		add_fid(fid,idmark);
		// window.location.href = "https://www.fc-guide.com/form/demand1.php";
		redrew_detail_view(fid);
		GB_FORM();
	}
}

function redrew_detail_view(fid){
	if(fid && !isNaN(fid)){
		var html = '<img src="/img/detail/added_list.jpg" alt="資料請求リストに追加済み" />';
		var html_big = '<a href="#" onclick="GB_FORM()"><img src="/img/detail/big_btn_on.jpg" alt="資料請求リストに追加済み。資料送付先の入力" /></a>';
		if(document.getElementById('buttondetail1_' + fid) != null){
			for(var i = 1; i <= 5; i++){
			 try {
 				var idname = 'buttondetail' + i + '_' +  fid;
 				$("#"+ idname).html(html);
 			} catch (e) {}
 			try {
 				var idname = 'buttondetail_big_' + i + '_' +  fid;
 				$("#"+ idname).html(html_big);
 			} catch (e) {}
			}
		}
		redrew_detail_window();
		redrew_detail_count();
	}
}

function redrew_detail_window(){
	var html = '<img src="/img/detail/added_list.jpg" alt="資料請求済み" />';
	$("#detail_model").html(html);
	$("#detail_money").html(html);
}

function redrew_detail_count(){
	$(".detail_dd_count").html(get_count_list());
}

function add_fc_from_recommend(fid, detail_fid,idmark){
	if(fid){
		add_fid(fid,idmark);
		if(fid == detail_fid){
			redrew_detail_view(fid);
		}
	}
}

function add_fc_from_recommend_all(fc_list_str, detail_fid,idmark){
	if(fc_list_str){
		add_fids(fc_list_str,idmark);
		var element = fc_list_str.split(':');
		for(var i = 0; i < element.length; i++){
			if(detail_fid){
				if(element[i] == detail_fid){
					redrew_detail_view(detail_fid);
					break;
				}
			}else{
				redrew_detail_view(element[i]);
			}
		}
	}
}


function add_detail_smt(fid, type) {
	add_fid(fid, 'detail');
	
	if(type == 'detail') {
		document.getElementById('next').innerHTML = '<a href="/smt/cart"><img src="/img/smt/btn-screen.jpg" alt=""></a>';
	}else if(type == 'search'){
		document.getElementById('fc_' + fid).innerHTML = '<a href="/smt/cart"><img src="/img/smt/btn-screen.jpg" alt=""></a>';
	}
}


