//*** basic v1.1 ***//


var gURL = window.location;
var gWeb = 1;
var gGia = '../';

if ('http' != gURL.protocol.substring(0, 4)) gWeb = 0;
var gHost = gURL.host;
var gPathname = gURL.pathname;

var gCommonDir = '../common/img/';
if (!gWeb) {
	gCommonDir = '.' + gCommonDir;
	gGia = '\\';
}



/* [customize start] */
//window.onload = function(){Vip('gmenu');}
/*
window.onload = function(){
//	var elmBg = document.all.tags('BODY');
//	elmBg.style.backgroundColor = '#67a160';
	document.bgColor = '#67a160';
}
*/
window.onunload = function(){/* for FireFox & Boa */}
/* Vip */
var gVIPArray = new Array('btn-about-tg-on.gif','btn-corporate-on.gif','btn-flesh-on.gif','btn-carrer-on.gif','btn-special-on.gif');
/* Popcon */
var defaultArray = new Array('#','_blank','640','480','20','10','yes','yes','yes','no','yes','yes','yes');
/* [customize end] */



//** Vip (Visual image preload) [update:2008.3.20] **//
//example:Vip('imagename-on.jpg','gmenu') *gmenu=gVIPArray

function Vip() {
	var nCount = 0;
	var imageSrcArray = new Array();
	function imgload(img) {
		imageSrcArray[nCount] = new Image(100,100);
		imageSrcArray[nCount].src = img;
		nCount++;
	}

	var imagesArray = Vip.arguments;
	var nMax = imagesArray.length;
	for (var i = 0; i < nMax; i++) {
		if ('gmenu' == imagesArray[i]) {
			for (var k = 0; k < gVIPArray.length; k++) {
				imgload(gVIPArray[k]);
			}
		} else {
			imgload(imagesArray[i]);
		}
	}
}



//** Boa (Button over action) [update:2007.9.11] **//

var gBtnArray = new Array();
var gBtnOvArray = new Array('','-on');

function Boa(ChangeID, n){
	var btnNouse = '-no.';

	var sFullpath = '';
	var sPath = '';
	var sName = '';
	var sExtension = '';
	var nLen1, nLen2, nLen3;

	if (!gBtnArray[ChangeID]) {

		gBtnArray[ChangeID] = new Array();

		sFullpath = document.getElementById(ChangeID).src;
		nLen1 = sFullpath.lastIndexOf('/');
		nLen2 = sFullpath.lastIndexOf('.');
		nLen3 = sFullpath.length;

		sPath = sFullpath.substring(0, nLen1 + 1);
		sName = sFullpath.substring(nLen1 + 1, nLen2);
		if (-1 < sFullpath.lastIndexOf(btnNouse)) sName = sFullpath.substring(nLen1 + 1, sFullpath.lastIndexOf(btnNouse));
		sExtension = sFullpath.substring(nLen2, nLen3);

		gBtnArray[ChangeID][0] = sPath + sName + gBtnOvArray[0] + sExtension;
		gBtnArray[ChangeID][1] = sPath + sName + gBtnOvArray[1] + sExtension;
	}

	if (1 != n && 0 != n && -1 < n.indexOf('.')) {
		sFullpath = gBtnArray[ChangeID][0];
		nLen1 = sFullpath.lastIndexOf('/');
		sPath = sFullpath.substring(0, nLen1 + 1);
		gBtnArray[ChangeID][n] = sPath + n;
	}

	document.getElementById(ChangeID).src = gBtnArray[ChangeID][n];
}



//** Popcon (Pop up control) [update:2008.3.20] **//
//example-minimum:Popcon(location,windowname)
//example-minimum:Popcon(location,windowname,'set') *set=defaultArray
//example-maximum:Popcon(location,windowname,width,height,left,top,menubar,toolbar,locationbar,directories,status,scrollbars,resizable)

function Popcon() {
	var popArray = Popcon.arguments;
	var popMax = popArray.length;
	if (2 <= popMax) {
		var conditionArray = new Array('url=','target=','width=','height=','left=','top=','menubar=','toolbar=','location=','directories=','status=','scrollbars=','resizable=');

		var sLocation = popArray[0];
		var sWindowName = popArray[1];
		var setCondition = '';

		var nMax = popMax;
		if ('set' == popArray[2]) {
			popMax--;
			nMax = defaultArray.length;
		}

		var t = '';
		for (var i = 2; i < nMax; i++) {
			if (i < popMax) {
				t = popArray[i];
			} else {
				t = defaultArray[i];
			}
			if (i < nMax - 1) t += ',';
			setCondition += conditionArray[i] + t;
		}
		var setWindow = window.open(sLocation,sWindowName,setCondition);
		setWindow.focus();
	}
	return false;
}



//** Div (Display id view change) **//

function Div(ChangeID, n) {
	if (n) {
		document.getElementById(ChangeID).style.display = 'block';
	} else {
		document.getElementById(ChangeID).style.display = 'none';
	}
}



//** Glay (Global menu layout) **//

var gTimerID;
var gChangeID = '';
var gFlag= 0;

function Glay(sID, nFl){
	if(nFl){ /* out */
		gChangeID = sID;
		gTimerID = setTimeout('Glayout()', 100);
	}else{ /* over */
		clearTimeout(gTimerID);
		document.getElementById(sID).style.display = 'block';
		Boa('g' + sID, 1);
		if ('' != gChangeID && sID != gChangeID) {
			document.getElementById(gChangeID).style.display = 'none';
			Boa('g' + gChangeID, 0);
		}
		gChangeID = sID;
	}
	gFlag = nFl;
}

//** Glayout **//

function Glayout(){
	if (1 == gFlag)	{
		document.getElementById(gChangeID).style.display = 'none';
		Boa('g' + gChangeID, 0);
	}
}



//** Coa (Category open action) **//

function Coa(ChangeID, targetID){
	var bFlg = 'block';
	var dNode = document.getElementById(targetID).getElementsByTagName('div');
	for(var i = 0; i < dNode.length; i++){
		if(ChangeID == 'all'){
			bFlg = 'block';
		} else if(ChangeID == dNode[i].id){
			bFlg = 'block';
		} else {
			bFlg = 'none';
		}
		if ('' != dNode[i].id && undefined != dNode[i].id && null != dNode[i].id) {
			document.getElementById(dNode[i].id).style.display = bFlg;
		}
	}
	return false;
}



//** os check (win/mac only) **//
/*
var sOsName = navigator.appVersion;
var sO = '';
if (-1 != sOsName.indexOf('Mac')) {
  sO = 'mac';
} else {
  sO = 'win';
}
*/



//** browser check (opera/safari/ie/nn only) **//
/*
var sBrowser = navigator.appName;
var sB = '';
if (-1 != navigator.userAgent.indexOf('Opera')) {
  sB = 'op';
} else if (-1 < navigator.appVersion.indexOf('Safari')) {
  sB = 'sa';
} else if ('M' == sBrowser.charAt(0)) {
  sB = 'ie';
} else if ('N' == sBrowser.charAt(0)) {
  sB = 'nn';
} else {
  sB = 'ot';
}
*/



//** customize function **//
var nTopicMore = 0;
function topicMore() {
	var imgArray = new Array('/img/btn-more.gif','/img/btn-close.gif');
	var altArray = new Array('もっと見る','一覧を閉じる');

	if (0 == nTopicMore) {
		nTopicMore = 1;
	} else {
		nTopicMore = 0;
	}
	document.getElementById('mmore').src = imgArray[nTopicMore];
	document.getElementById('mmore').alt = altArray[nTopicMore];
	Div('alltopics',nTopicMore);
}



//** cookie **//

var sProjectName = 'tokyuChintai';
var sCkNameFlag = sProjectName + 'Flag';
var sCkNameType = sProjectName + 'Type';
var nError = 0;

/* get cookie  */
function getCookie(key, tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = ' ' + document.cookie + '; path=/;';
	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('');
}

/* set cookie  */
function setCookie(key, val, tmp) {
	tmp = key + '=' + escape(val) + '; expires=Tue, 31-Dec-2030 23:59:59 GMT; path=/;';
	document.cookie = tmp;
}
function setCookieSession(key, val, tmp) {
	tmp = key + '=' + escape(val) + ';';
	document.cookie = tmp;
}

/* clear cookie  */
function clearCookie(key) {
	document.cookie = key + '=' + 'xx; expires=Tue, 1-Jan-1980 00:00:00 GMT;';
}

/* date */
function now_date() {
	var vNewDate = new Date();
	var ye = vNewDate.getYear();  if (ye < 1900) ye += 1900;
	var mo = vNewDate.getMonth() + 1;  if (mo < 10) mo = '0' + mo;
	var da = vNewDate.getDate();  if (da < 10) da = '0' + da;
	var ho = vNewDate.getHours();  if (ho < 10) ho = '0' + ho;
	var mi = vNewDate.getMinutes();  if (mi < 10) mi = '0' + mi;
	var se = vNewDate.getSeconds();  if (se < 10) se = '0' + se;
	var date = ye + '/' + mo + '/' + da + ' ' + ho + ':' + mi + ':' + se;
	return(date);
}

/* toppage view (flag = 1:borrow, 2:rent) */
function topFlag() {
	if (1 != getCookie(sCkNameFlag)) {
		Div('naviborw',0);
		Div('navirent',1);
	}
}
/* flag set (flag = 1:borrow, 2:rent) */
function flagSet(n) {
	if (n != getCookie(sCkNameFlag)) {
		setCookie(sCkNameFlag,n);
	}
}
/* rent view */
function rentView() {
	var n = gPathname.lastIndexOf(gGia) + 1;
	var sName = gPathname.substring(n);
	var pageNameArray = new Array('index.html','merit.html','support.html','area.html');
	var idNameArray = new Array('boperation','bmerit','bsupport','barea');
	var btnNameArray = new Array('gmenu-result','gmenu-merit','gmenu-system','gmenu-invite');

	for (var i = 0; i < pageNameArray.length; i++) {
		if (-1 < sName.indexOf(pageNameArray[i])) {
			document.getElementById(idNameArray[i]).src = gCommonDir + btnNameArray[i] + '-ac.gif';
			break;
		}
	}
}
/* borrow view (type = 1:design, 2:list, 3:access) */
var nType = 0;
var pageNameArray = new Array('不使用','/borrow/pickup/index.html','/borrow/list/index.html','/borrow/theme/index.html');
function borrowView() {
	var idNameArray = new Array('不使用','bpickup','blist','btheme');
	var btnNameArray = new Array('不使用','gmenu-pickup','gmenu-list','gmenu-theme');

	for (var i = 0; i < pageNameArray.length; i++) {
		if (-1 < gPathname.indexOf(pageNameArray[i])) {
			nType = i;
			setCookie(sCkNameType,nType);
			break;
		}
	}
	if (0 == nType) {
		nType = getCookie(sCkNameType);
		if (0 == nType || '' == nType) {
			nType = 2;
		}
	}
	document.getElementById(idNameArray[nType]).src = gCommonDir + btnNameArray[nType] + '-ac.gif';
}
function ref() {
	window.location.href = pageNameArray[nType];
	return false;
}
