/**
*	°³¹ß °øÅë ÇÔ¼ö js 
*  jquery.js ¹Ø¿¡¼­ »ç¿ëÇÒ °Í 
*/

/**
*	jqueryÀÇ ajaxÇÔ¼ö È£Ãâ
* 	@param url  url(ÇÊ¼ö)
* 	@param pars parameter(ÇÊ¼ö)
* 	@param success ¼º°ø ÈÄ È£ÃâÇÒ ÇÔ¼ö(ÇÊ¼ö)
* 	@param error errorÀÏ¶§ È£Ãâ ÇÒ ÇÔ¼ö(¾øÀ¸¸é alert) 
* 	@param async 
* 	@param type return°ª text or json (±âº» json)
*/
function AjaxRequest(url, pars, success, error, async, type){
	$.ajax({
		type:"POST",
		url:url,
		data:pars,
		dataType: type != null ? type : "json",
		async: (async == null || async == true) ? true : false,
		error: error!=null?error:function(req, s, e) {
			alert(req.responseText);
		},
		success:success,
		beforeSend:function(){

		},
		complete:function(){

		}
	});
}

/**
*	cookie °ü·Ã ÇÔ¼ö
*	@param	name	ÄíÅ° ÀÌ¸§
*	@param	value	ÄíÅ° °ª
*	@param	options ¿É¼Ç (expires, path, domain, secure)
*		set : 
*		$.cookie('name', value, {
*			expires :0,
*			path :'/',
*			domain :domainName,
*			secure :false
*		});
*		get :
*		$.cookie('name");
*/

jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') {
		options = options || {};
		if (value == null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime()
						+ (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}
		var path = options.path ? '; path=' + options.path : '';
		var domain = options.domain ? '; domain=' + options.domain : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [ name, '=', value, expires, path, domain, secure ].join('');
	} else {
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for ( var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					try {
						cookieValue = decodeURIComponent(cookie
								.substring(name.length + 1));
					} catch (e) {
						cookieValue = cookie.substring(name.length + 1);
					}
				}
			}
		}
		return cookieValue;
	}
}


function textLengthCheck(thisObj, maxLengthByte) {
	var tempByteLength = 0, cutByteLength = 0; 
	for(var i = 0; i < thisObj.value.length; i++) { 
		if(escape(thisObj.value.charAt(i)).length > 4) { 
			tempByteLength += 2;
		} else {
			tempByteLength++; 
		} 
		if(tempByteLength < maxLengthByte) { 
			cutByteLength++; 
		}
	} 
	if(tempByteLength > maxLengthByte) { 
		alert("ÃÖ´ë " + maxLengthByte + "ÀÚ±îÁö ÀÛ¼º°¡´ÉÇÕ´Ï´Ù.");
		thisObj.value = thisObj.value.substring(0, (cutByteLength%2==1)?cutByteLength:cutByteLength+1); 
	} 

}



/**
*	onload °´Ã¼¿¡ ÇÔ¼öÃß°¡ÇØ¼­ ¾²ÀÚ. 
*	onloadÀÌº¥Æ®¿¡ ÇÔ¼ö ¹«ÇÑ´ë Ãß°¡ °¡´É.¤»¤»
*
*	¿¹) ÀÌ¸§¸¸ ¾È°ãÄ¡°ÔÇÏ¸éµÊ.
*	OnloadEvt.aa = function(){alert('aaaaaaaaa');}
*	OnloadEvt.bb = function(){alert('bbbbbbbbb');}
**/
var OnloadEvt = {};
window.onload = function(){
	for(var obj in OnloadEvt){
			eval("OnloadEvt."+obj+"()");
	}
}


/**
* ÃßÃµ
**/
function recommend(idx){
	if(!confirm('ÃßÃµÇÏ½Ã°Ú½À´Ï±î?')) return;
	var url = "/common/board/recommend.asp";
	var param = "idx="+idx;
	AjaxRequest(url, param, rmdCallback);

	function rmdCallback(req){
		if(req.result=='-1'){
			alert("ÀÌ¹Ì ÃßÃµÇÑ °Ô½Ã¹°ÀÔ´Ï´Ù.");
		}else if(req.result=='-2'){
			alert("·Î±×¾Æ¿ô µÇ¾ú½À´Ï´Ù.");
			location.reload();
		}else{
			$(".recom").html(req.result);
			alert("ÃßÃµµÇ¾ú½À´Ï´Ù.");
		}
	}
}
/**
* ´ñ±Û
**/
function comment(mode, delIdx){
	if(mode=="insert"){
		var frm = document.cmtFrm;
		if(frm.content.value==""){
			alert("³»¿ëÀ» ÀÔ·ÂÇÏ¼¼¿ä");
			return;
		}
		frm.submit();
		$("#confirmBtn").attr("disabled", true);
	}else if(mode="del"){
		if(!confirm("Á¤¸» »èÁ¦ÇÏ½Ã°Ú½À´Ï±î?")) return;
		var frm = document.delFrm;
		frm.idx.value = delIdx;
		frm.submit();
	}
}

/**
*	¿ìÆí¹øÈ£ Ã£±âÆË¾÷(È¸¿ø°¡ÀÔ)
*/
function zipcode() {
	window.open("/popup/postal_code_search.asp", "zipcode", "width=420px, height=380px");
}

/**
*	ÀÚµ¿Æ÷Ä¿½º
*	@param	thisObj	
*	@param	id Æ÷Ä¿½ºÇÒ id
*	ex) <input type="text" id="text1" name="text1" maxlength="5" onkeyup="autoTabFocus(this, 'text2')" />
*/
function autoTabFocus(thisObj, id) {
	if (id == null) {
		return;
	}
	var maxLen = thisObj.getAttribute("maxlength");
	if (thisObj.value.length >= maxLen) {
		document.getElementById(id).select();
	}
}

/**
*	¿£ÅÍÅ° ÀÔ·Â½Ã ÇÔ¼ö ½ÇÇà
*	@param e event object
*	@param callback ½ÇÇàÇÒ ÇÔ¼ö
*	ex) <input type="text" id="test" name="test" onkeyup="enterEvent(event, returnFuntion)" />
*/
function enterEvent(e, callback) {
	if (e.keyCode == "13") {
		callback();
	}
}

function goLogin() {
	if(confirm("·Î±×ÀÎÈÄ ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.\n·Î±×ÀÎ ÆäÀÌÁö·Î ÀÌµ¿ÇÏ½Ã°Ú½À´Ï±î?")) {
		window.location.href = "/membership/login.asp?returnUrl="+window.location.href;
	}
}

/*¾ÆÀÌÇÁ·¹ÀÓ resize*/
function iframeResize(frameName) {
	var ifrm = $("#"+frameName);
	var innerDoc = (ifrm.get(0).contentDocument) ? ifrm.get(0).contentDocument : ifrm.get(0).contentWindow.document;
	ifrm.height(innerDoc.body.scrollHeight + 35);
	ifrm.width(innerDoc.body.scrollWidth + 35);
}


/* Ã¤¿ë °ü·Ã */
var fieldKind = {
	"È¦" : ["Ä³¼Å", "È¦ ¼­ºñ½º", "Á¡Àå", "¸Å´ÏÀú", "Ä¸Æ¾"]
	, "ÁÖ¹æ" : ["ÀÏ½Ä", "¾ç½Ä", "º£ÀÌÄ¿¸®"]
	, "±âÅ¸" : ["½Ä±â ¼¼Ã´"]
};

function setFieldKind(thisObj) {
	var fieldKind2Html = "<option value=\"\">2Â÷ Áö¿øºÐ¾ß ¼±ÅÃ</option>";
	if(thisObj.value != "") {
		var fieldKind2Array = fieldKind[thisObj.value];
		for(var i in fieldKind2Array) {
			fieldKind2Html += "<option value=\""+fieldKind2Array[i]+"\">"+fieldKind2Array[i]+"</option>"
		}
	}
	$("#fieldKind2").html(fieldKind2Html);
}

function initFieldKind() {
	var fieldKind1Html = "<option value=\"\">1Â÷ Áö¿øºÐ¾ß ¼±ÅÃ</option>";
	for(var i in fieldKind) {
		fieldKind1Html += "<option value=\""+i+"\">"+i+"</option>"
	}
	$("#fieldKind1").html(fieldKind1Html);
}

function scrap() {
	var doc = document.body.createTextRange();
	doc.moveToElementText($("#contents table")[0]);
	doc.select();
	doc.execCommand('copy');
	alert("º¹»çµÇ¾ú½À´Ï´Ù.\nCtrl+v·Î ¿øÇÏ´Â °÷¿¡ ºÙ¿©³Ö±â ÇÏ¼¼¿ä.");
}

function scrap2() {
	var doc = document.body.createTextRange();
	doc.moveToElementText($("#contents2 table")[0]);
	doc.select();
	doc.execCommand('copy');
	alert("º¹»çµÇ¾ú½À´Ï´Ù.\nCtrl+v·Î ¿øÇÏ´Â °÷¿¡ ºÙ¿©³Ö±â ÇÏ¼¼¿ä.");
}
