<?php
//include_once 'init.php';
?>
<style type="text/css">
#apDiv1 {
    position: absolute;
    width: 200px;
    height: 115px;
    z-index: 1;
    left: 21px;
    top: 454px;
}
</style>
<script type="text/javascript">

function AddToOrders(UserCodeNO,FunTxt){
    var oid=<?php
if (strlen($LastOrderID) == 0)
    echo '0';
else
    echo $LastOrderID;
?>;
    //document.title = '刷新中';
    var SQL_UserCode =encodeURIComponent($("#UserCode"+UserCodeNO).val());
    var urlp = "addMenu-product_limit.php?_dc="+new Date().getTime()+"&UserCode=" + SQL_UserCode;      
    //alert($("#UserCode"+UserCodeNO).val());
    var limitQty=new Number($("#limitQty"+UserCodeNO).val());
    var Quantity=new Number($("#Quantity"+UserCodeNO).text());
    //alert(Quantity);
    var QuantityOrg=Quantity;
    var Step=new Number($("#Step"+UserCodeNO).val());
    var Quantity2=Quantity+Step;
    var itemQuantity = $("#Quantity"+UserCodeNO);
    var itemMinus = $("#btnMinusmenu"+UserCodeNO);
    var itemRemark = $("#btnPopupOrderRemark"+UserCodeNO);
//    Quantity2=Quantity+Step;
//    if (FunTxt=='-') Quantity2=Quantity-Step; 
//    if (Quantity2<0) Quantity2=0; 
//    if (Quantity!=Quantity2 && (Quantity2<=limitQty || limitQty==-1)) {
//        Quantity=Quantity2;    
//        if (Quantity!=0) {
//            itemQuantity.text(Quantity).css("color","blue").css("text-align","center").css("display","inline");
//            itemMinus.css("display","inline");
//        }else{
//            itemQuantity.text(Quantity).css("color","blue").css("text-align","center").css("display","none");
//            itemMinus.css("display","none");
//        }
//        //$("#myDivAddToOrders").html('');
//        //updateorder(UserCodeNO,oid);
//    }else if (Quantity2>limitQty && limitQty!=-1){
//        //alert('最大只能预定'+ limitQty  + '份！');
//    }
    $.ajax({
        type: "POST", //提交的类型
        url: "addMenu-product_limit.php",//提交地址
        data: "_dc="+new Date().getTime()+"&UserCode=" + SQL_UserCode,//参数
        success: function(data){ //回调方法
            //limitQty=new Number(data);
			limitQty=-1;
            //alert(SQL_UserCode+ '  ' + data);
            if (limitQty==0) {
                alert('已售罄！');
                $("#myDiv"+UserCodeNO).html('已售罄！').css("color","red");
            }else{
                if (limitQty!=-1) $("#myDiv"+UserCodeNO).html('余:'+data).css("color","gray");
                //alert('/'+ Quantity + '/' + limitQty + '/' + Step + '/');
                Quantity=QuantityOrg;
                Quantity2=Quantity+Step;
                if (FunTxt=='-') Quantity2=Quantity-Step; 
                if (Quantity2<0) Quantity2=0; 
                if (Quantity!=Quantity2 && (Quantity2<=limitQty || limitQty==-1)) {
                    Quantity=Quantity2;
                    //alert('/'+ Quantity + '/' + limitQty + '/' + Step + '/');
                    if (Quantity!=0) {
                        itemQuantity.text(Quantity).css("color","blue").css("text-align","center").show();
                        if (<?php echo isset($forcein) && !empty($forcein)?$forcein:'0';?>==0) itemMinus.show();
						itemRemark.show();
                    }else{
                        itemQuantity.text(Quantity).hide();
                        itemMinus.hide();
						itemRemark.hide();
                    }
                    updateorder(UserCodeNO,oid,QuantityOrg);
                 }else if (Quantity2>limitQty && limitQty!=-1){
                    alert('最大只能预定'+ limitQty  + '份！');
                }
            }
    
        }
    });
}
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var currentdate = date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds()+ seperator2 + date.getMilliseconds();
    return currentdate;
}
function updateorder(UserCodeNO,oid,QuantityOrg){
    var SQL_UserCode =encodeURIComponent($("#UserCode"+UserCodeNO).val());
    var SQL_ProductName =encodeURIComponent($("#ProductName"+UserCodeNO).val());
    var SQL_UnitPrice =$("#UnitPrice"+UserCodeNO).val();
    var SQL_Quantity =$("#Quantity"+UserCodeNO).text();
    var itemAction = $("#action"+UserCodeNO);
   $.ajax({
        type: "POST", //提交的类型
        url: "addMenu-updateorder.php",//提交地址
        data: "_dc="+new Date().getTime()+"&oid=" + oid+"&UserCode=" + SQL_UserCode+"&ProductName=" + SQL_ProductName+"&UnitPrice=" + SQL_UnitPrice+"&Quantity=" + SQL_Quantity + "&QuantityOrg=" + QuantityOrg,//参数
        success: function(data){ //回调方法
        	var res = data.split(";");
    	    $("#myDivTotal").html(res[1]);
			itemAction.val(res[0]);
    	    loadcatalogo('');
        }
    });
}
function loadmenu(UserCodeNO){
    //var url = "loadmenu.php?_dc="+new Date().getTime()+"&CategoryID=" + UserCodeNO;      
    //$("#myDivLoadMenu").load('loadmenu.php').trigger('create');
    //alert("_dc="+new Date().getTime()+"&CategoryID=" + UserCodeNO+"&forcein=");
    $.ajax({
        type: "POST", //提交的类型
        url: "addMenu-loadmenu.php",//提交地址
        data: "_dc="+new Date().getTime()+"&CategoryID=" + UserCodeNO+"&forcein=<?php echo $forcein;?>",//参数
        success: function(data){ //回调方法
        $("#myDivLoadMenu").html(data).trigger('create');
        }
    });
}
function loadcatalogo(UserCodeNO){
    //var url = "loadmenu.php?_dc="+new Date().getTime()+"&CategoryID=" + UserCodeNO;      
    //$("#myDivLoadMenu").load('loadmenu.php').trigger('create');
    //alert(url);
    $.ajax({
        type: "POST", //提交的类型
        url: "addMenu-loadcatalogo.php",//提交地址
        data: "_dc="+new Date().getTime(),//参数
        success: function(data){ //回调方法
        $("#myDivLoadcatalogo").html(data).trigger('create');
        }
    });
}

</script> 
<?php  //print_r('forcein : '. $_SESSION['forcein']); die();?>  

<span id="myDivLoadcatalogo"><script type="text/javascript">loadcatalogo('');</script></span>  

                   
<span id="myDivLoadMenu"><script type="text/javascript">loadmenu('');</script></span> 