
String.prototype.bytes = function (str) {
	var len	= 0;
	str = this != window ? this : str;
	for (var i = 0, c = 0; i < str.length; i++) {
		c    = str.charAt(i);
		len += (c.charCodeAt() > 128) ? 2 : 1;
	}
	return len;
};

String.prototype.cut = function (len, tail) {
	if (tail == null) tail = "";
	for (var i = 0, l = 0; i < str.length; i++) {
		l += str.charCodeAt(i) > 128 ? 2 : 1;
		if (l > len) return str.substring(0, i) + tail;
	}
	return str;
};

String.prototype.decodeURL = function (str) {
	str	= this != window ? this : str;
	return decodeURIComponent(str.replace(/\+/g, "%20").replace(/\%21/g, "!").replace(/\%27/g, "'").replace(/\%28/g, "(").replace(/\%29/g, ")").replace(/\%2A/g, "*").replace(/\%7E/g, "~"));
};

String.prototype.encodeURL = function (str) {
	str	= this != window ? this : str;
	return encodeURIComponent(str).replace(/\%20/g, "+").replace(/!/g, "%21").replace(/'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\*/g, "%2A").replace(/\~/g, "%7E");
};

String.prototype.hasFinalConsonant = function (str) {
	str	= this != window ? this : str;
	var tmp = str.substr(str.length - 1);
	return ((tmp.charCodeAt(0) - 16) % 28 != 0);
};

String.prototype.trim = function (str) {
	str	= this != window ? this : str;
	return str.replace(/^\s+/g, "").replace(/\s+$/g, "");
};

function autoNext(self, nextId) {
	if (self.getAttribute && self.value.length == self.getAttribute("maxlength")) {
		var el = document.getElementById(nextId);
		if (el) el.focus();
	}
}

function onPressKey(keycode, callback) {
	if (event.keyCode == keycode) {
		event.cancelBubble = true;
		event.returnValue = false;
		if (callback != null) callback();
	}
}

function resizeFrame(el, dy) {
	if (el) {
		try {
			var doc = el.contentDocument ? el.contentDocument : el.contentWindow.document;
			var obj = el.style ? el.style : el;

			dy         = dy == null ? 0 : dy;
			obj.height = doc.body.scrollHeight + dy + "px";
		} catch (e) {}
	}
}

// 20091020 created by sorisaem <sorisaem@gmail.com>
function resizeWin(maxWidth, maxHeight) {
	var w = parseInt(document.body.scrollWidth);
	var h = parseInt(document.body.scrollHeight);
	var e = document.createElement("div");
	e.style.position = "absolute";
	e.style.left     = "0px";
	e.style.top      = "0px";
	e.style.width    = "100%";
	e.style.height   = "100%";
	document.body.appendChild(e);

	var dx = w - e.offsetWidth;
	var dy = h - e.offsetHeight;
	if (maxWidth  != null)
		dx = (document.body.clientWidth + dx) > maxWidth  ? maxWidth - document.body.clientWidth : dx;
	if (maxHeight != null)
		dy = (document.body.clientHeight + dy) > maxHeight ? maxHeight - document.body.clientHeight : dy;

	window.resizeBy(dx, dy);
	document.body.removeChild(e);
}

function scrollToAnchor(id) {
	var target = $("#" + id);
	if (target.length) {
		var offset = target.offset().top;
		$("html,body").animate({ scrollTop: offset + "px" }, 250);
	}

	return false;
}

// IE6 ÀÌÇÏ¹öÀü PNG24 Àû¿ëÇÏ±â - PKH2010510
function setPng24(obj) {
	obj.width=obj.width;
	obj.height=obj.height;
	obj.className=obj.className.replace("png24",'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+obj.src +"',sizingMethod='image');";
	obj.src='/images/spacer.gif';
	obj.id = obj.id;
	obj.alt = obj.alt;
	obj.usemap = obj.usemap;
	return '';
}

// int to numeric
function numberFormat(nStr) {
	nStr += '';
	var x  = nStr.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function hidePopup(setId) {
	if (document.getElementById("popupchk_" + setId).checked) {
		setCookie("popup_" + setId, "done", 1);
	}
	document.getElementById("Layer_" + setId).style.visibility = "hidden";
}

function getCookie(name) {
	var str = name + "=";
	var pos = 0;
	var tmp = 0;
	while (pos <= document.cookie.length) {
		var len = (pos + str.length);
		if (document.cookie.substring(pos, len) == str) {
			if ((tmp = document.cookie.indexOf(";", len)) == -1) {
				tmp = document.cookie.length;
			}

			return unescape(document.cookie.substring(len, tmp));
		}

		pos = document.cookie.indexOf(" ", pos) + 1;
		if (pos == 0) {
			break;
		}
	}

	return "";
}

function setCookie(name, value, expiredays) {
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";";
}

function basketAddDirect(gid) {
	if (gid) {
		if (window.event) window.event.returnValue = false; // for ie6

		var current_url = top.document.URL.encodeURL();
		location.href = "/cart/basket_add.php?gid=" + gid + "&gurl=" + current_url;
	}
}

function basketAddHidden(gid) {
	if (gid) {
		var param = { gid : gid, goodsEa : 1, cart_opt : "hidden" };
		$.post("/cart/basket_add.php", param, function (data) {
			if (data == "") alert("»óÇ°À» Àå¹Ù±¸´Ï¿¡ ´ã¾Ò½À´Ï´Ù.");
			else            alert(data.replace(/\\n/g, "\r\n"));
		});
	}
}

// À§½Ã¸®½ºÆ®¿¡ »óÇ°µî·Ï
function wishAdd(gid) {
	$.get("/mypage/wish_add.php?gid=" + gid, function (data) {
		if (data == "OK") {
			alert("Âò¹Ù±¸´Ï¿¡ »óÇ°ÀÌ µî·ÏµÇ¾ú½À´Ï´Ù");
			/*
			if (confirm("À§½Ã¸®½ºÆ®¿¡ »óÇ°ÀÌ µî·ÏµÇ¾ú½À´Ï´Ù.\n\nÀ§½Ã¸®½ºÆ®¸¦ È®ÀÎÇÏ½Ã°Ú½À´Ï±î?")) {
				location.href = "/mypage/?set=wish";
			}
			*/
		} else {
			alert(data);
		}
	});
}

function popupDetail(gid) {
	var win = window.open("/shop/detail_pop.html?gid=" + gid, "DetailPopup", "resizable=yes,scrollbars=yes,width=717,height=570");
	if (win) win.focus();
}

// 20091012 created by sorisaem <sorisaem@gmail.com>
function popupHanaEscrow() {
	var url = "http://www.hanaescrow.com/hnbecc/serviceJoinSrchManagement/escser003l.jsp?shopBsnNo=1068612259&mid=TG00019615";
	var win = window.open(url, "HanaEscrowPopup", "width=610,height=570,menubar=no,resizable=no");
	if (win) win.focus();
}

// 20091014 created by sorisaem <sorisaem@gmail.com>
function popupQuickService() {
	var win = window.open("/popup/pop_quick_service.html", "QuickServicePopup", "top=10,left=10,width=600,height=400,scrollbars=yes");
	if (win) win.focus();
}

// 20091014 created by sorisaem <sorisaem@gmail.com>
function popupDayDelivery() {
	var win = window.open("/popup/pop_day_delivery.html", "DayDeliveryPopup", "width=600,height=356");
	if (win) win.focus();
}

function popupKgtgBill(mxissueno, mxid) {
	switch (mxid) {
		case 1          :
		case "ezguide"  : mxid = "ezguide"; break;
		case "lcdzone1" : mxid = "lcdzone1"; break;
		case "lcdzone"  :
		default         : mxid = "lcdzone"; break;
	}

	var url  = "https://npg.tgcorp.com/dlp/tgcorpbill.jsp?MxID=" + mxid + "&MxIssueNO=" + mxissueno + "&Smode=3001&BillType=00";
	var win  = window.open(url, "KgtgBillPopup", "width=400,height=640,menubar=no,resizable=yes");
	if (win) win.focus();
}

function popupCashReceipt(pub_date, appr_no, type) {
	var url = "";
	var win = null;
	if (type == "1") { // LGµ¥ÀÌÄÞ
		url = "http://taxadmin.dacom.net/receipt/printGuest.jsp?authno=" + appr_no + "&transactiondate=" + pub_date;
		win = window.open(url, "CashReceiptPopup", "top=10,left=10,width=410,height=700,menubar=0,resize=0");
	} else if (type == "2") { // KGTG
		url = "https://www.kgtg.co.kr/customer/search02.jsp";
		win = window.open(url, "CashReceiptPopup");
	}

	if (win) win.focus();
}

function popupOfflineCard() {
	var win = window.open('/cart/pop_offlinecard.html', "OfflineCardPopup", "width=350,height=400");
	if (win) win.focus();
}

function popupNamecheckInfo() {
	var win = window.open("/member/pop_namecheck.html", "NamecheckInfoPopup", "width=450,height=579");
	if (win) win.focus();
}

function popupOpenCard() {
	alert("°áÁ¦½Ã½ºÅÛº¯°æÀ¸·Î 2011³â 4¿ù 12ÀÏ ¿ÀÈÄ 7½Ã ÀÌÀü¿¡ ÁÖ¹®ÇÏ½Å °í°´Àº KGTG(https://www.kgtg.co.kr/)¿¡¼­ ½ÂÀÎ³»¿ªÀ» È®ÀÎ ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.");

	var url = "http://ecredit.dacom.net/";
	var win = window.open(url, "");
	if (win) win.focus();

	/*
	var newWin = window.open('/shop/card_frame.html','cardsearch','toolbar=0,menubar=0,resizable=0,location=0,scrollbars=1,status=0,copyhistory=1,width=725,height=550');
	if (navigator.appVersion.indexOf("(X11") != -1 ||
		navigator.appVersion.indexOf("(Mac") != -1)
	{
		newWin = window.open(url,name)
	}
	*/
}

function popupReceipt(rec_no, type) {
	var url = "";
	var win = null;
	if (type == "1") {
		url = "/popup/pop_receipt2.html?authno=" + rec_no;
		win = window.open(url, "ReceiptPopup", "top=0,left=0,width=690,height=650,scrollbars=yes");
	} else if (type == "2") {
		url = "https://ssl.bohoun.com:4100/card/card_receipt.php?app_no=" + rec_no;
		win = window.open(url, "ReceiptPopup", "toolbar=0,menubar=0,resizable=0,location=0,scrollbars=0,status=0,copyhistory=1,width=400,height=700");
	} else if (type == "3") { // µ¥ÀÌÄÞ
		url = "http://pgweb.dacom.net/MpFlowCtrl?eventDiv1=search&eventDiv2=getReceipt&TRANSACTIONID=" + rec_no + "&SYSTEM=NEW";
		win = window.open(url, "ReceiptPopup", "toolbar=0,menubar=0,location=0,scrollbars=yes,width=440,height=620,resize=1,left=252,top=116");
	}

	if (win) win.focus();
}

function popupTax(oid, van) {
	if (van == "LCDZ") {
		alert("[ÀüÀÚ¼¼±Ý°è»ê¼­]´Â ÀÌ¸ÞÀÏ·Î ¹ß¼ÛµË´Ï´Ù.");
	} else {
		var win = window.open("/mypage/vat_client_view.php?oid=" + oid + "&van=" + van, "TaxPopup", "width=820,height=620,status=yes,resizable=yes,scrollbars=yes");
		if (win) win.focus();
	}
}

function popupTrans(tr_no, comp) {
	var url = "";
	var win = null;
	if (comp == "1") { // ´ëÇÑÅë¿î
		url = "http://www.doortodoor.co.kr/servlets/cmnChnnel?tc=dtd.cmn.command.c03condiCrg01Cmd&cust_id=&invc_no=" + tr_no;
		win = window.open(url, "TransPopup", "");
	} else if (comp == "2") { // ·ÎÁ¨ÅÃ¹è
		url = "http://www.ilogen.com/iLOGEN.Web/TRACE/TraceView.aspx?gubun=slipno&id=&slipno=" + tr_no;
		win = window.open(url, "TransPopup", "top=0,left=0,width=740,height=620,resizable=yes,scrollbars=yes");
	} else if (comp == "3") { // ·ÎÁ¨ÅÃ¹è¿¬µ¿
		url = "/popup/pop_logen.html?ord_no=" + tr_no;
		win = window.open(url, "TransPopup", "top=0,left=0,width=540,height=620,resizable=yes,scrollbars=yes");
	}

	if (win) win.focus();
}

// 20091023 created by sorisaem <sorisaem@gmail.com>
function popupZipcode(keyword, fn) {
	var win = window.open("/popup/pop_zipcode.html?keyword=" + keyword + "&fn=" + fn, "ZipcodePopup", "top=10,left=10,width=600,height=400,scrollbars=yes");
	if (win) win.focus();
}

// ±¸ÆäÀÌÁö¿ë
function detail(key) {
	popupDetail(key);
}

// ±¸ÆäÀÌÁö¿ë
function hidden_popup(setId) {
	hidePopup(setId);
}

// ±¸ÆäÀÌÁö¿ë
function namecheck_info() {
	popupNamecheckInfo();
}

// ±¸ÆäÀÌÁö¿ë
function offline_card() {
	popupOfflineCard();
}

// ±¸ÆäÀÌÁö¿ë	
function MM_openBrWindow(theURL, winName, features) { // v2.0
	window.open(theURL, winName, features);
}

// ±¸ÆäÀÌÁö¿ë
function pluscomma(nNumber) {
	nNumber = "" + nNumber;
	var objRegExp = new RegExp("(-?[0-9]+)([0-9]{3})");
	while (objRegExp.test(nNumber)) {
		nNumber = nNumber.replace(objRegExp, "$1,$2");
	}

	return nNumber;
}

function ellipsis(obj, length) {
	//obj.innerHTML = "test";
	return "";
}
	
function categoryHideFast() {
	$(".category_main .category_depth3").hide();
	$(".category_main .category_depth2").hide();
	$(".category_main .category_depth1").hide();
}

function popupDelivery(target) {
	var sizeTemp = "";
	if (target == "total") {
		sizeTemp = "width=520,height=500,scrollbars=yes";
	} else {
		sizeTemp = "width=520,height=500";
	}

	var win = window.open("/popup/pop_delivery.html?type=" + target, "PopupDelivery", sizeTemp);
	if (win) win.focus();
}

function popupBanking(target) {
	var win = window.open("/popup/pop_banking.html?type=" + target, "PopupQuick", "width=600,height=400");
	if (win) win.focus();
}

function popupOpenTime(target) {
	var win = window.open("/popup/pop_time.html?type=" + target, "PopupQuick", "width=600,height=400");
	if (win) win.focus();
}

function popupTelephone(target) {
	var win = window.open("/popup/pop_telephone.html?type=" + target, "PopupQuick", "width=600,height=400");
	if (win) win.focus();
}

function popupCardFree() {
	var win = window.open("/popup/pop_card.html", "PopupCardFree", "width=459,height=580");
	if (win) win.focus();
}

function popupWinXP() {
	var win = window.open("/popup/pop_winxp.html", "PopupWinXP", "width=678,height=800,resizable=yes,scrollbars=yes");
	if (win) win.focus();
}

function popupWin7() {
	var win = window.open("/popup/pop_win7.html", "PopupWin7", "width=680,height=800,resizable=yes,scrollbars=yes");
	if (win) win.focus();
}

function popupBuildPC() {
	var win = window.open("/popup/pop_build_pc.html", "PopupBuildPC", "width=720,height=800,resizable=yes,scrollbars=yes");
	if (win) win.focus();
}

function popupBootSeq() {
	var win = window.open("/popup/pop_boot_seq.html", "PopupBootSeq", "width=550,height=800,resizable=yes,scrollbars=yes");
	if (win) win.focus();
}

function popupLogin(return_url) {
	return_url = return_url ? "?return_url=" + return_url : "";

	var win = window.open("/popup/pop_login.html" + return_url, "PopupLogin", "width=610,height=464,resizable=no,scrollbars=no");
	if (win) win.focus();
}

function index_category_flash_off() {
	document.getElementById("index_category").width = "180";
	document.getElementById("index_category").height = "380";
}

function index_category_flash_on() {
	document.getElementById("index_category").width = "930";
	document.getElementById("index_category").height = "409";
}
