function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;		
	}else{
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/*Ã¼Å©¹Ú½º ÀÌ¹ÌÁö·Î*/
/**
 * Created by Çàº¹ÇÑ°í´Ï
 *
 * Homepage    : http://mygony.com
 * Last update : 2005/02/22
 *
 * 2004-09-23 
 *     - Ã¹¹øÂ° ¸±¸®Áî
 * 2005-02-22
 *     - checked ·Î ¼³Á¤ÇßÀ»°æ¿ì Ã¹¹øÂ° Å¬¸¯¿¡ ¹ÝÀÀÇÏÁö ¾Ê´ø ¿À·ù¼öÁ¤ (¿¬È÷ ´Ô)
 *     - undefined Ã¼Å© ±¸¹® ¼öÁ¤ (ºô ´Ô)
 */
function imgCbox(N, tabstop)
{
	var objs, cboxes, Img, Span, A;

	if (typeof N == 'undefined') return false;
	if (typeof tabstop == 'undefined') tabstop = true;
	if ((objs=document.getElementsByName(N)) == null) return false;

	for (var i=0; i < objs.length; i++) {
		if (objs[i].tagName.toLowerCase() != "input" || objs[i].type.toLowerCase() != "checkbox") continue;
		
		if (typeof imgCbox.Objs[N] == 'undefined') {
			imgCbox.Objs[N] = new Array;
			imgCbox.ImgObjs[N] = new Array;
		}
		
		var len = imgCbox.Objs[N].length;
		imgCbox.Objs[N][len] = objs[i];
		imgCbox.ImgObjs[N][len] = {};

		// anchor element for tab stop
		A = document.createElement("A");
		if (tabstop) {
			A.href = "javascript:;";
		}
		A.onclick =  new Function("imgCbox.onclick('"+N+"',"+len+")");
		A.style.borderWidth = "0px";
		A.style.cursor = "pointer";

		// for image cache
		Img = document.createElement("IMG");
		Img.src = objs[i].getAttribute("onsrc");
		Img.style.borderWidth = "0px";
		Img.style.display = objs[i].checked?"":"none";
		imgCbox.ImgObjs[N][len]["on"] = Img;
		A.appendChild(Img);

		Img = document.createElement("IMG");
		Img.src = objs[i].getAttribute("offsrc");
		Img.style.borderWidth = "0px";
		Img.style.display = objs[i].checked?"none":"";
		imgCbox.ImgObjs[N][len]["off"] = Img;
		A.appendChild(Img);

		// insert object
		Span = objs[i].parentNode;
		Span.style.display = "none";
		Span.parentNode.insertBefore(A, Span);

	}
}
imgCbox.onclick = function(N, idx) {
	var C = imgCbox.Objs[N][idx];
	var I = imgCbox.ImgObjs[N][idx];

	C.checked = !C.checked;
	if (C.checked) {
		I["on"].style.display = "";
		I["off"].style.display = "none";
	} else {
		I["on"].style.display = "none";
		I["off"].style.display = "";
	}
	
	// fire event
	if (typeof C.onclick != 'undefined' && C.onclick != null) C.onclick();
}
imgCbox.Objs = {};
imgCbox.ImgObjs = {};

//IE PNG use
function setPng24(obj) { 
      var browser = navigator.appName;
      var version = parseFloat(navigator.appVersion.replace (/^.*MSIE ([.0-9]+).*$/,"$1"));

      if(browser.indexOf("Internet Explorer") && version < 7.0 ) { // IE6 ÀÌÇÏ¿¡¼­¸¸ µ¿ÀÛ 2008-03-14 by zardsama
            obj.width=obj.height=1; 
            obj.className=obj.className.replace(/\bpng24\b/i,''); 
            obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
            obj.src='';  
            return ''; 
      }
}

function boxRound(mode,wh) { 

	if (mode=="top") {
			if (wh>0){
		document.write('<table width="'+wh+'" cellspacing="0" cellpadding="0" style="margin:0 auto;">');
			}else{
		document.write('<table width="100%" cellspacing="0" cellpadding="0" style="margin:0 auto;">');
			}
		document.write('<tr>');
		document.write('<td width="8" height="8"><img src="/_image/shop/box_left_top.gif" border="0" alt="" /></td>');
		document.write('<td width="100%" height="8" background="/_image/shop/box_top.gif"></td>');
		document.write('<td width="8" height="8"><img src="/_image/shop/box_right_top.gif" border="0" alt="" /></td>');
		document.write('</tr>');
		document.write('<tr>');
		document.write('<td colspan="3" bgcolor="#ececec" style="padding:0 1px;">');
		document.write('<table width="100%" cellspacing="0" cellpadding="0" bgcolor="#f3f3f3">');
		document.write('<tr>');
		document.write('<td style="padding:0 5px;">');
		document.write('<table width="100%" cellspacing="0" cellpadding="0" bgcolor="#ffffff">');
		document.write('<tr>');
		document.write('<td style="padding:3px 5px;">');
	}else if (mode=="bottom") {
		document.write('</td>');
		document.write('</tr>');
		document.write('</table>');
		document.write('</td>');
		document.write('</tr>');
		document.write('</table>');
		document.write('</td>');
		document.write('</tr>');
		document.write('<tr>');
		document.write('<td width="8" height="8"><img src="/_image/shop/box_left_bottom.gif" border="0" alt="" /></td>');
		document.write('<td width="100%" height="8" background="/_image/shop/box_bottom.gif"></td>');
		document.write('<td width="8" height="8"><img src="/_image/shop/box_right_bottom.gif" border="0" alt="" /></td>');
		document.write('</tr>');
		document.write('</table>');
	}
}

//TopBtn Scroll
function back_top() {
	x = document.body.scrollLeft;
	y = document.body.scrollTop;
	
	step = 2;

		while ((x != 0) || (y != 0)) {
			scroll (x, y);
			step += (step * step / 1);
			x -= step;
			y -= step;
			
			if (x < 0) x = 0;
			if (y < 0) y = 0;
		} 
	scroll (0, 0);
}

function rolloverImg(rId) {//·Ñ¿À¹ö
	var roll_id = document.getElementById(rId);

	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!roll_id) return true;

	var aPreLoad = new Array();
	var sTempSrc;
	var imgs = roll_id.getElementsByTagName("img");

	for(var i=0; i < imgs.length; i++) {
		var src = imgs[i].getAttribute('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace(ftype, 'o'+ftype);

		imgs[i].setAttribute('hsrc', hsrc);

		aPreLoad[i] = new Image();
		aPreLoad[i].src = hsrc;

		if (!imgs[i].className){
			imgs[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}

			imgs[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

function imgOver(imgEl,opt) {//·Ñ¿À¹ö2
    var src = imgEl.getAttribute('src');
    var ftype = src.substring(src.lastIndexOf('.'), src.length);
    
    if (opt == 'out') imgEl.src = imgEl.src.replace("o"+ftype, ftype);
    else imgEl.src = imgEl.src.replace(ftype, "o"+ftype);
}

function rollovers(){
	rolloverImg('mainCategory');
	//rolloverImg('categoryList');
	rolloverImg('categoryListPrd');
}

addLoadEvent(rollovers);

function viewDetailLayer(url) {
	if(!document.getElementById) return false;
	if(!document.getElementById('detailPop')) return false;
	var layer = document.getElementById ("detailPop");
	var getDetail = getHttpRequest(url);

	layer.innerHTML = getDetail;
	//layer.style.top = (document.body.scrollTop + 20)+"px";
	layer.style.display = "block";
}

function ckEnquiryFrm(f) {
	if (!f.email.value) {
		window.alert ("Please input 'email address'");
		return false;
	}

	if (!f.name.value) {
		window.alert ("Please input 'name'");
		return false;
	}
	return true;
}

function submitPrd() {
	var prd = document.getElementsByName("ckprd[]");
	var data = "";
	for (i = 0; i < prd.length; i++)	{
		if (prd[i].checked == true) data += "@"+prd[i].value;
	}

	data = data.replace (/^@+/,"");
	document.getElementById ("enquiryFrm").prd.value = data;
}


// Àå¹Ù±¸´Ï ÇÔ¼ö ÇÑ±Û¹®Á¦·Î 
var qna_edit=1;
function addCart2(f,next) {
	var astr = '';
	if (f.stat.value!=2)
	{
		ems='\n ÁË¼ÛÇÕ´Ï´Ù\n\n '+soldout_name+'µÈ »óÇ°Àº ÁÖ¹®ÇÒ ¼ö ¾ø½À´Ï´Ù        \n';
		if (typeof f.sold_reserve!='undefined' && f.sold_reserve.value=='Y')
		{
			ems+='\n ¿¹¾àÁÖ¹®ÇÏ±â¸¦ ÀÌ¿ëÇÏ½Ã¸é ÀÔ°íÈÄ ¿¬¶ôµå¸®°Ú½À´Ï´Ù        ';
		}
		alert(ems);
		return;
	}
	var min_ord=eval(f.min_ord.value);
	var max_ord=eval(f.max_ord.value);
	var buy_ea=eval(f.buy_ea.value);


	if (buy_ea<min_ord)
	{
		if(min_ord>1) astr='ÀÌ »óÇ°Àº ';
		alert(astr+'ÃÖ¼Ò '+min_ord+'°³ ÀÌ»ó ±¸¸ÅÇÏ¼Å¾ßÇÕ´Ï´Ù');
		f.buy_ea.value=min_ord;
		return;
	}
	if (max_ord && buy_ea>max_ord)
	{
		alert('ÀÌ »óÇ°Àº ÃÖ´ë '+max_ord+'°³±îÁö ±¸¸ÅÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù');
		f.buy_ea.value=max_ord;
		return;
	}

	opt_no=eval(f.opt_no.value);
	if (opt_no>0)
	{
		for (j=1; j<=eval(opt_no); j++)
		{
			if (f.elements['option_necessary'+j].value=="Y") // necessary
			{
				if (f.elements['option_type'+j].value==2) // select
				{
					if (!checkSel(f.elements['option'+j],f.elements['option_name'+j].value+'À»(¸¦)')) return;
				}
				else // radio, checkbox
				{
					if (!checkCB(f.elements['option'+j],f.elements['option_name'+j].value+'À»(¸¦)')) return;
				}

			}
			// <2006-12-01 : ¿É¼ÇÀç°íÃ¼Å© - Han
			if(f.elements['option_ea_ck'+j].value == "Y"){
				if(f.elements['option_ea_num'+j].value < 1){ alert("ÇØ´ç ¿É¼ÇÀº Ç°ÀýµÇ¾ú½À´Ï´Ù. - "+f.elements['option_name'+j].value+"   "); return; }
				if(buy_ea > f.elements['option_ea_num'+j].value){ 
					alert("ÇØ´ç ¿É¼ÇÀº "+f.elements['option_ea_num'+j].value+"±îÁö¸¸ ±¸¸Å°¡ °¡´ÉÇÕ´Ï´Ù. - "+f.elements['option_name'+j].value+"   ");
					f.buy_ea.value=f.elements['option_ea_num'+j].value;
					return;
				}
			}
			// >
		}
	}


	//cwith=confirm('\n Àå¹Ù±¸´Ï¿¡ ÀÖ´Â »óÇ°°ú ÇÔ²² ÁÖ¹®ÇÏ½Ã°Ú½À´Ï±î?\n\n \'Ãë¼Ò\'À» Å¬¸¯ÇÏ½Ã¸é ¼±ÅÃÇÏ½Å »óÇ°¸¸ ÁÖ¹®ÇÕ´Ï´Ù                  ');
	cwith=1;
	if (next==1 || (next==2 && cwith))
	{
		tg=hid_frame;
		ac=root_url+'/shop/cart.exe.php';
		f.next.value=next;
	}
	else
	{
		tg='';
		ac=root_url+'/shop/order.php';
	}
	
	f.exec.value='add';
	f.target=tg;
	f.action=ac;
	f.submit();

}

function printDetail() {
	var win;

	win = window.open(root_url+"/content/content.php?cont=printDetail&mode=1", "printDetail", "width=620px, height=600px, status=no");
}
