function fn_AllCheck(cls){
    if($("#AllChecked").val() == "true"){
        $("#AllChecked").val("false");
        $("."+cls).find("input[type=checkbox]").attr("checked", "");
    }else{
        $("#AllChecked").val("true");
        $("."+cls).find("input[type=checkbox]").attr("checked","checked");
    }
}
function fn_CountChange(id, type){
    var setNum;
    var getNum = $("#"+id).val();
    type == "up" ? setNum = Number(getNum) + 1 : setNum = getNum - 1
    if(type == "down"){
        if(setNum < 0){
            return;
        }
    }
    $("#"+id).val(setNum);
}

function ListCheckCart(form) {
	if(CheckField(form)) {
		Goods = new Array(form.goodsList.length);
		Qty = new Array(form.goodsQty.length);
		if (form.goodsQty.length){
		  for(seqno=0; seqno < form.goodsQty.length; seqno++){
			Goods[seqno] = form.goodsList[seqno].value;
			Qty[seqno] = form.goodsQty[seqno].value;
		  }
		} else {
			Goods[0] = form.goodsList.value;
			Qty[0] = form.goodsQty.value;
		}
		form.Qty.value=Qty.join("|");
		form.Goods.value=Goods.join("|");
		form.action="/Shops/Cart/ShoppingCart2.php";
		form.submit ();
		return true;
	}
}

function fn_BuyOK(form, val){
	if(confirm('해당 상품을 구매하시겠습니까?')){
		if (val == 0)
		{
            form.target="_parent";
            form.action="/Shops/ord_process_redirect.php";
		} else {
            form.submit();
		}
	}
}

function fn_CanSel(form){
    if(confirm('주문서 작성페이지로 돌아가시겠습니까?')){
		if(document.getElementById('popCheck').value == "1"){
			document.charset = "utf-8";
		}
        form.submit();
    }
}

function fn_CheckMember(form){
    var i = 0;
    $("#memberform").find("input[type=text], input[type=select]").each(function(){
        var txt = $(this).val();
        if(txt == ""){
            var msg = $(this).attr("hname");
            alert(msg);
            $(this).focus();
            i++;
            return false;
        }
    });
    if(i == 0){
        return true;
    }
}

function CheckOrder(form){
    var i = 0;
    $("#orderform").find("input[type=text], select").each(function(){
        var txt = $(this).val();
        var disabled = $(this).attr("disabled");
        if(txt == "" && !disabled){
            var msg = $(this).attr("hname");
            alert(msg);
            $(this).focus();
            i++;
            return false;
        }
    });
    if(i == 0){
        return true;
    }
}

function fn_PayChange(type){
    if(type=="card"){
        $("#BankInfo").hide();
		$("#virtualInfo").hide();
        $("#paytype").find("input[type=radio]").each(function(){
            if($(this).attr("option") != "card"){
                $(this).attr("disabled", true);
            }
        });
    }else if(type=="virtual"){
        $("#virtualInfo").show();
        $("#BankInfo").hide();
        $("#paytype").find("input[type=radio]").attr("disabled", false);
    }else{
        $("#BankInfo").show();
		$("#virtualInfo").hide();
        $("#paytype").find("input[type=radio]").attr("disabled", false);
    }
}

function fn_CopyInfo(){
    $("#orderform").find("input[type=text], select").each(function(){
        var objId = $(this).attr("name");
        objId = objId.replace("ord_","");
        $(this).val($("#"+objId).val());
    });
}

function fn_ClearInfo(){
    $("#orderform").find("input[type=text], select").val("");
}

function CheckPayType(form){
	if (form.paymethod[1].checked)
	{
		if (form.paycom.selectedIndex == 0 && form.paymethod[1].value=="0" ) {
			alert("입금하실 은행선택을 선택해주세요.");
			form.paycom.focus();
			return false;
		}
		if (form.ob_payname.value.length==0 && form.paymethod[1].value=="0") {
			alert("입금자를 입력해주세요.");
			form.ob_payname.focus();
			return false;
		}
	}
	return true;
}
function GoCartOrd(form){
    if(fn_CheckMember(form)==true){ 
        if(CheckOrder(form)==true){
            if(CheckPayType(form)==true){
                form.action = "/Shops/ord_process_redirect.php";
            }else{
                return false;
            }
        }else{
            return false;
        }
    }else{
        return false;
    }
}


function ListCheckCart(code) {
    $("#ActionFrame").attr("src",'/Shops/Cart/ShoppingCart.php?prod_code='+code+'&Action=Quick');
}

function ListCheckWish(code, TopNum) {
    $("#ActionFrame").attr("src",'/Member/WishAdd.php?prod_code='+code+'&topnum='+TopNum+'&Action=Quick');
}

function BuyCart(form) {
	form.shop_type.value="buy";
	form.action="/Shops/Cart/ShoppingCart.php";
    form.submit ();
}

function fn_GoBasket(){
var amount = document.getElementById("amount").value;

location.href="/Shops/Cart/ShoppingCart.php?prod_code=<?=$prod_code?>&qty="+amount;
}

function fn_Cart(Url){
    alert("2가지 상품이 포함된 제품입니다.");
    location.href=Url;
}

function fn_BasketDel(form){
    form.target = "ActionFrame";
    form.action = "/Member/BasketDelete.php?Action=Quick";
    form.submit();
}





//하나만 결제 할때
function fn_BuyOne(code){
    $("#shop_type").val("buy");
    $("#BuyList").attr("target","");
    $("#buycode").val("");
    var i=0;
    $("."+code).filter("input[type=text]").each(function(){
        if($(this).val() != "0"){
            type = $(this).attr("name");
            num  = $(this).val();
            old = $("#buycode").val();
            if (i != "0"){
                old = old + "-";
            }
            $("#buycode").val(old+code+"/"+type+"/"+num);
            i++;
        }
    });
    if(i != 0){
        $("#BuyList").attr("action","/Shops/Cart/ShoppingCart.php");
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}

//여러개 결제 할때
function fn_BuyMany(form){
	$("#shop_type").val("buy");
    $("#BuyList").attr("target","");
    $("#buycode").val("");
	var i=0;
    var type, num;
    old = $("#buycode").val();
	$("#"+form).find("input[type=checkbox]").each(function(){
      if($(this).attr("checked")==true){
        checkclass = $(this).attr("class");
        code = $(this).val();
		$("."+checkclass).filter("input[type=text]").each(function(){
			if($(this).val() != "0"){
				type = $(this).attr("name");
				num  = $(this).val();
				old = $("#buycode").val();
				if (i != "0"){
					old = old + "-";
				}
				$("#buycode").val(old+code+"/"+type+"/"+num);
				i++;
			}
		});
	  }
    });
    if(i != 0){
        $("#BuyList").attr("action","/Shops/Cart/ShoppingCart.php");
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}

function fn_Buy(form){
	$("#shop_type").val("buy");
    $("#BuyList").attr("target","");
    $("#buycode").val("");
	var i=0;
    var type, num;
    old = $("#buycode").val();
	$("#"+form).find("input[type=checkbox]").each(function(){
	  if($(this).attr("checked")==true){
        checkclass = $(this).attr("class");
        code = $(this).val();
		$("."+checkclass).filter("input[type=hidden]").each(function(){
			if($(this).val() != "0"){
				type = $(this).attr("name");
				old = $("#buycode").val();
				if (i != "0"){
					old = old + "-";
				}
				$("#buycode").val(old+code+"/"+type);
				i++;
			}
		});
	  }
    });
    if(i != 0){
        $("#BuyList").attr("action","/Shops/Buy.php");
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}

//여러개를 퀵메뉴로 보낼때 wish,cart 공통
function fn_CartPackage(val, id){
    $("#BuyList").attr("action","/Shops/Cart/ShoppingCart.php");
    $("#buycode").val("");
    var i = 0;
    $("#"+id).find("input[type=checkbox]").each(function(){
        if($(this).attr("checked")==true){
            checkclass = $(this).attr("class");
            code = $(this).val();
            $("."+checkclass).filter("input[type=text], input[type=hidden]").each(function(){
                if($(this).val() != "0"){
                    type = $(this).attr("name");
                    num  = $(this).val();
                    old = $("#buycode").val();
                    if (i != "0"){
                        old = old + "-";
                    }
                    $("#buycode").val(old+code+"/"+type+"/"+num);
                    i++;
                }
            });
        }
    });
    if(i != 0){
        if(val == 0){
            $("#shop_type").val("Quick");
            $("#BuyList").attr("target","ActionFrame");
        }else{
           $("#shop_type").val("");
           $("#BuyList").attr("target","");
        }
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}

function fn_WishPackage(val, id){
    $("#BuyList").attr("action","/Member/WishAdd.php");
    $("#buycode").val("");
    var i = 0;
    $("#"+id).find("input[type=checkbox]").each(function(){
        if($(this).attr("checked")==true){
            checkclass = $(this).attr("class");
            code = $(this).val();
            $("."+checkclass).filter("input[type=text], input[type=hidden]").each(function(){
                if($(this).val() != "0"){
                    type = $(this).attr("name");
                    num  = $(this).val();
                    old = $("#buycode").val();
                    if (i != "0"){
                        old = old + "-";
                    }
                    $("#buycode").val(old+code+"/"+type+"/"+num);
                    i++;
                }
            });
        }
    });

    if(i != 0){
        if(val == 0){
            $("#shop_type").val("Quick");
            $("#BuyList").attr("target","ActionFrame");
        }else{
            $("#shop_type").val("");
            $("#BuyList").attr("target","");
        }
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}


//하나만 넣을때 cart
function CheckCart(code, val) {
    $("#BuyList").attr("action","/Shops/Cart/ShoppingCart.php");
    $("#buycode").val("");
    var i=0;
    $("."+code).filter("input[type=text]").each(function(){
        if($(this).val() != "0"){
            type = $(this).attr("name");
            num  = $(this).val();
            old = $("#buycode").val();
            if (i != "0"){
                old = old + "-";
            }
            $("#buycode").val(old+code+"/"+type+"/"+num);
            i++;
        }
    });
    if(i != 0){
        if(val == 0){
            $("#shop_type").val("Quick");
            $("#BuyList").attr("target","ActionFrame");
        }else{
            $("#shop_type").val("");
            $("#BuyList").attr("target","");
        }
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}
//하나만 넣을때 wish
function CheckWish(code, val) {
    $("#BuyList").attr("action","/Member/WishAdd.php");
    $("#buycode").val("");
    var i=0;
    $("."+code).filter("input[type=text]").each(function(){
        if($(this).val() != "0"){
            type = $(this).attr("name");
            num  = $(this).val();
            old = $("#buycode").val();
            if (i != "0"){
                old = old + "-";
            }
            $("#buycode").val(old+code+"/"+type+"/"+num);
            i++;
        }
    });
    if(i != 0){
        if(val == 0){
            $("#shop_type").val("Quick");
            $("#BuyList").attr("target","ActionFrame");
        }else{
            $("#shop_type").val("");
            $("#BuyList").attr("target","");
        }
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}


//장바구니->위시리스트 하나 넣을때

function fn_OneGoWish(code,type){
    $("#BuyList").attr("action","/Member/WishAdd.php");
    $("#buycode").val("");
	var num;
	num = $("#"+code+"_"+type).val();
	$("#buycode").val(code+"/"+type+"/"+num);

	$("#shop_type").val("Quick");
	$("#BuyList").attr("target","ActionFrame");

    $("#BuyList").submit();
}

function fn_tkChange(val){
    if(val == 0){
        $("#orderform").hide();
        $("#order").hide();
        $("#orderform").find("input[type=text]").attr("disabled", true);

        var TkMoney = $(".TkMoney").text();
        TkMoney = Number(TkMoney.replace(",",""));
        if(TkMoney != 0){
            $(".TkMoney").text(0);
            var Total = $(".TotalPrice").text();
            $("input[name=SumTotalPrice]").val(Number(Total.replace(",","")));
            $(".SumTotalPrice").text($(".TotalPrice").text());
            $("input[name=TkMoney]").val("");
            $("#TKDC").val("1");
        }

    }else{
        $("#orderform").show();
        $("#order").show();
        $("#orderform").find("input[type=text]").attr("disabled", false);

        var TKDC = $("#TKDC").val();
        if(TKDC == "1"){
            $(".TkMoney").text("2,200");
            var Sum = $(".SumTotalPrice").text();
            Sum = Number(Sum.replace(",",""));
            var Total = number_format(Sum + 2200);
            $("input[name=SumTotalPrice]").val(Sum + 2200);
            $("input[name=TkMoney]").val(2200);
            name="TkMoney"
            $(".SumTotalPrice").text(Total);
            $("#TKDC").val("0");
        }
    }
}

function number_format(input){ 
    var input = String(input); 
    var reg = /(\-?\d+)(\d{3})($|\.\d+)/; 
    if(reg.test(input)){ 
        return input.replace(reg, function(str, p1,p2,p3){ 
                return number_format(p1) + "," + p2 + "" + p3; 
            }     
        ); 
    }else{ 
        return input; 
    } 
}

function setDay(t){// 일차를 파라메터로 받는다
 var now = new Date;
 var today = now.getYear() + "/" + (now.getMonth()+1) + "/" + now.getDate();//현재날짜
 var day = getThatday(today,t); //현재날짜와 일차를 파라미터로 보내서 결과리턴한다.
 var reday =day.split("/");
 reday[1].length == 1 ? reday[1] = "0"+reday[1] : reday[1] = reday[1];
 reday[2].length == 1 ? reday[2] = "0"+reday[2] : reday[2] = reday[2];
 $("#StartYear").val(reday[0]);
 $("#StartMonth").val(reday[1]);
 $("#StartDay").val(reday[2]);
}

function getThatday(today,t){ //날짜, 일차를 파라메터로 받는다.
	var pdate=new Array(); 
	var pday=today.split("/"); //날짜를 구분자로 나누어 배열로 변환한다.
	var ptoday=new Date(pday[0],pday[1]-1,pday[2]); //데이트객체 생성한다.
	var ptimestamp=ptoday.valueOf()+1000*60*60*24*t; //t일후의 타임스탬프를 얻는다. 음수라면 이전날짜를 얻는다.
	var thatday=new Date(ptimestamp); //t일후의 날짜객체 생성한다.
	pdate[pdate.length]=thatday.getYear(); //년
	pdate[pdate.length]=thatday.getMonth()+1; //월
	pdate[pdate.length]=thatday.getDate(); //일
	return pdate.join("/"); //배열을 / 구분자로 합쳐 스트링으로 변환후 반환
}

function fn_Print(id){
    $("#BuyList").attr("action","/Member/Print.php");
    $("#buycode").val("");
    var i = 0;
    $("#"+id).find("input[type=checkbox]").each(function(){
        if($(this).attr("checked")==true){
            checkclass = $(this).attr("class");
            code = $(this).val();
            $("."+checkclass).filter("input[type=text], input[type=hidden]").each(function(){
                if($(this).val() != "0"){
                    type = $(this).attr("name");
                    num  = $(this).val();
                    old = $("#buycode").val();
                    if (i != "0"){
                        old = old + "-";
                    }
                    $("#buycode").val(old+code+"/"+type+"/"+num);
                    i++;
                }
            });
        }
    });
    if(i != 0){
        var win = makeWin('/Member/Print.php','_Print','690','676');
        $("#BuyList").attr("target","_Print");
        $("#BuyList").submit();
    }else{
        alert("선택하신 물품 또는 수량이 없습니다.");
    }
}