var notWhitespace = /\S/
function cleanWhitespace(node) {
    var notWhitespace = /\S/
    for (var x = 0; x < node.childNodes.length; x++) {
        var childNode = node.childNodes[x]
        if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
            node.removeChild(node.childNodes[x])
            x--
        }
    }
}

function ctrl_c(id){
	var doc = document.getElementById(id).createTextRange();
	document.getElementById(id).select();
	doc.execCommand('copy');
	alert('Æ®·¢¹é ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù. Ctrl+V ¸¦ ÀÌ¿ëÇÏ¿© ºÙ¿©³ÖÀ¸¼¼¿ä.');
}
	
function comma(srcNumber){
	var txtNumber = '' + srcNumber;
	var txtSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
	var Number_arr = txtNumber.split('.');
	Number_arr[0] += '.';

	do {
		Number_arr[0] = Number_arr[0].replace(txtSplit, '$1,$2');
	} while (txtSplit.test(Number_arr[0]));

	if (Number_arr.length > 1) return Number_arr.join('');
	else return Number_arr[0].split('.')[0];
}

function decomma(price){
	len = price.length;
	var number = "";
	for(var i=0 ; i<len ; i++){
		str = price.substring(i,i+1);
		if(str != ",") number += str;
	}

return parseInt(number);
}



// ÄíÅ° ±Á±â
// 1:ÇÏ·ç
function setCookie(name,value,day) {
	var today = new Date();
	var expires = new Date(today.getTime() + (86400*1000)*day);
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}
	
// ÄíÅ°°ª ¹Þ±â
function getCookie(Name) {
	var search = Name + "=";
	if (document.cookie.length > 0) {                 
		offset = document.cookie.indexOf(search);
		if (offset != -1){                                                
			offset += search.length;                          
			end = document.cookie.indexOf(";", offset);   
			if (end == -1) 
			end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		} 
	}
}


// Æû°ª Ã¼Å©
var form_name = '';
function check_value(name,msg){
	if(document[form_name][name].value.length == 0){
		alert(msg);
		document[form_name][name].focus();
		return false;
	}
	return true;
}


/////////////// alert , cover , layer ½º¸£¸¤ open //////////////////////////////
// ·¹ÀÌ¾î ¿­±â (·¹ÀÌ¾î Å©±â¸¸ º¯°æ)
function open_div(id,width,height,speed){
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	if(!speed) speed=0.2;
	setTimeout("open_div_animation('"+id+"','"+width+"','"+height+"',"+speed+")",10);
}
	

function open_div_animation(id,width,height,speed){
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	var dw = (width - w) * speed;
	var dh = (height - h) * speed;

	if(dw > 0) dw = Math.ceil(dw); else dw = Math.floor(dw);
	if(dh > 0) dh = Math.ceil(dh); else dh = Math.floor(dh);

	nw = dw + w; if(nw == width) nh = height;
	nh = dh + h; if(nh == height) nw = width;

	document.getElementById(id).style.width = nw;
	document.getElementById(id).style.height = nh;

	if(dw != 0 || dh != 0) setTimeout("open_div_animation('"+id+"','"+width+"','"+height+"',"+speed+")",10);		
}
	
// ·¹ÀÌ¾î ¿­±â (·¹ÀÌ¾î À§Ä¡¿Í Å©±â º¯°æ)
function open_div2(id,width,height,top,left,speed){
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	if(!speed) speed=0.2;
	setTimeout("open_div_animation2('"+id+"','"+width+"','"+height+"','"+top+"','"+left+"',"+speed+")",10);
}

function open_div_animation2(id,width,height,top,left,speed){
	var t = parseInt(document.getElementById(id).style.top);
	var l = parseInt(document.getElementById(id).style.left);
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	var dt = (top - t) * speed;
	var dl = (left - l) * speed;
	var dw = (width - w) * speed;
	var dh = (height - h) * speed;

	if(dt > 0) dt = Math.ceil(dt); else dt = Math.floor(dt);
	if(dl > 0) dl = Math.ceil(dl); else dl = Math.floor(dl);
	if(dw > 0) dw = Math.ceil(dw); else dw = Math.floor(dw);
	if(dh > 0) dh = Math.ceil(dh); else dh = Math.floor(dh);

	nt = dt + t; if(nt == top) nt = top;
	nl = dl + l; if(nl == left) nl = left;
	nw = dw + w; if(nw == width) nh = height;
	nh = dh + h; if(nh == height) nw = width;

	document.getElementById(id).style.top = nt;
	document.getElementById(id).style.left = nl;
	document.getElementById(id).style.width = nw;
	document.getElementById(id).style.height = nh;

	if(dw != 0 || dh != 0) setTimeout("open_div_animation2('"+id+"','"+width+"','"+height+"','"+top+"','"+left+"',"+speed+")",10);		
}

// ·¹ÀÌ¾î ¿­±â (·¹ÀÌ¾î À§Ä¡¿Í Å©±â º¯°æ)
function open_div3(id,width,height,top,left,speed){
		
	var w = parseInt(parent.document.getElementById(id).style.width);
	var h = parseInt(parent.document.getElementById(id).style.height);

	if(!speed) speed=0.2;
	setTimeout("open_div_animation3('"+id+"','"+width+"','"+height+"','"+top+"','"+left+"',"+speed+")",10);
}

function open_div_animation3(id,width,height,top,left,speed){
	var t = parseInt(parent.document.getElementById(id).style.top);
	var l = parseInt(parent.document.getElementById(id).style.left);
	var w = parseInt(parent.document.getElementById(id).style.width);
	var h = parseInt(parent.document.getElementById(id).style.height);

	var dt = (top - t) * speed;
	var dl = (left - l) * speed;
	var dw = (width - w) * speed;
	var dh = (height - h) * speed;

	if(dt > 0) dt = Math.ceil(dt); else dt = Math.floor(dt);
	if(dl > 0) dl = Math.ceil(dl); else dl = Math.floor(dl);
	if(dw > 0) dw = Math.ceil(dw); else dw = Math.floor(dw);
	if(dh > 0) dh = Math.ceil(dh); else dh = Math.floor(dh);

	nt = dt + t; if(nt == top) nt = top;
	nl = dl + l; if(nl == left) nl = left;
	nw = dw + w; if(nw == width) nh = height;
	nh = dh + h; if(nh == height) nw = width;

	parent.document.getElementById(id).style.top = nt;
	parent.document.getElementById(id).style.left = nl;
	parent.document.getElementById(id).style.width = nw;
	parent.document.getElementById(id).style.height = nh;

	if(dw != 0 || dh != 0) setTimeout("open_div_animation3('"+id+"','"+width+"','"+height+"','"+top+"','"+left+"',"+speed+")",10);		
}

// ·¹ÀÌ¾î ¿­±â (·¹ÀÌ¾î Å©±â º¯°æ)
function open_div4(id,width,height,speed){
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	if(!speed) speed=0.2;
	setTimeout("open_div_animation4('"+id+"','"+width+"','"+height+"',"+speed+")",10);
}

function open_div_animation4(id,width,height,speed){
	var w = parseInt(document.getElementById(id).style.width);
	var h = parseInt(document.getElementById(id).style.height);

	var dw = (width - w) * speed;
	var dh = (height - h) * speed;

	if(dw > 0) dw = Math.ceil(dw); else dw = Math.floor(dw);
	if(dh > 0) dh = Math.ceil(dh); else dh = Math.floor(dh);

	nw = dw + w; if(nw == width) nh = height;
	nh = dh + h; if(nh == height) nw = width;

	document.getElementById(id).style.width = nw;
	document.getElementById(id).style.height = nh;

	if(dw != 0 || dh != 0) setTimeout("open_div_animation4('"+id+"','"+width+"','"+height+"',"+speed+")",10);		
}

function usePoint_bk(curpoint,goodsprice,addprice,deliprice)
{
	//alert(goodsprice+" "+addprice+" "+deliprice);
	document.all.o_point.value = 0;
	var sspoint = document.all.salepoint.value;
	var len = sspoint.length;
	var li_p = sspoint.substring( len-2, len );

	if( li_p > 0 ) {
		alert("100´ÜÀ§¸¸ ÀÔ·ÂÇÒ¼ö ÀÖ½À´Ï´Ù.");
		return;
	}	

	if( parseInt(curpoint) < 20000) {
		alert("20,000Æ÷ÀÎÆ® ÀÌ»óºÎÅÍ »ç¿ëÇÒ¼ö ÀÖ½À´Ï´Ù.");
		return;
	}

	if( parseInt(document.all.salepoint.value) > parseInt(curpoint) ) {
		alert("Æ÷ÀÎÆ® ±Ý¾×ÀÌ ÃÊ°ú µÇ¾ú½À´Ï´Ù.");
		return;
	}
	if( parseInt(document.all.salepoint.value) > parseInt(goodsprice) ) {
		alert("»óÇ° ±Ý¾×º¸´Ù Æ÷ÀÎÆ® »ç¿ë ±Ý¾×ÀÌ Å­´Ï´Ù.\nÃß°¡ ¹è¼Ûºñ´Â Æ÷ÀÎÆ®·Î °áÁ¦ ÇÒ ¼ö ¾ø½À´Ï´Ù.");
		return;
	}

	if( parseInt(document.all.salepoint.value) > 0 && parseInt(document.all.salepoint.value) < 10000) {
		alert("Æ÷ÀÎÆ®´Â 10,000Æ÷ÀÎÆ® ÀÌ»ó ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		return;
	}

	if( parseInt(document.all.salepoint.value) == 0) {
		document.all.good_mny.value = parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice);
		document.all.gdp.value = parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice);
		document.all.o_point.value = parseInt(goodsprice);
		alert("Æ÷ÀÎÆ® »ç¿ëÀÌ Ãë¼Ò µÇ¾ú½À´Ï´Ù.");
		return;
	}

	document.all.gdp.value 		= (parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice))-parseInt(document.all.salepoint.value);
	document.all.o_price.value 	= parseInt(document.all.realp.value) - parseInt(document.all.salepoint.value);
	document.all.o_point.value 	= document.all.salepoint.value;
	document.all.o_delivery.value 	= parseInt(addprice) + parseInt(deliprice);
	//$("salpp").innerHtml = comma(parseInt(curpoint)-parseInt(document.all.salepoint.value));
	
        if( parseInt(document.all.salepoint.value) >= 10000) {
                alert("Æ÷ÀÎÆ® "+comma(document.all.salepoint.value)+" »ç¿ëÇÕ´Ï´Ù.");
                return;
        }
	$("tprice").innerHTML = comma((parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice))-parseInt(sspoint));
}

function changePayment(A,goodsprice,addprice,deliprice,cpprice)
{
	if(A=='point')
	{
		window.payMethodpoint.style.display='inline';
		if( parseInt(goodsprice) >= 50000 ) { 
			window.payMethodcp.style.display='none';
			//document.getElementById('salecpprice').value = cpprice;
		}
		document.getElementById('o_cpprice').value = 0;
		document.getElementById('gdp').value= (parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice));
		document.getElementById('o_price').value    = parseInt(document.getElementById('realp').value);
		$("tprice").innerHTML = comma(parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice));
	}
	if(A=='cp') 
	{
		document.getElementById('salepoint').value = 0;
		var salcp = document.getElementById('salecpprice').value;
		window.payMethodpoint.style.display='none';
		window.payMethodcp.style.display='inline';

		document.getElementById('gdp').value= (parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice))-parseInt(salcp);
		document.getElementById('o_price').value    = parseInt(document.getElementById('realp').value) - parseInt(salcp);
		document.getElementById('o_cpprice').value    = parseInt(salcp);
		document.getElementById('o_delivery').value = parseInt(addprice) + parseInt(deliprice);
		$("tprice").innerHTML = comma((parseInt(goodsprice)+parseInt(addprice)+parseInt(deliprice))-parseInt(salcp));
	}
}


