// ����n ����
if (document.getElementById && !document.all){
	var isNS = true;
	var isIE = false;
} else {
	var isIE = true;
	var isNS = false;
}
/*
window.onerror = HandleError;
function HandleError(message, url, line) {
  var str = "An error has occurred in this dialog." + ""
  + "Error: " + line + "" + message;
  window.status = str;
  return true;
} // Error �߻�� ����
*/
// Microsoft IE���� captureEvent�� ����� ��� ȣȯ; '�Ͽ� ���
if(!window.event && window.captureEvents) {
	// set up event capturing for mouse events (add or subtract as desired)
	window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
	// set window event handlers (add or subtract as desired)
	window.onmouseover = WM_getCursorHandler;
	window.onmouseout = WM_getCursorHandler;
	window.onclick = WM_getCursorHandler;
	window.ondblclick = WM_getCursorHandler;
	// create an object to store the event properties 
	window.event = new Object;
}

// Microsoft IE�� Netscape�� Event Handler ȣȯ
function WM_getCursorHandler(e) {
	// set event properties to global vars (add or subtract as desired)
	window.event.clientX = e.pageX;
	window.event.clientY = e.pageY;
	window.event.x = e.layerX;
	window.event.y = e.layerY;
	window.event.screenX = e.screenX;
	window.event.screenY = e.screenY;
	// route the event back to the intended function
	if ( routeEvent(e) == false ) {
		return false;
	} else {
		return true;
	}
}

// �۾� �� �̹���
var loading = "&nbsp;<img src=/img/common/loading.gif>";

// �ʼ� �Է°� Ȯ��
function validateRequired(field) {
    var bValid = false;
    if (field.type == 'text' ||
        field.type == 'textarea' ||
        field.type == 'file' ||
        field.type == 'select-one' ||
        field.type == 'radio' ||
        field.type == 'password') {
        
        var value = '';
		// ��; ��n�´�.
		if (field.type == "select-one") {
			var si = field.selectedIndex;
			if (si >= 0) {
				value = field.options[si].value;
			}
		} else {
			value = field.value;
		}
          
        if (value == '') {
        	alert(field.title + "(;)�� �Է��Ͻʽÿ�.");
        	field.focus();
        	bValid = false;
        } else {
        	bValid = true;
        }
    }
    return bValid;
}

// �ҽ� �ʵ��� ������ ���; ��� �� ��� �ʵ��� ��8�� ġȯ�Ѵ�.
function makeShort(src, dest) {
	var str;
	str = src.value;
	str = trim(str);
	dest.value = str;
}

// ���ڿ��� ��� f��
function trim(str) {
	var len, index;
	if (str.length > 0) {
		while(true){
			index = str.indexOf(" ");
			if (index == -1) break;
			len = str.length;
			str = str.substring(0, index) + str.substring((index+1),len);
		}
	}
	return str;
}

// ���� ���� Ȯ��
function isNumber(obj) {
	if (isNaN(obj.value)) {
		alert("���ڸ� �Է��Ͻʽÿ�.");
		obj.select();
		return false;
	}
	return true;
}

// d��
function Sort(obj) {
	var str = obj.value;
	var arr = new Array();
	var tmp = new Array();
	
	// ',' �յ��� ���; f���Ѵ�.
	str = str.replaceAll(", ", ",");
	str = str.replaceAll(" ,", ",");
	// ��Ʈ��; ',' ��'�� �и�
	arr = str.split(",");
	// ��Ʈ��; d��
	tmp = arr.sort();
	// �迭�� ��Ʈ��; �ϳ��� ��Ʈ��8�� ����
	obj.value = tmp.join(",");
}
function getOffsetTop(obj)
{	return obj ? obj.offsetTop + getOffsetTop(obj.offsetParent) : 0; }

function getOffsetLeft(obj)
{ return obj ? obj.offsetLeft + getOffsetLeft(obj.offsetParent) : 0; }
// �˾� â ����
function popup_window(top, width, height, url, exec) {		
	var div = $('child_popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "child_popup_window";
		div.className = "child_popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";
		Element.show(div);
	}
	go(url, div, exec);
	
	Drag.init(document.getElementById("child_popup_window"));
	
}

// �˾�â ����2
function popup_window2(top, left, width, height) {
	var div = $('popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		Element.show(div);
	}
	
	Drag.init(document.getElementById("popup_window"));
}
function setOpacity(obj,value)
{
	if(typeof(obj)=='string') obj=document.getElementById(obj);
	obj.style.opacity = (value / 100);
	obj.style.MozOpacity = (value / 100);
	obj.style.KhtmlOpacity = (value / 100);
	obj.style.filter = "alpha(opacity=" + value + ")";
}
function getViewport(){
	var w=0;
	var h=0;

	if(window.innerWidth) w=window.innerWidth;
	if(document.documentElement.clientWidth){
		var w2 = document.documentElement.clientWidth;
		if(!w || w2 && w2 < w) w=w2;
	}else if(document.body){
		w=document.body.clientWidth;
	}

	if(window.innerHeight) h=window.innerHeight;
	if(document.documentElement.clientHeight) h=document.documentElement.clientHeight;
	else if(document.body) h=document.body.clientHeight;

	return [w,h];
}
// �˾�â ��'��3
function popup_window3(top, left, width, height, url, exec) {
	var div = $('popup_window');
	var alphaDiv = $('alphaDiv');
	var alphaDiv_opacity = 15;
	var alphaDiv_color = '#000';

	alphaDiv.style.background = alphaDiv_color;
	setOpacity(alphaDiv,alphaDiv_opacity);
	Position.clone(document.body,alphaDiv);
		
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1000;
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1000;
		Element.show(div);
	}		

	
	var startupInfo = "['center']";
	var dlgPos = new Array(2);
	var dlgSize = new Array(2);
	if ( !startupInfo || !startupInfo[0] ) startupInfo = new Array('center', new Array(2), new Array(2));
	if ( !startupInfo[1] ) startupInfo[1] = new Array(2);
	
	    // set size
	if ( !startupInfo[2] || startupInfo[2][0] < 1 || startupInfo[2][1] < 1 || startupInfo[2][0] == 'undefined' || startupInfo[2][1] == 'undefined' || !startupInfo[2][0] || !startupInfo[2][1] ) {
	    div.style.display = 'block';
	    var tmp=Element.getDimensions(div);
	    dlgSize[0]=tmp.width; dlgSize[1]=tmp.height;
	    div.style.display = 'none';
	}
	else
	{
	    dlgSize=startupInfo[2];
	}
	
	Position.prepare();
	// set position
	if ( startupInfo[0]=='center' ) {
		var scrPos=new Array(Position.deltaX,Position.deltaY);
		var scrSize=getViewport();
	
	    startupInfo[1][0]=scrPos[0]+scrSize[0]/2-dlgSize[0]/2;
	    startupInfo[1][1]=scrPos[1]+scrSize[1]/2-dlgSize[1]/2;
	}
	else if ( startupInfo[0]=='absolute' )
	{
	}
	else if ( startupInfo[0]=='relative' )
	{
	    var scrPos=new Array(Position.deltaX,Position.deltaY);
	
	    startupInfo[1][0]+=scrPos[0];
	    startupInfo[1][1]+=scrPos[1];
	}
	
	// drawing dialogBox
	if ( startupInfo[1] && startupInfo[1][0] && startupInfo[1][1] )
	{
	    dlgPos=startupInfo[1];
	
	    div.style.left=dlgPos[0]+'px';
	    div.style.top=dlgPos[1]+'px';
	    if(dlgSize[0]>0 && dlgSize[1]>0)
	    {
	        div.style.width=dlgSize[0]+'px';
	        div.style.height=dlgSize[1]+'px';
	    }
	}
    	
	alphaDiv.style.display='block';
	div.style.display='block';
	
	go(url, div, exec);
	
	Drag.init(document.getElementById("popup_window"));
	
}
// �˾� â ����
function popup_window4(top, width, height, url, exec) {		
	var div = $('popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "popup_window";
		div.className = "popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";
		div.style.zIndex = 11;
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = (document.body.clientWidth - width)/2 + "px";		
		Element.show(div);
	}
	go(url, div, exec);	
}
// �˾� �� ��ο� �˾� â ����
function child_popup_window4(top, left, width, height, url, exec) {
	var div = $('child_popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "child_popup_window";
		div.className = "child_popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1001;
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1001;
		Element.show(div);
	}
	go(url, div, exec);
}
// �˾� �� ��ο� �˾� â ����
function child_popup_window(top, left, width, height, url, exec) {
	var div = $('child_popup_window');
	if (!div) {
		div = document.createElement("div");
		div.id = "child_popup_window";
		div.className = "child_popup_window";
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1001;
		document.body.appendChild(div);
	} else {
		div.style.top = top + "px";
		div.style.width = width + "px";
		div.style.height = height + "px";
		div.style.overflow = "auto";
		div.style.left = left + "px";
		div.style.zIndex = 1001;
		Element.show(div);
	}
	go(url, div, exec);
	
	Drag.init(document.getElementById("child_popup_window"));
	
}

function goPopup(type) {
	if (type == '1') {
		var url = "/tag/getTagList.jsp?target=book";
		popup_window3("325", "260", "600", "300", url, "");
	}
}

// f��8�� åd�� ��n�1�
function view_bookList(page, book_title) {
	book_title = trim(book_title);
	var top = "250";
	var width = "500";
	var height = "180";
	var url = "/Book.do";
	url = url + "?action=listBookByTitle";
	url = url + "&page=" + page;
	url = url + "&book_title=" + encodeURIComponent(book_title);
	var exec = "";
	popup_window(top, width, height, url, exec);
}

// �α���
function login(){
	var top = "250";
	var width = "250";
	var height = "120";
	var url = "/loginForm.do";
	var exec = "$('user_id').focus()";
	popup_window(top, width, height, url, exec);
}

// �α׾ƿ�
function logOut() {
	document.location.href = "/logOut.do";
}

// ȸ����
function signUp() {
	var top = "250";
	var width = "270";
	var height = "230";
	var url = "/signUpForm.do";
	var exec = "";
	popup_window(top, width, height, url, exec);
}

// ȸ��d��
function member() {
	document.location.href = "/Member.do?action=memberInfo";
}

// �޷�
function view_calendar(formNM, objNM, preDate, size, pos, year, month) {
	var top = "250";
	var width = "400";
	var height = "280";
	var url = "/util/calendar.jsp?formNM=" + formNM + "&objNM=" + objNM + "&preDate=" + preDate + "&size=" + size + "&pos=" + pos + "&year=" + year + "&month=" + month;
	var exec = "";
	popup_window(top, width, height, url, exec);
}

// �˾� ���� �޷�
function view_child_calendar(formNM, objNM, preDate, size, pos, year, month) {
	var top = "300";
	var width = "400";
	var left = (document.body.clientWidth - width)/2 + "";
	var height = "280";
	var url = "/util/childCalendar.jsp?formNM=" + formNM + "&objNM=" + objNM + "&preDate=" + preDate + "&size=" + size + "&pos=" + pos + "&year=" + year + "&month=" + month;
	var exec = "";
	child_popup_window(top, left, width, height, url, exec);
}

// Ưd DIV 'ġ�� ����; ����
function go(url, dest, exec){
	
	new Ajax.Updater(
					 dest, 
					 url, 
					 {
					  asynchronous: true, 
					  method: 'get', 
					  onLoading: Element.update(dest, loading), 
					  onComplete: function(result){
					  				eval( '(' + exec + ')' ); 
					  			  },
					  evalScripts: true 
					 }
					);
	
}

// Ưd DIV 'ġ�� ����; ����(POST���)
function goPost(url, dest, postString, exec){
	new Ajax.Updater(dest, 
					 url, 
					 {
					  parameters: postString, 
					  onLoading: Element.update(dest, loading), 
					  onComplete: function(result){ 
					  				eval(exec); 
					  			  },
					  evalScripts: true 
					 }
					);
}

// ���ڿ����� Ưd �κ��� ���ڿ�; ��ü
String.prototype.replaceAll = function( searchStr, replaceStr ) {
	var temp = this;
	while( temp.indexOf( searchStr ) != -1 ) {
		temp = temp.replace( searchStr, replaceStr );
	}
	return temp;
}

// �˻�
function search() {
	var keyword_type = "";
	var keyword_content = "";
	keyword_type = $('keyword_type').value;
	keyword_content = $('keyword_content').value;
	
	if (keyword_content == "" || 
	    keyword_content == "%") {
		alert("�˻� �Է��Ͽ� �ֽʽÿ�.");
		$('keyword_content').focus();
		return;
	} else if (keyword_content.length < 2) {
		alert("2���� �̻��� �˻� �Է��Ͽ� �ֽʽÿ�.");
		$('keyword_content').select();
		$('keyword_content').focus();
		return;
	}
	
	if (keyword_type == '11' || keyword_type == '12' ||
	    keyword_type == '13' || keyword_type == '14' ||
	    keyword_type == '15') {	
		getBookSearchList(keyword_type, keyword_content);
	} else if (keyword_type == '21') {
		getReviewSearchList(keyword_type, keyword_content);
	} else if (keyword_type == '31') {
		getTagSearchList(keyword_type, keyword_content);
	} else if (keyword_type == '41') {
		getSentenceSearchList(keyword_type, keyword_content);
	} else {
		document.location.href = "/Search.do?action=searchForm&keyword_content=" + encodeURIComponent(keyword_content);
	}
	
}

// �̹��� ���� �ڵ� v��
function resizeImgByHeight(img, height) {  
	if(img.height > height) {
		img.height = height;
	}
}

// �̹��� ���� �ڵ� v��
function resizeImgByWidth(img, width) {
	if (img.width > width) {
		img.width = width;
	}
}

// ������ ������ �����
function addComma(val) {
	tmpLen = val.length;
	c = Math.floor(tmpLen/3);
	d = tmpLen % 3;
	if ( d == 0 ) {
		d = 3;
		c--;
	}
	ee = val.substr(0,d)
	for( i = 0; i < c; i++) {
		ee+="," + val.substr( 3*i+d, 3 );
	}
		
	return ee;

}

// ����õ� ������ �����Ϳ��� ','�� f��
function delComma(inputNumber, sTargetStr, sReplaceStr) {
	var pos = 0;
	var preStr = "";
	var postStr = "";
	pos = inputNumber.indexOf(sTargetStr);
	while (pos != -1) {
		preStr  = inputNumber.substr(0,pos);
		postStr = inputNumber.substr(pos+1,inputNumber.length);
		inputNumber = preStr + sReplaceStr + postStr;
		pos = inputNumber.indexOf(sTargetStr);
	}
	return inputNumber;
}

// ������ ����(IE������ ���)
function copyURL(sData,sMode) {
	switch(sMode) {
		case "link":
			var sMsg = '�� �ּҰ� ����Ǿ�4ϴ�.\n';
			break;
		case "title":
			var sMsg = '�� f��� �ּҰ� �Բ� ����Ǿ�4ϴ�.\n';
			break;
			default:
			var sMsg = '����Ǿ�4ϴ�.\n';
	}
	sMsg += '�ٿ��ֱ�(Ctrl + V)�� �ؼ� ����ϼ���.';
	window.clipboardData.setData('Text',sData);
	window.alert(sMsg);
}

//by kny 2007.01.25
//blog ? open
function openBlog(openURL) {
		window.open(openURL);
}

function loginCheck(){
		//alert("�α����� �ּ���");	
		loginForm();	
}

function loginIframe() {
    var width = "293";
	var height = "310";
	
	var scleft = document.documentElement.scrollLeft;
	var sctop = document.documentElement.scrollTop;
	
	var screenwidth = document.documentElement.clientWidth ;
	var screenheight = document.documentElement.clientHeight;
	var left = parseInt((screenwidth - width)/2) + scleft;
	var top = parseInt((screenheight - height)/2) + sctop;
                			
	var url = "Member.do?action=loginIframe";
	var exec = "";
	popup_window4(top, width, height, url, exec);
}

loginForm = function() {	
			
	var width = "293";
	var height = "310";
	
	var scleft = document.documentElement.scrollLeft;
	var sctop = document.documentElement.scrollTop;
	
	var screenwidth = document.documentElement.clientWidth ;
	var screenheight = document.documentElement.clientHeight;
	var left = parseInt((screenwidth - width)/2) + scleft;
	var top = parseInt((screenheight - height)/2) + sctop;
                			
	var url = "Member.do?action=loginForm";
	var exec = "";
	popup_window4(top, width, height, url, exec);	
}

// Ưd�� ���� ���̰� ��d�� ���̸� �ʰ��ϴ��� Ȯ���Ѵ�.
function checkMaxLength(val, len) {
	if (val.length > len) {
		alert(len + "�ڸ��� �ʰ��Ͽ� �Է��Ͽ��4ϴ�.");
		return false;
	} else {
		return true;
	}
}

// Ưd�� ���� ���̰� ��d�� �Ѱ迡 �̴��ϴ��� Ȯ���Ѵ�.
function checkMinLength(val, len) {
	if (val.length < len) {
		alert(len + "�ڸ� �̻� �Է��Ͻʽÿ�.");
		return false;
	} else {
		return true;
	}
}

// Ưd�� ���� ���̰� ��d�� ��'�� ��w�ϴ��� Ȯ���Ѵ�.
function checkLength(val, minLen, maxLen) {
	if (val.length > maxLen) {
		alert(maxLen + "�ڸ��� �ʰ��Ͽ� �Է��Ͽ��4ϴ�.");
		return false;
	} else if (val.length < minLen) {
		alert(minLen + "�ڸ� �̻� �Է��Ͻʽÿ�.");
		return false;
	} else {
		return true;
	}
}

// �α��� �� �� �7� �޼��� Ȯ���Ѵ�.
function checkLoginMsg(error_msg) {
	if (error_msg.length > 0) {
		alert("�α��� �7� : " + error_msg);
		document.LoginForm.user_id.focus();
	}
}

/*-------------------------------------------------------------------------
 	Spec      : Open Window
 	Parameter : winurl    -> �ش� ������
	Parameter : winname   -> �ش� Window Name
	Parameter : winwidth  -> Window Width Size
	Parameter : winheight -> Window Heigth Size
	Parameter : adjust    -> Window 'ġ 3: ����
	Parameter : resizable -> Window âv���
	Parameter : scrollbar -> Window Scroll
	Example   : a href="openwin()";
-------------------------------------------------------------------------*/
function openwin( winurl, winname, winwidth, winheight, adjust, resizable, scrollbar ) {
	
    var width  = winwidth;
    var height = winheight;
    var left, top;

    switch( adjust ) {
	case 1: //top left aligned
		left = top = 0;
		break;
	case 2: //top RIGHT aligned
		left = window.screen.availWidth - width - 10;
		top = 0;
		break;
	case 3: //centered
		left = (window.screen.availWidth - width) / 2;
		top = (window.screen.availHeight - height) / 2;
		break;
	case 4: //bottom left aligned
		left = 0;
		top = window.screen.availHeight - height - 25 - 10;
		break;
	case 5: //bottom RIGHT aligned
		left = window.screen.availWidth - width - 10;
		top = window.screen.availHeight - height - 25 - 10;
		break;
    }
    var dynamic = "";
    if( adjust > 0 ) dynamic = "left=" + left + ",top=" + top;
    dynamic = dynamic + ",width=" + width + ",height=" + height;
    if( resizable ) dynamic = dynamic + ",resizable=yes";
    else dynamic = dynamic + ",resizable=no";
    if( scrollbar ) dynamic = dynamic + ",scrollbars=yes";
    else dynamic = dynamic = dynamic + ",scrollbars=no";
    remotecontrol = window.open( winurl, winname, "toolbar=no," + dynamic + ",directories=no,status=no,menubar=no");
}