﻿/// <reference path="../jQuery-vsdoc.js" />
function AddToCart(prdid,exch)
{
    if($("#SumMoney").html() == "--"){
        alert("该商品组合不存在");
		return;
    }
	var storage = $("#storage").val();
	var pcount = $("#BuyNum").val();
    
	 if(storage <= 0){
		if(confirm('库存不足，是否进行缺货登记'))
		{
			window.location.href='/UserCenter/usermessage.aspx?prdid=' + prdid;
		}else{
			alert('库存不足!');	
		}
		return ;	
	 }else{
        if(parseInt(pcount)>parseInt(storage)){
            alert('库存不足!');
            return;	
        }
     }
	
	//商品属性 attrids/spec_/
    var attrids="0";
//    var aobj = $("input[type='hidden'][name='attrids']");
//    aobj.each(function() {
//        var tmp = $(this).val();
//        var tt=0; 
//        $("input[type='radio'][name='spec_" + tmp + "']").each(function() {
//            if (this.checked == true) {
//                tt = $(this).val();
//                return;
//            }
//        });
//        attrids = attrids + "," + tt;
//    });
     var errstr="请选择：\n";
     var haveol="0";
     var aobj = $("input[type='hidden'][name='attrids']");
     aobj.each(function() {if($(this).val()!="0") {
            attrids = attrids + "," + $(this).val();
        }else {   
            var tmpid=$(this).attr("id");
            tmpid=tmpid.replace(/attrid_/,"");
            errstr=errstr+$("#attrtitle_"+tmpid).html()+"\n";
            haveol="1";
        }
     }); 
     if(haveol=="1"){
        alert(errstr);
        return;
     }else{
        window.location.href = "/shopping/initcart.aspx?action=buy&prdid=" + prdid + "&pcount=" + pcount + "&exch="+exch+"&attrids="+attrids;
	    return false;
	}
}
