var sep = '|';
var	data = new Array();
var lang = 'jp';
re = new RegExp("english", "i");
if(location.href.match(re)){
	lang = 'en';
}
footmarkGetCookie();

function footmarkAdd(){
	var title;
	var url;
	
	
	title = document.title;
	buf = title.split('|');
	title = encodeURI(buf[(buf.length -1)]);
	url = document.URL;
	
	while(url.match(/\=/)){
		url = url.replace('=','%eq%');
	}
	dd = new Date();
	if(dd.getYear() < 1900){
		current = (dd.getYear()+1900)+'/'+(dd.getMonth()+1)+'/'+dd.getDate();
	}else{
		current = (dd.getYear())+'/'+(dd.getMonth()+1)+'/'+dd.getDate();
	}
	if(url != undefined){
		hist = "0%:%"+url+'|'+title+'|'+current+'%sep%';
		for(i=0; i<20; i++){
			if(data[i]['url'] != ''){
				hist = hist+(i+1)+'%:%'+data[i]['url']+'|'+data[i]['title']+'|'+data[i]['date']+'%sep%';
				document.cookie = "data_"+i+"=; expires=Thu, 1-Jan-2000 00:00:00 GMT; domain=tohnichi.jp; path=/;";
				document.cookie = "data_"+i+"=; expires=Thu, 1-Jan-2000 00:00:00 GMT; domain=tohnichi.co.jp; path=/;";
			}
		}
		document.cookie = "hist="+hist+"; expires=Thu, 1-Jan-2030 00:00:00 GMT; domain=tohnichi.jp; path=/;";
		document.cookie = "hist="+hist+"; expires=Thu, 1-Jan-2030 00:00:00 GMT; domain=tohnichi.co.jp; path=/;";
	}
}

function footmarkList(){
	html = '';
	for(i=0; i<20; i++){
		if(data[i]['title'] != ''){
			html+='<table width="500" border="0" cellspacing="0" cellpadding="0">' + "\n";
			html+='	<tr>' + "\n";
			html+='		<td>' + "\n";
			html+='			<table width="500" border="0" cellspacing="5" cellpadding="0">' + "\n";
			html+='				<tr>' + "\n";
//			html+='					<td align="left" class="tx_base12px"><a href="#" onClick="window.opener.location.href=\''+decodeURI(data[i]['url'])+'\';return false;">'+decodeURI(data[i]['title'])+'</a></td>' + "\n";
			html+='					<td align="left" class="tx_base12px"><a href="#" onClick="window.opener.location.href=\''+data[i]['url']+'\';return false;">'+decodeURI(data[i]['title'])+'</a></td>' + "\n";
			html+='					<td width="90" align="center" class="tx_base12px">'+decodeURI(data[i]['date'])+'</td>' + "\n";
			html+='				</tr>' + "\n";
			html+='				<tr>' + "\n";
			html+='					<td colspan="2" bgcolor="#CCCCCC"><img src="/common/img/spacer.gif" width="10" height="1"></td>' + "\n";
			html+='				</tr>' + "\n";
			html+='			</table>' + "\n";
			html+='		</td>' + "\n";
			html+='	</tr>' + "\n";
			html+='	<tr>' + "\n";
			html+='		<td><img src="/common/img/spacer.gif" width="10" height="10"></td>' + "\n";
			html+='	</tr>' + "\n";
			html+='</table>' + "\n";
		}
	}
	if(html == ''){
		if(lang == 'jp'){
			html = '<p class="tx_base12px">足跡はありません。</p>';
		}else{
			html = '<p class="tx_base12px">No previous track</p>';
		}
	}
	docObj = getObj('footmarkHistory');
	docObj.innerHTML = html;
	return true;
}

function setLastFootmark(mode){
	if(mode != 0) mode = 1;
	title = decodeURI(data[0]['title']);
	if(title.length > 12){
		title = title.substring(0,12) + '...';
	}
	
	html = '';
	if(title == ''){
		if(lang == 'jp'){
			html = ' 前回の足跡はありません。 ';
		}else{
			html = ' No previous track ';
		}
	}else{
		//html = ' <a href="'+decodeURI(data[1]['url'])+'">'+title+'</a> ';
		html = ' <a href="'+data[1]['url']+'">'+title+'</a> ';
	}
	docObj = getObj('lastFootmark');
	docObj.innerHTML = html;
	if(mode == 1){
		footmarkAdd();
	}
}

function footmarkGetCookie(){
	arrRaw = document.cookie.split('; ')
	rawdata = new Array();
	for(i=0;i<arrRaw.length;i++){
		a = arrRaw[i].split('=');
		if(a[0] == 'hist'){
			b = a[1].split('%sep%');
			for(j=0;j<b.length;j++){
				c = b[j].split('%:%');
				if(c[1] != undefined){
					rawdata[c[0]] = c[1];
				}else{
					rawdata[c[0]] = '';
				}
			}
		}
	}
	for(i=0;i<20;i++){
		data[i] = new Array();
		if(rawdata[i] != 'undefined' && rawdata[i] != undefined){
			buf = rawdata[i].split(sep);
			data[i]['url'] = buf[0];
			data[i]['title'] = buf[1];
			data[i]['date'] = buf[2];
		}else{
			data[i]['url'] = '';
			data[i]['title'] = '';
			data[i]['date'] = '';
		}
	}
	return true;
}

