/* ブラウザの判定 */
var ie = ie4 = ie5 = false;
var ns = ns4 = ns6 = false;
var op = op6 = op7 = false;
var mz = false;

/* 個別判定 */
(document.all)?((document.getElementById)?((document.bgColor)?ie5=true:
(document.createTextNode)?op7=true:op6=true):ie4=true):
((document.layers)?ns4=true:((document.getElementById)?ns6=true:void(0)));

/* 大別判定 */
ie = (ie4 || ie5);
ns = (ns4 || ns6);
op = (op6 || op7);

function onload_main() {
	if (arg['edt']=='on') {
		show_editor(true);
	}
	e('srb').value = '';
	if (typeof arg['msg'] != 'undefined') { e('system_msg').innerHTML = decodeURI(arg['msg']); }
	onload_set_srb();
	setup_fancyzoom();
}

function setup_fancyzoom() {
	setupZoom();
}

/* */
var toid;

function onload_set_srb() {
	toid = setTimeout("onload_set_srb_do()",5000);
}

function onload_set_srb_do() {
	e('srb').value = 'on';
	e('ce_submit').value = '　投稿　';
	clearTimeout(toid);
}

/* 履歴を残さないリンク */
function linkto(url,enc,win) {

	if (enc != undefined) document.charset=enc;
	if (enc == undefined) url = encodeURI(url);

	if (win == undefined) {

		if (ie) {
			location.href = url;
		} else {
			location.replace (url);
		}

	} else {

		window.open(url);

	}

	if (enc != undefined) document.charset='utf-8';
}

function select_option(eid,value) {
	element = e(eid);
	for (i=0;i<element.options.length;i++) {
		if (element.options[i].value == value) {
			element.options[i].selected = true;
			break;
		}
	}
}

function radio_value(radio) {
	val = '';
	for (i=0; i<radio.length; i++) {
		if (radio[i].checked) {
			val = radio[i].value;
		}
	}
	return val;
}

function e(id) {

	if (ie) {
		obj = document.all(id);
	} else {
		obj = document.getElementById(id);
	}

	return (obj);
}

// Ajax を使って HTML を埋め込む
function includeHTML(tagid,url,msg) {

	if (msg!='') { document.getElementById(tagid).innerHTML = msg; }

	var XMLhttpObject = null;
	try {
		XMLhttpObject = new XMLHttpRequest();
	} catch(e) {
		try {
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				return null;
			}
		}
	}

	if (XMLhttpObject) {
		XMLhttpObject.onreadystatechange = function() {
			if ((XMLhttpObject.readyState == 4) && (XMLhttpObject.status == 200)) {
				document.getElementById(tagid).innerHTML = XMLhttpObject.responseText;
			}
		}
		XMLhttpObject.open("GET",url,true);
		XMLhttpObject.send(null);
	}

}

// エディタフォームの表示切替
function show_editor(show) {

	if (show) {

		e('comment_editor_form').style.display = '';
		e('comment_editor_show').style.display = 'none';
		e('comment_editor_hide').style.display = '';

	} else {

		e('comment_editor_form').style.display = 'none';
		e('comment_editor_show').style.display = '';
		e('comment_editor_hide').style.display = 'none';

	}

}

function show_delpost_info() {

	alert('この画像は削除スポットにあります。将来削除される可能性があります。');

}

// actを設定してsubmitする
function action_submit(vact,cfmsg) {
	if (cfmsg != '') {
		if (!confirm(cfmsg)) {
			return false;
		}
	}
	e('act').value = vact;
	return true;
}

// Cookie 設定関数
function setCookie(name,value,expire) {
	document.cookie
		= name + '=' + escape(value)
		+ ((expire==null)?'':('; expires='+expire.toGMTString()))
	;
}

// Cookie 取得関数
function getCookie(name) {
	var search = name + '=';
	if (document.cookie.length>0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1){
			offset += search.length;
			end     = document.cookie.indexOf(';',offset);
			if(end == -1)
				end = document.cookie.length;
			//return unescape(document.cookie.substring(offset,end));
			return decodeURIComponent(document.cookie.substring(offset,end));
		}
	}
	return null;
}

function setCookieValue(name,field,def) {
	var cval = getCookie(name);
	if (cval != null) {
		e(field).value = cval;
	} else {
		e(field).value = def;
	}
}

// GETパラメータを取得 ==============================================

var arg = new Object();

getArg();

function getArg() {

	var q = location.href + '&';
	q = q.match(/\?(.+)/);

	if (q != null && q.length == 2) {

		q = q[1];
		while ( q != null && q != '' ) {
			qq = q.match(/(.+?)=(.*?)&/);
			q = RegExp.rightContext;
			if ( qq != null ) {
				arg[qq[1]] = qq[2];
			}
		}

	}

}
