
//快速购物
$(document).ready(function(){
    //添加文本框
    $('#btnAdd').click(function(){
        var count = $('#count').val();
        count = Number(count) + 1;
        var html = '<tr><td><input type="text" name="productNo' + count + '"><span name="info' + count + '"></span></td></tr>';
        $('.trSubmit').before(html);
        $('#count').val(count);
    });
    
    //提交前先检查商品是否存在
    $('input[@type=submit]').click(function(){
        var pass = true;
        var productNos = '';
        $('input[@name^=productNo]').each(function(){
            productNos += $.trim($(this).val()) != '' ? $.trim($(this).val()) + ',' : '';
            $(this).next().html('');
        });
        
        if(productNos.length != '')
        {
            productNos = productNos.substring(0,productNos.length-1);
            var weburl = 'ajax.aspx?NoCopyright=1&type=GetProductStatus&ProductNos=' + productNos + "&ran=" + Math.random();
            $.ajax({
                url:weburl,
                async:false,    //同步
                success:function(data){
                    if(data.indexOf('NotExist') != -1 || data.indexOf('NotForSale') != -1 || data.indexOf('NotStorage') != -1)
                    {
                        pass = false;
                        var items = data.split('|');
                        var itemIndex = 0;
                        $('input[@name^=productNo]').each(function(index){
                            if($.trim($(this).val()) != '')
                            {
                                var Msg = '';
                                var errorInfo = items[itemIndex].split(',')[1]
                                switch(errorInfo)
                                {
                                    case 'NotExist':
                                        Msg = NotExist;    //var NotExist = 'GetResourceString("ProductNotExist")';
                                        break;
                                    case 'NotForSale':
                                        Msg = NotForSale;
                                        break;
                                    case 'NotStorage':
                                        Msg = NotStorage;
                                        break;
                                    case 'OK':
                                        Msg = '';
                                        break;
                                }
                                $(this).next().html(Msg);
                                itemIndex += 1;
                            }//end if
                        });//end each()
                    }//end if
                },    
                error:function(){alert('system error');pass=false;}
            });//end $.ajax()
        }
        else
        {
            alert('请输入商品编号');
            pass = false;
        }
        return pass;
    });
    
})  //end ready