function add_basket( arg )
{
	if( check_frm() )
	{
		frm.command.value = 'add';
		frm.redirect.value = arg ;
		if(frm.option13 != undefined){
			alert('상품옵션은 15개까지만 가능합니다.\n관리자에 문의하십시요');	
			return;
		}		                       
		frm.submit();
	}
}

function check_frm() {
    var frm = document.frm;
    if (frm.p_sale_price_type.value == 'M') {
    	alert("주문할수 없는 상품입니다. 운영자에게 문의해 주세요");
    	return false;
    }
    if (iPrdItemType != '1') {
    	for (var i=0; i < iOptionsLen; i++) {
    		oObj = document.getElementById('option' + i);
    		if (oObj.options.selectedIndex < 1) {
    			alert('필수 옵션이 선택되지 않았습니다.');
    			oObj.focus();
    			return false;    
    		}
    	}
    }
    // by jsyoon 옵션문구 크기 체크 
    if(frm.option_add != undefined && frm.add_option_name != undefined) {
    	var txtval = frm.add_option_name.value
    	var bsize = 0;
    	bsize = 255 - str_size_check(txtval) - 1;
    	if(!frm.option_add.value.length) {
    		alert('필수옵션이 선택되지 않았습니다');
    		return false;
    	}
    	
    	if(!check_byte(frm.option_add, bsize, "옵션문구는 한글 " + Math.floor(bsize / 2) + "자이내로만 입력가능합니다.")){
    		frm.option_add.focus();
    		return false;
    	}
    }
    
    if (! frm.quantity.value) {
    	alert ('수량을 입력해 주십시오.');
    	frm.quantity.focus();
    	return false;
    }
    
    for (i = 0; i < frm.quantity.value.length; i++) {
    	if (! (frm.quantity.value.charAt(i) >= '0' && frm.quantity.value.charAt(i) <= '9')) {
    		alert ('수량은 숫자만 가능합니다.');
    		frm.quantity.select();
    		return false;
    	}
    }
    
    if (!frm.prd_item_code.value) {
    	alert('상품옵션에 에러가 있습니다. 관리자에게 문의하세요');
    	return false;
    }
    
    //if (parseInt(frm.quantity.value) > parseInt(frm.product_min.value)) {
    //	alert ('최소 주문수량은 ' + frm.product_min.value + ' 입니다.');
    //	frm.quantity.select();
    //	return false;
    //}
    if (parseInt(frm.quantity.value) < 1) {
    	alert('주문수량은 1개 이상이어야 합니다.');
    	frm.quantity.select();
    	return false;
    }

	return true;
}

function review_read( id )
{
	show_id = document.all[id]

	if( show_id.style.display == 'block' )
	{
		show_id.style.display = 'none'
	}
	else
	{
		show_id.style.display = 'block'
	}
}

function recommend_mail_pop( product_no, category_no, display_group )
{
        
        //alert('추천메일보내기 준비중입니다.');

        option = "'toolbar=no," +
                "location=no," +
                "directories=no," +
                "status=no," +
                "menubar=no," +
                "scrollbars=yes," +
                "resizable=yes," +
                "width=576," +
                "height=568," +
                "top=300," +
                "left=200"

	filename = "/front/php/recommend_mail/recommend_mail.php?product_no=" + product_no + "&category_no=" + category_no;
	filename += "&display_group=" + display_group

        open_window( filename, option, "recommend_mail_pop" );
}

function changeImage(img_url, width, height){
	document.big_img.src = img_url;
	document.big_img.width = width;
	document.big_img.height = height;
    	return;
}

// 상품의 복합형, 조합형별로 옵션 아이디를 가져오는 함수  
// by jsyoon 05/11/17
function get_option_ids(otype, idx) {
	var count = 0;
	var thisfrm = document.frm;
	var selfrm;
	var retval = '';
	var tmpval;
	
	// 조합형인경우 
	if(otype == 'T') {
		if(thisfrm.opid.length == undefined){
			selfrm = eval("document.frm." + thisfrm.opid.value);
			tmpval = selfrm.options[selfrm.options.selectedIndex].value;
			if(tmpval == 0)
				return '';				
			return  tmpval + "-0-0";
		}	
		for(var i =0; i < 3; i++) {
			if(thisfrm.opid[i] == undefined){
					tmpval = 0;
			} else {
				selfrm = eval("document.frm." + thisfrm.opid[i].value);
				tmpval = selfrm.options[selfrm.options.selectedIndex].value;
				// 옵션중 선택되지 않은 항목이 있는경우 return
				if(tmpval == 0)
					return '';							
			}
			
			if(i == 0)
				retval =+ tmpval;
			else
				retval = retval + "-" + tmpval;					
		}
		// 복합형인경우 	
	} else if(otype == 'F'){
		for(var i =0; i < 3; i++) {
			if(i == (idx - 1)) {
				if(thisfrm.opid.length == undefined)
					selfrm = eval("document.frm." + thisfrm.opid.value);
				else	
					selfrm = eval("document.frm." + thisfrm.opid[i].value);
				tmpval = selfrm.options[selfrm.options.selectedIndex].value;
			} else {
				tmpval = 0;
			}
			if(i == 0)
				retval =+ tmpval;
			else
				retval = retval + "-" + tmpval;					
		}					
	} else if(otype == 'E'){
        if(thisfrm.opid.length == undefined)    
        {
            selfrm = eval("document.frm." + thisfrm.opid.value); 
        }
        else
        {
		    selfrm = eval("document.frm." + thisfrm.opid[(idx - 1)].value);
        }

		tmpval = selfrm.options[selfrm.options.selectedIndex].value;
	        if(tmpval == 0)
			return '';
		retval = idx + "-" + tmpval;
		
	}
	return retval;
}

function coupon_apply(no)
{
	var frm = eval("document.coupon_" + no);
	frm.submit();
}

