//var currentPage = window.location.href;

if(window.$ == undefined){
} else {
$(function(){
	//友の会ログイン
	//$("#mansion > .login").hide();
	var nowLogin = false;

	if ($.cookie('OnesclubMypageSession') == 'OK') {
		nowLogin = true;
		//club.js
		if ($(".pickup").attr("class")) {
			getCLUB_PICKUP();
		}
		if ($(".ranking").attr("class")) {
			getCLUB_RANKING();
		}
	}

	setLoginArea(nowLogin);

	//画像プリロード
	var preloadImgs = [];
	var preImgs = preloadImgs;
	preImgs["onesOn"] = new Image();
	preImgs["onesOn"].src = "images/login/btn_onesclub_on.gif";


	//イベント・キャンペーン情報
	$(".floatL .info dl").find("dd:last").addClass("lastChild");

	//ピックアップ物件（トップページ）
	$(".floatR > .pickup > ul").children("li:odd").addClass("odd");
	
	//ライフスタイル情報トップ（/mansion/lifestyle/index.html）
	$("#mansion .main div > ul.list").children("li:nth-child(3n)").css("marginRight", 0);


	//ナビゲーション（エリア選択プルダウン）の処理
	$(".nav").find("ul.nav01_area").hover(function(){
		$(this).show();
		$(this).css("display", "block");
	},function(){
		$(this).hide();
		$(this).css("display", "none");
	});
	
	$("div.nav > div > ul > li.nav01").children("a").hover(function(){
		$(".nav").find("ul.nav01_area").show();
	}, function(){
		$(".nav").find("ul.nav01_area").hide();
	});

});
}
/* ==

　ログインエリアの表示セット

============================================================================================== */
function setLoginArea(nowLogin){
	var strHTML = '';
	var myD = new Date();
	var myHours = myD.getHours();
	var strNowURL = '';
	var re;

	if(nowLogin != true){ //マイページにログインしていない時
		strHTML += '<form method="post" action="https://www3.daiwahouse.co.jp/mansion/onesclub/login.asp">';

		// *** 2009/03/30 Y.Yasui execコードの追加およびアルファベットに変更 ***
		strHTML += '	<input type="hidden" name="exec" value="login">';
		// *** 2009/03/30 Y.Yasui execコードの追加およびアルファベットに変更 ***

		strHTML += '<p class="about"><a href="http://www3.daiwahouse.co.jp/mansion/support/tomokai.html" title="ダイワハウスマンション友の会とは？"><span>ダイワハウスマンション友の会とは？</span></a></p>';
		strHTML += '<ul>';
		strHTML += '<li><label for="mypageId"><img src="/mansion/images/login/txt_id.gif" alt="ID" width="16" height="16" /></label>';
		strHTML += '<input type="text" name="id" id="mypageId" maxlength="255" /></li>';
		strHTML += '<li><label for="mypagePass"><img src="/mansion/images/login/txt_pass.gif" alt="PASS" width="35" height="16" /></label>';
		strHTML += '<input type="password" name="pass" id="mypagePass" maxlength="255" /></li>';
		strHTML += '<li class="btn"><input name="mypageLogin" type="image" src="/mansion/images/login/btn_login.gif" id="mypageLogin" value="login" alt="LOGIN" onmouseover="this.src=\'/mansion/images/login/btn_login_on.gif\';" onmouseout="this.src=\'/mansion/images/login/btn_login.gif\';" /></li>';
		strHTML += '</ul>';
		strHTML += '<p class="pass"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/password.asp" title="パスワードを忘れた方"><span>パスワードを忘れた方</span></a></p>';
		strHTML += '<p class="btn"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/regist_club.asp" title="ご入会はこちら"><span>ご入会はこちら</span></a></p>';

		strHTML += '</form>';

		$("#mansion div.login").html(strHTML);
		
		/* 09/04/21 
		$("#mansion div.login").slideUp("slow");
		$("#mansion div.nav").find("p.btn").bind("click", function(){
			if($("#mansion div.login").css("display") == "none"){
				$("#mansion div.login").slideDown("slow");
				$(this).find("a").css("backgroundImage", "url(/mansion/images/login/btn_onesclub_on.gif)");
			}else{
				$("#mansion > .login").slideUp("slow");
				$(this).find("a").css("backgroundImage", "url(/mansion/images/login/btn_onesclub.gif)");
			}
		});
		*/

	}else{ //マイページにログインしている時
		//CSS用IDを加える
		$("#mansion div.login").attr({id: "mypage"});
		if (myHours > 4 && myHours < 18) {
			strHTML += '<p>こんにちは！' + getCookie("cname") + '様</p>';
		} else {
			strHTML += '<p>こんばんは！' + getCookie("cname") + '様</p>';
		}
		strHTML += '<ul class="nav">';
		if (document.domain == 'www.daiwahouse.co.jp' || document.domain == 'www3.daiwahouse.co.jp') {
			strHTML += '<li class="nav01"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/index.asp" title="マイページTOP">マイページTOP</a></li>';
			strHTML += '<li class="nav02"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/consultant/index.asp" title="友の会相談室">友の会相談室</a></li>';
			strHTML += '<li class="nav03"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/regist/s_history.asp" title="資料請求履歴">資料請求履歴</a></li>';
			strHTML += '<li class="nav04"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/mail/index.asp" title="メールマガジン確認">メールマガジン確認</a></li>';
			strHTML += '<li class="nav05"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/regist/personal.asp" title="登録者情報変更">登録者情報変更</a></li>';
			strHTML += '<li class="nav06"><a href="https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/regist/secession.asp" title="退会">退会</a></li>';
		} else {
			strHTML += '<li class="nav01"><a href="/mansion/onesclub/mypage/index.asp" title="マイページTOP">マイページTOP</a></li>';
			strHTML += '<li class="nav02"><a href="/mansion/onesclub/mypage/consultant/index.asp" title="友の会相談室">友の会相談室</a></li>';
			strHTML += '<li class="nav03"><a href="/mansion/onesclub/mypage/regist/s_history.asp" title="資料請求履歴">資料請求履歴</a></li>';
			strHTML += '<li class="nav04"><a href="/mansion/onesclub/mypage/mail/index.asp" title="メールマガジン確認">メールマガジン確認</a></li>';
			strHTML += '<li class="nav05"><a href="/mansion/onesclub/mypage/regist/personal.asp" title="登録者情報変更">登録者情報変更</a></li>';
			strHTML += '<li class="nav06"><a href="/mansion/onesclub/mypage/regist/secession.asp" title="退会">退会</a></li>';
		}
		strHTML += '</ul>';
		//書き換え
		$("#mansion div.login").html(strHTML);

		//ログアウト処理(OnClickイベント)
		$("#mansion div.nav").find("p.btn").find("a").css("backgroundImage", "url(/mansion/images/login/btn_logout.gif)").bind("click", function(){
			//クッキー削除
			 delCookie();
			//セッション削除ページへ移動
			document.write('<html><body><form action="'+ 'https://www3.daiwahouse.co.jp/mansion/onesclub/mypage/sessionlogout.asp' + '" name="returnForm"></form></body></html>')
			document.forms[0].submit();
		});
	}
}

function jumpurl(strURL) {
	document.write('<form action="'+ strURL + '" name="returnForm"></form>')
	document.returnForm.submit();
}

/* ==

　ピックアップ物件の高さ調整　※※実行のコントロールは「/common/js/fontSize.js」に設定あり※※

============================================================================================== */
function setHeight(){
	
	//height調整
	var nameH = 0;
	$(".pickup").find("p.name").each(function(){
		$(this).css("height", "auto");
		var thisH = $(this).height();
		if(nameH < thisH){ nameH = thisH; }
	});
	$(".pickup").find("p.name").css({"height": nameH + "px", paddingBottom: "7px"});

	var trafficH = 0;
	$(".pickup").find("p.traffic").each(function(){
		$(this).css("height", "auto");
		var thisH = $(this).height();
		if(trafficH < thisH){ trafficH = thisH; }
	});
	$(".pickup").find("p.traffic").css({"height": trafficH + "px", paddingBottom: "7px"});

}


/* ==

　友の会ログインエラー表示

============================================================================================== */
function loginError(){
	
	var errorHTML = "";
	errorHTML += "<div class=\"loginError\"><div>";
	errorHTML += "<p class=\"txt\"><strong>ログインできませんでした。</strong><br>もう一度IDもしくはPWをご確認ください。</p>";
	errorHTML += "<p class=\"txt02\">ダイワハウスマンション友の会では、最新の物件情報や住まいに役立つ情報、イベント情報など、たくさんおお得な情報を配信しております。<br />ぜひこの機会にワンズクラブへご入会ください。</p>";
	errorHTML += "<p class=\"txtlink\"><a href=\"https://www3.daiwahouse.co.jp/mansion/onesclub/regist_club.asp\" target=\"_blank\">新規ご入会はこちらから</a></p>";
	errorHTML += "<p class=\"btn\"><a href=\"#\">×閉じる</a></p>"
	errorHTML += "</div></div>";
	
	$("body").append(errorHTML);

	$("div.loginError > div > p.txtlink").find("a").bind("click", function(){ errorRemove(); });
	$("div.loginError > div > p.btn").find("a").bind("click", function(){ errorRemove(); });
	
}

function errorRemove(){
	$("div.loginError").fadeOut("fast", function(){ $("div.loginError").remove(); });
	return false;
}

function loadHeader(){

	//友の会ログイン
	//$("#mansion > .login").hide();
	var nowLogin = false;

	if ($.cookie('OnesclubMypageSession') == 'OK') {
		nowLogin = true;
		//club.js
		if ($(".pickup").attr("class")) {
			getCLUB_PICKUP();
		}
		if ($(".ranking").attr("class")) {
			getCLUB_RANKING();
		}
	}

	setLoginArea(nowLogin);

	//画像プリロード
	var preloadImgs = [];
	var preImgs = preloadImgs;
	preImgs["onesOn"] = new Image();
	preImgs["onesOn"].src = "images/login/btn_onesclub_on.gif";


	//イベント・キャンペーン情報
	$(".floatL .info dl").find("dd:last").addClass("lastChild");

	//ピックアップ物件（トップページ）
	$(".floatR > .pickup > ul").children("li:odd").addClass("odd");
	
	//ライフスタイル情報トップ（/mansion/lifestyle/index.html）
	$("#mansion .main div > ul.list").children("li:nth-child(3n)").css("marginRight", 0);


	//ナビゲーション（エリア選択プルダウン）の処理
	$(".nav").find("ul.nav01_area").hover(function(){
		$(this).show();
		$(this).css("display", "block");
	},function(){
		$(this).hide();
		$(this).css("display", "none");
	});
	
	$("div.nav > div > ul > li.nav01").children("a").hover(function(){
		$(".nav").find("ul.nav01_area").show();
	}, function(){
		$(".nav").find("ul.nav01_area").hide();
	});

}

function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
		}
		xx1 = xx2 + 1;
	}
	return("");
}

function delCookie(){

// *** 2009/03/30 Y.Yasui クッキー削除 ***
	var dTime = new Date();
	dTime.setYear(dTime.getYear() - 1);
	document.cookie = "OnesclubMypageSession=;path=/;domain=daiwahouse.co.jp;expires=" + dTime.toGMTString();
// *** 2009/03/30 Y.Yasui クッキー削除 ***

}
