function commaSplit(srcNumber) 
{ 
	var txtNumber = '' + srcNumber; 

	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])'); 
	var arrNumber = txtNumber.split('.'); 
	arrNumber[0] += '.'; 
	do { 
		arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2'); 
	} 
	while (rxSplit.test(arrNumber[0])); 
	if (arrNumber.length > 1) { 
		return arrNumber.join(''); 
	} 
	else { 
		return arrNumber[0].split('.')[0]; 
	} 
}
function commaInsert(field)
{
	field.value = commaSplit(filterNum(field.value));
}
function filterNum(str) 
{ 
	re = /^\$|,/g; 
	return str.replace(re, ""); 
}
function TypeCheck (s, spc) 
{
	var i;

	for(i=0; i< s.length; i++) 
	{
		if (spc.indexOf(s.substring(i, i+1)) < 0) 
		{
			return false;
		}
	}        
	return true;
}
function is_number(){
	if ((event.keyCode<48)||(event.keyCode>57)){
		alert("\n¼ýÀÚ¸¸ ÀÔ·ÂÇÏ¼Å¾ß ÇÕ´Ï´Ù.             \n");
		event.returnValue=false;
	}
}
function num_plus(ths , danwee , f)
{
	var f = (!f) ? document.view_form : f;
	var jaego = parseInt(filterNum(f.jaego.value));
	var ipgo = parseInt(f.ipgo.value);
	var fnum = parseInt(ths.value);
	ths.value = fnum + parseInt(danwee);
	ths.focus();

	if (ipgo != 0) {
		if (fnum > jaego-1)
		{
			alert('\nÀç°í¼ö·®À» ÃÊ°úÇÏ¿´½À´Ï´Ù.          \n');
			ths.value = fnum;
			return false;
		}
	}
}
function num_minus(ths , danwee , f)
{
	var f = (!f) ? document.view_form : f;
	var jaego = parseInt(filterNum(f.jaego.value));
	var ipgo = parseInt(f.ipgo.value);
	var fnum = parseInt(ths.value);
	
	ths.value = (fnum > parseInt(danwee)) ? fnum - parseInt(danwee) : parseInt(danwee);
	ths.focus();
}
function jaego_check(ths , danwee, f)
{
	var f = (!f) ? document.view_form : f;
	var jaego = parseInt(filterNum(f.jaego.value));
	var ipgo = parseInt(f.ipgo.value);
	var fnum = parseInt(ths.value);
	var i;
	if (ipgo != 0) {
		if (ths.value % parseInt(danwee))
		{
			alert('\nº» Á¦Ç°Àº '+danwee+'ÀÇ ¹è¼ö·Î¸¸ ÁÖ¹®ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.           \n');
			ths.value = danwee;
			return false;
		}
		if (fnum > jaego+1)
		{
			alert('\nÀç°í¼ö·®À» ÃÊ°úÇÏ¿´½À´Ï´Ù.          \n');
			ths.value = parseInt(jaego/parseInt(danwee))*parseInt(danwee);
			return false;
		}
	}
}
function goods_buy(uid,type,skin,f)
{
	var f = (!f) ? document.view_form : f;
	var jx = f.js.value;
	view_page_setup(f,jx);

	if( type == 'buy' || type == 'cart' || type == 'hyup')
	{
		if(parseInt(f.buy_num.value) < 1)
		{
			alert('\nÁË¼ÛÇÕ´Ï´Ù.\n\nº» »óÇ°Àº Ç°Àý»óÅÂÀÔ´Ï´Ù..        \n');
			return false;
		}
	} 

	if ( type == 'buy')
	{
		if (!confirm('Á¤¸»·Î ¹Ù·Î ±¸¸ÅÇÏ½Ã°Ú½À´Ï±î?             '))
		{
			return false;
		}
		f.mode.value = type;
		f.submit();
	}
	if ( type == 'cart')
	{
		if (!confirm('Á¤¸»·Î Àå¹Ù±¸´Ï¿¡ ´ãÀ¸½Ã°Ú½À´Ï±î?             '))
		{
			return false;
		}
		f.mode.value = type;
		f.submit();
	}
	if ( type == 'hyup')
	{
		if (!confirm('Á¤¸»·Î Á¦Ç°±¸ÀÔÀ» ÀÇ·ÚÇÏ½Ã°Ú½À´Ï±î?             '))
		{
			return false;
		}
		f.mode.value = type;
		f.submit();
	}
	if ( type == 'wish')
	{
		if (!f.member_id.value)
		{
			if (!confirm('\n\nÈ¸¿øÀ¸·Î ·Î±×ÀÎÇÏ¼Å¾ß ÀÌ¿ëÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.           \n\nÁö±Ý ·Î±×ÀÎÇÏ½Ã°Ú½À´Ï±î?'))
			{
				return false;
			}
			else {
				location.href = "./login.php?pwd="+location.href;
				return false;
			}
		}
		if (!confirm('Á¤¸»·Î À§½Ã¸®½ºÆ®¿¡ ´ãÀ¸½Ã°Ú½À´Ï±î?             '))
		{
			return false;
		}
		var url = "cart.php?mode=wish&type=mall&uid=" + uid;
		window.open(url , 'wishwin' , 'top=3000,left=0,width=100,height=100');
	}
	if ( type == 'mail')
	{
		var uid_exp = uid.split(':');
		var url = "./instance/mailer/"+skin+"/mailer.php?type=mall&uid="+uid_exp[0]+"&cat="+uid_exp[1];
		window.open(url,'mail_win', 'width=500,height=500,scrollbars=no');
	}
}
function view_page_setup(f,js)
{
	var f  = (!f)  ? document.view_form : f;
	var js = (!js) ? f.js.value : js;

	var i,j;
	var y = 0;
	var z = 0;
	var g_original = 0;
	var g_price = 0;
	var g_point = 0;
	var g_jaego = (f.price_type.value != "2") ? parseInt(filterNum(f.jaego.value)) : 0;
	var g_ipgo  = (f.price_type.value != "2") ? parseInt(filterNum(f.ipgo.value))  : 0;
	
	if (f.price_type.value == "3")
	{
		f.price.value = "º°µµÇùÀÇ";
		f.point.value = "¹ÌÁ¤";

		if (g_ipgo)
		{	
			eval("document.all.jaego_span"+js).style.visibility = "visible";
			f.jaego.size  = commaSplit(g_jaego).length;
			f.jaego.value = commaSplit(g_jaego);
		}
		else {
			eval("document.all.jaego_span"+js).style.visibility = "hidden";
		}
		
		if (g_ipgo)
		{
			var jaego = parseInt(filterNum(f.jaego.value));
			var fnum = parseInt(f.buy_num.value);
			if (fnum > jaego)
			{
				//alert('\nÁÖ¹®¼ö·®ÀÌ Àç°í¼ö·®º¸´Ù ¸¹¾Æ ÁÖ¹®¼ö·®À»        \n\nÇöÀç Àç°í¼ö·®À¸·Î º¯°æÇÏ¿´½À´Ï´Ù.          \n');
				f.buy_num.value = jaego;
				return false;
			}
		}
		return false;
	}

	for(i = 0; i < f.length; i++)
	{
		if(f[i].name.substr(0,9) == 'tmp_price' && f[i].value)
		{
			var cha = f[i].value.split('|');
			g_original += parseInt(cha[1]);
			g_price += parseInt(cha[1]);
			g_point += parseInt(cha[2]);
			g_ipgo  += parseInt(cha[3]);
			g_jaego += parseInt(cha[3]) - (parseInt(cha[4])+parseInt(cha[5]));
			f.ipgo.value = cha[3];
		}
		if(f[i].name.substr(0,9) == 'tmp_optio' && f[i].value)
		{
			if (f[i].type == 'radio')
			{
				var opt = f[i].value.split('|');
				if (opt[4] != '0' && parseInt(opt[4]) - (parseInt(opt[5]) + parseInt(opt[6])) < 1)
				{
					f[i].checked = false;
				}
				if(f[i].checked == true) {
					g_price += parseInt(opt[2]);
					g_point += parseInt(opt[3]);
				}
			}
			else {
				var opt = f[i].value.split('|');
				if (opt[4] != '0' && parseInt(opt[4]) - (parseInt(opt[5]) + parseInt(opt[6])) < 1)
				{
					for(j = 0; j < f[i].options.length; j++) {
						var scha = f[i].options[j].value.split('|');
						if (scha[4] == '0' || parseInt(scha[4]) - (parseInt(scha[5]) + parseInt(scha[6])) > 0)
						{ 
							y++;
							if (y == 1)
							{
								f[i].options[j].selected = true;
								g_price += parseInt(scha[2]);
								g_point += parseInt(scha[3]);
							}
						}
					}
				}
				else {
					g_price += parseInt(opt[2]);
					g_point += parseInt(opt[3]);
				}
			}
		}
	}
	if (f.price_type.value == "1")
	{
		g_original += parseInt(f.price_original.value);
		g_price += parseInt(f.price_original.value);
		g_point += parseInt(f.point_original.value);
	}

	if (parseInt(f.halin_event_tmp.value))
	{
		var event_halin_price = parseInt(g_original * (parseInt(f.halin_event_tmp.value)/100));
		f.original_price.value = commaSplit(g_original) + "¿ø";
		f.halin_event.value = commaSplit(event_halin_price) + "¿ø ("+f.halin_event_tmp.value+"%)";
		g_price -= event_halin_price;
	}
	if (parseInt(f.halin_member_tmp.value))
	{
		var event_halin_price1 = parseInt(g_original * (parseInt(f.halin_member_tmp.value)/100));
		f.halin_member.value = commaSplit(event_halin_price1) + "¿ø ("+f.halin_member_tmp.value+"%)";
		g_price -= event_halin_price1;
	}


	f.price.value = commaSplit(g_price) + "¿ø";
	f.point.value = commaSplit(g_point) + "¿ø";

	if (g_ipgo)
	{	
		eval("document.all.jaego_span"+js).style.visibility = "visible";
		f.jaego.size  = commaSplit(g_jaego).length;
		f.jaego.value = commaSplit(g_jaego);
	}
	else {
		eval("document.all.jaego_span"+js).style.visibility = "hidden";
	}
	
	if (g_ipgo)
	{
		var jaego = parseInt(filterNum(f.jaego.value));
		var fnum = parseInt(f.buy_num.value);
		if (fnum > jaego)
		{
			//alert('\nÁÖ¹®¼ö·®ÀÌ Àç°í¼ö·®º¸´Ù ¸¹¾Æ ÁÖ¹®¼ö·®À»        \n\nÇöÀç Àç°í¼ö·®À¸·Î º¯°æÇÏ¿´½À´Ï´Ù.          \n');
			f.buy_num.value = jaego;
			return false;
		}
	}

}
function getJeolsa(money , num , alt)
{
	var money = ''+parseInt(money)+'';
	var jeolsa = money.substr(money.length - num , num);
	var rmoney = money - jeolsa;
	if (alt && jeolsa != '0')
	{
		alert(jeolsa + '¿øÀÌ Àý»çµÇ¾ú½À´Ï´Ù.       ');
	}
	return rmoney;
}
function checkID(type)
{
	var obj = document.member_info;
	
	str = obj.MB_ID.value;
	
	ids.innerHTML = "";
	ids.innerHTML += "<iframe src='include/lib/id_check.php?id="+str+"&type="+type+"' frameborder='0' width=300 height=20></iframe>";
}
function OpenZipcode(pwd,fname,z1,z2,ad,ad1) 
{
	var gpwd = (pwd) ? pwd : '.';
	var url = gpwd+'/pack/zipsearch/zipcode.php?form='+fname+'&zip1='+z1+'&zip2='+z2+'&address='+ad+'&address1='+ad1;
	window.open(url,'zip_win','width=460,height=550,statusbar=no,scrollbars=yes,toolbar=no');
}
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 mainlog_check()
{
	var f = document.mainlog_form;

	if (!f.MB_ID.value)
	{
		alert('¾ÆÀÌµð¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä              ');
		f.MB_ID.focus();
		return false;
	}
	if (!f.MB_PW.value)
	{
		alert('ÆÐ½º¿öµå¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä              ');
		f.MB_PW.focus();
		return false;
	}
	return true;
}
function AutoResize(img){ 
  foto1= new Image(); 
  foto1.src=(img); 
  Controlla(img); 
} 
function Controlla(img){ 
  if((foto1.width!=0)&&(foto1.height!=0)){ 
    viewFoto(img); 

  } 
  else{ 
    funzione="Controlla('"+img+"')"; 
    intervallo=setTimeout(funzione,20); 
  } 
} 


function viewFoto(img){ 
  largh=foto1.width+0; 
  altez=foto1.height+0; 
  stringa="width="+largh+",height="+altez; 

var open_img = img;
  finestra=window.open('about:blank','',stringa); 
  finestra.document.writeln("<html><head><meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ks_c_5601-1987'></head><body leftmargin=0 topmargin=0><img src='"+open_img+"' onClick='self.close();'></body></html>"); 
  finestra.document.close(); 
}
function JS_view(objhtml) { 
    document.write(objhtml); 
} 
function obj_swf(filenm, widthSWF, heightSWF) {
 document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"     codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" width="' + widthSWF + '" height="' + heightSWF + '" align=middle name=img_1 VIEWASTEXT id=OBJECT1>');
 document.writeln('<param name="AllowScriptAccess" value="never"> ');
 document.writeln('<param name="quality" value="high">');
 document.writeln('<param name="bgcolor" value="#ffffff">');
 document.writeln('<param name="wmode" value="transparent">');
 document.writeln('<param name="movie" value="' + filenm + '">');
 document.writeln('<embed AllowScriptAccess="never" src="' + filenm + '" width="' + widthSWF + '" height="' + heightSWF + '" ></embed>');
 document.writeln('</object>');
}

