// JavaScript Document

//画像マウスオーバー
/*
	Standards Compliant Rollover Script
	Author : Daniel Nolan
	http://www.bleedingego.co.uk/webdev.php
*/

function initRollovers() {
	if (!document.getElementById) return;
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

//送信ボタン ロールオーバー
function submitOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("post-btn")) return false;
	var submit_btn = document.getElementById("post-btn");
	submit_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	submit_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//ログインボタン ロールオーバー
function loginOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("login-btn")) return false;
	var login_btn = document.getElementById("login-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -42px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//確認画面へ進むボタン ロールオーバー
function confirmOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("confirm-btn")) return false;
	var login_btn = document.getElementById("confirm-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -42px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//戻るボタン ロールオーバー
function backOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("back-btn")) return false;
	var login_btn = document.getElementById("back-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//確認画面へ進むボタン ロールオーバー
function agreeOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("agree-btn")) return false;
	var login_btn = document.getElementById("agree-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//マイページへ ロールオーバー
function toMypageOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("mypage-btn")) return false;
	var login_btn = document.getElementById("mypage-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//マイページに戻る ロールオーバー

function toBackMypageOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("back-mypage-btn")) return false;
	var login_btn = document.getElementById("back-mypage-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//マイポイント ロールオーバー

function toMypointOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("mypoint-btn")) return false;
	var login_btn = document.getElementById("mypoint-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//戻る ロールオーバー

function toBackOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("toback-btn")) return false;
	var login_btn = document.getElementById("toback-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//キャンセル ロールオーバー

function CancelOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("cancel-btn")) return false;
	var login_btn = document.getElementById("cancel-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//購入 ロールオーバー

function PurchaseOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("purchase-btn")) return false;
	var login_btn = document.getElementById("purchase-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//TOPページへ戻る
function backTopOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("backto-topbtn")) return false;
	var login_btn = document.getElementById("backto-topbtn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//入力内容確認
function inputConrifrmOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("inputconfirm-btn")) return false;
	var login_btn = document.getElementById("inputconfirm-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}


//解約手続きに進む
function toCancelOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("tocancel-btn")) return false;
	var login_btn = document.getElementById("tocancel-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//解約する
function leaveOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("leave-btn")) return false;
	var login_btn = document.getElementById("leave-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//次へ
function nextOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("next-btn")) return false;
	var login_btn = document.getElementById("next-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//購入手続きへ
function toPurchaseOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("topurchase-btn")) return false;
	var login_btn = document.getElementById("topurchase-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//表示ボタン
function displayOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("display-btn")) return false;
	var login_btn = document.getElementById("display-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -20px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//ログインボタン（大）
function loginOverB() {
	if(!document.getElementById) return false;
	if(!document.getElementById("login-btn-b")) return false;
	var login_btn = document.getElementById("login-btn-b");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//コミック詳細へ
function comicDetailOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("comicdetail-btn")) return false;
	var login_btn = document.getElementById("comicdetail-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//小説詳細へ
function novelDetailOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("noveldetail-btn")) return false;
	var login_btn = document.getElementById("noveldetail-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//カード変更手続き
function toChangecardOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("tochangecard-btn")) return false;
	var login_btn = document.getElementById("tochangecard-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//詳細検索 検索
function searchBtnOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("search-btn")) return false;
	var login_btn = document.getElementById("search-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//詳細検索 検索
function resetBtnOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("reset-btn")) return false;
	var login_btn = document.getElementById("reset-btn");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -44px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//他のキーワード 検索ボタン
function searchBtnSOver() {
	if(!document.getElementById) return false;
	if(!document.getElementById("search-btn-s")) return false;
	var login_btn = document.getElementById("search-btn-s");
	login_btn.onmouseover = function() {
		this.style.backgroundPosition = '0 -20px';
	}
	login_btn.onmouseout = function() {
		this.style.backgroundPosition = '0 0';
	}
}

//ログイン、ログアウトのHTML切り替え

function setCookie(name, value, domain, path, expires, secure) {
	if (!name) return;

	var str = name + "=" + escape(value);
	if (domain) {
		if (domain == 1) domain = location.hostname.replace(/^[^\.]*/, "");
		str += "; domain=" + domain;
	}
	if (path) {
		if (path == 1) path = location.pathname;
		str += "; path=" + path;
	}
	if (expires) {
		var nowtime = new Date().getTime();
		expires = new Date(nowtime + (60 * 60 * 24 * 1000 * expires));
		expires = expires.toGMTString();
		str += "; expires=" + expires;
	}
	if (secure && location.protocol == "https:") {
		str += "; secure";
	}

	document.cookie = str;
}

function getCookie(name) {
	if (!name || !document.cookie) return;

	var cookies = document.cookie.split("; ");
	for (var i = 0; i < cookies.length; i++) {
		var str = cookies[i].split("=");
		if (str[0] != name) continue;
		return unescape(str[1]);
	}
	return;
}

function loginCheck(){
	
	var checker = getCookie("LOGIN");
	var element = document.getElementById("login_replace_area");
	
	if(checker == "false" ) {
		element.innerHTML = "<div id='login_area'><div id='login_area_wrap'><div id='login_name'><p class='left'><img src='/img/common/txt_login_welcome.gif' width='48' height='14' alt='ようこそ' /></p><p class='right'>ゲスト<span>様</span></p></div><div id='login_point'><p class='left'><img src='/img/common/txt_login_point.gif' width='54' height='10' alt='マイポイント' /></p><p class='right'>400<span>pt</span></p></div><div class='login_input'><dl><dt><label for='id'><img src='/img/common/txt_login_id.gif' width='96' height='12' alt='ID（メールアドレス）' /></label></dt><dd><input type='text' class='textfield' name='id' id='id' value='' /></dd></dl><dl class='mgnTop5'><dt><label for='pass'><img src='/img/common/txt_login_pass.gif' width='57' height='13' alt='パスワード' /></label></dt><dd><input type='text' class='textfield' name='pass' id='pass' value='' /></dd></dl></div><div class='forget_pass'><a href=''><img class='imgover' src='/img/common/txtbtn_pass_forget.gif' width='113' height='12' alt='パスワードを忘れた方' /></a></div><div id='login_btn'><input type='submit' name='login-btn' id='login-btn' value='ログイン' /></div><div id='entry_btn'><dl><dt><img src='/img/common/txt_login_entry.gif' width='110' height='12' alt='新規の方はこちらから' /></dt><dd><a href='/entry/pre'><img class='imgover' src='/img/common/btn_entry.gif' width='180' height='42' alt='会員登録' /></a></dd></dl></div></div></div>";
	} else if(checker== "true" ){
		element.innerHTML = "<div id='during_login_area'><div id='during_login_area_wrap'><div id='login_name'><p class='left'><img src='/img/common/txt_login_welcome.gif' width='48' height='14' alt='ようこそ' /></p><p class='right'>ゲスト<span>様</span></p></div><div id='login_point'><p class='left'><img src='/img/common/txt_login_point.gif' width='54' height='10' alt='マイポイント' /></p><p class='right'>400<span>pt</span></p></div><p class='login_status'><img src='/img/common/txt_login_now.gif' width='54' height='13' alt='ログイン中' /></p><div id='mypage_btn'><a href='#'><img class='imgover' src='/img/common/btn_login_to_mypage.gif' width='180' height='60' alt='マイページ' /></a></div><div id='logout_btn'><a href='#'><img class='imgover' src='/img/common/btn_login_logout.gif' width='180' height='37' alt='ログアウト' /></a></div></div></div>";
	}
}

//検索窓の挙動

function searchTextIn() {
	if(!document.getElementById) return false;
	if(!document.getElementById("searchtext")) return false;
	var s_textfield = document.getElementById("searchtext");
	s_textfield.value = "キーワードを入力してください。";
}

var count = 0;
function focusAction() {
	if(!document.getElementById) return false;
	if(!document.getElementById("searchtext")) return false;
	var s_textfield = document.getElementById("searchtext");
	s_textfield.onfocus = function() {
		count++;
		if(count < 2) {
			this.style.color = "#505050";
			this.value = "";
		}
	}
}

function focusCheck() {
	if(count < 1) {
		var s_textfield = document.getElementById("searchtext");
		s_textfield.value="";
	}
}

//ブックマーク
function addBookmark() { 
	var url = window.location;
	var title = "ハーレクイン ライブラリ";
	
	if (window.sidebar) { 
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) { 
		window.external.AddFavorite( url, title); 
	} else if( window.opera && window.print ) { 
		return true; 
	} 
}

function UAcheck() {
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf("safari") != -1){
		document.getElementById("bookmark").style.display = "none";
	}
}

//window.onloadの待ち行列
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


addLoadEvent(initRollovers);
addLoadEvent(searchTextIn);
addLoadEvent(focusAction);
addLoadEvent(UAcheck);
//addLoadEvent(loginCheck);
addLoadEvent(submitOver);
addLoadEvent(loginOver);
addLoadEvent(confirmOver);
addLoadEvent(backOver);
addLoadEvent(agreeOver);
addLoadEvent(toMypageOver);
addLoadEvent(inputConrifrmOver);
addLoadEvent(toCancelOver);
addLoadEvent(leaveOver);
addLoadEvent(nextOver);
addLoadEvent(toPurchaseOver);
addLoadEvent(displayOver);
addLoadEvent(loginOverB);
addLoadEvent(comicDetailOver);
addLoadEvent(novelDetailOver);
addLoadEvent(toBackMypageOver);
addLoadEvent(toChangecardOver);
addLoadEvent(searchBtnOver);
addLoadEvent(searchBtnSOver);
addLoadEvent(resetBtnOver);
addLoadEvent(toMypointOver);
addLoadEvent(toBackOver);
addLoadEvent(CancelOver);
addLoadEvent(PurchaseOver);
