function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//	ë¸???¼ì?°ì?? ???ë³?
var ua	= navigator.userAgent.toLowerCase();
var isIE			= (ua.indexOf("msie")		> -1) ? true : false;
var isGecko	= (ua.indexOf("gecko")	> -1) ? true : false;

// script & css ê°???¸ì?¤ë?? ëª¨ë??
var ScriptLoader				= new Object() ;
ScriptLoader.IsLoading	= false ;
ScriptLoader.Queue			= new Array() ;
ScriptLoader.AddScript	= function( scriptPath ){ ScriptLoader.Queue[ ScriptLoader.Queue.length ] = scriptPath ; 	if ( !this.IsLoading ) this.CheckQueue() ;}
function ScriptLoader_OnLoad(){ 	if ( this.tagName == 'LINK' || !this.readyState || this.readyState == 'loaded' ) ScriptLoader.CheckQueue() ;}
ScriptLoader.CheckQueue = function() {
	if ( this.Queue.length > 0 ){ this.IsLoading = true ; var sScriptPath = this.Queue[0] ; var oTempArray = new Array() ;
		for ( i = 1 ; i < this.Queue.length ; i++ ) oTempArray[ i - 1 ] = this.Queue[ i ] ;
		this.Queue = oTempArray ; this.LoadFile( sScriptPath ) ;
	}else{
		this.IsLoading = false ;	if ( this.OnEmpty ) this.OnEmpty() ;
	}
}

ScriptLoader.LoadFile = function( filePath ) {
	var e ;
	if ( filePath.lastIndexOf( '.js' ) > 0 ){ e = document.createElement( "script" ) ; e.type	= "text/javascript" ;}else{ e = document.createElement( 'LINK' ) ; 	e.rel	= 'stylesheet' ;	e.type	= 'text/css' ;	 e.href = filePath;}
	document.getElementsByTagName("head")[0].appendChild( e ) ; 
	if ( e.tagName == 'LINK' ){	if (isIE ) e.onload = ScriptLoader_OnLoad ; else ScriptLoader.CheckQueue() ; e.href = filePath ;}else{ e.onload = e.onreadystatechange = ScriptLoader_OnLoad ; e.src = filePath ;}
}

//	??¤í?¬ë¦½??¸í????? ë¡????
//	??¤í?¬ë¦½??¸í????? ë¡????
ScriptLoader.AddScript("http://redbook.chosun.com/common/200707/dhtm/prototype.js");
ScriptLoader.AddScript("http://redbook.chosun.com/common/200707/css/chosun.css");

//	ajaxê´????
function ajaxRequest(array){	
	var url					= array[0]+".php";
	var pars				= array[1];
	var div					= array[2];
	var loadingHeight= parseInt(array[3]);
	if(array[4]){
		method = array[4];
	}else{
		method = 'get';
	}
	var loading	= "<DIV  style='width:100%;height:"+ loadingHeight +"px; text-align:center; padding-top: "+(parseInt(loadingHeight/2)-10)+"px;'><img src='/images/loading.gif' valign='absmiddle'></DIV>";

	$(div).innerHTML = loading

	var myAjax	= null;
	var myAjax	= new Ajax.Updater({success: div}, url,
								{
									method				: method,
									parameters		: pars,
									onFailure			: reportError,
									onSuccess			: setResult,
									asynchronous	: true,
									evalScripts		: true
								});	
}

var setResult = function(request){
	var divEle = document.createElement('div');
	divEle.setAttribute('id', 'opGetDiv');
	opGetDiv.innerHTML = "<textarea style='display:hidden'  id='opGetResult'>"+request.responseText+"</textarea>";
}

function ajaxResult(array, func){	
	var url					= array[0]+".php";
	var pars				= array[1];
	var div					= array[2];
	var loadingHeight= parseInt(array[3]);
	if(array[4]){
		method = array[4];
	}else{
		method = 'get';
	}
	var loading	= "<DIV  style='width:100%;height:"+ loadingHeight +"px; text-align:center; padding-top: "+(parseInt(loadingHeight/2)-10)+"px;'><img src='/images/loading.gif' valign='absmiddle'></DIV>";

	$(div).innerHTML = loading

	var myAjax	= null;
	var myAjax	= new Ajax.Updater({success: div}, url,
								{
									method				: method,
									parameters		: pars,
									onFailure			: reportError,
									onSuccess			: func,
									asynchronous	: true,
									evalScripts		: true
								});	
}

var setResult = function(request){
	var divEle = document.createElement('div');
	divEle.setAttribute('id', 'opGetDiv');
	opGetDiv.innerHTML = "<textarea style='display:hidden'  id='opGetResult'>"+request.responseText+"</textarea>";
}

var reportError	= function(request){ alert("error:"+request.responseText); }

// ë°???´í?? ê¸¸ì?´ë?? ë¦¬í??
function get_byte_length(input) { 
	var byte_length = 0; 
	for (var i = 0; i < input.value.length; i++) { 
		var one_char = escape(input.value.charAt(i)); 
		if (one_char.length == 1) byte_length ++; 
		else if (one_char.indexOf("%u") != -1) byte_length += 2; 
		else if (one_char.indexOf("%") != -1) byte_length += one_char.length / 3; 
	}
	return byte_length; 
} 


//	???ê¸? ê´????
//	???ê¸? ë³´ì?´ê¸° ??¨ê¸°ê¸?
function showHide(objId){
	if($(objId).style.display == "block"){
		$(objId).style.display = 'none';
		$("hideLayer").style.display = 'none';
		$("showLayer").style.display = 'block';
	}else{
		$(objId).style.display = 'block';
		$("showLayer").style.display = 'none';
		$("hideLayer").style.display = 'block';		
	}
}

function check_comment_length(maxByte, minHeight) {
	var content	= $("frm").comment;
	var length		= get_byte_length($("frm").comment);

	content.style.wordWrap = 'break-word'; 
	content.style.wordBreak= 'break-all'; 
	var width = content.style.width; 
	if(content.scrollHeight < minHeight) { 
		content.style.height = minHeight; 
	}else{ 
		content.style.height = content.scrollHeight + 2; 
		content.style.width = width; 
	} 
	if (length > maxByte) {
		length = "<font color='red'>"+ maxByte + " Byteê°? ì´?ê³¼ë???????µë?????.</font>";
		
	}
	$("comment_length").innerHTML = length;

	
}
var commentText = '?????¸ì?? ëª????ë¥? ??¼ì?????ê±°ë?? ê°???¸ì??ë³´ë?? ???ì¶??????? ê¸???? ê²????ë¬¼ì?? ??¼ê????? ì£¼ì????????. ê´???? ë²???? ?????? ì²?ë²? ë°???? ??? ?????µë?????.';

function submit_comment(maxLeng, minLeng){
	var f = $('frm');
	var content = f.comment;
	var length = get_byte_length(content);

	if(content.value == '' || content.value == commentText){
		alert('???ê¸???? ?????¥í?? ì£¼ì??ê¸? ë°??????????.');
		content.focus();
		return false;
	}
	if(length < minLeng){
		alert(minLeng/2+'??? ??´ì?? ?????¥í???????? ??©ë?????.');
		content.focus();
		return false;
	}
	if(length > maxLeng){
		alert('ìµ???? ?????? ??©ë?? '+maxLeng+' Byteê°? ì´?ê³¼ë???????µë?????.');
		content.focus();
		return false;
	}
	addNew_comment();
}

function addNew_comment(){
	var f			= $('frm');
	var pars	=  Form.serialize(f);

	ajaxRequest(Array("comment_process", pars, "comment_content", "60", "post"));
	f.comment.value = '';
	check_comment_length(2000, 42)

}

function board_submit_comment(maxLeng, minLeng){
	var f = $('frm');
	var content = f.comment;
	var length = get_byte_length(content);	

	if(content.value == '' || content.value == commentText){
		alert('???ê¸???? ?????¥í?? ì£¼ì??ê¸? ë°??????????.');
		content.focus();
		return false;
	}
	if(length < minLeng){
		alert(minLeng/2+'??? ??´ì?? ?????¥í???????? ??©ë?????.');
		content.focus();
		return false;
	}
	if(length > maxLeng){
		alert('ìµ???? ?????? ??©ë?? '+maxLeng+' Byteê°? ì´?ê³¼ë???????µë?????.');
		content.focus();
		return false;
	}
	addNew_comment();
}

function submit_reply(maxLeng){
	var f = $('reply_frm');
	var content = f.content;
	var length = get_byte_length(content);
	
	if(content.value == ''){
		alert('??µê????? ?????¥í?? ì£¼ì??ê¸? ë°??????????.');
		content.focus();
		return false;
	}
	
	if(length < 20){
		alert('10ê¸???? ??´ì?? ??¨ê²¨ì£¼ì?¸ì??');
		content.focus();
		return false;
	}
	if(length > maxLeng){
		alert('ìµ???? ?????? ??©ë?? '+maxLeng+' Byteê°? ì´?ê³¼ë???????µë?????.');
		content.focus();
		return false;
	}
	addNew_reply();
}

function addNew_reply(){
	var f			= $('reply_frm');
	var pars	=  Form.serialize(f);

	ajaxRequest(Array("reply_process", pars, "COMMENT_VIEW", "60", "post"));	

}


// ?????¥ê????? NULL??¸ì?? ì²´í?? 
function is_null(input) { return (input.value == null || input.value == ""); }

	function delete_file() {

		var start_pos, end_pos
		var sel = frm_board.attached_file;

		for (var i = 0; i < sel.options.length; i++) {
		
			if (sel.options[i].selected) {
				start_pos = 0
				end_pos = sel.options[i].value.indexOf("||") - 1;
				file_size.innerHTML = parseInt(file_size.innerHTML) - sel.options[i].value.substring(0, end_pos - start_pos + 1);
				sel.options[i] = null;
			}
		
		}
	}

	function upload_file() {
		window.open("http://ijakga.barobook.com/common/upload_board_file.asp?from=barobook", "upload_file", "width=400,height=163,status=yes,scrollbars=no");
	}

	function add_uploaded_file_list(upload_path, file_name, size) {

		var sel = frm_board.attached_file;

		if (sel.options.length == 1 && sel.options[0].value == "") {
			sel.options[0].value = upload_path + "||" + file_name + "||" + size;
			sel.options[0].text = file_name;
		} else {
			sel.options[sel.options.length] = new Option(file_name + "(" + size + "bytes)", size + "||" + upload_path + "||" + file_name);
		}

		file_size.innerHTML = parseInt(file_size.innerHTML) + size;
	}

	function submit_board() {
		
		var f = frm_board;
		var sel = frm_board.attached_file;

		if (is_null(f.title)) {
			alert("???ëª©ì?? ë°??????? ?????¥í???????? ??©ë?????.");
			f.title.focus();
			return false;
		}

		f.content.value = getSource();

		if (is_null(f.content)) {
			alert("??´ì?©ì?? ?????¥í???????? ??©ë?????.");
			HtmlEdit.focus;
			return false;
		}

		for (var i = 0; i < sel.options.length; i++) {
			sel.options[i].selected = true;
		}

		return true;

	}

	function init_comment_frame() {

	    var objBody	    =	ifrm_comment.document.body;
	    var objFrame	=	document.all["ifrm_comment"];

	    objFrame.style.height = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);
	    objFrame.style.width = '100%';

	}

	function reload_board_comment_list(board_id, board_item_no) {
		ifrm_comment.location.href = "/common/board_comment.asp?board_id=" + board_id + "&board_item_no=" + board_item_no;
	}



	function controlImage(_image)
{
	controlImageReSize(_image, 520, 10000);
}

function controlImageReSize(_image, nWidth, nHeight)
{
	var newX;
	var newY;
	var newHeight;
	var newWidth;
	var maxWidth = nWidth;
	var maxHeight = nHeight;
	var newImg = new Image();
	newImg.src = _image.src;
	imgw = newImg.width;
	imgh = newImg.height;
	if (imgw > maxWidth || imgh > maxHeight)
	{
		if (imgw > imgh)
		{
			if (imgw > maxWidth)
			   newWidth = maxWidth;
			else
			   newWidth = imgw;
			newHeight = Math.round((imgh * newWidth) / imgw);
		}
		else
		{
			if (imgh > maxHeight)
			   newHeight = maxHeight;
			else
			   newHeight = imgh;
			newWidth = Math.round((imgw * newHeight) / imgh);
		}
	}
	else
	{
		newWidth = imgw;
		newHeight = imgh;
	}
	newX = maxWidth / 2 - newWidth / 2;
	newY = maxHeight / 2 - newHeight / 2;
	_image.onload = null;
	_image.src = newImg.src;
	_image.width = newWidth;
	_image.height = newHeight;
}


function go_login(returl){
	location.href='http://membership.chosun.com/login/index_adult.jsp?returl='+returl;
}



function load_banner_area(display_position, objImg, main_class) {

		
		var url = "/banner/call_banner.php";
		var pars = "display_position="+ display_position+"&objImg="+objImg+"&main_class="+main_class;

		var myAjax = null;
			myAjax = new Ajax.Request (
				url,
				{
					method: 'get',
					asynchronous: true,
					parameters: pars,
					onSuccess: show_banner
				});
	}

	function show_banner(request) {
		
		var reJson =  request.responseText; 				// ??´ì?©ì?? ??½ì?´ì?¨ë??	
		var evalData = eval("(" + reJson + ")");				// ?????´ì?? ??´ì?©ì?? JSON Object ??????ë¡? ë³????
		var isBanner = evalData.banner[0].isBanner;	

		// ë°°ë???????¼ì??ë¬´ë?? ì²´í?? ??? ?????¼ë©´ ê´?ê³?????????????
		if(isBanner == "Y"){
			
			imgSrc		= evalData.banner[0].filename;		
			imgObj		= $(evalData.banner[0].objImg);
			link_url	= evalData.banner[0].link_url;

			strHTML	=		"<a href="+ link_url + " target=\"_blank\">";
			strHTML	+=	"<img src=\""+imgSrc+"\" border=\"0\">";
			strHTML	+=	"</a>"
			imgObj.innerHTML = strHTML;
			imgObj.style.display = 'block';
		}else{
			imgObj = $(evalData.banner[0].objImg);
			imgObj.style.display = 'none';
		}
			
	}


	// ë¬¸ì?? ë©????
	function mail_open(url, Width, Height){
		window.open(url, 'mail_frm', 'toolbas=no,scrollbars=no,width='+Width+',height='+Height);
	}