// chuoh.js
// common scripts for www.chuoh.co.jp

var W = 800
var IW
var TD = '/'
var SearchCreated = false
var Search
var ISRESIZEFIX = false

// CSS for mac
if (navigator.platform == 'MacPPC') {document.write('<link rel="stylesheet" href="'+TD+'css/chuoh_mac.css" type="text/css">');}


function get_innerwidth()
{
	if (is.ns5) {
		IW = document.body.offsetWidth
	}
	else if (is.ns) {
		IW = (navigator.platform == 'MacPPC') ? window.outerWidth-27 : window.innerWidth-16;
	}
	else if (is.ie) {
		IW = document.body.clientWidth
	}
}

// search tab
function write_search()
{
	with (document) {
		write('<div id="SearchDiv" style="position: absolute; left: 119px; top: -300px; height: 326px; width:400px; visibility: hidden; z-index: 4;">')
		write('<form name="SearchForm" action="'+TD+'books/search.php" method="get">')
		write('<table cellpadding="1" cellspacing="0" border="0" bgcolor="#C0C0C0" height="300"><tr><td valign="bottom">')
		write('<table cellpadding="2" cellspacing="0" border="0" bgcolor="#EEEEEE">')
		write('<tr><td colspan="4"><img src="'+TD+'img/0.gif" width="1" height="100"</td></tr>')
		write('<tr><td class="word-s" nowrap>'+unescape(is.ie?'%u30AD%u30FC%u30EF%u30FC%u30C9':'%83L%81%5B%83%8F%81%5B%83h')+'</td><td class="word-s" colspan="2"><input type="text" name="KEYWORD" size="25" maxlenth="20" class="keyword"></td><td align="center"><input type="image" src="'+TD+'img/searchbtn.gif" width="53" height="18" border="0"></td></tr>')
		write('<tr><td class="word-s" align="right" nowrap>'+unescape(is.ie?'%u691C%u7D22%u5BFE%u8C61':'%8C%9F%8D%F5%91%CE%8F%DB')+'</td><td class="word-s"><select name="TARGET" class="target"><option value="BOOKDESC">'+unescape(is.ie?'%u66F8%u7C4D%u5185%u5BB9':'%8F%91%90%D0%93%E0%97e')+'<option value="TITLE">'+unescape(is.ie?'%u66F8%u7C4D%u540D':'%8F%91%90%D0%96%BC')+'<option value="AUTHOR">'+unescape(is.ie?'%u8457%u8005':'%92%98%8E%D2')+'<option value="ISBN">ISBN'+unescape(is.ie?'%u30B3%u30FC%u30C9':'%83R%81%5B%83h')+'</select></td><td class="word-s" class="word-s" align="right">'+unescape(is.ie?'%u8868%u793A%u4EF6%u6570':'%95%5C%8E%A6%8C%8F%90%94')+'</td><td class="word-s"><select name="PER_PAGE" class="perpage"><option value="10">10<option value="20">20<option value="50">50</select>'+unescape(is.ie?'%u4EF6':'%8C%8F')+'</td></tr>');
		write('</table></td></tr></table>')
		write('<a href="javascript:move_search();"><img src="'+TD+'img/searchtab.gif" width="120" height="26" border="0"></a>')
		write('</form>')
		write('</div>')
	}
}

function move_search()
{
	if (Search.y == SEARCH_Y) {
		Search.moveTo(null,SEARCH_Y+50)
		resizefix()
		Search.doc.forms['SearchForm'].elements['KEYWORD'].focus()
	}
	else {
		Search.moveTo(null,SEARCH_Y)
	}
}

function centerize(lyr, offsetx)
{
	lyr.moveTo((IW-W > 0) ? Math.floor((IW-W)/2)+offsetx : offsetx, null)
}

// resize event handling
window.onresize = function()
{
	if (is.ns4) {
		history.go(0)
	}
	else {
		get_innerwidth()
		if (SearchCreated) centerize(Search, SEARCH_X);
		each_centerize()
		//resizefix()
	}
}

// onload init handling
function default_init(not_search)
{
	DynLayerInit()
	get_innerwidth()

	if ( not_search != true ) {
		Search = new DynLayer('SearchDiv')
		SEARCH_X = Search.x
		centerize(Search, SEARCH_X)
		SEARCH_Y = Search.y
		Search.show()
		SearchCreated = true
	}
	Loading.hide()
}

function write_loading()
{
	document.write('<div id="LoadingDiv"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="center"><img src="'+TD+'img/nl.gif" width="123" height="11" vspace="25"></td></tr></table></div>')
}

function resizefix()
{
	if (ISRESIZEFIX) return;
	ISRESIZEFIX = true
	if ((navigator.platform == 'MacPPC' && is.ie) || is.ie5 ) {
		window.resizeBy(1,1);
		window.resizeBy(-1,-1);
	}
	ISRESIZEFIX = false
}