function openImageBox(type) {
	window.open("/imagebox.php?o=1&s="+type,"ArticleImageBox","width=630,height=400,toolbar=no,scrollbars=yes,status=no");
}

function openFileBox(type, target, opt) {
	window.open("/imagebox.php?a=file_input&s="+type+"&t="+target,"ArticleImageBox","width=630,height=490,toolbar=no,scrollbars=yes,status=no");
}

function openURLBox(type, target, opt) {
	value1 = prompt("Please insert URL. e.g) http://fbl.riceblast.snu.ac.kr/");
	value2 = prompt("Please insert the name of URL. e.g) Go to the FBL Blog");
	putURL(type, target, value1, value2);
}

function save_pos(obj) {
	if (obj.createTextRange) obj.currentPos = document.selection.createRange().duplicate();
	return true;
}

function set_tag_support(obj, prefix, postfix) {
	if (document.selection) {
		if (obj.createTextRange && obj.currentPos) {
			obj.currentPos.text = prefix + obj.currentPos.text + postfix;
			obj.focus();
			save_pos(obj);
		} else obj.value = obj.value + prefix + postfix;
	} else if (obj.selectionStart && obj.selectionEnd) {
		var s1 = obj.value.substring(0, obj.selectionStart);
		var s2 = obj.value.substring(obj.selectionStart, obj.selectionEnd);
		var s3 = obj.value.substring(obj.selectionEnd);
		obj.value = s1 + prefix + s2 + postfix + s3;
	} else obj.value += prefix + postfix;
	return true; 
} 

function putImage(id, to) {
	//var imageurl = "[img|id="+id+"|border="+document.input.bordersize.value+"|vspace="+document.input.vspacesize.value+"|hspace="+document.input.hspacesize.value+"|align="+document.input.aligntype.value+"]";
	var imageurl = "<img id="+id+" border="+document.input.bordersize.value+" vspace="+document.input.vspacesize.value+" hspace="+document.input.hspacesize.value+" align="+document.input.aligntype.value+">";

	if ( to == 'input' ) {
		opener.set_tag_support(opener.document.input.comment, imageurl, '');
	} else {
		opener.set_tag_support(opener.document.modify.comment, imageurl, '');
	}	
	this.close();
}

function putFile(id, file_name, to, target) {
	var fileurl = "[file|id="+id+"|name="+file_name+"]";
	var obj = eval('opener.document.'+to+'.'+target);
	opener.set_tag_support(obj, fileurl, '');
	this.close();
}

function putURL(to, target, value1, value2) {
	var url = "[url|url="+value1+"|name="+value2+"]";
	var obj = eval('document.'+to+'.'+target);
	set_tag_support(obj, url, '');
}

function checkLoginData(form) {
	if (form.id.value == '') {
		alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		form.id.focus();
		return;
	}

	if (form.pw.value == '') {
		alert('¾ÏÈ£¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		form.pw.focus();
		return;
	}

	form.submit();
}

function checkKeyPw() {
	if (event.keyCode == 13) {
		checkLoginData(document.login);
	}
}


