/*
 * Handles a submission of the search form
 */
// Àå¹Ù±¸´Ï ´ã±â

function insertCartSubmitHandler(product_id, member_id, sessionid, typecode) {

  var cartproperties = new Object();

  cartproperties['member_id'] = member_id;
  cartproperties['sessionid'] = sessionid;
  cartproperties['typecode'] = typecode;
  
  if(present_ids != null) {  
	  var present_ids_obj = document.getElementsByName("present_ids");
  }
  //»çÀºÇ°,ºÎ·Ï
  if(present_ids_obj  !=  null){
    var present_ids = "";
    
    if(present_ids_obj.length > 0){
      for (i=0; i<present_ids_obj.length; i++) {
        present_ids = present_ids + present_ids_obj[i].value + ",";
        
        var presentdetail_id_obj = document.getElementsByName("presentdetail_id_"+i+"_"+present_ids_obj[i].value);
        if(presentdetail_id_obj != null && presentdetail_id_obj.length> 0){
          if (presentdetail_id_obj.type == 'select-one') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = l_checkedSelect(presentdetail_id_obj);
          }else if (presentdetail_id_obj[0].type == 'select-one') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = l_checkedSelect(presentdetail_id_obj[0]);
          }else if (product_ids_obj.type == 'hidden') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = presentdetail_id_obj.value;
          }else if (product_ids_obj[0].type == 'hidden') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = presentdetail_id_obj[0].value;
          }
        }
      }
      cartproperties['present_ids'] = present_ids;
    }else{
      cartproperties['present_id'] = present_ids_obj.value;
      
      var presentdetail_id_obj = document.getElementsByName("presentdetail_id_"+i+"_"+present_ids_obj.value);
      
      if(presentdetail_id_obj != null && presentdetail_id_obj.length> 0){
        if (presentdetail_id_obj.type == 'select-one') {
          cartproperties['presentdetail_id_'+i+'_'+present_ids_obj.value] = l_checkedSelect(presentdetail_id_obj);
        }else if (presentdetail_id_obj[0].type == 'select-one') {
          cartproperties['presentdetail_id_'+i+'_'+present_ids_obj.value] = l_checkedSelect(presentdetail_id_obj[0]);
        }else if (presentdetail_id_obj.type == 'hidden') {
          cartproperties['presentdetail_id_'+i+'_'+present_ids_obj.value] = presentdetail_id_obj.value;
        }else if (presentdetail_id_objp[0].type == 'hidden') {
          cartproperties['presentdetail_id_'+i+'_'+present_ids_obj.value] = presentdetail_id_obj[0].value;
        }
      }
    }
  }else{
    cartproperties['present_id'] = 0;
    cartproperties['presentdetail_id'] = 0;
  }
  
  // ÇÑ°³¸¸ ´ã±â-->¼ö·® ÀÔ·Â ÇÊµå Ãß°¡08.04.18
  if (product_id > 0) {
    cartproperties['product_id'] = product_id;

    //¼ö·®
    if(document.qtyForm != null && document.qtyForm.qty != null){
      var qty_obj = document.qtyForm.qty;
      cartproperties['qty'] = qty_obj.value;
    }

  } else {
    // ¿©·¯°³ ´ã±â checkbox,hidden,select-one:product_ids
    var product_ids_obj = document.getElementsByName("product_ids");
    if (product_ids_obj != null) {
      var product_ids = "";
      for (i=0; i<product_ids_obj.length; i++) {

        if (product_ids_obj[i].type == 'hidden') {
          product_ids = product_ids + product_ids_obj[i].value + ",";
        }
        if (product_ids_obj[i].type == 'checkbox') {
          if (product_ids_obj[i].checked == true) {
            product_ids = product_ids + product_ids_obj[i].value + ",";
          }
        }
        if (product_ids_obj[i].type == 'select-one') {
          product_ids = product_ids + product_ids_obj[i].options[product_ids_obj[i].selectedIndex].value + ",";
        }
      }
      if (product_ids != "") {
        cartproperties['product_ids'] = product_ids;
      }
    }
  }

  var subscriptionstartyear = document.getElementById("subscriptionstartyear");
  var subscriptionstartmonth = document.getElementById("subscriptionstartmonth");
  if (subscriptionstartyear != null && subscriptionstartmonth != null) {
    cartproperties['subscriptionstartyearmonth'] = l_checkedSelect(subscriptionstartyear) + "-" + l_checkedSelect(subscriptionstartmonth);
  } else {
    cartproperties['subscriptionstartyearmonth'] = "";
  }

  if (cartproperties['product_id'] == null && cartproperties['product_ids'] == null) {
    alert("Àå¹Ù±¸´Ï¿¡ ´ãÀ» »óÇ°À» ¼±ÅÃÇÏ¼¼¿ä.");
    return false;
  }

  // call manager
  cartManager.insertCart(cartproperties, displayInsertCartResultPopup);

  return false;
}

function insertCartTextBookSubmitHandler(member_id, sessionid, product_id, qty, size) {

  var cartproperties = new Object();
  cartproperties['member_id'] = member_id;
  cartproperties['sessionid'] = sessionid;

  if(size ==1){
    cartproperties['product_id'] = product_id;
    cartproperties['qty'] = qty;
  }else if(size ==2){
    cartproperties['product_ids'] = product_id;
    cartproperties['qtys'] = qty;
  }

  cartManager.insertCart(cartproperties, displayInsertCartTextBookResultPopup);

  return false;
}

// ÂòÆË¾÷¿¡¼­ Àå¹Ù±¸´Ï ´ã±â
function insertCartSubmitHandlerPopupToList(product_id, member_id, sessionid) {

  var cartproperties = new Object();
  cartproperties['product_id'] = product_id;
  cartproperties['member_id'] = member_id;
  cartproperties['sessionid'] = sessionid;
  cartManager.insertCart(cartproperties, displayInsertCartResultPopupToList);
  return false;
}

// ¹Ù·Î±¸¸Å
function insertCartAndBuySubmitHandler(product_id, member_id, sessionid, ispopup) {

  var cartproperties = new Object();
  cartproperties['member_id'] = member_id;
  cartproperties['sessionid'] = sessionid;
  
  var present_ids_obj = document.getElementsByName("present_ids");
  
  var str_presentdetail_id = "";
  //»çÀºÇ°,ºÎ·Ï
  if(present_ids_obj  !=  null){
    var present_ids = "";
    if(present_ids_obj.length > 0){
      for (i=0; i<present_ids_obj.length; i++) {
        present_ids = present_ids + present_ids_obj[i].value + ",";
        
        var presentdetail_id_obj = document.getElementsByName("presentdetail_id_"+i+"_"+present_ids_obj[i].value);
        
        if(presentdetail_id_obj != null && presentdetail_id_obj.length > 0){

          if (presentdetail_id_obj.type == 'select-one') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = l_checkedSelect(presentdetail_id_obj);
            str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_"+i+"_"+present_ids_obj[i].value+"="+l_checkedSelect(presentdetail_id_obj);
          }else if (presentdetail_id_obj[0].type == 'select-one') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = l_checkedSelect(presentdetail_id_obj[0]);
            str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_"+i+"_"+present_ids_obj[i].value+"="+l_checkedSelect(presentdetail_id_obj[0]);
          }else if (presentdetail_id_obj.type == 'hidden') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = presentdetail_id_obj.value;
            str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_"+i+"_"+present_ids_obj[i].value+"="+presentdetail_id_obj.value;
          }else if (presentdetail_id_obj[0].type == 'hidden') {
            cartproperties['presentdetail_id_'+i+'_'+present_ids_obj[i].value] = presentdetail_id_obj[0].value;
            str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_"+i+"_"+present_ids_obj[i].value+"="+presentdetail_id_obj[0].value;
          }
        }
      }
      cartproperties['present_ids'] = present_ids;
    }else{

      cartproperties['present_id'] = present_ids_obj.value;
      
      var presentdetail_id_obj = document.getElementsByName("presentdetail_id_0_"+present_ids_obj.value);
      
      if(presentdetail_id_obj != null && presentdetail_id_obj.length > 0){
        if (presentdetail_id_obj.type == 'select-one') {
          cartproperties['presentdetail_id_0_'+present_ids_obj.value] = l_checkedSelect(presentdetail_id_obj);
          str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_0_"+present_ids_obj.value+"="+l_checkedSelect(presentdetail_id_obj);
        }else if (presentdetail_id_obj[0].type == 'select-one') {
          cartproperties['presentdetail_id_0_'+present_ids_obj.value] = l_checkedSelect(presentdetail_id_obj[0]);
          str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_0_"+present_ids_obj.value+"="+l_checkedSelect(presentdetail_id_obj[0]);  
        }else if (presentdetail_id_obj.type == 'hidden') {
          cartproperties['presentdetail_id_0_'+present_ids_obj.value] = presentdetail_id_obj.value;
          str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_0_"+present_ids_obj.value+"="+presentdetail_id_obj.value;
        }else if (presentdetail_id_obj[0].type == 'hidden') {
          cartproperties['presentdetail_id_0_'+present_ids_obj.value] = presentdetail_id_obj[0].value;
          str_presentdetail_id  = str_presentdetail_id + "&presentdetail_id_0_"+present_ids_obj.value+"="+presentdetail_id_obj[0].value;          
        }
      }
      
    }
  }else{
    cartproperties['present_id'] = 0;
    cartproperties['presentdetail_id'] = 0;
  }
  
  if(document.popForm != null) {
      var pop = document.popForm.pop;
      var qty = document.popForm.qty.value;
      var subscriptionstartyearmonth = document.popForm.subscriptionstartyearmonth.value;
  }

  // ÇÑ°³¸¸ ´ã±â
  if (product_id > 0) {
    cartproperties['product_id'] = product_id;

    //¼ö·®
    if(document.qtyForm != null && document.qtyForm.qty != null){
      var qty_obj = document.qtyForm.qty;
      cartproperties['qty'] = qty_obj.value;
     }

  } else {

    // ¿©·¯°³ ´ã±â checkbox,hidden,select-one:product_ids
    var product_ids_obj = document.getElementsByName("product_ids");
    if (product_ids_obj != null) {
      var product_ids = "";
      for (i=0; i<product_ids_obj.length; i++) {
        if (product_ids_obj[i].type == 'hidden') {
          product_ids = product_ids + product_ids_obj[i].value + ",";
        }
        if (product_ids_obj[i].type == 'checkbox') {
          if (product_ids_obj[i].checked == true) {
            product_ids = product_ids + product_ids_obj[i].value + ",";
          }
        }
        if (product_ids_obj[i].type == 'select-one') {
          product_ids = product_ids + product_ids_obj[i].options[product_ids_obj[i].selectedIndex].value + ",";
        }
      }
      if (product_ids != "") {
        cartproperties['product_ids'] = product_ids;
      }
    }
  }

  var subscriptionstartyear = document.getElementById("subscriptionstartyear");
  var subscriptionstartmonth = document.getElementById("subscriptionstartmonth");
  if (subscriptionstartyear != null && subscriptionstartmonth != null) {
    cartproperties['subscriptionstartyearmonth'] = l_checkedSelect(subscriptionstartyear) + "-" + l_checkedSelect(subscriptionstartmonth);
  } else {
    cartproperties['subscriptionstartyearmonth'] = "";
  }

  if (cartproperties['product_id'] == null && cartproperties['product_ids'] == null) {
    alert("±¸¸ÅÇÏ½Ç »óÇ°À» ¼±ÅÃÇÏ¼¼¿ä.");
    return false;
  }
  
  var str_present = "";
  
  if(cartproperties['present_id'] != null){
    str_present = "present_id="+cartproperties['present_id'];
    
  }else if(cartproperties['present_ids'] != null){
    str_present = "present_ids="+cartproperties['present_ids'];
     
  }

  str_present = str_present+ str_presentdetail_id;
  
  var arr_splitUrl = document.URL.split('/');
  var top_domain  = arr_splitUrl[2];
  
  // Àå¹Ù±¸´Ï ´ã±â ¾øÀÌ ¼¼¼Ç ¸ðµå·Î ¹Ù·Î±¸¸Å
  if (cartproperties['product_id'] > 0) {

    if (ispopup == null) {
      if(pop != null) {
        opener.top.document.location = "https://"+top_domain+"/shopping/malls/buy.html?act=buy&product_id="+cartproperties['product_id']+"&subscriptionstartyearmonth="+subscriptionstartyearmonth+"&qty="+qty+"&"+str_present;
        window.close();
      } else {
        top.document.location = "https://"+top_domain+"/shopping/malls/buy.html?act=buy&product_id="+cartproperties['product_id']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&qty="+cartproperties['qty']+"&"+str_present;
      }
    } else {
      opener.top.location = "https://"+top_domain+"/shopping/malls/buy.html?act=buy&product_id="+cartproperties['product_id']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&qty="+cartproperties['qty']+"&"+str_present;
      window.close();
    }
  } else if (cartproperties['product_ids'] != '') {
    if (ispopup == null) {
      top.document.location = "https://"+top_domain+"/shopping/malls/buy.html?act=buy&product_ids="+cartproperties['product_ids']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&"+str_present;
    } else {
      opener.top.location = "https://"+top_domain+"/shopping/malls/buy.html?act=buy&product_ids="+cartproperties['product_ids']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&"+str_present;
      window.close();
    }
  }

  //cartManager.insertCart(cartproperties, displayInsertCartAndBuyResult);

  return false;
}


// ¼±¹°ÇÏ±â
function insertCartAndGiftSubmitHandler(product_id, member_id, sessionid, prefix) {

  var cartproperties = new Object();
  cartproperties['member_id'] = member_id;
  cartproperties['sessionid'] = sessionid;

  // ÇÑ°³¸¸ ´ã±â
  if (product_id > 0) {
    cartproperties['product_id'] = product_id;

    //¼ö·®
    if(document.qtyForm != null && document.qtyForm.qty != null){
      var qty_obj = document.qtyForm.qty;
      cartproperties['qty'] = qty_obj.value;
     }

  } else {

    // ¿©·¯°³ ´ã±â checkbox,hidden,select-one:product_ids
    var product_ids_obj;
    if (prefix != null) {
      product_ids_obj = document.getElementsByName("product_"+prefix+"_ids");
    } else {
      product_ids_obj = document.getElementsByName("product_ids");
    }
    if (product_ids_obj != null) {
      var product_ids = "";
      for (i=0; i<product_ids_obj.length; i++) {
        if (product_ids_obj[i].type == 'hidden') {
          product_ids = product_ids + product_ids_obj[i].value + ",";
        }
        if (product_ids_obj[i].type == 'checkbox') {
          if (product_ids_obj[i].checked == true) {
            product_ids = product_ids + product_ids_obj[i].value + ",";
          }
        }
        if (product_ids_obj[i].type == 'select-one') {
          product_ids = product_ids + product_ids_obj[i].options[product_ids_obj[i].selectedIndex].value + ",";
        }
      }
      if (product_ids != "") {
        cartproperties['product_ids'] = product_ids;
      }
    }
  }

  var subscriptionstartyear = document.getElementById("subscriptionstartyear");
  var subscriptionstartmonth = document.getElementById("subscriptionstartmonth");
  if (subscriptionstartyear != null && subscriptionstartmonth != null) {
    cartproperties['subscriptionstartyearmonth'] = l_checkedSelect(subscriptionstartyear) + "-" + l_checkedSelect(subscriptionstartmonth);
  } else {
    cartproperties['subscriptionstartyearmonth'] = "";
  }

  if (cartproperties['product_id'] == null && cartproperties['product_ids'] == null) {
    alert("¼±¹°ÇÏ½Ç »óÇ°À» ¼±ÅÃÇÏ¼¼¿ä.");
    return false;
  }

  // Àå¹Ù±¸´Ï ´ã±â ¾øÀÌ ¼¼¼Ç ¸ðµå·Î ¼±¹°ÇÏ±â
  if (cartproperties['product_id'] > 0) {

      if(sessionid==''){//Àå¹Ù±¸´Ï¿¡¼­ ¼±¹°ÇÏ±â ÇßÀ» °æ¿ì
        l_commonPopup("/shopping/malls/gift_step1_popup.html?act=step1&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&qty="+cartproperties['qty'], "gift_step1_popup", 420, 360, "yes", "no", "yes");
      }else{
        l_commonPopup("/shopping/malls/gift_step1_popup.html?act=step1&product_id="+cartproperties['product_id']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth']+"&qty="+cartproperties['qty'], "gift_step1_popup", 420, 360, "yes", "no", "yes");
      }

  } else if (cartproperties['product_ids'] != '') {

      if(sessionid==''){//Àå¹Ù±¸´Ï¿¡¼­ ¼±¹°ÇÏ±â ÇßÀ» °æ¿ì
        l_commonPopup("/shopping/malls/gift_step1_popup.html?act=step1&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth'], "gift_step1_popup", 420, 360, "yes", "no", "yes");
      }else{
        l_commonPopup("/shopping/malls/gift_step1_popup.html?act=step1&product_ids="+cartproperties['product_ids']+"&subscriptionstartyearmonth="+cartproperties['subscriptionstartyearmonth'], "gift_step1_popup", 420, 360, "yes", "no", "yes");
      }
  }

  return false;
}

// Âò¿¡¼­ Àå¹Ù±¸´Ï ´ã±âÈÄ ROW Ãß°¡
function insertCartAddRowSubmitHandler(product_id, member_id, sessionid) {
  // ¿©·¯°³ ´ã±â checkbox:product_ids
  if (product_id == 0) {
    var product_ids_obj = document.getElementsByName("product_ids");
    var product_ids = "";
    for (i=0; i<product_ids_obj.length; i++) {
      if (product_ids_obj[i].checked == true) {
        product_ids = product_ids + product_ids_obj[i].value + ",";
      }
    }
    if (product_ids == "") {
      alert("Àå¹Ù±¸´Ï¿¡ ´ãÀ» »óÇ°À» ¼±ÅÃÇÏ¼¼¿ä.");
    } else {
      cartManager.insertCart({product_ids:product_ids, member_id:member_id, sessionid:sessionid}, displayInsertCartAddRowResult);
    }
  // ÇÑ°³¸¸ ´ã±â
  } else {
    cartManager.insertCart({product_id:product_id, member_id:member_id, sessionid:sessionid}, displayInsertCartAddRowResult);
  }
  return false;
}

// Àå¹Ù±¸´Ï¿¡¼­ »©±â
function deleteCartSubmitHandler(cart_id) {
  cartManager.deleteCart(cart_id, displayDeleteCartResult);
  return false;
}

// Àå¹Ù±¸´Ï¿¡¼­ ¼ö·®º¯°æ
function updateCartSubmitHandler(cart_id, qty, fgonoff) {
  cartManager.updateCart({cart_id:cart_id, qty:qty}, displayUpdateCartResult);
  return false;
}

/*
 * Displays a list of catalogue items
 */
// Àå¹Ù±¸´Ï ´ã±â callback
function displayInsertCartResultPopup(map) {

	if (map.cart_id > 0) {
		if(cartWin != null){
			//if (cartWin.document.readyState=="complete") {
			  cartWin.location.href="/shopping/myshopping/cart_list_popup.html?act=popup";
			  cartWin.focus();
			//}
	  }else{
	  var popup = isPopupBlock(); // ±×³É Ãß°¡ÇÑ°Å ¿ä°Å ºüÁö¸é popup_box null ¿¡·¯°¡ ³ª±æ·¡ ³Ö¾úÀ½.
			if (!isPopupBlock()) {
		  	l_commonPopup("/shopping/myshopping/cart_list_popup.html?act=popup", "cart_list_popup", 740, 400, "yes", "no", "yes");
		  } else {
		  	if(confirm("¼±ÅÃÇÏ½Å »óÇ°ÀÌ Àå¹Ù±¸´Ï¿¡ Ãß°¡ µÇ¾úÀ¸³ª,\n\rÆË¾÷ÀÌ Â÷´ÜµÇ¾î Àå¹Ù±¸´Ï¸¦ º¼ ¼ö ¾ø½À´Ï´Ù.\n\rÀå¹Ù±¸´Ï ÆäÀÌÁö·Î ¹Ù·Î °¡½Ã°Ú½À´Ï±î?")) {
		  		document.location = "/shopping/myshopping/cart_list.html";
		  	}
		  }
		}
	} else if(map.cart_id == -1||map.cart_id == -4) {
	  alert("ÇØ´ç »óÇ°Àº "+map.qty+"±Ç±îÁö¸¸ ±¸ÀÔ °¡´ÉÇÕ´Ï´Ù.");
	  cartWin.close();
	}	else if(map.cart_id == -2) {
    alert("¿Â¶óÀÎ ÄÁÅÙÃ÷´Â ¸¶ÀÌ ÆäÀÌÁö·Î Á¦°øµÇ´Â ¼­ºñ½ºÀÌ¹Ç·Î ·Î±×ÀÎ ÈÄ ÁÖ¹®ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.");
    document.location = "/member/loginCheck.html";
    cartWin.close();
  } else if(map.cart_id == -3) {
    alert("¼±ÅÃÇÏ½Å »óÇ°¿¡ ¿Â¶óÀÎ ÄÁÅÙÃ÷ »óÇ°ÀÌ ÀÖ½À´Ï´Ù.\n\r ¿Â¶óÀÎ ÄÁÅÙÃ÷´Â È¸¿ø±¸¸Å¸¸ °¡´ÉÇÕ´Ï´Ù.");
    cartWin.close();
  } else {
		alert("¼±ÅÃÇÏ½Å »óÇ°Àº ¿Â¶óÀÎ ¹ÌÆÇ¸Å ÀÌ°Å³ª ÆÇ¸Å°¡ ÁßÁöµÈ »óÇ° ÀÔ´Ï´Ù.");
		cartWin.close();
	}
  return false;
}
// ÆË¾÷¿¡¼­ Àå¹Ù±¸´Ï ´ã±â callback
function displayInsertCartResultPopupToList(cart_id) {
  opener.location = "/shopping/myshopping/cart_list.html";
  return false;
}
// ¹Ù·Î±¸¸Å callback
function displayInsertCartAndBuyResult(cart_id) {
  //TODO
  if (opener != null) {
    opener.location.href= "/shopping/malls/purchase_form.html";
    window.close();
  } else {
    document.location.href= "/shopping/malls/purchase_form.html";
  }
  return false;
}
// ¼±¹°ÇÏ±â callback
function displayInsertCartAndGiftResult(cart_id) {
  //TODO
  alert("ÀÛ¾÷Áß..");
  return false;
}
// Âò¿¡¼­ Àå¹Ù±¸´Ï ´ã±âÈÄ ROW Ãß°¡ callback
function displayInsertCartAddRowResult(cart_id) {
  document.location.reload();
  return false;
}
// Àå¹Ù±¸´Ï¿¡¼­ »©±â callback
function displayDeleteCartResult(cart_id) {
  var delline = $('delline_'+cart_id);
  if (delline != null){
   new Effect.SwitchOffAndRemoveElementAtCart(delline);
   delline.innerHTML  = '';
  }
  return false;
}
// Àå¹Ù±¸´Ï¿¡¼­ ¼ö·®º¯°æ callback
function displayUpdateCartResult(cart) {
  var qty = $('qty_'+cart_id.value);
  if (cart.fgcartupdate == '0') {
    alert("ÇØ´ç »óÇ°Àº ¿Â¶óÀÎ ÄÁÅÙÃ÷ »óÇ°ÀÌ¹Ç·Î ¼ö·®À» º¯°æÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
    rowSum(cart.id, cart.price, cart.qty);
  } else if (cart.fgcartupdate == '1') {
    alert('¿äÃ»ÇÏ½Å ÁÖ¹®¼ö·® Áß ÀÏºÎ´Â Àç°íºÎÁ·À¸·Î ±¸¸Å¸¦ ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.');
    rowSum(cart.id, cart.price, cart.qty);
  } else if (cart.fgcartupdate == '2') {
    rowSum(cart.id, cart.price, cart.qty); // ¼ö·®º¯°æ¼º°ø
  } else if(cart.fgcartupdate == '-1') {
    alert("ÇØ´ç »óÇ°Àº "+cart.pqty+"±Ç±îÁö¸¸ ±¸ÀÔ °¡´ÉÇÕ´Ï´Ù.");
    rowSum(cart.id, cart.price, cart.qty);
  } else if(cart.fgcartupdate == '-3') {
    alert("ÇØ´ç »óÇ°¿¡ ¿Â¶óÀÎ ÄÁÅÙÃ÷  »óÇ°ÀÌ ÀÖÀ¸¹Ç·Î ¼ö·®À» º¯°æÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
    rowSum(cart.id, cart.price, cart.qty);
  }
  return false;
}

/*
 * Àå¹Ù±¸´Ï °è»ê
 */
function trim(val) {
  for (i=0; i<val.length; i++) {
    if (val.substring(i, i+1) == " ")
      val = val.substring(i+1);
  }
  for (i=val.length; i>=0; i--) {
    if (val.substring(i, i-1) == " ")
      val = val.substring(0, i-1);
  }
  return val;
}

function replaceZeroAndNULL(val, setval) {
  if (trim(val) == "" || trim(val) == "0")
    val = setval;
  return val;
}

function replaceValue(obj, setval) {
  obj.value = replaceZeroAndNULL(obj.value, setval);
}

function checkNumber(obj) {
  var str = obj.value;
  for (ii=0; ii<str.length; ii++) {
    if (isNaN(str.substring(ii, ii+1))) {
      obj.value = replaceZeroAndNULL(str.substring(0, ii), "1");
      //obj.focus();
      return false;
    }
  }
  if (trim(str) == '' || trim(str) == '0') {
    obj.value = replaceZeroAndNULL(str, "1");
    obj.select();
    //obj.focus();
    return false;
  }
  obj.blur();
  return true;
}

function rowSum(cart_id, price, qty) {
  var sumSPAN = $('rowsum_'+cart_id);
  var priceHIDDEN = $('price_'+cart_id);
  var qtyTEXT = $('qty_'+cart_id);
  sumSPAN.innerHTML = l_formatMoney(price*qty);
  priceHIDDEN.value = price*qty;
 // qtyTEXT.focus();
  qtyTEXT.value = qty;
  totalSum();
}

function rowSumReserve(cart_id, price, qty) {
  var sumSPAN = $('rowsum_'+cart_id);
  var priceHIDDEN = $('price_'+cart_id);
  var qtyTEXT = $('qty_'+cart_id);
  sumSPAN.innerHTML = l_formatMoney(price*qty);
  priceHIDDEN.value = price*qty;
 // qtyTEXT.focus();
  qtyTEXT.value = qty;
  totalSum();
}

function rowDelete(cart_id) {
  var qty = $('qty_'+cart_id);
  var price = $('price_'+cart_id);
  qty.value = 0;
  price.value = 0;
  totalSum();
}

function totalSum() {
	
  if(document.getElementById("fgreserve").value == "R"){
	 // var cart_ids = document.getElementsByName('cart_id_reserve');
	  var groupDate = document.getElementById("groupDate").value;
	  var cart_ids = document.getElementsByName(groupDate);	  
	  var totalQtySPAN_NAME 			= 'totalQtySPAN_'+groupDate ;
	  var totalProductPriceSPAN_NAME	= 'totalProductPriceSPAN_'+groupDate ;
	  var totalPriceSPAN_NAME 			= 'totalPriceSPAN_'+groupDate ;
	  
	  
	  var totalQtySPAN = document.getElementById(totalQtySPAN_NAME);
	  var totalProductPriceSPAN = $(totalProductPriceSPAN_NAME);
	  var totalPriceSPAN = $(totalPriceSPAN_NAME);
	  
	  var totalQty = new Number(0);
	  var totalProductPrice = new Number(0);
	  var totalPrice = new Number(0);

	  for (i=0; i<cart_ids.length; i++) {
	    var cart_id = cart_ids[i];
	    var qty = $('qty_'+cart_id.value);
	    var price = $('price_'+cart_id.value);
	    totalQty = totalQty + new Number(qty.value);
	    totalProductPrice = totalProductPrice + new Number(price.value);
	  }
	  totalPrice = totalProductPrice;
	  totalQtySPAN.innerHTML = totalQty;
	  totalProductPriceSPAN.innerHTML = l_formatMoney(totalProductPrice);
	  totalPriceSPAN.innerHTML = l_formatMoney(totalPrice);

	  if (totalPrice == 0) {
	    document.location.reload();
	  }	  
  }else{
	  var cart_ids = document.getElementsByName('cart_id');
	  var totalQtySPAN = $('totalQtySPAN');
	  var totalProductPriceSPAN = $('totalProductPriceSPAN');
	  var totalPriceSPAN = $('totalPriceSPAN');	  
	  
	  var totalQty = new Number(0);
	  var totalProductPrice = new Number(0);
	  var totalPrice = new Number(0);

	  for (i=0; i<cart_ids.length; i++) {
	    var cart_id = cart_ids[i];
	    var qty = $('qty_'+cart_id.value);
	    var price = $('price_'+cart_id.value);
	    totalQty = totalQty + new Number(qty.value);
	    totalProductPrice = totalProductPrice + new Number(price.value);
	  }
	  totalPrice = totalProductPrice;
	  totalQtySPAN.innerHTML = totalQty;
	  totalProductPriceSPAN.innerHTML = l_formatMoney(totalProductPrice);
	  totalPriceSPAN.innerHTML = l_formatMoney(totalPrice);

	  if (totalPrice == 0) {
	    document.location.reload();
	  }	  
  }
	  


  return totalPrice;
}
function FreecodeAdd(product_id){
    l_commonPopup("/shopping/myshopping/freeproduct_add_popup.html?act=popup&product_id="+product_id, "freeproduct_add_popup", 320, 265, "no", "no", "yes");
}

