function CartAdditem(vals) {
	// wishlist °¡ ¾Æ´Ò°æ¿ì
	var keys = vals;

	if(keys !=3) {

		var form_s = document.form_showitem;

		// ¿É¼Ç°ª ¼±ÅÃ¿©ºÎ¿¡ µû¸¥ Ã¼Å©
		var n=0;
		var select_obj="";
		var optionprice = 0;
		var quantity = document.form_showitem.quantity.value;	// ÁÖ¹®¼ö·®

		// ´Ù½Ã°è»ê
		if(Sum_option()==false) {
			return;
		}

		if(isNaN(quantity) || quantity <1) {
			alert("¼ö·®À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä");
			document.form_showitem.quantity.value=1;
			return;
		}

		if(form_s.op2_name != null) {
			if(form_s.op2_name[0].selected==true) {
						alert(form_s.op2_title.value+"¸¦ ¼±ÅÃÇØ ÁÖ¼¼¿ä");
						form_s.op2_name.focus();
						return;
			}
		}
		if(form_s.opq_name != null) {
			var opq_val = form_s.opq_name.value;
			if(eval("document.form_showitem."+opq_val+"[0]").selected==true) {
						alert(form_s.op3_title.value+"¸¦ ¼±ÅÃÇØ ÁÖ¼¼¿ä");
						eval("document.form_showitem."+opq_val).focus();
						return;
			}
		}

		for(var i=0; i<8; i++) {
				n = n+1;
				var type_name = "option"+n+"_type";
				var val_name = "value_"+n;
				var o_name = "o_name"+n;
				var ch_num = 0;

				var optiontype_obj = eval("document.form_showitem."+type_name);

				if(optiontype_obj !=null) {		// ¿É¼ÇÀÌ »ç¿ëµÇ¾ú´ÂÁö 
					var optiontype = optiontype_obj.value;		// ¿É¼Çº° Å¸ÀÔ(T,R,C,S,P)
					var optionname = eval("document.form_showitem."+o_name).value;
					var value_name = eval("document.form_showitem."+val_name);			// ¿É¼Çº¯¼ö¸í

					if( optiontype !="P" ) {
									if(optiontype =="S") {

											var value_val =  value_name.value;	// ¿É¼Ç°ª
											var value_ln = value_val.length;	

											if(value_name !=null) {
													if(value_name[0].selected==true) {
															alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
															value_name.focus();
															return;
													}
											} // if(value_name !=null)

									} else if(optiontype =="R") {	// radio box
											
											var radio_ln = value_name.length;	// ¶óµð¿À ¹öÆ° °¹¼ö
							
											if(radio_ln >0) {
													for(var r=0; r<radio_ln; r++) {
															if(value_name[r].checked == true) {
																ch_num++;
															}
													}

													if(ch_num <1 ) {
																	alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
																	return;
													} // if(value_name !=null)
											} else {
															if(value_name.checked==false) {
																	alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
																	return;
															}
											}
									} else if(optiontype =="C") {	// check box
											var checkbox_ln = eval("document.form_showitem.elements['"+val_name+"[]']").length;

											if(checkbox_ln >0 ) {
													for(var c=0; c<checkbox_ln; c++) {
														if(eval("document.form_showitem.elements['"+val_name+"[]']["+c+"]").checked==true) {
																ch_num++;
														}
													}
													if(ch_num < 1) {
																alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
																return;
													}

											} else {
													if(eval("document.form_showitem.elements['"+val_name+"[]']").checked==false) {
																alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
																return;
													}
											}
									} else if(optiontype =="T") {
											if(value_name.value =="") {
														alert(optionname+"À» ¼±ÅÃÇÏ¼¼¿ä!");
														value_name.focus();
														return;
											}
									
									} // if(optiontype =="S") END
						}	// if(optiontype !="P" ) END
				}	// if(optiontype_obj !=null) END
				
		}	// for(var i=0; i<8; i++) END

	}	// if(keys !=3) end

	if(keys==1) {	//Àå¹Ù±¸´Ï ´ã±â(1)
		document.form_showitem.action = "cart_additem.php";
		document.form_showitem.AddType.value = "ADD";
		document.form_showitem.submit();

	} else if(keys==2) {	//¹Ù·Î ±¸¸Å(2)
		document.form_showitem.action = "cart_additem.php";
		document.form_showitem.AddType.value = "NOW";
		document.form_showitem.submit();
	} else if(keys==3) {	//Wish List(3)
		document.form_showitem.action = "wishlist_additem.php";
		document.form_showitem.AddType.value = "WISH";
		document.form_showitem.submit();
	}
}

// ¿É¼Çº° ¼ö·®¿¡ µû¸¥ ÆÇ¸Å°¡ ¹× ¼ö·® °è»ê
function Sum_option() {
	var form = document.form_showitem;
	var p_sprice = form.p_sprice.value;	// ½ÇÁ¦ ÆÇ¸Å°¡
	var option_pricetype = form.option_pricetype.value;	 // ¿É¼Çº° °¡°Ý Àû¿ë¹æ½Ä(A-Ãß°¡, S-µ¶¸³Àû)
	var total_quantity = form.total_quantity.value;	// »óÇ°ÀüÃ¼ ¼ö·®
	var quantity = form.quantity.value;	// ÁÖ¹®ÇÒ ¼ö·®
	var quantity_type = form.quantity_type.value;	// ¼ö·®Àû¿ëÅ¸ÀÔ(1-ÇÏ³ª·ÎÀû¿ë,2-1´Ü°è,3-´Ü°è,4-¹«ÇÑ´ë)
	var new_total_price;		// »õ·Î °è»êµÈ ÁÖ¹®±Ý¾×
	var new_quantity;			// »õ·Î °è»êµÉ ÁÖ¹®¼ö·®
	var total_2, total_3;	

	//-- ¼ö·® Ã¼Å©(ÀÏ¹Ý¼ö·®)
	if(isNaN(quantity) || quantity <1) {
		alert("¼ö·®À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä");
		document.form_showitem.quantity.value=1;
		return false;
	}

	// ---- ÀÏ¹Ý ¿É¼Çº° °¡°Ý

	var n=0;
	var select_obj="";
	var optionprice = 0;

	for(var i=0; i<8; i++) {
			n = n+1;
			var type_name = "option"+n+"_type";
			var val_name = "value_"+n;
	
			var optiontype_obj = eval("document.form_showitem."+type_name);

			if(optiontype_obj !=null) {
				var optiontype = optiontype_obj.value;		// ¿É¼Çº° Å¸ÀÔ(T,R,C,S,P)
				var value_name = eval("document.form_showitem."+val_name);			// ¿É¼Çº¯¼ö¸í

				//if(value_name != null) {	
		//alert(optiontype);
						if( optiontype !="T" && optiontype !="P" ) {

								if(optiontype =="S") {

										var value_val =  value_name.value;	// ¿É¼Ç°ª
										var value_ln = value_val.length;	

										if(value_name !=null) {

												if(value_name[0].checked) {
													optionprice +=0;			// ¿É¼Çº° °¡°ÝÇÕ

												} else {
													if(value_ln>0) {
														
														var value_array = value_val.split("/");	
														optionprice += eval(value_array[1]);			// ¿É¼Çº° °¡°ÝÇÕ

													}
												}

										} // if(value_name !=null)

								} else if(optiontype =="R") {	// radio box
										
										var radio_ln = value_name.length;	// ¶óµð¿À ¹öÆ° °¹¼ö

										for(var r=0; r<radio_ln; r++) {
												if(value_name[r].checked == true) {
													var value_array = value_name[r].value.split("/");	
													optionprice += eval(value_array[1]);			// ¿É¼Çº° °¡°ÝÇÕ
												}
										}

								} else if(optiontype =="C") {	// check box
										var checkbox_ln = eval("document.form_showitem.elements['"+val_name+"[]']").length;

										if(checkbox_ln >0 ) {
											for(var c=0; c<checkbox_ln; c++) {
												if(eval("document.form_showitem.elements['"+val_name+"[]']["+c+"]").checked==true) {
													var value_array = eval("document.form_showitem.elements['"+val_name+"[]']["+c+"]").value.split("/");	
													optionprice += eval(value_array[1]);			// ¿É¼Çº° °¡°ÝÇÕ
												}
											}
										} else {
												if(eval("document.form_showitem.elements['"+val_name+"[]']").checked==true) {
													var value_array = eval("document.form_showitem.elements['"+val_name+"[]']").value.split("/");	
													optionprice += eval(value_array[1]);			// ¿É¼Çº° °¡°ÝÇÕ	

												}
										}

								}
						}
			} // if(optiontype_obj !=null)  end 
	}	// for(var i=0; i<8; i++) end

	// ---  ¿É¼Çº° ¼ö·® °¡°Ý°è»ê
	if(quantity_type==2) {

			if(form.op2_name[0].selected==true) {
					total_2 = 0;
					total_3 = 0;
					new_quantity = quantity;	
					alert(form.op2_title.value+"¸¦ ¼±ÅÃÇØ ÁÖ¼¼¿ä");
					form.op2_name.focus();

					// -- ÀüÃ¼ ÁÖ¹®±Ý¾× °è»ê
					if(option_pricetype=="A") {		// Ãß°¡
							new_total_price = (eval(p_sprice) + eval(optionprice)) * eval(new_quantity);
					} else {		// µ¶¸³Àû
							if(optionprice >0) {
								new_total_price = eval(optionprice) * eval(new_quantity);
							}else {
								new_total_price = eval(p_sprice) * eval(new_quantity);
							}
					}

					document.form_showitem.P_SPRICE.value = eval(new_total_price);
					document.form_showitem.P_SPRICE.value = Pprice_string("form_showitem", "P_SPRICE");
					// -- ÀüÃ¼ ÁÖ¹®±Ý¾× °è»ê ³¡

					return false;
			} else {
					var op2_value = form.op2_name.value;		// Ç×¸ñ°ª(Ç×¸ñ/°¡°Ý/¼ö·®)
					var op2_array = op2_value.split("/");				
			
					total_2 = eval(op2_array[1]);	
					total_3 = 0;
					new_quantity = eval(op2_array[2]);		// ¿É¼Çº° ÇöÀç Àç°í·®

					//-- ¼ö·® Ã¼Å©(¼ö·®)
					if(eval(op2_array[2]) >= eval(quantity)) {	// ÁÖ¹®°¡´ÉÇÑ ¼ö·®ÀÎÁö Ã¼Å©
							new_quantity = quantity;		// ¿É¼Çº° ÇöÀç Àç°í·®								
					} else {
							alert("ÇöÀç º¸À¯¼ö·®ÀÌ ºÎÁ·ÇØ¼­ "+eval(op2_array[2])+"°³ ÀÌ»ó ±¸ÀÔÇÒ ¼ö ¾ø½À´Ï´Ù.");
							document.form_showitem.quantity.value = eval(op2_array[2]);
							new_quantity = eval(op2_array[2]);
					}
					
					//document.form_showitem.option_price_1.value=eval(op2_array[1]);
					//document.form_showitem.option_value_1.value=op2_array[0];
			}
	} else if(quantity_type==3) {

			if(form.op2_name[0].selected==true) {
				alert("¸ÕÀú "+form.op2_title.value+"¸¦ ¼±ÅÃÇØ ÁÖ¼¼¿ä");
				form.op2_name.focus();

				// -- ÀüÃ¼ ÁÖ¹®±Ý¾× °è»ê
				if(option_pricetype=="A") {		// Ãß°¡
						new_total_price = (eval(p_sprice) + eval(total_2) + eval(optionprice)) * eval(new_quantity);
				} else {		// µ¶¸³Àû
						if((eval(optionprice) + eval(total_2)) >0) {
							new_total_price = (eval(optionprice) + eval(total_2)) * eval(new_quantity);
						} else {
							new_total_price = eval(p_sprice) * eval(new_quantity);
						}
						if(new_total_price <1) {
							new_total_price = parseInt(new_total_price);
						}
				}
				document.form_showitem.P_SPRICE.value = eval(new_total_price);
				document.form_showitem.P_SPRICE.value = Pprice_string("form_showitem", "P_SPRICE");
				// -- ÀüÃ¼ ÁÖ¹®±Ý¾× °è»ê ³¡

				return false;
			} else {
					var op2_value = form.op2_name.value;	
					
					// ¼±ÅÃÇÑ ¿É¼Ç ·¹ÀÌ¾î Ç×¸ñ¸¸ º¸ÀÌ±â
					var layername = op2_value.split("/");  //Ç×¸ñ, ·¹ÀÌ¾îÀÌ¸§, ÀüÃ¼·¹ÀÌ¾î¼ö

					for(var i=1; i<=layername[2]; i++) {
						var new_layer = "LAY"+i;
						var opqname = "select"+i;
						if(i==layername[1]) {
								if(navigator.appName.charAt(0)=="M") {		// ÀÍ½ºÇÃ·Î¿ö
									document.all[new_layer].style.visibility='visible';
									//document.all[new_layer].style.display='block';
									document.form_showitem.opq_name.value=opqname;
								} else {
									document.getElementById("new_layer").visibility='show';
									document.form_showitem.value=opqname;
								}
						} else {
								if(navigator.appName.charAt(0)=="M") {		// ÀÍ½ºÇÃ·Î¿ö
									document.all[new_layer].style.visibility='hidden';	
									//document.all[new_layer].style.display='none';
									document.form_showitem.value=opqname;
								} else {
									document.getElementById("new_layer").visibility='hide';
									document.form_showitem.value=opqname;
								}		
						}
					}	// for(var i=1; i<=layername[2]; i++) end
					
					var opq_val = form.opq_name.value;	 // ÇöÀç Ãâ·ÂµÈ select nameÀ» °¡Á®¿Â´Ù

					if(eval("document.form_showitem."+opq_val+"[0]").selected==true) {						
							total_2 = 0;
							total_3 = 0;
							new_quantity = quantity;	
					} else {
							var op3_value = eval("document.form_showitem."+opq_val).value;		// Ç×¸ñ°ª(Ç×¸ñ/°¡°Ý/¼ö·®)
							var op3_array = op3_value.split("/");

							total_2 = 0;
							total_3 = eval(op3_array[1]);

							//-- ¼ö·® Ã¼Å©(¼ö·®)
							if(eval(op3_array[2]) >= eval(quantity)) {	// ÁÖ¹®°¡´ÉÇÑ ¼ö·®ÀÎÁö Ã¼Å©
									new_quantity = quantity;		// ¿É¼Çº° ÇöÀç Àç°í·®								
							} else {
									alert("ÇöÀç º¸À¯¼ö·®ÀÌ ºÎÁ·ÇØ¼­ "+eval(op3_array[2])+"°³ ÀÌ»ó ±¸ÀÔÇÒ ¼ö ¾ø½À´Ï´Ù.");
									document.form_showitem.quantity.value = eval(op3_array[2]);
									new_quantity = eval(op3_array[2]);

									//document.form_showitem.option_value_1.value=layername[0];					
									//document.form_showitem.option_price_2.value=eval(op3_array[1]);
									//document.form_showitem.option_value_2.value=op3_array[0];

							}
					}

			}

	} else if(quantity_type==1){

			if(total_quantity >= eval(quantity)) {	// ÁÖ¹®°¡´ÉÇÑ ¼ö·®ÀÎÁö Ã¼Å©
				new_quantity = quantity;
			} else {
				alert("ÇöÀç º¸À¯¼ö·®ÀÌ ºÎÁ·ÇØ¼­ "+total_quantity+"°³ ÀÌ»ó ±¸ÀÔÇÒ ¼ö ¾ø½À´Ï´Ù.");
				document.form_showitem.quantity.value = total_quantity;
				new_quantity = total_quantity;
			}

			total_2 = 0;
			total_3 = 0;

	} else {		
			//-- ¼ö·® Ã¼Å©(¹«ÇÑ¼ö·®)
			new_quantity = quantity;

			total_2 = 0;
			total_3 = 0;
	}

	// -- ÀüÃ¼ ÁÖ¹®±Ý¾× °è»ê
	if(option_pricetype=="A") {		// Ãß°¡
			new_total_price = (eval(p_sprice) + eval(optionprice) + eval(total_2) + eval(total_3)) * eval(new_quantity);

	} else {		// µ¶¸³Àû
			if((eval(optionprice) + eval(total_2) + eval(total_3)) >0) {
				new_total_price = (eval(optionprice) + eval(total_2) + eval(total_3)) * eval(new_quantity);
			} else {
				new_total_price = eval(p_sprice) * eval(new_quantity);
			}

	}

	document.form_showitem.P_SPRICE.value = eval(new_total_price);
	document.form_showitem.P_SPRICE.value = Pprice_string("form_showitem", "P_SPRICE");
}



// °¡°Ý¿¡ ',', ¿ø ºÙÀÌ±â
function Pprice_string(form, obj) {
	var price_ln = eval("document."+form+"."+obj+".value").length;
	var val="";
	var n_val="";
	var r=0;
	if(eval("document."+form+"."+obj+".value") >0) {
		for(var i=eval(price_ln); i >= 0; i--) { 
			val = eval("document."+form+"."+obj+".value").charAt(i);

			if(r%3==1 && r !=1 ) { 
				n_val =val+ "," +n_val;
			} else {
				n_val = val + n_val; 
			}
			r++;
		}	

		if(document.form_showitem.corner_case.value=="ML") {
			return n_val+ " Á¡";
		} else {
			return n_val+ " ¿ø";
		}
	} else {
		return "0 ¿ø";
	}
}
