﻿
  
  var tblHead = '<table width="166" height="126" class="left_game" style="padding-left:5px; border-collapse:collapse;">\
            <tr style="font-weight:bold; color:#509d2b; height:25px;border-bottom:#aea0dd 1px solid; ">\
				<td width="82"  style="padding-left:5px;border-bottom:#aea0dd 1px solid;">ProductName</td>\
				<td width="30" style="border-bottom:#aea0dd 1px solid;">Price</td>\
				<td width="32" style="border-bottom:#aea0dd 1px solid;">Delete</td>\
			</tr>';
                        
  var tblBody = '';                     
                                         
  var tblFoot =    '</table>';
                
   $(document).ready(function(){
        initShoppingCart();
    });
  
  function AddPktToCart(guid, guid2){
            $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=pkt&pid=' + guid + '&pitem=' + guid2,
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody != '')
                    {
                        $('#divShoppingCart').html('');
                        $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                        $('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        
         function initShoppingCart(){
            $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=init',
                dataType:'json',
                success:function(data){
                    if(data == null)
                    {
                        return;
                    }
                    var totalPrice = 0;
                    tblBody = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody != '')
                    {
                        $('#divShoppingCart').html('');
                        $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                        $('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        function AddJnToCart(serType)
        {
            var pj = $('#pj'+serType).val();
            var pjname = $('#pjname'+serType).val();
            var start = $('#start'+serType).val();
            var end = $('#end'+serType).val();
//            alert(pj+"|||"+pjname+"|||"+start+"|||"+end);
            
             $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=jn&pj=' + pj + '&pjname=' + pjname +'&start=' + start +'&end=' +end,
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody != '')
                    {
                        $('#divShoppingCart').html('');
                        $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                        $('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        
        function delShoppingCart(guid)
        {
             $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=del&guid=' + guid,
                dataType:'json',
                success:function(data){
                    if(data == '')
                    {
                        $('#divShoppingCart').html('');
                        $('#totalPrice').html('$0.00');
                    }
                    else
                    {
                        var totalPrice = 0;
                        tblBody = '';
                        for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                        }
                        if(tblBody != '')
                        {
                            $('#divShoppingCart').html('');
                            $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                            $('#totalPrice').html('$' + totalPrice.toFixed(2));
                        }
                    }
                }
            });
        }
        
        
        
        function AddZbToCart(pid)
        {
            
             $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=zb&pid=' + pid,
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody != '')
                    {
                        $('#divShoppingCart').html('');
                        $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                        $('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        function AddLevelToCart()
        {
            var hisltStart = $('#hd_s_level').val();
            var hisltEnd = $('#hd_e_level').val();
            
            var goldServer = $('#sltServers').val();
            var goldAmount = $('#sltProducts option:selected').text();
            var goldPrice  = $('#sltProducts option:selected').val();
            
            var DIYName=$('#inptDIYName').val();
            var DIYPrice=$('#inptDIYPrice').val();
            var DIYTime=$('#inptDIYTime').val();
            var DIYDescrip=$('#inptDIYDescrip').val();
            //alert(DIYName+"--"+DIYPrice+"--"+DIYTime+"--"+DIYDescrip+"---"+hisltStart+"---"+hisltEnd+"---"+goldServer+"---"+goldAmount+"---"+goldPrice);
            
             $.ajax({
                url:'/PLShoppingCart.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=level&hisltStart=' + hisltStart + '&hisltEnd=' + hisltEnd + '&goldPrice=' + goldPrice + '&goldServer=' + goldServer + '&goldAmount=' + goldAmount+'&DIYPackageName='+escape(DIYName)+'&DIYPackagePrice='+  escape(DIYPrice)+'&DIYPackageTimeLilit='+escape(DIYTime)+'&DIYPackageDescrip='+escape(DIYDescrip),
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody +=  '<tr><td height="48" style=" padding-left:5px;border-bottom:#aea0dd 1px dotted;">' + data[i].ProductName + '</td><td style="border-bottom:#aea0dd 1px dotted;">$' + data[i].Price + '</td><td style="border-bottom:#aea0dd 1px dotted;"><div align="center"><a href="#" onclick="delShoppingCart(\''+ data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody != '')
                    {
                        $('#divShoppingCart').html('');
                        $('#divShoppingCart').html(tblHead + tblBody + tblFoot);
                        $('#totalPrice').html('$' + totalPrice.toFixed(2));
                        
                    }
                }
            });
        }