﻿var rstblHead = '<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 rstblBody = '';                     
                                     
var rstblFoot = '</table>';


jQuery(document).ready(function(){
    initRSShoppingCart();
});


function initRSShoppingCart(){
    jQuery.ajax({
        url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
        type:'get',
        data:'operate=init',
        dataType:'json',
        success:function(data){
            if(data == null)
            {
                return;
            }
            jQuery('#RSLeft1_RSShoppingCart1_DivAddToCart').show();
            var totalPrice = 0;
            rstblBody = '';
            for(var i = 0; i < data.length; i++){
                rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                <td>\
                <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
            }
            if(rstblBody != '')
            {
                jQuery('#RSDivShoppingCart').html('');
                jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                jQuery('#rsTotalPrice').html(totalPrice.toFixed(2));
            }
        }
    });
}


function delRSShoppingCart(guid)
{
     jQuery.ajax({
        url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
        type:'get',
        data:'operate=del&rsGuid=' + guid,
        dataType:'json',
        success:function(data){
            if(data == '')
            {
                jQuery('#RSDivShoppingCart').html('');
                jQuery('#rsTotalPrice').html('0.00');
            }
            else
            {
                var totalPrice = 0;
                rstblBody = '';
                for(var i = 0; i < data.length; i++){
                    rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                    <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                    <td>\
                    <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
                }
                if(rstblBody != '')
                {
                    jQuery('#RSDivShoppingCart').html('');
                    jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                    jQuery('#rsTotalPrice').html(totalPrice.toFixed(2));
                }
            }
        }
    });
}

function AddPassToCart(rsGuid,discount,name)
{
     jQuery.ajax({
        url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
        type:'get',
        data: 'operate=pass&rsGuid=' + rsGuid + "&dicount=" + discount + "&typeName=" + name,
        dataType:'json',
        success:function(data){
            var totalPrice = 0;
            rstblBody = '';
            for(var i = 0; i < data.length; i++){
                rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                <td>\
                <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
            }
            if(rstblBody != '')
            {
                        jQuery('#RSLeft1_RSShoppingCart1_DivAddToCart').show();
                jQuery('#RSDivShoppingCart').html('');
                jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                jQuery('#rsTotalPrice').html(totalPrice.toFixed(2));
            }
        }
    });
}

function AddPassToCart1(rsGuid,index,discount,name)
{
    var ddl = document.getElementById("rptItems"+index+"");
	var index = null;
	var selectcount =null;   
    var sindex =  null;  
    if(ddl != null)
    {
			var index = ddl.selectedIndex;
			var selectcount =ddl.options[index].text;   
			var sindex =  ddl.options[0].text;  
    }
    if(selectcount == null)
    {
        AddPassToCart(rsGuid,discount,name);
        return ;
    }
                jQuery('#RSLeft1_RSShoppingCart1_DivAddToCart').show();
     jQuery.ajax({
        url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
        type:'get',
        data: 'operate=pass&rsGuid=' + rsGuid + "&dicount=" + discount + "&count=" + selectcount + "&indexs=" + (selectcount / sindex) + "&typeName=" + name,
        dataType:'json',
        success:function(data){
            var totalPrice = 0;
            rstblBody = '';
            for(var i = 0; i < data.length; i++){
                rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                <td>\
                <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
            }
            if(rstblBody != '')
            {
                jQuery('#RSDivShoppingCart').html('');
                jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                jQuery('#rsTotalPrice').html(totalPrice.toFixed(2));
            }
        }
    });
}

function AddPkToCart(rsGuid, txtpname, txtpdescrip, txtptime ,txtpprice, hidordertype,name)
{
//        var txtpname = jQuery('#txtpname').val();
//        var txtpdescrip = jQuery('#txtpdescrip').val();
//        var txtptime = jQuery('#txtptime').val();
//        var txtpprice  = jQuery('#txtpprice').val();
//        var hidordertype=jQuery('#hidordertype').val();
                    jQuery('#leftpart_RSShoppingCart1_DivAddToCart').show();
    jQuery.ajax({
        url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
        type: 'get',
        data: 'operate=pkt&rsGuid=' + rsGuid + '&txtpname=' + txtpname + '&txtpdescrip=' + txtpdescrip + '&txtptime=' + txtptime + '&txtpprice=' + txtpprice + '&hidordertype=' + hidordertype + '&typeName=' + name,
        dataType:'json',
        success:function(data){
                var totalPrice = 0;
                rstblBody = '';
                for(var i = 0; i < data.length; i++){
                    rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                    <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                    <td>\
                    <a href="#" onclick="delRSShoppingCart(\'' + data[i].Guid + '\');return false;"><img  src="/images/del.gif"/></a></div></td></tr>\
                        <tr>\
    <td colspan="3"><div class="cart_product_bottom"></div></td>\
    </tr>';
                    totalPrice += data[i].ProductPrice;
                }
                if(rstblBody != '')
                {
                    jQuery('#RSDivShoppingCart').html('');
                    jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                    jQuery('#rsTotalPrice').html(totalPrice.toFixed(2));
                }
        }
    });
}

function AddLevelToCart(name)
{
    if(fillhidtxt())
    {
                jQuery('#leftpart_RSShoppingCart1_DivAddToCart').show();
        var ddlstart = jQuery('#ddlStart').val();
        var ddlend = jQuery('#ddlEnd').val();
        
        var txtprofession = jQuery('#txtprofession').val();
        var txtattack = jQuery('#txtattack').val();
        var txtdefence  = jQuery('#txtdefence').val();
        
        var txtstrength=jQuery('#txtstrength').val();
        var lblTime=jQuery('#lblTime').val();
        var lblPrice=jQuery('#lblPrice').val();
        var hidordertype=jQuery('#hidordertype').val();
        //alert(ddlstart+"--"+ddlend+"--"+txtprofession+"--"+txtattack+"--"+txtdefence+"--"+txtstrength+"--"+lblTime+"--"+lblPrice+"--"+hidordertype);
         jQuery.ajax({
            url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
            type: 'get',
            data: 'operate=level&ddlstart=' + ddlstart + '&ddlend=' + ddlend + '&txtprofession=' + txtprofession + '&txtattack=' + txtattack + '&txtdefence=' + txtdefence + '&txtstrength=' + txtstrength + '&lblTime=' + lblTime + '&lblPrice=' + lblPrice + '&hidordertype=' + hidordertype + '&typeName=' + name,
            dataType:'json',
            success:function(data){
                    var totalPrice = 0;
                    rstblBody = '';
                    for(var i = 0; i < data.length; i++){
                        rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                        <td>\
                        <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
                    }
                    if(rstblBody != '')
                    {
                        jQuery('#RSDivShoppingCart').html('');
                        jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                        jQuery('#rsTotalPrice').html('' + totalPrice.toFixed(2));
                    }
            }
        });
    }
}


function AddMutiToCart(name)
{
    jQuery('#rsleft_RSShoppingCart1_DivAddToCart').show();
    if(checkmutiform())
    {

        var txtdescrip = jQuery('#txtdescrip').val();
        var txttime = jQuery('#txttime').val();
        var txtprice  = jQuery('#txtprice').val();
        var hidordertype=jQuery('#hidordertype').val();
        //alert(txtdescrip+"--"+txttime+"--"+txtprice+"--"+hidordertype);
         jQuery.ajax({
            url:'/runescape/RSShoppingCart.aspx?rd=' + Math.random(),
            type: 'get',
            data: 'operate=muti&txtdescrip=' + txtdescrip + '&txttime=' + txttime + '&txtprice=' + txtprice + '&hidordertype=' + hidordertype + '&typeName=' + name,
            dataType:'json',
            success:function(data){
                    var totalPrice = 0;
                    rstblBody = '';
                    for(var i = 0; i < data.length; i++){
                        rstblBody +=  '<tr><td>' + data[i].ProductName + '</td>\
                        <td>' + data[i].ProductPrice.toFixed(2) + '</td>\
                        <td>\
                        <a href="#" onclick="delRSShoppingCart(\'' + 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].ProductPrice;
                    }
                    if(rstblBody != '')
                    {
                        jQuery('#RSDivShoppingCart').html('');
                        jQuery('#RSDivShoppingCart').html(rstblHead + rstblBody + rstblFoot);
                        jQuery('#rsTotalPrice').html('' + totalPrice.toFixed(2));
                    }
            }
        });
    }
}
