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.removeNode = function(){ return this.parentNode.removeChild(this); }
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;
}

/*** º»¹® ÀÌ¹ÌÁö Å©±â ¸®»çÀÌÂ¡ ***/
function innerImgResize(id)
{
	var objContents = $(id);
	if (!objContents) return;
	var innerWidth = objContents.clientWidth;
	var img = objContents.getElementsByTagName('img');
	for (var i=0;i<img.length;i++){
		if (img[i].width>innerWidth){
			img[i].height = img[i].height * innerWidth / img[i].width;
			img[i].width = innerWidth;

			img[i].title = "View Original Image!!";
			img[i].style.cursor = "pointer";

			img[i].setAttribute('rel','lytebox');
			if (!document.all) img[i].setAttribute('href',img[i].src);
			img[i].onclick = function(){
				/*popupWindow(this.src);*/
				myLytebox.start(this, false, false); return false;
			};
		}
	}
}

/*** °´Ã¼ »ðÀÔ ***/
function insertBefore( newElement, targetElement ){
	targetElement.parentNode.insertBefore( newElement, targetElement );
}

function insertAfter( newElement, targetElement ){
	var parent = targetElement.parentNode;
	if ( parent.lastChild == targetElement ) {
		parent.appendChild ( newElement ) ;
	} else {
		parent.insertBefore( newElement, targetElement.nextSibling );
	}
}

function removeNode(o){ return o.parentNode.removeChild(o); }


/**************************** ÀÌÀü¹öÁ¯ ½ºÅ©¸³Æ® ***************************/
function array_search(needle,haystack){
	for(var i in haystack){
		if(haystack[i]==needle){return i;}    
	}
	return false;
}

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 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 nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length ){
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 ) break;
	}
	return "";
}

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,""),10);
	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) return;
	if (e==8 || e==13 || e==45 || 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;
		if (El[i].disabled) El[i].checked = false;
	}
}

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)!="object") obj = $(obj);
	if (typeof(obj)=="undefined" || obj==null) return;
	if (!mode) obj.style.display = (obj.style.display!="block") ? "block" : "none";
	else obj.style.display = mode;
}

function popup(src,width,height) {
	var scrollbars = "1";
	var resizable = "no";
	if (typeof(arguments[3])!="undefined") scrollbars = arguments[3];
	if (arguments[4]) resizable = "yes";
	window.open(src,'','width='+width+',height='+height+',scrollbars='+scrollbars+',toolbar=no,status=no,resizable='+resizable+',menubar=no');
}

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

function getDiscount(price,code) {
	if (!code) return 0;
	if (code.charAt(code.length-1)!="%") return code;
	code = code.substr(0,code.length-1);
	var div = (arguments[2]==null) ? 1 : arguments[2];
	var ret = rounddown(price * code / 100,div);
	if (arguments[3]>0 && arguments[3]<ret) ret = arguments[3];
	return ret;
}

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

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 chkDisabeld(obj)
{
	if (!selectDisabled(obj)) return false;
}

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

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

/*** ½ºÅ©·Ñ Á¦¾î ***/
function innerScroll(obj)
{
	if (event.wheelDelta >= 120) obj.scrollTop -= 40;
	else if (event.wheelDelta <= -120) obj.scrollTop += 40;
	//obj.scrollBy(0,event.wheelDelta / -3);
	return false;
}

function mTop(fstx,fsty,lstx,lsty) {
	var Timer;
	var winHeight = document.body.scrollTop;
	if(Timer) clearTimeout(Timer);
	
	startx = 0;
	starty = winHeight;
	if(!fstx || fstx < 0) fstx = 0;
	if(!fsty || fsty < 0) fsty = 0;
	
	var speed = 7;
	if(!lstx) lstx = 0 + startx;
	if(!lsty) lsty = 0 + starty;
	lstx += (fstx - startx) / speed;
	if (lstx < 0) lstx = 0;
	lsty += (fsty - starty) / speed;
	if (lsty < 0) lsty = 0;
	var posX = Math.ceil(lstx);
	var posY = Math.ceil(lsty);
	window.scrollTo(posX, posY);
	if((Math.floor(Math.abs(startx - fstx)) < 1) && (Math.floor(Math.abs(starty - fsty)) < 1)){
		clearTimeout(Timer);
		//window.scroll(fstx,fsty);
	}
	else if(posX != fstx || posY != fsty){
		Timer = setTimeout("mTop("+fstx+","+fsty+","+lstx+","+lsty+")",15);
	}
	else{
		clearTimeout(Timer);
	}
}

/*** blink ÅÂ±×È¿°ú ***/
function doBlink() {
    var blink = document.all.tags("BLINK");
    for (var i=0; i < blink.length; i++) {
        blink[i].style.visibility = (blink[i].style.visibility =="visible") ? "hidden":"visible";
    }
}
if (document.all) setInterval("doBlink()",500);

/*** »óÇ° ÆË¾÷À©µµ¿ì¿¡¼­ ±¸¸Å¹öÆ° ÀÌº¥Æ® ***/
function exec_dyn(fm,mode)
{
	if (chkForm(fm)){
		if (mode=="wishlist") fm.action = "../mypage/wishlist.php";
		else fm.action = "../order/cart.php";
		fm.mode.value = mode;
		fm.submit();
	}
}

/*** ¸¶¿ì½º ¿À¹ö ÀÌ¹ÌÁö ½º¿Ò left.mypage.htm ½ºÅ²¿¡ Àû¿ë***/
function swap_image(obj,mode){
	switch (mode)
	{
		case "over": obj.src=obj.src.replace("off.","on."); break;
		case "out": obj.src=obj.src.replace("on.","off."); break;
	}
}

function copy2clipboard(obj)
{
	var doc = document.body.createTextRange();
	doc.moveToElementText(obj);
	doc.select();
	doc.execCommand('copy');
	//alert("¼±ÅÃºÎºÐÀÌ Å¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù");
}