
/***********************************************************************
	mt.js
		Last Update : Jul.25.2005
***********************************************************************/



/*設定
***********************************************************************/

//カテゴリーリスト
//※表示させたい順番に「,」で区切って記述してください
//※名前を「' '」で囲むのを忘れずに。
//※カテゴリを変更したら、必ず「/marble_tile/custom.txt」の変数(BG_FORM_DATA)の値も修正してください

category_List=['Diary','News','Chop!','Repair','Sale'];


//サムネイルサイズ上限
//※このサイズ以上の画像をリサイズ(このサイズ未満は原寸表示)
rimitW=160;
rimitH=1000;


//画像のボーダー表示(0 … OFF、1 … ON)
imgBorderFlag=0;


//画像のボーダー設定
imgPadding=3;	//余白
imgBorder='1px dotted #777';	//幅・種類・色


//画像のクリックで拡大画像表示(0 … OFF、1 … ON)
showImgFlag=1;


//コメント表示ウィンドウのサイズ
cWinW=420;
cWinH=550;



/*OS & ブラウザ分岐
***********************************************************************/

_win=(navigator.appVersion.indexOf('Win')>-1)?1:0;
_mac=(navigator.appVersion.indexOf('Mac')>-1)?1:0;
_macOSX=(navigator.userAgent.indexOf('OS X')>-1)?1:0;

_safari=(navigator.userAgent.indexOf('Safari')!=-1)?1:0;
if(_safari){ var ua=navigator.userAgent.split(' '); var vn=ua[ua.length-1].split('/')[1]; var _safari13=(vn >= 312)?1:0; }
_opera=(window.opera)?1:0;
_ie=(!_opera && navigator.appName.charAt(0)=='M')?1:0;
_ie52=(_ie && navigator.userAgent.split(';')[1].split(' ')[2]>=5.2)?1:0;//for Mac OSX IE
_nn=(!_safari && navigator.appName.charAt(0)=='N')?1:0;



/*画像のリサイズ処理(onload後に実行)
***********************************************************************/

postImgList=[];

function setImgSize(){
	var Left=Top=0;
	var objW, objH, Scale, Serial;

	for(i=0; (imgObj=document.getElementsByTagName('img')[i]); i++){
		if(imgObj.className=='postImg'){

			//画像サイズ取得
			objW=imgObj.width;
			objH=imgObj.height;

			//画像サイズのリスト作成
			postImgList[imgObj.id]=[objW,objH];

			//画像リサイズ
			Scale=Math.min(Math.min(rimitW/objW,rimitH/objH),1);
			objW=Math.floor(objW*Scale);
			objH=Math.floor(objH*Scale);
			imgObj.style.width=objW+'px';
			imgObj.style.height=objH+'px';

			//画像の枠線設定
			if(imgBorderFlag){
				imgObj.parentNode.style.display='block';
				imgObj.parentNode.style.padding=imgPadding+'px';
				//imgObj.parentNode.style.border=imgBorder;
				imgObj.parentNode.style.width=objW+'px';
			}

			showLAYER(imgObj);
		}
	}
}



/*ページロード後に呼出し
***********************************************************************/

window.onload=setImgSize;



/*画像の表示
***********************************************************************/

function showImg(imgURL,imgTitle,idName){

	//フラグがfalseなら実行しない
	if(!showImgFlag) return;

	//変数宣言
	var imgWidth, imgHeight, scale, newWinLeft, newWinTop, newWinWidth, newWinHeight, html, newWin;

	//画像サイズリストからターゲットのサイズを取得
	imgWidth=postImgList[idName][0];
	imgHeight=postImgList[idName][1];

	//画像サイズがモニタサイズより大きかった場合の処理
	if(screen.availWidth<imgWidth || screen.availHeight<imgHeight){
		scale=Math.min(screen.availWidth/imgWidth,screen.availHeight/imgHeight);
		imgWidth=Math.floor(imgWidth*scale*0.8);
		imgHeight=Math.floor(imgHeight*scale*0.8);
	}

	//Image用ウィンドウ位置
	newWinLeft=(screen.availWidth-imgWidth)/2;
	newWinTop=(screen.availHeight-imgHeight)/2;

	//Image用ウィンドウサイズ
	newWinWidth=(_safari)?Math.floor(imgWidth*0.99):imgWidth;
	newWinHeight=(_safari)?Math.floor(imgHeight*0.99):imgHeight;

	//Image用HTML
	html='<html><head><title>'+imgTitle+'</title></head><body style="margin:0;padding:0;">'
	+'<div><img src="'+imgURL+'" width="'+imgWidth+'" height="'+imgHeight+'" alt=""></div>'
	+'</body></html>';

	//ウィンドウオープン
	newWin=window.open('','','width='+newWinWidth+',height='+newWinHeight+',left='+newWinLeft+',top='+newWinTop+',directories=0,location=0,menubar=0,scrollbars=no,status=0,toolbar=0,resizable=0');

	//HTMLを挿入・スクロールバーを隠す(Netscape)
	newWin.document.open();
	newWin.document.write(html);
	newWin.document.close();
	newWin.document.body.style.overflow='hidden';
}



/*送信前に未記入項目確認
***********************************************************************/
function send(type){
	var formObj=document.engine;
	switch(type){
		case 'entry':
			var checkList=[['title','タイトル'],['text','コメント']]; break;
		case 'comment':
			var checkList=[['name','名前'],['comment','コメント']]; break;
	}

	for(i=0; i<checkList.length; i++){
		if(formObj.elements[checkList[i][0]].value==''){
			alert(checkList[i][1]+'欄が未記入です');
			formObj.elements[checkList[i][0]].focus();
			return;
		}
	}
	formObj.submit();
}



/*記事を削除する前に確認
***********************************************************************/
function confirmDEL(url){
	var result=confirm('選択したログを削除してよいですか？');
	if(result){ location.href=url; }
}



/*日付挿入
***********************************************************************/
function setDate(cbObj){
	var fTextObj=document.getElementById('CGI_CUSTOM_DATE');
	var nowT, Y, Mo, D, H, Mi, S;

	if(cbObj.checked){
		nowT=new Date();
		Y=nowT.getFullYear();
		Mo=nowT.getMonth()+1; if(Mo<10) Mo='0'+Mo;
		D=nowT.getDate(); if(D<10) D='0'+D;
		H=nowT.getHours(); if(H<10) H='0'+H;
		Mi=nowT.getMinutes(); if(Mi<10) Mi='0'+Mi;
		S=nowT.getSeconds(); if(S<10) S='0'+S;

		/*fTextObj.style.display='inline';*/
		fTextObj.value=Y+'/'+Mo+'/'+D+'('+H+':'+Mi+':'+S+')';
	}else{
		fTextObj.value='';
		/*fTextObj.style.display='none';*/
	}
}



/*レイヤーの表示
***********************************************************************/
function showLAYER(div){ div.style.visibility='visible'; }



/*エントリ毎のコメント数参照
***********************************************************************/
function refComCount(Serial){
	if(logList[Serial] != null){ document.write('('+logList[Serial]+')'); }
	else document.write('(0)');
}



/*コメント用ウィンドウ表示
***********************************************************************/
function showComment(Serial,Title){
	Title=escape(Title);
	var Target='../tokyo_bbs/tokyo_bbs.cgi?mode=show&call_dir=../mt_comment&engine_dir=../tokyo_bbs&search_domain=parentSerial&search_mode=1&search_word='+Serial+'&entry='+Title;

	window.open(Target,'Comment','width='+cWinW+',height='+cWinH+',scrollbars=1,status=1,resizable=1');
}



