﻿
  
  var tblHead1 = '<table style="width:97%;"> \
    <tr class="cart_title">\
      <td >ProductName</td>\
	  <td >Price</td>\
	  <td >Del</td>\
    </tr>\
    <tr>\
    <td height="1px" colspan="3"><hr noshade="noshade" size="1" color="#04840b"></td>\
    </tr>';
                        
  var tblBody1 = '';                     
                                         
  var tblFoot1 =    '</table>';
                
   jQuery(document).ready(function(){
        initShoppingCart();
    });
  
  function AddPktToCart(guid, guid2){
            jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=pkt&pid=' + guid + '&pitem=' + guid2,
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody1 = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>$' + data[i].Price + '</td>\
                        <td >\
                        <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody1 != '')
                    {
                        jQuery('#divShoppingCart').html('');
                        jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                        jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                        jQuery("#divShoppingCartWOW").show();
                    }
                }
            });
        }
        
        
         function initShoppingCart(){
            jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=init',
                dataType:'json',
                success:function(data){
                    if(data == null)
                    {
                    jQuery("#divShoppingCartWOW").hide();
                        return;
                        
                    }
                    var totalPrice = 0;
                    tblBody1 = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>$' + data[i].Price + '</td>\
                        <td>\
                        <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody1 != '')
                    {
                        jQuery('#divShoppingCart').html('');
                        jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                        jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        function AddJnToCart(serType)
        {
            var pj = jQuery('#pj'+serType).val();
            var pjname = jQuery('#pjname'+serType).val();
            var start = jQuery('#start'+serType).val();
            var end = jQuery('#end'+serType).val();
//            alert(pj+"|||"+pjname+"|||"+start+"|||"+end);
            
             jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.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;
                    tblBody1 = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>$' + data[i].Price + '</td>\
                        <td>\
                        <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody1 != '')
                    {
                        jQuery('#divShoppingCart').html('');
                        jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                        jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        
        function delShoppingCart(guid)
        {
             jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=del&guid=' + guid,
                dataType:'json',
                success:function(data){
                    if(data == '')
                    {
                        jQuery('#divShoppingCart').html('');
                        jQuery('#totalPrice').html('$0.00');
                    }
                    else
                    {
                        var totalPrice = 0;
                        tblBody1 = '';
                        for(var i = 0; i < data.length; i++){
                            tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                            <td>$' + data[i].Price + '</td>\
                            <td>\
                            <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                            totalPrice += data[i].Price;
                        }
                        if(tblBody1 != '')
                        {
                            jQuery('#divShoppingCart').html('');
                            jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                            jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                        }
                    }
                }
            });
        }
        
        
        
        function AddZbToCart(pid)
        {
            
             jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.aspx?rd=' + Math.random(),
                type:'get',
                data:'operate=zb&pid=' + pid,
                dataType:'json',
                success:function(data){
                    var totalPrice = 0;
                    tblBody1 = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>$' + data[i].Price + '</td>\
                        <td><div align="center">\
                        <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody1 != '')
                    {
                        jQuery('#divShoppingCart').html('');
                        jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                        jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                    }
                }
            });
        }
        
        function AddLevelToCart()
        {
            var hisltStart = jQuery('#hd_s_level').val();
            var hisltEnd = jQuery('#hd_e_level').val();
            
            var goldServer = jQuery('#ddlServers').val();
            var goldAmount = jQuery('#ddlProduct option:selected').text();
            var goldPrice = jQuery('#ddlProduct option:selected').val();
            
            var DIYName=jQuery('#inptDIYName').val();
            var DIYPrice=jQuery('#inptDIYPrice').val();
            var DIYTime=jQuery('#inptDIYTime').val();
            var DIYDescrip=jQuery('#inptDIYDescrip').val();
            //alert(DIYName+"--"+DIYPrice+"--"+DIYTime+"--"+DIYDescrip+"---"+hisltStart+"---"+hisltEnd+"---"+goldServer+"---"+goldAmount+"---"+goldPrice);
            
             jQuery.ajax({
                url:'/powerleveling/PLShoppingCart_WOW.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;
                    tblBody1 = '';
                    for(var i = 0; i < data.length; i++){
                        tblBody1 +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>$' + data[i].Price + '</td>\
                        <td><div align="center">\
                        <a href="#" onclick="delShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                        totalPrice += data[i].Price;
                    }
                    if(tblBody1 != '')
                    {
                        jQuery("#divShoppingCartWOW").show();
                        jQuery('#divShoppingCart').html('');
                        jQuery('#divShoppingCart').html(tblHead1 + tblBody1 + tblFoot1);
                        jQuery('#totalPrice').html('$' + totalPrice.toFixed(2));
                        
                    }
                }
            });
        }