
cookie_key = 'CakeCookie[fid_list]';

var no_dialog = false;
function show_addfid_dialog() {
 if (!no_dialog) {
	var now = new Date();
	$('#dialog90').jqm({ajax: '/ax/addfcdialog/' + parseInt(now.getTime())});
 //$('#dialog90').jqmShow({ajaxtext: '<div style="margin-top:10px; margin-left: 10px; border:1px solid #ddd5a4;padding:5px 0 5px 0;background-color:#fff6cb; width:474px; text-align:center;"><span style="color:#ff3200; font-size:14px; font-weight:bold;">資料請求リスト追加中・・・</span></div>'});
 $('#dialog90').jqmShow();
 $('#dialog90').html('<div style="margin-top:10px; margin-left: 8px; border:1px solid #ddd5a4;padding:5px 0 5px 0;background-color:#fff6cb; width:474px; text-align:center;"><span style="color:#ff3200; font-size:14px; font-weight:bold;">資料請求リスト追加中・・・</span></div>');
 pageTracker._trackEvent('cart', 'add', 'showdialog');
 }
 else {
 pageTracker._trackEvent('cart', 'add', 'direct');
 }
}


function add_fid(fid,idmark){
	var idname = '';
	if(idmark){
		var name1 = $("#corporate_" + idmark + '_' + fid).html();
		var name2 = $("#bcondition_" + idmark + '_' + fid).html();
	}else{
		var name1 = $("#corporate_" + fid).html();
		var name2 = $("#bcondition_" + fid).html();
	}
	add_fidlist(fid, name1, name2);
}

function add_fids(fidlist,idmark){
	var element = fidlist.split(':');
	for(var i = 0; i < element.length; i++){
		if(idmark == "lp") {
			add_fidlist_lp(element[i], idmark);
		}else{
			add_fid(element[i], idmark);
		}
	}
	
	if (idmark == 'ranking') {
			show_addfid_dialog();
	}
}

function add_fidlist(fid, name1, name2){
	var list_val = $.cookie(cookie_key);
	if(fid){
		if(!is_exist(fid)){
			if(list_val){
				$.cookie(cookie_key, list_val + ':' + fid, {path: '/', expires: 180});
			}else{
				$.cookie(cookie_key, fid, {path: '/', expires: 180});
			}
			redrew_demand_list(fid, name1, name2);
			if (fid != 416) { // kanjyuku
 				//show_addfid_dialog();
 			}
		}
	}
}

function add_fidlist_lp(fid, idmark) {
	var list_val = $.cookie(cookie_key);
	if(fid){
		if(!is_exist(fid)){
			if(list_val){
				$.cookie(cookie_key, list_val + ':' + fid, {path: '/', expires: 180});
			}else{
				$.cookie(cookie_key, fid, {path: '/', expires: 180});
			}
		}
	}
}


function delete_all_fidlist(){
	$.cookie(cookie_key, '', {path: '/', expires: -1 });
}


function get_count_list(){
	var count = 0;
	var list_val = $.cookie(cookie_key);
	if(list_val){
		var element = list_val.split(':');
		if(element){
			count = element.length;
		}
	}
	return count;
}


function is_exist(fid){
	var bret = false;
	var list_val = $.cookie(cookie_key);
	if(list_val){
		if(fid){
			var element = list_val.split(':');
			for (var i = 0; i < element.length; i++) {
				if(fid == element[i]){
					bret = true;
					break;
				}
			}
		}
	}

	return bret;
}

function redrew_demand_list(id, name1, name2){
	redrew_demand_list_side(id, name1, name2);
	redrew_demand_list_main(id, name1, name2);
}

function redrew_demand_list_side(id, name1, name2){
 /*** bf
	var html = '<li><a href="/fc/' +  id + '.html" class="common03-l">' + name1 + '</a><span>(' + name2 + ')</span></li>';
	$("#add_ddlist_side").append(html);

	var count = '（<em>' +  get_count_list() + '</em>件）';
	$("#count_side").html(count);

	$("#ddlist_side_message").html("");
***/

	var html = $("#add_ddlist_side").html() + '<li><a href="/fc/' +  id + '.html" class="common03-l">' + name1 + '</a><span>(' + name2 + ')</span></li>';
	
	//$("#add_ddlist_side").append(html);
	$("#add_ddlist_side").html(html);
	$("#listitems").css("display", "");
	$("#nonmsg").remove();
	

	var count = '（<em>' +  get_count_list() + '</em>件）';
	$("#count_side").html(count);

	$("#ddlist_side_message").html("");


	var link1 = '<a href="https://www.fc-guide.com/form/demand1.php" class="btn"><img name="ss_on" src="/img/common/nv/nv_list-btn.jpg" alt="一括資料請求" /></a>';
	var link2 = '<a href="https://www.fc-guide.com/form/demand1.php" class="btn"><img name="ss_on" src="/img/common/nv_sub/btn.jpg" alt="一括資料請求" /></a>';
	$("#ddlist_side_image1").html(link1);
	$("#ddlist_side_image2").html(link2);
}

function redrew_demand_list_main(id, name1, name2){
	var html = '<li class="common03-l"><nobr><a href="/fc/' +  id + '.html">' + name1 + '</a><span>(' + name2 + ')</span></nobr></li>';
	$("#add_ddlist_main").append(html);

	var count = '（<em>' +  get_count_list() + '</em>件）';
	$("#count_main").html(count);

	$("#ddlist_main_message").html("");

	var link = '<a href="https://www.fc-guide.com/form/demand1.php" class="btn"><img name="ss_on" src="/img/list/reqest_list-btn.jpg" alt="一括資料請求" /></a>';
	$("#ddlist_main_image").html(link);
}

function get_demand_list(){
	var list_val = $.cookie(cookie_key);
	return (list_val != null)?list_val.split(':'):null;
}

/***********************************************
 *
 * old func converter
 * 2009.09.13
 *
 ***********************************************/
function fncAdd(fid, spname) {
	add_fid(fid, 'detail');
    redrew_special_view(fid); 
    //document.location.href = '/form/demand1.php';
	GB_FORM();
    //document.location.href = 'https://www.fc-guide.com/form/demand1.php';
}

function redrew_special_view(fid){
	if(fid && !isNaN(fid)){
		var html = '<img src="/img/detail/added_list.jpg" alt="資料請求済み" />';
		if(document.getElementById('buttondetail1_' + fid) != null){
			for(var i = 1; i <= 5; i++){
				var idname = 'buttondetail' + i + '_' +  fid;
				$("#"+ idname).html(html);
			}
		}
		redrew_special_window();
		redrew_special_count();
	}
}

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

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



