/**
 * Àå¹Ù±¸´Ï´ã±â
 * @param passField ÆÐ½º¿öµå element - form.element
 * @param confirmField ÆÐ½º¿öµå È®ÀÎ element - form.element
 * @return boolean
 */

	var _shopCartArray_ = new Array();
	var _wishListArray_ = new Array();
	var _goshopCartYn_ = false;
	var _goshopWishYn_ = false;
	var _refreshTarget_ = "";	
	var _refreshSrcWindow_ = "";
	
	var _user_checkbox_ = function(isChecked) {
		this.checked = isChecked;
	}
	
	function _fn_checkShopCart_(checkbox, item_id, unit_id, order_qty, last_sale_price, ctl_comp_item_info, sale_shop_gubun_code, shop_id) {

		if (typeof(_shopCartArray_[item_id]) == "undefined" || typeof(_shopCartArray_[item_id]) == null ) {
			var shopCart = new ShopCart();
			shopCart.checkbox = checkbox;
			//shopCart.session_id = "<%=Const.SESSION_ID%>";
			shopCart.item_id = item_id;
			shopCart.unit_id = unit_id;
			shopCart.selected_unit_id = unit_id;
			shopCart.order_qty = order_qty;
			shopCart.selected_order_qty = order_qty;
			shopCart.sale_price = last_sale_price;
			if (typeof(sale_shop_gubun_code) != "undefined" && typeof(sale_shop_gubun_code) != null ) shopCart.sale_shop_gubun_code = sale_shop_gubun_code;
			if (typeof(shop_id) != "undefined" && typeof(shop_id) != null ) shopCart.shop_id = shop_id;

			_shopCartArray_[item_id] = shopCart;
			
			//¼¼Æ®»óÇ°ÀÏ °æ¿ì ¼¼Æ®»óÇ°ÀÇ °¹¼ö¸¸Å­ µ¹¸°´Ù.
			//if (typeof(ctl_selected_comp_item_id) != "undefined" && typeof(ctl_selected_comp_item_id) != null ) {
			if(ctl_comp_item_info != null && ctl_comp_item_info.length > 0) {
			
				//var ctl_selected_comp_item_id = fn_toArray(ctl_selected_comp_item_id);	//¹è¿­ÀÌ ¾Æ´Ñ°ÍÀº ±æÀÌ 1Â¥¸® ¹è¿­·Î º¯È¯
				//var ctl_selected_comp_unit_id = fn_toArray(ctl_selected_comp_unit_id);	//¹è¿­ÀÌ ¾Æ´Ñ°ÍÀº ±æÀÌ 1Â¥¸® ¹è¿­·Î º¯È¯
				//var ctl_selected_qty          = fn_toArray(ctl_selected_qty);	//¹è¿­ÀÌ ¾Æ´Ñ°ÍÀº ±æÀÌ 1Â¥¸® ¹è¿­·Î º¯È¯
				var shopCartCompArray = new Array();

				for (var i=0;i<ctl_comp_item_info.length;i++) {
					var shopCartComp = new ShopCartComp();
					//shopCartComp.session_id = "<%=Const.SESSION_ID%>";
					shopCartComp.item_id = item_id;
					shopCartComp.unit_id = unit_id;
					shopCartComp.selected_unit_id = unit_id;
					shopCartComp.comp_item_id = ctl_comp_item_info[i].item_id;
					shopCartComp.comp_unit_id = ctl_comp_item_info[i].unit_id;
					shopCartComp.selected_comp_unit_id = ctl_comp_item_info[i].unit_id;
					shopCartComp.comp_qty = ctl_comp_item_info[i].order_qty;
					shopCartCompArray.push(shopCartComp);
				}
				_shopCartArray_[item_id].shopCartComps = shopCartCompArray;
			}
		}
	}


	function _fn_checkWishList_(checkbox, item_id, unit_id, last_sale_price) {
		if (typeof(_wishListArray_[item_id]) == "undefined" || typeof(_wishListArray_[item_id]) == null ) {
			var wishList = new WishList();
			wishList.checkbox = checkbox;
			wishList.item_id = item_id;
			wishList.selected_unit_id = unit_id;
			wishList.sale_price = last_sale_price;
			_wishListArray_[item_id] = wishList;
		}
	}
 	
	function _fn_registShopCart_(goshopCartYn, sale_shop_gubun_code, shop_id, shop_area_id, shop_area_link_id, shop_area_link_gubun_code, target, targetSrcWindow) {

		var shopCarts = new Array();
		var shopcart_item_count = 0;
		if (typeof(goshopCartYn) != "undefined" && typeof(goshopCartYn) != null ) 			
			_goshopCartYn_ = goshopCartYn;
		else
			_goshopCartYn_ = false;
			
		for (var i in _shopCartArray_) {
			var shopCart = _shopCartArray_[i];
			if (shopCart.checkbox.checked) {
			
				if (typeof(sale_shop_gubun_code) != "undefined" && typeof(sale_shop_gubun_code) != null ) shopCart.sale_shop_gubun_code = sale_shop_gubun_code;
				if (typeof(shop_id) != "undefined" && typeof(shop_id) != null ) shopCart.shop_id = shop_id;
				if (typeof(target) != "undefined" && typeof(target) != null ) _refreshTarget_ = target;
				if (typeof(targetSrcWindow) != "undefined" && typeof(targetSrcWindow) != null ) _refreshSrcWindow_ = targetSrcWindow;
				
				//shopCart.shop_area_id = shop_area_id;
				//shopCart.shop_area_link_id = shop_area_link_id;
				//shopCart.shop_area_link_gubun_code = shop_area_link_gubun_code;
				
				shopCarts.push(shopCart);
				shopcart_item_count++;
			}
		}
		if (shopCarts.length <= 0) {
			alert("»óÇ°À» ¼±ÅÃÇÏ¼¼¿ä!");
			return;
		} else {	
			DWRMgr.registShopCartOnly(shopCarts, _fn_cart_result_);
		}

	}
	
	function _fn_registWishList_(goshopWishYn, sale_shop_gubun_code, shop_id, shop_area_id, shop_area_link_id, shop_area_link_gubun_code, target, targetSrcWindow) {
		var wishLists = new Array();
		var wishlist_item_count = 0;
		if (typeof(goshopWishYn) != "undefined" && typeof(goshopWishYn) != null ) 
			_goshopWishYn_ = goshopWishYn;
		else
			_goshopWishYn_ = false;
			
		for (var i in _wishListArray_) {
			var wishList = _wishListArray_[i];
			if (wishList.checkbox.checked) {
			
				if (typeof(sale_shop_gubun_code) != "undefined" && typeof(sale_shop_gubun_code) != null ) wishList.sale_shop_gubun_code = sale_shop_gubun_code;
				if (typeof(shop_id) != "undefined" && typeof(shop_id) != null ) wishList.shop_id = shop_id;
				if (typeof(target) != "undefined" && typeof(target) != null ) _refreshTarget_ = target;
				if (typeof(targetSrcWindow) != "undefined" && typeof(targetSrcWindow) != null ) _refreshSrcWindow_ = targetSrcWindow;

				//wishLists.shop_area_id = shop_area_id;
				//wishLists.shop_area_link_id = shop_area_link_id;
				//wishLists.shop_area_link_gubun_code = shop_area_link_gubun_code;
							
				wishLists.push(wishList);
				wishlist_item_count++;
			}
		}
		if (wishLists.length <= 0) {
			alert("»óÇ°À» ¼±ÅÃÇÏ¼¼¿ä!");
			return;
		} else {
			DWRMgr.registWishListOnly(wishLists, _fn_wish_result_);
			//fn_getRiaSystem();
		}	

	}
	
	function _fn_cart_result_(result) {
		_fn_clear_check_for_cart_();
		if(result == "00") {
			if (_goshopCartYn_) {
				_goshopCartYn_ = false;
				if (typeof(_refreshTarget_) != "undefined" && typeof(_refreshTarget_) != null && _refreshTarget_ != "") {
					_refreshTarget_.fn_goPage('fn_goCart');
					if (typeof(_refreshSrcWindow_) != "undefined" && typeof(_refreshSrcWindow_) != null ) _refreshSrcWindow_.close();
					_refreshSrcWindow_ = "";
					_refreshTarget_ = null;
				} else
					fn_goPage('fn_goCart');	
			} else {
		     	alert("¼±ÅÃÇÏ½Å »óÇ°ÀÌ Àå¹Ù±¸´Ï¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.");
			}
			
			fn_getRiaSystem();
			
		} else if (result == "99") {
			openLoginPop("_fn_registShopCart_");
		} else if (result == "98" || result == "97") {
			alert("À¯È¿ÇÑ »óÇ°ÀÌ ¾Æ´Õ´Ï´Ù.");
		}
	}
	
	function _fn_wish_result_(result) {
		_fn_clear_check_for_wishlist_();
		if(result == "00") {
			if (_goshopWishYn_) {
				_goshopWishYn_ = false;
			
				if (typeof(_refreshTarget_) != "undefined" && typeof(_refreshTarget_) != null ) {
					_refreshTarget_.fn_goPage('fn_goWish');
					if (typeof(_refreshSrcWindow_) != "undefined" && typeof(_refreshSrcWindow_) != null ) _refreshSrcWindow_.close();
					_refreshSrcWindow_ = "";
					_refreshTarget_ = null;
				}
				else
					fn_goPage('fn_goWish');	
				
			}
		    else {
				alert("¼±ÅÃÇÏ½Å »óÇ°ÀÌ À§½Ã¸®½ºÆ®¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.");
			
				fn_getRiaSystem();	
			}
				
						
		} else if (result == "99") {		
			openLoginPop("_fn_registWishList_");
		}
	}	

	function _fn_clear_check_for_cart_() {
		_shopCartArray_ = new Array();
	}	
	
	function _fn_clear_check_for_wishlist_() {
		for (var i=0;i<_wishListArray_.length;i++)
			_wishListArray_.pop();
	}	
	
	
	function _fn_registShopCart_riasyatem_(goshopCartYn, sale_shop_gubun_code, shop_id, shop_area_id, shop_area_link_id, shop_area_link_gubun_code) {

		var shopCarts = new Array();
		var shopcart_item_count = 0;
		if (typeof(goshopCartYn) != "undefined" && typeof(goshopCartYn) != null ) 			
			_goshopCartYn_ = goshopCartYn;
		else
			_goshopCartYn_ = false;
			
		for (var i in _shopCartArray_) {
			var shopCart = _shopCartArray_[i];
			if (shopCart.checkbox.checked) {
			
				if (typeof(sale_shop_gubun_code) != "undefined" && typeof(sale_shop_gubun_code) != null ) shopCart.sale_shop_gubun_code = sale_shop_gubun_code;
				if (typeof(shop_id) != "undefined" && typeof(shop_id) != null ) shopCart.shop_id = shop_id;

				
				//shopCart.shop_area_id = shop_area_id;
				//shopCart.shop_area_link_id = shop_area_link_id;
				//shopCart.shop_area_link_gubun_code = shop_area_link_gubun_code;
				
				shopCarts.push(shopCart);
				shopcart_item_count++;
			}
		}
		if (shopCarts.length <= 0) {
			alert("»óÇ°À» ¼±ÅÃÇÏ¼¼¿ä!");
			return;
		} else {	
			_fn_clear_check_for_cart_();
			DWRMgr.registShopCartOnly(shopCarts, _fn_cart_result_);
			return riasystem();
		}

	}