$(document).ready(/*程序加载时添加事件*/
    function(){
		//修改数量
       $("input[@name='amount']").change(function(){
            var pAmount = this.value;
            if(isNaN(parseInt(this.value))){
                pAmount = "1";
                this.value = 1;
            }else{
                if(parseInt(this.value) == 0){
                    pAmount = "1";
                    this.value = 1;
                }
            }
            
            var pName = $(this).parent().parent().find("td:eq(0)").text();
            var subTotalPrice = $(this).parent().next();
			
            $.getJSON("shopjq.aspx",{"cmd":"edit","pid": escape(this.id),"num":pAmount},function (data){
                 var resultStr = "修改成功！" + RedColor(pName) + " 现在数量: " + RedColor(pAmount) +" 小计价格：" + RedColor(data[0].productprice);   
				 //alert(subTotalPrice.text());
                     /*
                     if(data[0].havepresent.toLowerCase() == "true"){//如果有赠品，则增加赠品的数量
                        var preIDs = data[0].presentids;
                        var preArray = preIDs.split(",");
                        for(var i=0;i < (preArray.length-1);i++){
                            $("#pAmount-" + preArray[i]).text(pAmount);                            
                        }
                     }*/
                     
                     subTotalPrice.text(data[0].productprice);
                    //subTotalPrice.text(data[0].subtotalprice);
                    //ShowMsg(resultStr);
                   //计算统计金额
                  $("#SumTotal").text(data[0].subtotalprice);
                   
                  // alert(document.getElementById(sum));
                    //CalcSubPrice();
                    //ShowMsg("xxx");
		    });
		    });
		    
        /*购物车列表*/
        $("input[@name='amount']").click(function(){
            this.select();
        });
        //修改数量,阻止输入非法字符
        $("input[@name='amount']").keypress(function(event){
            if(event.keyCode && (event.keyCode < 48 || event.keyCode > 57)){event.preventDefault();}
        });
        $("#ClearShopCart").click(function(){
            if(!confirm('确定要清空购物车吗？'))
            {
            return false;
            }
            var $parent = $("#ShopCartList");
            $.getJSON("shopjq.aspx",{"cmd":"clear","pid":"0"},function(data){
            //删除商品所在行
            $parent.remove();
            });
        });
	});
//delete
function DeleteProduct(o,pid)
{
    if(!confirm('really want to delete this item?'))
    {
    return false;
    }
    var $parent = $(o).parent().parent();
    $parent.css("background-color","#FFF9A6");
    $.getJSON("shopjq.aspx",{"cmd":"del","pid":escape(pid)},function(data){
        var pName = $parent.find("td:eq(0)").text();
        ShowMsg("商品：" + RedColor(pName) + " 删除成功!");
        $("#SumTotal").text(data[0].subtotalprice);
        //alert(data[0].subtotalprice);
        //删除商品所在行
        $parent.remove();
    });
    
    //计算统计金额
    // CalcSubPrice();
};
//清空购物车

//返回红色的span
function RedColor(str){
    return "<span style='color:Red;'>" + str + "</span>";
}
//显示提示框
function ShowMsg(msg){
//alert(msg);
//$("<div id='div-msg' style='position:absolute;width:350px; padding:20px;'>"+msg+"</div>").prependTo("body");
 
    if($("#div-msg").css("background-color") == "transparent"){
    $("#div-msg").css("background-color","#FFF4B9")
    } 
    $("#div-msg").css("background-color","#FFF4B9")
    $("#div-msg").fadeTo(2000,1);
    $("#div-msg").html("&nbsp;&nbsp;&nbsp;"+msg+"&nbsp;&nbsp;&nbsp;");

    setTimeout("HideMsg()",2000);
}
//从ID中获取ProductID
function GetPID(id){
    if(id.indexOf("-") != -1){
        return id.substring((id.indexOf("-")+1),id.length);
    }
    else{
        return id;
    }
}
//隐藏
function HideMsg(){
    $("#div-msg").fadeTo("slow",0);
}
/*
//保存数据时,显示一个正在加载的层
//s层的名称 0:是否有.net验证控件(true:有 false:无)border:1px solid #000;
document.write("<div id='ShowMessage' style='position:absolute;width:350px;display:none; padding:20px;'><table width='100%' rder='0' cellspacing='0' cellpadding='0'><tr><td style='background-color:#fff; border:1px solid #ccc; padding:20px;font-size:14px; font-weight:bold; color:#f00;' id='ShowImg'><img src='Images/wait.gif' align='absmiddle'></td><td width='5' rowspan='2' valign='top' style='background:#f4f4f4;  width:5px; vertical-align:top;'><img id='shadow' src='Skin/Default/Images/Icon_Sque01.gif' ></td></tr><tr><td style='background:#f4f4f4; border-left:10px solid #fff; height:5px;'></td></tr></table></div>");
function ShowDiv(s,o,type)
{
	var smg = "正在保存数据,请稍候......";
	if(o)
	{
		if(!Page_ClientValidate())
		{
			return;
		}
	}
	
	switch(type)
	{
		case 1:
			smg = "正在保存数据,请稍候......";			
			break;
		case 2:
			smg = "正在加载数据,请稍候......";
			break;
	}
	var sm = document.getElementById(s);
	var si = document.getElementById("ShowImg");
	var shadow = document.getElementById("shadow");
	if(sm == null)return;
	if(shadow != null)shadow.src = "Skin/" + CurrentSkinName + "/Images/Icon_Sque01.gif";
	if(si != null)
	{
		si.innerHTML = "<img src='Skin/" + CurrentSkinName + "/Images/wait.gif' align='absmiddle'>" + smg;
	}
	//alert(si.innerHTML);
	sm.style.top = document.body.scrollTop+((document.body.clientHeight-200)/2);
	sm.style.display= '';
	sm.style.left = document.body.scrollLeft+((document.body.clientWidth-350)/2);
	window.setTimeout("ShowDiv('"+s+"',"+o+","+type+")",100);
}
*/

 
