

//==================================================================
// ¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ° ¸·±â / ¿À¸¥ÂÊ ÄÁÅØ½ºÆ®¸Þ´º disable
function right(e) { 
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) { 
		return false; 
	} else if (navigator.appName == 'Microsoft Internet Explorer' && 
			(event.button == 2 || event.button == 3)) { 
		return false; 
	} 
	return true; 
} 

function processKey() { 
	if( (event.ctrlKey == true && 
			(event.keyCode == 78 || event.keyCode == 82)) || 
			(event.keyCode >= 112 && event.keyCode <= 123)) { 

	  event.keyCode = 0; 
	  event.cancelBubble = true; 
	  event.returnValue = false; 
	} 
}

//document.onmousedown	= right; 
//document.oncontextmenu	= function(){return false;} 
//document.onkeydown = processKey; 

//==================================================================

// ÄíÅ°°ªÀ» °¡Á®¿Â´Ù
function get_cookies(name) { 

	var cookies_name = name + "="; 
	var x = 0; 

	while ( x <= document.cookie.length ) { 
		var y = (x + cookies_name.length); 
		if (document.cookie.substring(x, y) == cookies_name) { 			
			if ((end_of_cookies = document.cookie.indexOf(";", y)) == -1) end_of_cookies = document.cookie.length; 
				return unescape(document.cookie.substring( y, end_of_cookies)); 
        } 

		x = document.cookie.indexOf(" ", x) + 1; 
		if (x == 0) break; 
    } 
	return ""; 
} 

 
// ÄíÅ°°ªÀ» ÀúÀåÇÑ´Ù
function set_cookies(name, value, expire_days) { 

	if (expire_days != null) {
		var todayDate = new Date(); 
		todayDate.setDate( todayDate.getDate() + expire_days); 
	    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
	} else {
	    document.cookie = name + "=" + escape( value ) + "; path=/;" 
	}
} 


/* Browser Info*/
var ua			= navigator.userAgent.toLowerCase();
var isMSIE	= (ua.indexOf("msie") > -1) ? true : false;
var isGecko	= (ua.indexOf("gecko") > -1) ? true : false;
var isOpera	= (ua.indexOf("opera") > -1) ? true : false;
var isMSIE7 = (ua.indexOf("msie 7") > -1) ? true : false;
var isNetscape = (ua.indexOf("netscape") > -1) ? true : false;



/* Script File Load */
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 ;
	}
}

/* Check Empty Value */
function _empty(input) { return (input.value == null || input.value.replace(/ /gi,"") == ""); }

/* Return File Exp */
function _get_exp(filePath) { return filePath.slice(filePath.lastIndexOf(".")+1).toLowerCase(); }

/* Remove Space In String */
function trim(inputString) {
  if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} 

/* Byte Length*/
function _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; 
}

/* insertAfter(<>insertBefore)*/
function insertAfter(newElement, targetElement){
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement){
		parent.appendChild(newElement);
	}else{
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

// ÀÔ·Â°ª¿¡ ½ºÆäÀÌ½º ÀÌ¿ÜÀÇ ÀÇ¹ÌÀÖ´Â °ªÀÌ ÀÖ´ÂÁö Ã¼Å© 
function is_empty(input) { return (input.value == null || input.value.replace(/ /gi,"") == ""); }

// ÀÔ·Â°ªÀÌ »ç¿ëÀÚ°¡ Á¤ÀÇÇÑ Æ÷¸Ë Çü½ÄÀÎÁö Ã¼Å© 
function is_valid_format(input,format) { return (input.value.search(format) != -1); } 

// ÀÔ·Â°ªÀÌ ÀÌ¸ÞÀÏ Çü½ÄÀÎÁö Ã¼Å© 
function is_email_format(input) { 
	var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/; 
	return is_valid_format(input, format); 
} 

// ¾×¼¿ÆÄÀÏÀÎÁö ¿©ºÎ È®ÀÎ
function isExcel(str){
	var chkStr = "";
	var pos = str.lastIndexOf(".");
	chkStr = str.substring(pos);
	
	if (chkStr.toUpperCase() == ".XLS"){
		return true;
	} else {
		return false;
	}
}

// TXT ÆÄÀÏÀÎÁö ¿©ºÎ È®ÀÎ
function isText(str){
	var chkStr = "";
	var pos = str.lastIndexOf(".");
	chkStr = str.substring(pos);
	
	if (chkStr.toUpperCase() == ".TXT"){
		return true;
	} else {
		return false;
	}
}


/* window.onload ½Ã ½ÇÇàµÉ ÇÔ¼öÃß°¡ ½ÃÅ°´Â ÇÔ¼ö */
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != "function"){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}


/* Æû ÀÔ·Â°ª Check*/
function frmchk_char(str, condition)
/*
¼³¸í		: Æû ÀÔ·Â°ªÀ» Á¤±Ô½ÄÆÐÅÏÀ» ÀÌ¿ëÇØ¼­ Ã¼Å©ÇÔ
»ç¿ë¹ý	: frmchk_char(¹®ÀÚ¿­, Á¶°Ç)
°á°ú°ª	: true/false
Á¶°Ç		: 
	0 = Ã¹±ÛÀÚ ¿µ¹®, ¿µ¹®, ¼ýÀÚ, _ »ç¿ë°¡´É
	1 = ¿µ¹®¸¸ »ç¿ë°¡´É
	2 = ¼ýÀÚ¸¸ »ç¿ë°¡´É
	3 = ÇÑ±Û¸¸ »ç¿ë°¡´É
	4 = ¿µ¹®, ¼ýÀÚ »ç¿ë°¡´É
	5 = ¿µ¹®, ¼ýÀÚ, ÇÑ±Û »ç¿ë°¡´É
	6 = ÇÑ±Û, ¼ýÀÚ »ç¿ë°¡´É
	7 = ÇÑ±Û, ¿µ¹® »ç¿ë°¡´É
	8 = ÇÑ±ÛÀ» Æ÷ÇÔÇÏ´ÂÁö ¿©ºÎ
*/
{
	var objPattern
	switch(condition){
		case(0) :
			objPattern = /^[a-zA-Z]{1}[a-zA-Z0-9_]+$/;
			break;
		case(1) :
			objPattern = /^[a-zA-Z]+$/;
			break;
		case(2) :
			objPattern = /^[0-9]+$/;
			break;
		case(3) :
			objPattern = /^[°¡-ÆR]+$/;
			break;
		case(4) :
			objPattern = /^[a-zA-Z0-9]+$/;
			break;
		case(5) :
			objPattern = /^[°¡-ÆRa-zA-Z0-9]+$/;
			break;
		case(6) :
			objPattern = /^[°¡-ÆR0-9]+$/;
			break;
		case(7) :
			objPattern = /^[°¡-ÆRa-zA-Z]+$/;
			break;
		case(8) :
			objPattern = /[°¡-ÆR]/;
			break;
		case(9) :
			objPattern = /[a-zA-Z0-9]/;
			break;
	}
	return objPattern.test(str);
}

/* Image File PreLoading */
function preLoading(_array){
	if(!_array || _array < 0) return false;
	var _img = new Array;
	for (var i = 0; i < _array.length; i++)
	{
		_img[i] = new Image();
		_img[i].src = _array[i];
	}
}


// Áñ°ÜÃ£±â ±â´É Ãß°¡
function addFavorite(){
	if(!document.getElementById) return false;
	if(!document.getElementById("favor")) return false;
	var favorId = document.getElementById("favor");	
	var _favorUrl = "http://www.loveyent.com/";
	var _favorTitle = "·¯ºñ¾Ø - ·Î¸Ç½ºÀÇ ¸ÞÄ«"
	favorId.onclick = function(){
		if(window.sidebar){
			window.sidebar.addPanel(_favorTitle, _favorUrl, "");
		}else if(window.external){			
			try{
				window.external.AddFavorite(_favorUrl, _favorTitle); 
			}catch(e){
				return true;
			}
		}else{
			this.href = _favorUrl;
			this.title = _favorTitle;
			this.rel = "sidebar";
			return true;
		}
	};	
}

addLoadEvent(addFavorite);


/* Å×ÀÌºí¸®½ºÆ® ¸¶¿ì½º ¿À¹ö½Ã ¹è°æ»ö */
function listOver()
{
	if(!document.getElementById) return false;
	if(!document.getElementsByTagName) return false;
	if(!document.getElementsByTagName("table")) return false;

	var listTable = document.getElementsByTagName("table");
	for (var i = 0; i < listTable.length; i++ )
	{
		if(listTable[i].className == "boardList"){
			var _tbody = listTable[i].getElementsByTagName("tbody");
			var _rows = _tbody[0].getElementsByTagName("tr");		
			for (var j = 0; j < _rows.length; j++ )
			{
				_rows[j].onmouseover	= function() { this.style.backgroundColor = "#faf8ef"; };
				_rows[j].onmouseout	= function() { this.style.backgroundColor = ""; };
			}
		}else if(listTable[i].className == "m_boardLIst"){
			var _tbody = listTable[i].getElementsByTagName("tbody");
			var _rows = _tbody[0].getElementsByTagName("tr");		
			for (var j = 0; j < _rows.length; j++ )
			{
				_rows[j].onmouseover	= function() { this.style.backgroundColor = "#fbfbfb"; };
				_rows[j].onmouseout	= function() { this.style.backgroundColor = ""; };
			}
		}
	}
}
addLoadEvent(listOver);


/* ·Î±×ÀÎ Form ÄÁÆ®·Ñ ¹× ¹«°á¼º °Ë»ç */
function login_control(){
	if(!document.getElementById("login_form"))	return false;

	var login_frm = document.getElementById("login_form");

	login_frm.onsubmit = function()
	{			
		if (this.login_id.value == "" || this.login_id.value == null){
			alert("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
			this.login_id.focus();
			return false;
		}else if(this.login_pwd.value == "" || this.login_pwd.value == null){
			alert("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
			this.login_pwd.focus();
			return false;
		}else{
			return true;
		}
	};
	
	var _id = document.getElementById("login_id");
	var _pwd = document.getElementById("login_pwd");

	if(_id.className != "loginbox" && _id.className != "loginbox01"){
		if (_id.value == "") {		// Firefox Bug
			_id.style.cssText = "background: #FFFFFF url(/images/n_id.gif) 4px 4px no-repeat;";
		}else{
			_id.style.cssText="background: #FFFFFF;";
		}
		if (_pwd.value == "") _pwd.style.cssText = "background: #FFFFFF url(/images/n_pw.gif) 4px 4px no-repeat;"; 
		_id.onfocus = function() {  this.style.cssText="background: #FFFFFF;";};
		_pwd.onfocus = function() { this.style.cssText="background: #FFFFFF;";};

		_id.onblur = function() { if (this.value == "") this.style.cssText = "background: #FFFFFF url(/images/n_id.gif) 4px 4px no-repeat;"; };
		_pwd.onblur = function() { if (this.value == "") this.style.cssText = "background: #FFFFFF url(/images/n_pw.gif) 4px 4px no-repeat;"; };		
	}else{
		login_frm.login_id.focus();
	}
}

addLoadEvent(login_control);

/* content Area ÀÌ¹ÌÁö Å©±â Á¶Àý */
function controlImage(){
	if(!document.getElementById("view_content"))	return false;
	var _content = document.getElementById("view_content");

	if(!_content.getElementsByTagName("img"))		return false;
	var contentImg = _content.getElementsByTagName("img");
	var _width = _content.clientWidth -28;			//ÇöÀç content AreaÀÇ ³Êºñ¿¡¼­ ÆÐÆÃÀ» »« ³Êºñ
	
	for (var i = 0; i < contentImg.length ;i++ )
	{
		var imgWidth = contentImg[i].width;		//ÀÌ¹ÌÁöÀÇ ³Êºñ		
		if (imgWidth > _width)
		{
			contentImg[i].width =  _width;
		}			
	}		
}
addLoadEvent(controlImage);


/* °Ë»ö°ü·Ã*/
function search_frm()
{
	if(!document.getElementById("search_frm"))	 return false;
	var f = document.getElementById("search_frm");
	f.onsubmit = function(){	
		if(_length(this.word) == 0){
			alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇÏ¼¼¿ä!");
			this.word.focus();
			return false;
		}
		if (f.category.value != "all")
		{
			f.action="/search/search.asp";
		}
		
		return true;
	}
}
addLoadEvent(search_frm);



/* ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å© */
function chk_ssn(jNum1, jNum2){
	var sum = 0;
	for (var i = 0; i < jNum1.length; i++){
		// °¢ÀÚ¸®ÀÇ ¼ýÀÚ¸¦ °öÇØ¼­ ´õÇÔ
		sum += (i + 2) * jNum1.charAt(i);
	}

	for (i = 0; i < 2; i++)	{
		// 7 ~ 8ÀÚ¸®±îÁö Ã³¸®
		sum += (i+8) * jNum2.charAt(i);
	}

	for (i = 2; i < 6; i++){
		// 9 ~ 13ÀÚ¸®±îÁö Ã³¸®
		sum += (i) * jNum2.charAt(i);
	}

	var chkSum = sum % 11;
	var chkCode;
	if (chkSum == 0){
		chkCode = 10;
	}else if(chkSum == 1){
		chkCode = 11;
	}else{
		chkCode = chkSum;
	}
	var chk1 = 11 - chkCode; //³ª¸ÓÁö¿¡¼­ 11À» »«´Ù.
	var chk2 = parseInt(jNum2.charAt(6))
	
	if( chk1 != chk2){
		return false;
	}else{
		return true;
	}

}


function chkAdult_frm(){
	if(!document.getElementById("chkAdult_frm"))	return false;
	var f = document.getElementById("chkAdult_frm");
	f.jNum1.onkeyup = function(){		
		if(this.value.length == 6){
			f.jNum2.focus();
		}
	}

	f.onsubmit = function(){
		var j1 = this.jNum1;
		var j2 = this.jNum2;
		if (_length(this.name) == 0)
		{
			alert("ÀÌ¸§À» ÀÔ·ÂÇÏ¼¼¿ä");
			this.name.focus();
			return false;
		}
		if (j1.value.length != 6 || j2.value.length != 7)
		{
			alert("ÁÖ¹Îµî·Ï¹øÈ£ 13ÀÚ¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
			j1.focus();
			return false;
		}

		if (!frmchk_char(j1.value, 2) || !frmchk_char(j2.value, 2))
		{
			alert("ÁÖ¹Îµî·Ï¹øÈ£´Â ¼ýÀÚ¸¸ ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.");
			j1.value = "";
			j2.value = "";
			j1.focus();
			return false;
		}

		if (!chk_ssn(j1.value, j2.value))
		{
			alert("À¯È¿ÇÏÁö ¾ÊÀº ÁÖ¹Îµî·Ï¹øÈ£ÀÔ´Ï´Ù.\n¿Ã¹Ù¸¥ ÁÖ¹Îµî·Ï¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
			j1.value = "";
			j2.value = "";
			j1.focus();
			return false;
		}
	}
	
}
addLoadEvent(chkAdult_frm);


function bbs_writeFrm_chk(){
	if(!document.getElementById("bbs_writeFrm"))	return false;
	var f = document.getElementById("bbs_writeFrm");

	f.onsubmit = function(){
		if (_length(this.title) == 0)
		{
			alert("Á¦¸ñÀ» ÀÔ·ÂÇÏ¼¼¿ä");
			this.title.focus();
			return false;
		}

		if (_length(this.content) == 0)
		{
			alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
			this.content.focus();
			return false;
		}

		return true;
	};
}
addLoadEvent(bbs_writeFrm_chk);

function preloadImages(arr){
	var docImgs = new Array();
	for (var i = 0; i < arr.length; i++)
	{	
		docImgs[i] = new Image();
		docImgs[i].setAttribute("src", arr[i]);
		//alert(docImgs[i].src)
	}
}


/* ÀüÃ¼ Ã¢ ·Îµù(»ç¿ëÀÚ°¡ ´Ù¸¥ °´Ã¼ Á¦¾îºÒ°¡) */
var loadingProgressFull = function(objId){
	this.objId = objId;
}
loadingProgressFull.prototype.Create = function(){
	var doc = (document.body) ? document.body : document.documentElement;
	var obj = this.obj = document.createElement("div");
	var objId = this.objId
	obj.setAttribute("id", objId);
	obj.style.position = "absolute";
	obj.style.zIndex = "100";
	obj.style.backgroundColor = "#999999";
	obj.style.backgroundImage = "url(http://images.barobook.com/ijakga/images/loading.gif)";
	obj.style.backgroundRepeat = "no-repeat";
	obj.style.backgroundPosition = "50% 50%";	
	obj.style.width = doc.clientWidth + "px";
	obj.style.height = doc.clientHeight + "px";
	obj.style.filter = "alpha(opacity=35)";
	obj.style.opacity = "0.35";
	obj.style.display = "none";
	obj.style.left = "0";
	obj.style.top = "0";
	doc.appendChild(obj);
}
loadingProgressFull.prototype.Loading = function(){
	if (!this.obj)	this.Create();
	var obj = this.obj;
	obj.style.display = "block";
}
loadingProgressFull.prototype.Completed = function(){
	if(!this.obj)	this.Create();
	var obj = this.obj;
	obj.style.display = "none";
}

