//----- director functions -----
selection = null;
function buildD_PD(which) {
	var src = document.location.href;
	var myId = src.substring(src.lastIndexOf('/')+1,src.lastIndexOf('.'));
	var h = '<select name="'+((which != null)?('ディレクター指名'+which):'')+'" onchange="selectD_PD(this)" style="width:100%" size="1">';
	if (window.name=='D_window') { curD = myId } else { h += '<option value="">▼選択' }
	for (var id in DList) { h += '<option value="'+id+':'+DList[id].name+'"'+((myId == id)?' selected':'')+'>['+DList[id].loc+']'+DList[id].name }
	h += '</select>';
	document.write(h);
}
function selectD_PD(who) {
	if (window.name=='D_window') {
		var id = who.value;
		var dlm = id.indexOf(':');
		if (dlm > 0) id = id.substring(0,dlm);
		if (who.value != '') { document.location.href = id+'.html'; curD = id }
	}
}
function showDInfo(which) {
	var id = document.forms[0]['ディレクター指名'+which].value;
	if (id != "") {
		var dlm = id.indexOf(':');
		if (dlm > 0) id = id.substring(0,dlm);
		openWindow('info/'+id+'.html','D_window');
		selected = which;
	}
}
function selectD_info() {
	if (self.opener.document.location.href.indexOf('coord.html') >= 0) {
		self.opener.setD_PD(curD);
	} else {
		self.opener.top.document.location.href="../coord.html?"+curD;
	}
	self.close();
}
function setD_PD(curD) {
	if (curD == null) {
		var src = document.location.href;
		var Di = src.lastIndexOf('?');
		if (Di < 0) { return }
		var curD = src.substring(Di+1);
		var curPD = document.forms[0]['ディレクター指名1'];
	} else {
		var curPD = document.forms[0]['ディレクター指名'+selected];
	}
	i = 0;
	for (var id in DList) {
		i++; if (id==curD) { break }
	}
	curPD.selectedIndex=i;
}
//----- list functions -----
clicked = false;
function toggleListItem(who) {
	var p = who.offsetParent;
	p.id = (p.id == '') ? 'o' : '';
}
function clickItemLink(wName) {
	clicked = true;
	openWindow('',wName);
}
function clickBtn(link) {
	clicked=true;
	top.location.href=link;
}
function clickDItem(who) {
	if (!clicked) {
		var link = 'info/'+who.id+'.html';
		openWindow(link,'D_window');
	} else { clicked = false }
}
function clickFAItem(who) {
	if (!clicked) { openWindow(FAList[who.id],'FA_window') }
	else { clicked = false }
}
//----- db functions -----
function addDirector(id,loc,name) {
	if (window.DList == null) { DList = {} };
	DList[id] = { loc:loc,name:name }
}
function addFAItem(id,url) {
	if (window.FAList == null) { FAList = {} };
	FAList[id] = url;
}
//----- window functions -----
function openWindow(link,wName,maxW,maxH) {
	switch (wName) {
		case 'FA_window' : var p = 'directories,location,menubar,resizable,scrollbars,status,toolbar=1'; break;
		case 'ext_window' : var p = 'directories,location,menubar,resizable,scrollbars,status,toolbar=1'; break;
		default : var p = 'resizable,scrollbars=1';
	}
	if (maxW == null) { maxW = 800 }
	if (maxH == null) { maxH = 640 }
	var d = calcPopDims(maxW,maxH);
	p += ',width='+d.w+',height='+d.h+',left='+d.l+',top='+d.t;
	if (wName == null) { wName = '_window' };
	window.open(link,wName,p);
}
function calcPopDims(maxW,maxH) {
	var sw = window.screen.availWidth;
	var sh = window.screen.availHeight;
	var w = (sw <= maxW*1.25) ? Math.round(sw*0.8) : maxW;
	var h = (sh >= maxH*1.25) ? Math.round(sh*0.8) : maxH;
	var l = Math.round((sw-w)/2);
	var t = Math.round((sh-h)/4);
	return {w:w,h:h,l:l,t:t};
}

