// JavaScript Document


/****************************************************
 ** クッキー関連
 ****************************************************/

/* 保存されているクッキーから、指定したクッキー名の値を取得
 * getCookie(クッキー名);
 */
function getCookie(c_name) {
	var st = "";
	var ed = "";
	if(document.cookie.length > 0) {
		st = document.cookie.indexOf(c_name + "=");
		if(st != -1) {
			st = st + c_name.length + 1;
			ed = document.cookie.indexOf(";", st);
			if(ed == -1) {
				ed = document.cookie.length;
			}
			return unescape(document.cookie.substring(st, ed));
		}
	}
	return "";
}

/* クッキー確認 トップページ用
 * checkCookie_top();
 */
function checkCookie_top() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id != "") { /* 会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("index_item_an");
		Element.remove("index_item_ch");
		Element.remove("index_item_ot2");
		Element.remove("top_ng_cart");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");
		Element.remove("ng_menu02");
		Element.remove("ng_menu03");
		Element.remove("ng_menu04");
		Element.remove("ng_menu05");
		Element.remove("index_item_re");
		Element.remove("index_item_ot");
		Element.remove("index_item_bo");
		Element.remove("top_ok_cart");
	}
}

/* クッキー確認 ノーマルページ用
 * checkCookie_normal();
 */
function checkCookie_normal() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id != "") { /* 会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("top_ng_cart");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");
		Element.remove("ng_menu02");
		Element.remove("ng_menu03");
		Element.remove("ng_menu04");
		Element.remove("ng_menu05");
		Element.remove("top_ok_cart");
	}
}

/* クッキー確認 おすすめレシピ用
 * checkCookie_normal();
 */
function checkCookie_recipe() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		while(document.getElementById("ng01") != null){
			Element.remove("ng01");
		}
		while(document.getElementById("ok2_01") != null){
			Element.remove("ok2_01");
		}
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		while(document.getElementById("ng01") != null){
			Element.remove("ng01");
		}
		while(document.getElementById("ok1_01") != null){
			Element.remove("ok1_01");
		}
	} else { /* 一般のとき */
		Element.remove("ng_menu01");
		Element.remove("ng_menu02");
		Element.remove("ng_menu03");
		Element.remove("ng_menu04");
		Element.remove("ng_menu05");
		while(document.getElementById("ok1_01") != null){
			Element.remove("ok1_01");
		}
		while(document.getElementById("ok2_01") != null){
			Element.remove("ok2_01");
		}
	}
}

/* クッキー確認 商品一覧ページ用（ゼロ活力シリーズ）
 * checkCookie_products_zk();
 */
function checkCookie_products_zk() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（オールパンシリーズ）
 * checkCookie_products_all();
 */
function checkCookie_products_all() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（真空容器シリーズ）
 * checkCookie_products_vacuum();
 */
function checkCookie_products_vacuum() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（電子レンジ調理器シリーズ）
 * checkCookie_products_stove();
 */
function checkCookie_products_stove() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng01");	Element.remove("ng02");
		Element.remove("ok2_01");	Element.remove("ok2_02");
		Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng01");	Element.remove("ng02");
		Element.remove("ok1_01");	Element.remove("ok1_02");
		Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok1_01");	Element.remove("ok1_02");
		Element.remove("ok2_01");	Element.remove("ok2_02");
		Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（その他の商品シリーズ）
 * checkCookie_products_other();
 */
function checkCookie_products_other() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（料理集）
 * checkCookie_products_book();
 */
function checkCookie_products_book() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（シリコンツールシリーズ）
 * checkCookie_products_silicon();
 */
function checkCookie_products_silicon() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品一覧ページ用（活力なべシリーズ）
 * checkCookie_products_sw();
 */
function checkCookie_products_sw() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ok2_01");	Element.remove("ok2_02");	Element.remove("ok2_03");	Element.remove("ok2_04");	Element.remove("ok2_05");
		Element.remove("ok2_06");	Element.remove("ok2_07");	Element.remove("ok2_08");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ok1_01");	Element.remove("ok1_02");	Element.remove("ok1_03");	Element.remove("ok1_04");	Element.remove("ok1_05");
		Element.remove("ok1_06");	Element.remove("ok1_07");	Element.remove("ok1_08");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok1_01");	Element.remove("ok1_02");	Element.remove("ok1_03");	Element.remove("ok1_04");	Element.remove("ok1_05");
		Element.remove("ok1_06");	Element.remove("ok1_07");	Element.remove("ok1_08");
		Element.remove("ok2_01");	Element.remove("ok2_02");	Element.remove("ok2_03");	Element.remove("ok2_04");	Element.remove("ok2_05");
		Element.remove("ok2_06");	Element.remove("ok2_07");	Element.remove("ok2_08");
	}
}

/* クッキー確認 商品一覧ページ用（天使のアイテム）
 * checkCookie_products_angel();
 */
function checkCookie_products_angel() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok002");	Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */	Element.remove("ng001");	Element.remove("ok001");	Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok001");	Element.remove("ok002");	Element.remove("ok9_01");
	}
}

/* クッキー確認 商品紹介ページ用（両方閲覧可能）
 * checkCookie_products_detail();
 */
function checkCookie_products_detail() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng01");
		Element.remove("ok2_01");
		Element.remove("ng02");
		Element.remove("ok2_02");
		Element.remove("ng03");
		Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng01");
		Element.remove("ok1_01");
		Element.remove("ng02");
		Element.remove("ok1_02");
		Element.remove("ng03");
		Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok1_01");
		Element.remove("ok1_02");
		Element.remove("ok2_01");
		Element.remove("ok2_02");
		Element.remove("ok3_01");
		Element.remove("ok9_01");
	}
}

/* クッキー確認 商品紹介ページ用（両方閲覧可能料理集）
 * checkCookie_products_detail_b();
 */
function checkCookie_products_detail_book() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng01");
		Element.remove("ok2_01");
		Element.remove("ng03");
		Element.remove("ng9_01");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng01");
		Element.remove("ok1_01");
		Element.remove("ng03");
		Element.remove("ng9_01");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok1_01");
		Element.remove("ok2_01");
		Element.remove("ok3_01");
		Element.remove("ok9_01");
	}
}

/* クッキー確認 商品紹介ページ用（会員のみ閲覧可能）
 * checkCookie_products_detail_m();
 */
function checkCookie_products_detail_m() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id == 1) { /* 購入済会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng9_01");
		Element.remove("ok2_01");
		Element.remove("ok2_02");
	} else if(asahikei_id == 2) { /* 未購入会員のとき */
/*		Element.remove("ng"); 会員ページを一旦外しているため。 */
		Element.remove("ng9_01");
		Element.remove("ok1_01");
		Element.remove("ok1_02");
	} else { /* 一般のとき */
		Element.remove("ng_menu01");	Element.remove("ng_menu02");	Element.remove("ng_menu03");	Element.remove("ng_menu04");	Element.remove("ng_menu05");
		Element.remove("ng_submenu01");	Element.remove("ng_submenu02");	Element.remove("ng_submenu03");	Element.remove("ng_submenu04");	Element.remove("ng_submenu05");
		Element.remove("ok1_01");
		Element.remove("ok1_02");
		Element.remove("ok2_01");
		Element.remove("ok2_02");
		Element.remove("ok3_01");
		Element.remove("ok9_01");
	}
}

/* クッキー確認 フッター用
 * checkCookie_footer();
 */
function checkCookie_footer() {
	var asahikei_id = getCookie("asahikei_id");
	if(asahikei_id != "") { /* 会員のとき */
		Element.remove("fo_ng_cart");
	} else { /* 一般のとき */
		Element.remove("fo_ok_cart");
	}
}


/****************************************************
 ** フォントチェンジャー関連
 ****************************************************/

/* フォントサイズ変更用 */
FontChanger = Class.create();
FontChanger.prototype = {
	id: null,
	cookieManager: null,
	cookieName: 'body.style.fontSize',
	initialize: function(id) {
		this.id = id || 'fontChanger';
		this.cookieManager = new CookieManager();
		var fontSize = this.cookieManager.getCookie(this.cookieName);
		if(fontSize) document.body.style.fontSize = fontSize;
	},
	setCookieShelfLife: function(days) {
		this.cookieManager.cookieShelfLife = days;
	},
	change: function(fontSize) {
		document.body.style.fontSize = fontSize;
		this.cookieManager.setCookie(this.cookieName, fontSize);
	},
	reset: function() {
		document.body.style.fontSize = '';
		this.cookieManager.clearCookie(this.cookieName);
	},
	show: function() {
		var id = this.id;
		document.writeln([
			'<dl id="' + id + '">',
			'<dt>文字サイズ</dt>',
			'<dd style="cursor: pointer; font-size: 120%;" id="' + id + '-large">大</dd>',
			'<dd style="cursor: pointer; font-size: 100%;" id="' + id + '-medium">中</dd>',
			'<dd style="cursor: pointer; font-size: 80%;" id="' + id + '-small">小</dd>',
			'</dl>'
		].join("\n"));
		Event.observe($(id + '-small' ), 'click', this.onClickSmall.bind(this));
		Event.observe($(id + '-medium' ), 'click', this.onClickMedium.bind(this));
		Event.observe($(id + '-large' ), 'click', this.onClickLarge.bind(this));
	},
	onClickSmall: function(e) { this.change('80%' ); },
	onClickMedium: function(e) { this.change('100%' ); },
	onClickLarge: function(e) { this.change('120%' ); }
};

FontChanger.start = function(id) {
	var fontChanger = new FontChanger(id);
	fontChanger.show();
};


/****************************************************
 ** 商品紹介ページ関連
 ****************************************************/

/* 商品詳細サムネイル */
function imgch(url) {
	document.getElementById("image").src = url;
}


/****************************************************
 ** 動画ページ関連
 ****************************************************/

/* 動画切り替え */
function getPage(pageURL) {
	xmlhttp = createXMLHttp();
	if(xmlhttp) {
		xmlhttp.onreadystatechange = setPageData;
		
		if(pageURL == "normal") {
			if(getCookie("asahikei_movie")) {
				pageURL = getCookie("asahikei_movie");
			} else {
				pageURL = "090508_zero_cm.html";
			}
		}
		xmlhttp.open("GET", pageURL);
		xmlhttp.send(null);
	} else {
		alert("XMLHttpRequestに失敗しました。");
	}
}

function setPageData() {
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		document.getElementById("flash_area").innerHTML = xmlhttp.responseText;
	}
}

function createXMLHttp() {
	try {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		try {
			return new XMLHttpRequest();
		} catch(e) {
			return null;
		}
	}
	return null;
}


/****************************************************
 ** ページトップへ
 ****************************************************/
function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	
	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;
	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));
	window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
	
	if (x > 0 || y > 0) {
		window.setTimeout("backToTop()", 25);
	}
}
