﻿var $j = jQuery.noConflict();
function setTabStyle(tabId) {
   if($j("div[class=team_pl]")[0])
   {
        $j('div[class=team_pl] > ul > li > a').each(function(i) {
            $j(this).attr('class', 'tab_pl1');
        });
   }
   else
   {
      $j('div[class=sw_team_pl] > ul > li > a').each(function(i) {
            $j(this).attr('class', 'tab_pl1');
        });
   }
   $j('#' + tabId).attr('class', 'tabactive');
}

function showPackage(domId) {
    setTabStyle(domId);
    var gameCode = $j('#hfGameCode').val();
    $j('#div_profession').css("display", 'none');
    $j('#div_arena').css("display", 'none');
    $j('#div_package').hide();
    $j('#imgWaite').css("display", 'none');
    if ($j('#div_package').html() != '') {
        $j('#div_package').show(300);
        return;
    }

    $j.ajax(
	{
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetPackage&gameCode=' + gameCode+'&rd='+Math.random(),
	    dataType: 'json',
	    success: function(json) {
	        var html = '';
	        for (var i = 0; i < json.length; i++) {
	            var guid = json[i].Guid;
	            var name = json[i].PackageName;
	            var price = json[i].PackagePrice;
	            var days = json[i].PackageTimeLimit;
	            var items = json[i].Items;
	            var itemName = '';
	            var itemGuid = '';
	            for (var j = 0; j < items.length; j++) {
	                itemName += items[j].ItemName;
	                if (j == items.length - 1)
	                    itemGuid += items[j].Guid;
	                else
	                    itemGuid += items[j].Guid + '|';
	            }
	            var fmHead='';
	            if(gameCode=='130' || gameCode=='118')
	            {
	               fmHead='<form id="fm_pk" action="/powerleveling/PLOrderInfo_SWG.aspx?gameCode=' + gameCode + '&pl=pk" method="post">';
	            }
	            else
	            {
	               fmHead = '<form id="fm_pk" action="/powerleveling/PLOrderInfo.aspx?gameCode=' + gameCode + '&pl=pk" method="post">';
	            }
	            var tbl = '<div class="pl_pro1">\
									<p><a href="javascript:">' + name + '</a></p>\
									<p>' + itemName + '</p>\
									<p align="right"; style="float:right">\
										<input type="submit" class="button3" value="Select" />\
										<input type="hidden" name="pk_itemGuid" value=' + itemGuid + '></hidden>\
										<input type="hidden" name="pk_guid" value=' + guid + '></hidden>\
									<p>\
									<p><div class="pl_001">Price: <span class="red">$ ' + price + '</span> Time: <span class="red">' + days + ' Days</span></div></p>\
									<div class="clearboth"></div>\
								   </div>';
	            var fmEnd = '</form>';
	            html += fmHead + tbl + fmEnd;
	        }
	        $j('#div_package').html(html);
	        $j('#div_package').show(300);
	        $j('#imgWaite').css("display", 'none');

	       
	    }
	});
    $j('#imgWaite').css("display", 'block');
}

function showArena(domId) {
    setTabStyle(domId);
    var gameCode = $j('#hfGameCode').val();
    $j('#div_package').css("display", 'none');
    $j('#div_profession').css("display", 'none');
    $j('#imgWaite').css("display", 'none');
    if ($j('#div_arena').html() != '') {
        $j('#div_arena').show(300);
        return;
    }

    $j.ajax(
	{
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetArena&gameCode=' + gameCode + '&rd=' + Math.random(),
	    dataType: 'json',
	    success: function(json) {
	        var html = '';
	        for (var i = 0; i < json.length; i++) {
	            var name = json[i].SeriesName;
	            var tblHead = '<table cellspacing="0" cellpadding="0" width="100%" class="pl_table02">\
										<tbody>\
										  <tr>\
											<th style=\'width:50%;\'>' + name + '</th>\
											<th style=\'width:15%;\'>Price </th>\
											<th style=\'width:15%;\'>Time </th>\
											<th>&nbsp;</th>\
										  </tr>\
										</tbody>';
	            var tblBody = '';
	            var pro = json[i].Projects;
	            var fmHead='<form action="/powerleveling/PLOrderInfo.aspx?gameCode=' + gameCode + '&pl=zb" method="post">';
	            if(gameCode=='130' || gameCode=='118')
	            {
	                fmHead='<form action="/powerleveling/PLOrderInfo_SWG.aspx?gameCode=' + gameCode + '&pl=zb" method="post">';
	            }
	            for (var j = 0; j < pro.length; j++) {
	                var itemName = pro[j].ItemTypeName;
	                var price = pro[j].ItemTypePrice;
	                var days = pro[j].ItemTypeTime;
	                var guid = pro[j].Guid;
	                tblBody += '<tr>\
										 <td style=\'width:50%;\'>' + itemName + '</td>\
										 <td style=\'width:15%;\'>$ ' + price + '</td>\
										 <td style=\'width:15%;\'>' + days + ' Days</td>\
										 <td>'+fmHead+'<input type="hidden" id="pid" value="' + guid + '" name="pid" /><input type="submit" class="button3" value="Select"></form></td>\
										</tr>';
	            }
	            html += tblHead + tblBody + '</table>';
	        }
	        $j('#div_arena').html(html);
	        $j('#div_arena').show(300);
	        $j('#imgWaite').css("display", 'none');
	    }
	});
    $j('#imgWaite').css("display", 'block');
}

function showProfession(domId) {
    setTabStyle(domId);
    var gameCode = $j('#hfGameCode').val();
    $j('#div_package').css("display", 'none');
    $j('#div_arena').css("display", 'none');
    $j('#imgWaite').css("display", 'none');
    if ($j('#div_profession').html() != '') {
        $j('#div_profession').show(300);
        return;
    }

    $j.ajax(
	{
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetProfessional&gameCode=' + gameCode + '&rd=' + Math.random(),
	    dataType: 'html',
	    success: function(html) {
	        $j('#div_profession').html(html);
	        $j('#div_profession').show(300);
	        $j('#imgWaite').css("display", 'none');
	       
	    }
	});
    $j('#imgWaite').css("display", 'block');
}

// MarkHonor
var subMarkUrl = '';
function calMarkOfHonor(selectDays) {
    var oTr = $j(selectDays).parents("tr:first");
    var baseGuid = $j('#mark_base_guid',oTr).val();
    var jnGuid = $j('#select_mark',oTr).val();
    var gameCode = $j("#hfGameCode").val();
    var start = selectDays.value;
    $j.ajax(
	{
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetItemPrice&pguid=' + baseGuid + '&nguid=' + jnGuid + '&slevel=' + start + '&elevel=-1&gamecode=' + gameCode + '&length=1' + '&rd=' + Math.random(),
	    dataType: 'html',
	    success: function(html) {
	        $j('#select_mark_level',oTr).attr("disabled", false);
	        if (html == '') {
	            $j('#markPrice',oTr).val('');
	            $j('#markDays',oTr).val('');
	            subMarkUrl = '';
	            return;
	        }

	        var price = html.split('\n')[0];
	        var days = html.split('\n')[1];
	        $j('#markPrice',oTr).val(price);
	        $j('#markDays',oTr).val(days);
	        if(gameCode=='130' || gameCode=='118')
	        {
	          subMarkUrl = '/powerleveling/PLOrderInfo_SWG.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + start + '&end=-1' + '&gameCode=' + gameCode;
	        }
	        else
	        {
	          subMarkUrl = '/powerleveling/PLOrderInfo.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + start + '&end=-1' + '&gameCode=' + gameCode;
	        }
	    }
	});
    $j('#select_mark_level',oTr).attr("disabled", true);
}

function markSubmit() {
    if ($j('#markPrice').val() == '' || $j('#markPrice').val() == '0.00' || subMarkUrl == '')
        return;
    window.location = subMarkUrl;
}

function markChange() {
    var oTr = $j(this).parents("tr:first");
    subMarkUrl = '';
    $j('#markPrice',oTr).val('');
    $j('#markDays',oTr).val('');
    $j('#select_mark_level',oTr).val('-1');
}

//  ReputationPl
var subRUrl = '';
function rChange() {
    subRUrl = '';
    $j('#rPrice').val('');
    $j('#rDays').val('');
    $j('#select_r_level2').val('-1');
}

function calR(selectR) {
    var baseGuid = $j('#r_base_guid').val();
    var jnGuid = $j('#select_r').val();
    var level1 = $j('#select_r_level1').val();
    var level2 = selectR.value;
    var gameCode = $j("#hfGameCode").val();
    if (level2 == '-1') {
        $j('#rPrice').val('');
        $j('#rDays').val('');
        return;
    }

    $j.ajax(
	{
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetItemPrice&PGuid=' + baseGuid + '&NGuid=' + jnGuid + '&Start=' + level1 + '&End=' + level2 + '&gamecode=' + gameCode + '&length=2' + '&rd=' + Math.random(),
	    dataType: 'html',
	    success: function(html) {
	        selectR.disabled = false;
	        if (html == '') {
	            $j('#rPrice').val('');
	            $j('#rDays').val('');
	            subRUrl = '';
	            return;
	        }

	        var price = html.split('\n')[0];
	        var days = html.split('\n')[1];
	        $j('#rPrice').val(price);
	        $j('#rDays').val(days);
	        if(gameCode=='130' || gameCode=='118')
	        {
	          subRUrl = '/powerleveling/PLOrderInfo_SWG.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + level1 + '&end=' + level2 + '&gameCode=' + gameCode;
	        }
	        else
	        {
	          subRUrl = '/powerleveling/PLOrderInfo.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + level1 + '&end=' + level2 + '&gameCode=' + gameCode;
	        }
	    }
	});
    selectR.disabled = true;
}

function rSubmit() {
    if ($j('#rPrice').val() == '' || $j('#rPrice').val() == '0.00' || subRUrl == '')
        return;

   window.location = subRUrl;
}

// Profession
var subPUrl = '';
function pChange() {
    subPUrl = '';
    $j('#pPrice').val('');
    $j('#pDays').value = '';
    $j('#select_p_level').val('-1');
}

function calP(selectP) {
    var baseGuid = $j('#p_base_guid').val();
    var jnGuid = $j('#select_p').val();
    var gameCode = $j("#hfGameCode").val();
    var level = selectP.value;
    if (level == '-1') {
        $j('#pPrice').val('');
        $j('#pDays').val('');
        return;
    }

    $j.ajax(
	{ 
	    url: '/powerleveling/plAjax.aspx',
	    type: 'get',
	    data: 'methodName=GetItemPrice&pguid=' + baseGuid + '&nguid=' + jnGuid + '&slevel=' + level + '&elevel=-1&gamecode=' + gameCode + '&length=1' + '&rd=' + Math.random(),
	    dataType: 'html',
	    success: function(html) {
	        selectP.disabled = false;
	        if (html == '') {
	            $j('#pPrice').val('');
	            $j('#pDays').val('');
	            subPUrl = '';
	            return;
	        }

	        var price = html.split('\n')[0];
	        var days = html.split('\n')[1];
	        $j('#pPrice').val(price);
	        $j('#pDays').val(days);
	        if(gameCode=='130' || gameCode=='118')
	        {
	          subPUrl = '/powerleveling/PLOrderInfo_SWG.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + level + '&end=-1' + '&gameCode=' + gameCode;
	        }
	        else
	        {
	          subPUrl = '/powerleveling/PLOrderInfo.aspx?pl=jn&pj=' + baseGuid + '&pjname=' + jnGuid + '&start=' + level + '&end=-1' + '&gameCode=' + gameCode;
	        }
	    }
	});
    selectP.disabled = true;
}

function pSubmit() {
    if ($j('#pPrice').val() == '' || $j('#pPrice').val() == '0.00' || subPUrl == '')
        return;

    window.location = subPUrl;
}

