//------------------------------------------------------------
//  history management
//------------------------------------------------------------


var HOST="";

//クッキーへの最大保存数(保存したい数ー1)

var defaultcnt=49;
//===処理===

var defDB=new Array();


//定義ファイル更新ここから

defDB[0]=new Array(1010001,"/powerflex/lineup.html",1,0);

//定義ファイル更新ここまで





var defDBlength=defDB.length;
var hisRCURL;




function sethistoryCookie(val)
{
	var tmp;
	tmp = "history=" + val + "; ";
	tmp += "expires=Fri, 31-Dec-2030 23:59:59; ";
	tmp += "path=/;"
	tmp += "domain=" + document.domain;
	document.cookie = tmp;

}

function search_historyCookie(urldata) {
	//アクセス日時を取得
	var mySysDate=new Date();
	var myYear=mySysDate.getFullYear();
	var myMonth=parseInt(mySysDate.getMonth())+1;
	var myDate=mySysDate.getDate();
	var myHour=mySysDate.getHours();
	var myMinutes=mySysDate.getMinutes();
	var accessdate=myYear+"/"+myMonth+"/"+ myDate;
	var historyDBstr="";
	var accessCnt=1;//訪問回数
	var splitTag=":";
	var uDBNo="";

	gethistoryCookie();//cookie情報を取得
	if(historyDB.length>defaultcnt){
		var cnt=defaultcnt; //保存したい数-1
	}
	else{
		var cnt=historyDB.length;
	}

	if(historyDB[0]=="rejecthistory"){
	}
	else{
		//cookieに保存
		for(var i=0; i<defDBlength; i++) {
			if(defDB[i][1]==urldata) {
				if(historyDB[0]!==0){

					for(var j=0; j<cnt; j++) {
		
					//アクセス回数をカウント
						historyDB_split=historyDB[j].split("?");
						var DBNo=historyDB_split[0];
						if(defDB[i][0]==DBNo) {
							accessCnt=parseInt(historyDB_split[2]);
							accessCnt+=1;//一致するものがあったらカウントアップ
							uDBNo="";
						}
						else{
							if(j==(cnt-1)){
								splitTag="";
							}
							historyDBstr+=historyDB[j]+splitTag;//連結
						}
					}
					//cookieに保存
					cookie_val=defDB[i][0]+"?"+accessdate+"?"+accessCnt+":"+historyDBstr;
					sethistoryCookie(cookie_val);
				}
				else{
					cookie_val=defDB[i][0]+"?"+accessdate+"?"+accessCnt+":";
					sethistoryCookie(cookie_val);
				}
			}
			else{
				var historyUrl= false;
			}
		}
	}
}


function gethisHostName(url){
  if(url.indexOf('://')>0){
    var path = url.split('://');
    if(path[1].indexOf('/')<0)  return path[1];
    var parts = path[1].split('/');
    return parts[0];
  }
  return '';
}

function gethistoryUrl(){
	var geturl=location.href;
	var hostName=gethisHostName(geturl);
	var https= geturl.indexOf("https");
	var htmlnum= geturl.indexOf("html")+4;
	var geturllength=geturl.length;
	//URLを整形（変数やアンカー削除））
	if(geturllength!=htmlnum){
		geturl=geturl.substring(0,htmlnum);	
	}

	if(https==-1){
		//右コラムインデックス用URL
		hisRCURL="";
		
		geturl = geturl.split(hostName);
		var splitNum = 1;
		if (geturl[splitNum]) {
			var urldata = geturl[splitNum];
		}
		else {
			//error処理記述
		var urldata = geturl;
		}
	}
	else{
		var urldata = geturl;

		//右コラムインデックス用URL
		hisRCURL=HOST;
	}
		search_historyCookie(urldata);
}


function gethistoryCookie() {
	var theName = "history=";
	var theCookie = document.cookie+";";
	var start = theCookie.indexOf(theName);
	if (start != -1) 
	{
		end = theCookie.indexOf(";",start);
		var theData = theCookie.substring(start+theName.length,end);
		historyDB=theData.split(":");

	} 
	else{
		historyDB=new Array();
		historyDB[0]=0;
	}
	
}
main_text="";


gethistoryUrl();





////////////
//右コラム用//
////////////

var txtDB=new Array();
var tmpCookieDB=new Array();
var tmpCookieDBdate=new Array();
var cflag=0;
var pflag=0;
var c_noflag=0;
var p_noflag=0;
var allnohistory='<div id="nohistory" class="t" style="margin:10px">履歴はありません</div>';
var nohistory='<tr><td colspan="5"><div id="nohistory" class="t" style="margin:10px">履歴はありません</div></td></tr>';
//var cookie_val="";

//定義ファイル更新ここから

txtDB[0]=new Array(1010001,"トップページ");


var txtDBlength = txtDB.length;


//カテゴリー用DB 
var hCatDB=new Array();
hCatDB[0]='';
hCatDB[1]='商品ラインナップ';
hCatDB[2]='円預金';
hCatDB[3]='円仕組預金';
hCatDB[4]='二重通貨定期預金等';
hCatDB[5]='外貨預金';
hCatDB[6]='投資信託';
hCatDB[7]='個人年金保険';
hCatDB[8]='住宅ローン';
hCatDB[9]='株式・外債';
hCatDB[10]='クレジットカード';
hCatDB[11]='その他';
hCatDB[12]='今月のキャンペーン';
hCatDB[13]='50歳以上の方へ';
hCatDB[14]='店舗・ATMのご案内';
hCatDB[15]='総合口座PowerFlex';
hCatDB[16]='マーケット・マネー情報';
hCatDB[17]='はじめて運用される方へ';
hCatDB[18]='インターネットバンキング';
hCatDB[19]='安全なお取引のために';
hCatDB[20]='総合口座PowerFlex';
hCatDB[21]='その他';
hCatDB[22]='新生プラチナサービス';
hCatDB[23]='運用されている方へ';
hCatDB[24]='外国債券';
hCatDB[25]='保険';
hCatDB[26]='医療・がん・女性のための保険';
hCatDB[27]='自動車保険';
hCatDB[28]='モバイルバンキング';
hCatDB[29]='カードローン';
hCatDB[30]='ステップアッププログラム';


var hCatDBlength=hCatDB.length;



gethistoryCookie();
function checkhisCookie() {

	var hostName=getHostName(location.href);
	var geturl = location.href.split(hostName);
	var splitNum = 1;
	if (geturl[splitNum]) {
		var urldata = geturl[splitNum];

	}
	else {
		//error処理記述

	}
	if(urldata=="/rireki.html"){

		var checkboxText="";
		if(historyDB[0]=="rejecthistory"){
			checkboxText='<form name="nohistory"><input type="checkbox" name="myCHK" onclick="rejecthistory(1)" checked>履歴を残さない<span style="color:CC4444">（履歴を残さない設定になっています。）</span></form>';
		}
		else{
			checkboxText='<form name="nohistory"><input type="checkbox" name="myCHK" onclick="rejecthistory(0)">履歴を残さない</form>';

		}
				var historycheckbox = document.getElementById("historycheckbox");
				historycheckbox.innerHTML = checkboxText;
	}
}

/*
if (window.addEventListener) 
{
	window.addEventListener("load", checkhisCookie, false);
}
else if (window.attachEvent) 
{
	window.attachEvent("onload", checkhisCookie);
}
else {
	window.onload = checkhisCookie();

}
*/

function historyCookie() {
	var theName = "history=";
	var theCookie = document.cookie+";";
	var start = theCookie.indexOf(theName);
	if (start != -1) 
	{
		var end = theCookie.indexOf(";",start);
		historytheData = theCookie.substring(start+theName.length,end);
		if(!historytheData){

		}
		else{

			showhistoryDB=historytheData.split(":");
		}
	} 
	else{
	}
}
function returnhistoryCookie() {
	var theName = "history=";
	var theCookie = document.cookie+";";
	var start = theCookie.indexOf(theName);
	var historytheData;
	if (start != -1) 
	{
		var end = theCookie.indexOf(";",start);
		historytheData = theCookie.substring(start+theName.length,end);
	
	} 
	else{
	
	}
	return historytheData;
}


//インデックスページ用

function showRCHistoryP(aShowNo) {
var cflag=0;
var xflag=0;//同番号連続カウント防止フラグ
var contents_text="";
var main_text="";
	showhistoryDB=new Array();
	historyCookie();

	if(showhistoryDB.length>aShowNo){
		var showlength=parseInt(aShowNo); //表示数
	}
	else{
		var showlength=showhistoryDB.length-1;	
	}	

	if(showlength!=-1){
		//商品ページ
		for(var k=0; k < showhistoryDB.length; k++) {
			//アクセス回数をカウント
			showhistoryDB_split=showhistoryDB[k].split("?");
			var DBNo=showhistoryDB_split[0];
			var cat=DBNo.substring(1,3);
			if(!DBNo){
				break;
			}
			var dflag=0;
			if(DBNo<2000000){
				for(var n=0; n<defDBlength; n++) {
					if((defDB[n][0]==DBNo)&&(dflag==0)){
					var defDBNo=n;
					dflag=1;
					}
				}
				//カテゴリーの検索
				for(var j=0; j<hCatDBlength; j++) {
					if(j==cat){
						var hCategory=hCatDB[j];
					}
				}
				for(var m=0; m<txtDBlength; m++) {
					if((txtDB[m][0]==DBNo)&&(xflag==0)){
						var popup=DBNo.substring(3,4);
						if(popup==9){
							contents_text+='<div style="margin-bottom:1em;"><span style="line-height:normal"><a href="'+hisRCURL+defDB[defDBNo][1]+'" target="_blank">'+hCategory+' '+txtDB[m][1]+'</a></span></div>\n';
						}
						else{
							contents_text+='<div style="margin-bottom:1em;"><span style="line-height:normal"><a href="'+hisRCURL+defDB[defDBNo][1]+'">'+hCategory+' '+txtDB[m][1]+'</a></span></div>\n';
						}
					cflag+=1;
					xflag=1;
					}
				}
				xflag=0;
			}
			else{
			}
			if(cflag==showlength){
				break;
			}
		}

		if(cflag==0){
				contents_text+='<div>履歴はありません</div>';		
		}
		
			main_text+=contents_text;
			document.write(main_text);
	}
	else{
			document.write('<div>履歴はありません</div>');
	}

}



function showRCHistoryC(aShowNo) {
var cflag=0;
var xflag=0;//同番号連続カウント防止フラグ
var contents_text="";
var main_text="";
	showhistoryDB=new Array();
	historyCookie();

	if(showhistoryDB.length>aShowNo){

		var showlength=parseInt(aShowNo); //表示数
	}
	else{
		var showlength=showhistoryDB.length-1;	
	}	

	if(showlength!=-1){
		//特集ページ
		for(var k=0; k<showhistoryDB.length; k++) {
			//アクセス回数をカウント


//alert("showhistoryDB="+showhistoryDB);
			showhistoryDB_split=showhistoryDB[k].split("?");
			var DBNo=showhistoryDB_split[0];
			var cat=DBNo.substring(1,3);
			if(!DBNo){
				break;
			}
			var dflag=0;
			if(DBNo>2000000){
				for(var n=0; n<defDBlength; n++) {
					if((defDB[n][0]==DBNo)&&(dflag==0)){
						var defDBNo=n;
						dflag=1;
					}
				}
				//カテゴリーの検索
				for(var j=0; j<hCatDBlength; j++) {
					if(j==cat){
						var hCategory=hCatDB[j];
					}
				}
				for(var m=0; m<txtDBlength; m++) {
					if((txtDB[m][0]==DBNo)&&(xflag==0)){
						var popup=DBNo.substring(3,4);
						if(popup==9){
							contents_text+='<div style="margin-bottom:1em;"><span style="line-height:normal"><a href="'+hisRCURL+defDB[defDBNo][1]+'" target="_blank">'+hCategory+' '+txtDB[m][1]+'</a></span></div>\n';
						}
						else{
							contents_text+='<div style="margin-bottom:1em;"><span style="line-height:normal"><a href="'+hisRCURL+defDB[defDBNo][1]+'">'+hCategory+' '+txtDB[m][1]+'</a></span></div>\n';
						}


					cflag+=1;
					xflag=1;

					}
				}
				xflag=0;
			}
			else{
			}
			if(cflag==showlength){

				break;
			}
		}

		if(cflag==0){
				contents_text+='<div>履歴はありません</div>';		
		}
		
			main_text+=contents_text;
			document.write(main_text);
	}
	else{
			document.write('<div>履歴はありません</div>');
	}

}





//キャンセルコード（cancellRRightColumn）がhtml内で宣言されてなければ実行
//表示コードまたはメニューがある場合表示
var cancell = (function() {return this;}).apply(null, []);
if (!("cancellRRightColumn" in cancell)) {
	if (document.getElementById("menu0") ) {
		showRRightColumn();
	}
	else if(("RRightColumn" in cancell)){
		showRRightColumn();	
	}
	else{
	
	}
}


//ウインドウサイズ取得
function getWindowWidth(){
  if(window.innerWidth) return window.innerWidth; // Mozilla, Opera, NN4
  if(document.documentElement && document.documentElement.clientWidth){ // 以下 IE
   return document.documentElement.clientWidth;
  }
  else if(document.body && document.body.clientWidth){
   return document.body.clientWidth;
  }
  return 0;
}


function showRRightColumn() {

	//ウィンドウの幅を取得
	body_width = getWindowWidth();

	if(body_width<810){
//		alert("body_widthは810より小さい body_width"+body_width);
	}

	else{

	//	alert("body_widthは810以上　 body_width"+body_width);

	if(nv == 1)   {
	//		alert("印刷用画面");

	}
	else{


		document.write('<link type="text/css" rel="stylesheet" href="/sr/css/pfnavi.css">');
		document.write('<div style="position:absolute;top:80px;left:810px;width:170px;">');
		document.write('<table border="0" cellpadding="0" cellspacing="0" width="170">');

		document.write('<tr><td><img src="/sr/imgs/rightright/rr_column_bg_top.gif" width="170" height="20" alt=""></td></tr>');
		document.write('<tr><td background="/sr/imgs/rightright/rr_column_bg_middle.gif">');
		document.write('<div style="width:130px;margin:0px 20px 0px 20px;">');
		document.write('<div class="txt" style="margin:5px 0px 10px 0px;"><a href="/campaign/0906stock/index.html" onclick="urchinTracker(\'/click_count/right_banner/0906_stockcam/\');"><img src="/sr/imgs/rightright/rr_column_bnr_0906_stockcam.gif" alt="新生銀行ではじめるネットで株式・外債キャンペーン（金融商品仲介サービス）" width="130" height="750" border="0"></a></div>');
		document.write('</td></tr>');
		document.write('<tr><td><img src="/sr/imgs/rightright/rr_column_bg_bottom2.gif" width="170" height="12" alt=""></td></tr>');

		document.write('</table>');
		document.write('<table border="0" cellpadding="0" cellspacing="0" width="170">');
		document.write('<tr><td><img src="/sr/imgs/rightright/rr_column_bg_top.gif" width="170" height="20" alt=""></td></tr>');
		document.write('<tr><td background="/sr/imgs/rightright/rr_column_bg_middle.gif">');
		document.write('<div style="width:130px;margin:0px 20px 0px 20px;">');	
		document.write('<div class="txt" style="margin:5px 0px 10px 0px;"><img src="/sr/imgs/rightright/rr_column_title.gif" alt="貯蓄、投資、住宅ローンのこと。ちょっと聞いてみたい。" width="130" height="74" border="0"></div>');
		document.write('<div class="txt" style="margin:5px 5px 10px 5px; color:#333333;">金融商品についてわからないことや、資産運用に関するお悩みなど、どうぞお気軽にご相談ください。</div>');
		document.write('<div class="txt" style="margin-bottom:20px;"><a href="javascript:link(https_+ \'/enquete/e_branch_reserve.html\')\;"><img src="/sr/imgs/rightright/rr_column_btn_02.gif" alt="店舗で運用相談" width="130" height="106" border="0"></a></div>');
		document.write('<div class="txt"><img src="/sr/imgs/rightright/rr_column_history_title.gif" width="130" height="23" alt="最近訪問したページ"></div>');
		document.write('<div class="txt" style="color:#333333;background-color:#eeeeee;padding:3px 5px 3px 5px;"><strong>商品・キャンペーン</strong></div>');
		document.write('<div><img src="/sr/imgs/rightright/rr_column_history_line.gif" width="130" height="1" alt=""></div>');
		document.write('<div class="txt" style="padding-top:1em;">');
			showRCHistoryP("3") ; 
		document.write('</div>');
		document.write('<div><img src="/sr/imgs/rightright/rr_column_history_line.gif" width="130" height="1" alt=""></div>');
		document.write('<div class="txt" style="color:#333333;background-color:#eeeeee;padding:3px 5px 3px 5px;"><strong>コンテンツ・サービス</strong></div>');
		document.write('<div><img src="/sr/imgs/rightright/rr_column_history_line.gif" width="130" height="1" alt=""></div>');
		document.write('<div class="txt" style="padding-top:1em;">');
			showRCHistoryC("3") ; 
		document.write('</div>');
		document.write('<div><img src="/sr/imgs/rightright/rr_column_history_line.gif" width="130" height="1" alt=""></div>');
		document.write('<div class="txt" style="padding-top:0.5em;text-align:right;"><img src="/imgs/arrow_s.gif" alt=""><a href="javascript:link(http_+ \'/rireki.html\')\;">履歴一覧</a></div>');
		document.write('</div>');
		document.write('</td></tr>');
		document.write('<tr><td><img src="/sr/imgs/rightright/rr_column_bg_bottom.gif" width="170" height="20" alt=""></td></tr>');

		document.write('</table>');
		document.write('</div>');

		}
	}


}
