﻿function SpareChange()
{
    var sparePartIDs=GetSpareID();
    if(sparePartIDs!="")
    {
        AjaxMethodPL.GetSparePriceInfo
        (
            parseInt($("input[id$='hdServiceConfigID']").val()),
            sparePartIDs,
            function(result){
                 if(null==result.error){
                    if(result.value!=null){
                        var princeInfo=eval(result.value);
                        $("span[mark='currencyMark']").text(princeInfo.CurrencyMark);
                        //$("#currencyMark").text(princeInfo.CurrencyMark);
                        $("#Amount").text(princeInfo.Amount);
                        $("#Times").text(princeInfo.Days);
                        $("#VipAmount").text(princeInfo.VipAmount);
                    }
                }
            }
        )
    }
}

function GetSpareID()
{
    var sparePartIDs="";
    $("select[id$='_SparePart'] option:selected").each(function(){
        if($(this).val()!=0){
            sparePartIDs += ",";
            sparePartIDs += $(this).val();            
        }
    });
    if(sparePartIDs.length>1){
        sparePartIDs = sparePartIDs.substring(1,sparePartIDs.length);//删除第一个","
    }
    if(0==sparePartIDs.length){
        $("#Amount").text(0);
        $("#Times").text(0);
        alert("Please select the service");
    }
    return sparePartIDs;
}

function CharacterClassChange()
{
    AjaxMethodPL.GetSpareInfo
    (
        parseInt($("input[id$='hdServiceConfigID']").val()),
        parseInt($("select[id$='DDL_CharacterClass'] option:selected").val()),
        function(result){
            var Neck=$("select[id$='DDL_Neck_SparePart']")[0];
            var Back=$("select[id$='DDL_Back_SparePart']")[0];
            var Finger=$("select[id$='DDL_Finger_SparePart']")[0];
            var Waist=$("select[id$='DDL_Waist_SparePart']")[0];
            var Feet=$("select[id$='DDL_Feet_SparePart']")[0];
            var Wrist=$("select[id$='DDL_Wrist_SparePart']")[0];
            var Trinket=$("select[id$='DDL_Trinket_SparePart']")[0];
            Neck.options.length=1;
            Back.options.length=1;
            Finger.options.length=1;
            Waist.options.length=1;
            Feet.options.length=1;
            Wrist.options.length=1;
            Trinket.options.length=1;
            if(null==result.error){
                if(result.value!=null){
                    var dt = result.value;
                    if(0==dt.Rows.length){
                        return;    
                    }
                    for(i=0;i<dt.Rows.length;++i){
                        if(1==dt.Rows[i].TypeID){
                            Neck.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                        else if(2==dt.Rows[i].TypeID){
                            Back.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                        else if(3==dt.Rows[i].TypeID){
                            Finger.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                        else if(4==dt.Rows[i].TypeID){
                            Waist.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        } 
                        else if(5==dt.Rows[i].TypeID){
                            Feet.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                        else if(6==dt.Rows[i].TypeID){
                            Wrist.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                        else if(7==dt.Rows[i].TypeID){
                            Trinket.options.add(new Option(dt.Rows[i].ItemName,dt.Rows[i].ItemID)); 
                        }
                    }
                }             
            } 
            $("#Amount").text(0);
            $("#Times").text(0);          
        }
    )    
}

function Add()
{
    var sparePartIDs=GetSpareID();
    if(sparePartIDs!="")
    {
        AjaxMethodPL.AddSpareOrder
        (
            parseInt($("input[id$='hdServiceConfigID']").val()),
            sparePartIDs,
            parseInt($("select[id$='DDL_CharacterClass'] option:selected").val()),
            function(result){                
                //函数在common文件里
                AddTemp_CallBack(result);
            }
        )
    }
}
