/*** prototype ***/

String.prototype.trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

String.prototype.str_replace = function(str1,str2) {
	return this.split(str1).join(str2);
}

String.prototype.josa = function(nm) {
	var nm1 = nm.trim().substring(0, nm.trim().indexOf("/"));
	var nm2 = nm.trim().substring(nm.trim().indexOf("/") + 1, nm.trim().length);
	var a = this.substring(this.length - 1, this.length).charCodeAt();
	a = a - 44032;
	var jongsung = a % 28;
	return (jongsung) ? nm1 : nm2;
}


/*** essential func. ***/

function _ID(id) {
	return document.getElementById(id);
}

function addOnloadEvent(fnc) {
	if (typeof window.addEventListener!="undefined") window.addEventListener( "load", fnc, false );
	else if (typeof window.attachEvent!="undefined") window.attachEvent( "onload", fnc );
	else {
		if (window.onload!=null){
			var oldOnload = window.onload;
			window.onload = function ( e ) {
				oldOnload( e );
				window[fnc]();
			};
		} else window.onload = fnc;
	}
}

function get_objectTop(obj) {
	if (obj.offsetParent==document.body || obj==document.body) return obj.offsetTop;
	else return obj.offsetTop + get_objectTop(obj.offsetParent);
}

function get_objectLeft(obj) {
	if (obj.offsetParent==document.body) return obj.offsetLeft;
	else return obj.offsetLeft + get_objectLeft(obj.offsetParent);
}

function embed(src,width,height,vars)
{

	document.write('\
	<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">\
	<PARAM NAME=movie VALUE="'+src+'">\
	<PARAM NAME=quality VALUE=high>\
	<PARAM NAME=wmode VALUE=transparent>\
	<PARAM NAME=bgcolor VALUE=#FFFFFF>\
	<PARAM NAME=flashvars VALUE="' + vars + '">\
	<EMBED src="'+src+'" quality=high bgcolor=#FFFFFF WIDTH="'+width+'" HEIGHT="'+height+'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="https://www.macromedia.com/go/getflashplayer" flashvars="' + vars + '"></EMBED>\
	</OBJECT>\
	');
}

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
 } 
 
 function getCookie (name) { 
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) { //while open var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	} //while close return null;
} 

function setCookie (name, value) { 
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

/*** user func. ***/

function comma(x) {
	var temp = "";
	var x = String(uncomma(x));
	num_len = x.length;
	co = 3;
	while (num_len>0){
		num_len = num_len - co;
		if (num_len<0){
			co = num_len + co;
			num_len = 0;
		}
		temp = ","+x.substr(num_len,co)+temp;
	}
	return temp.substr(1);
}

function uncomma(x) {
	var reg = /(,)*/g;
	x = parseInt(String(x).replace(reg,""));
	return (isNaN(x)) ? 0 : x;
}

function autoComma(obj){
	if (event.keyCode!=9) obj.value=comma(obj.value);
}

function onlynumber() {
	var e = event.keyCode;
	window.status = e;
	if (e>=48 && e<=57 || e>=96 && e<=105 ) return;
	if (e==8 || e==13 || e==46) return;
	event.returnValue = false;
}

function chkBox(El,mode) {
	if (!El) return;
	if (typeof(El)!="object") El = document.getElementsByName(El);
	for (i=0;i<El.length;i++) El[i].checked = (mode=='rev') ? !El[i].checked : mode;
}

function isChked(El,msg) {
	if (!El) return;
	if (typeof(El)!="object") El = document.getElementsByName(El);
	if (El) for (i=0;i<El.length;i++) if (El[i].checked) var isChked = true;
	if (isChked) return (msg) ? confirm(msg) : true;
	else {
		alert ("¼±ÅÃµÈ »çÇ×ÀÌ ¾ø½À´Ï´Ù");
		return false;
	}
}

function vLayer(obj,mode) {
	if (typeof(obj)=="undefined") return;
	if (typeof(obj)!="object") obj = _ID(obj);
	if (!mode) obj.style.display = (obj.style.display!="block") ? "block" : "none";
	else obj.style.display = mode;
}

function popup(src,width,height,scrollbars) {
	scrollbars = (arguments[3]==0) ? 0 : 1;
	window.open(src,'','width='+width+',height='+height+',scrollbars='+scrollbars);
}

function popupZipcode(rfunc)
{
	var dir = "";
	if (arguments[1]) dir = arguments[1];
	window.open(dir+'../module/zipcode.php?rfunc='+rfunc,'','width=417,height=350,scrollbars=yes');
}

function getDiscount(price,code) {
	if (!code) return 0;
	if (code.charAt(code.length-1)!="%") return code;
	code = code.substr(0,code.length-1);
	var ret = rounddown(price * code / 100,1);
	return ret;
}

function putCell(obj,inner)
{
	var tmp = obj.insertCell();
	tmp.innerHTML = inner;
}

function putInput(fm,name,value)
{
	var obj = document.createElement('input');
	obj.name = name;
	obj.value = value;
	fm.insertBefore(obj);
}

function in_array(val,arr)
{
	for (var i=0;i<arr.length;i++){
		if (arr[i]==val) return true;
	}
	return false;
}

/**
 * selectDisabled(oSelect)
 *
 * ¼¿·ºÆ®¹Ú½º¿¡ disabled ¿É¼ÇÃß°¡
 */
function selectDisabled(oSelect) {
	var isOptionDisabled = oSelect.options[oSelect.selectedIndex].disabled;
    if (isOptionDisabled){
        oSelect.selectedIndex = oSelect.preSelIndex;
        return false;
    } else oSelect.preSelIndex = oSelect.selectedIndex;
    return true;
}

function rounddown(x)
{
	var div = (arguments[1]==null) ? 2 : arguments[1];
	var t = Math.pow(10,div);
	x = Math.floor(x / t) * t;
	return x + 0;
}

/*** Àå¹Ù±¸´Ï »óÇ° °³¼ö ¼öÁ¤ ***/
function chgCart(obj,idx)
{
	var ret = parseInt(obj.value) + idx;
	if (ret<1) ret = 1;
	obj.value = ret;
}

/*** ³¯Â¥ ÀÚµ¿ »ðÀÔ ***/
function autoDate(obj1,obj2,val1,val2)
{
	if (typeof(obj1)!=Object) obj1 = _ID(obj1);
	if (typeof(obj2)!=Object) obj2 = _ID(obj2);
	obj1.value = val1;
	obj2.value = val2;
}


/*** °ü¸®ÀÚ ÀÌ¸ÞÀÏ È¸¿ø °Ë»ö ***/
function openLayer(obj,mode)
{
	obj = _ID(obj);
	if (mode) obj.style.display = mode;
	else obj.style.display = (obj.style.display!="none") ? "none" : "block";
}