function trim(str){
return  str.replace(/(^\s*)|(\s*$)/g,"");
}
function itemTable(){
var objTable=document.getElementById("tokenInfoBox").getElementsByTagName("table");
for(var i=0;i<objTable.length;i++){
objTable[i].onmouseover=function(){
this.style.background="#1b1b1b";
}
objTable[i].onmouseout=function(){
this.style.background="";
}
}
}

function updateEquipRarity(value){
$("#selectBar").html(value);
}

$(document).ready(function(){
init();
itemTable();
$("#searchSets").click(function(){
searchingItemEquipPack();
});
$("#searchWeapons").click(function(){
 searchingItemEquipPack();
});
$("#ItemLevel").click(function(){
sortEquip("ItemLevel");
});
$("#ItemPrice").click(function(){
sortEquip("ItemPrice");
});
var  equipPackageName="";
var  radioName=document.getElementsByName("season8");
for(var i=0;i<radioName.length;i++){
   if(radioName[i].checked){
   equipPackageName=radioName[i].value;
   }
}
showCurrentItem(equipPackageName);
});

var showFlag=false;
function init(){
$(".select_Three a").click(function(){ 
this.blur();
});
$(".select_Three a").focus(function(){ 
 this.blur();
});

$("#selectClassArrow").click(function(){ 
          $("#selectClassText").toggle("slow");
          //if($("#selectClassText").css("display")=="block"){
          // showFlag=true;
          //}else{
         // showFlag=false;
         // }
       if($("#selectTypeText").css("display")=="block"){
             $("#selectTypeText").toggle("slow");
          }
          if($("#selectSlotText").css("display")=="block"){
             $("#selectSlotText").toggle("slow");
          }
          if($("#selectLevelText").css("display")=="block"){
             $("#selectLevelText").toggle("slow");
          }
       $("#selectClassList li").each(function(){
          $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectClassBar").html($(this).text());
             $("#itemClass").val($(this).text());
             $("#selectClassText").hide();
          });
       });
});
$("#selectSlotArrow").click(function(){ 
          $("#selectSlotText").toggle("slow");
          //if($("#selectSlotText").css("display")=="block"){
           // showFlag=true;
           //}else{
          // showFlag=false;
          // }
          if($("#selectTypeText").css("display")=="block"){
             $("#selectTypeText").toggle("slow");
          }
          if($("#selectClassText").css("display")=="block"){
             $("#selectClassText").toggle("slow");
          }
           if($("#selectLevelText").css("display")=="block"){
             $("#selectLevelText").toggle("slow");
          }
          $("#selectSlotList li").each(function(){
          $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectSlotBar").html($(this).text());
             $("#itemSlot").val($(this).text());
             $("#selectSlotText").hide();
          });
       });
});

$("#selectLevelArrow").click(function(){ 
          $("#selectLevelText").toggle("slow");
          //if($("#selectLevelText").css("display")=="block"){
          //       showFlag=true;
        // }else{
         //       showFlag=false;
         // }
          if($("#selectTypeText").css("display")=="block"){
             $("#selectTypeText").toggle("slow");
          }
          if($("#selectClassText").css("display")=="block"){
             $("#selectClassText").toggle("slow");
          }
          if($("#selectSlotText").css("display")=="block"){
             $("#selectSlotText").toggle("slow");
          }
      $("#selectLevelList li").each(function(){
           $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectLevelBar").html($(this).text());
             $("#packName").val($(this).text());
             $("#selectLevelText").hide();
            });
      });
});
$("#selectTypeArrow").click(function(){ 
          $("#selectTypeText").toggle("slow");
          //if($("#selectTypeText").css("display")=="block"){
          // showFlag=true;
         //}else{
          // showFlag=false;
        // }
          if($("#selectSlotText").css("display")=="block"){
             $("#selectSlotText").toggle("slow");
          }
          if($("#selectLevelText").css("display")=="block"){
             $("#selectLevelText").toggle("slow");
          }
          if($("#selectClassText").css("display")=="block"){
             $("#selectClassText").toggle("slow");
          }
       $("#selectTypeList li").each(function(){
          $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectTypeBar").html($(this).text());
             $("#selectTypeText").hide();
          });
       });
});
}

$(document).click(function(){
          if($("#selectClassText").css("display")=="block"){
                 $("#selectClassText").hide();
          }
         if($("#selectSlotText").css("display")=="block"){
                 $("#selectSlotText").hide();
          }
          if($("#selectLevelText").css("display")=="block"){
                 $("#selectLevelText").hide();
          }
            if($("#selectTypeText").css("display")=="block"){
                 $("#selectTypeText").hide();
          }
          if($("#selectSecondSlotText").css("display")=="block"){
             $("#selectSecondSlotText").hide();
          }
          if($("#selectSecondLevelText").css("display")=="block"){
             $("#selectSecondLevelText").hide();
          }
             if($("#selectSecondTypeText").css("display")=="block"){
             $("#selectSecondTypeText").hide();
          }
});

function  loadingItemEquipPack(){
$("#tokenInfoBox").hide();
$("#loadeffect").show("slow");
var  currentPage="1";
var  loadURL="Arena_Sets_View/loadingArenaSets.jsp?currentPage="+currentPage;
var  equipPackageName="";
var  itemName="";
var  radioName=document.getElementsByName("season8");
for(var i=0;i<radioName.length;i++){
   if(radioName[i].checked){
   equipPackageName=radioName[i].value;
   }
}
if(equipPackageName=="Arena Season 8 Weapons"){
loadURL+="&itemName=Season Weapons";
loadURL+="&equipPackageName="+equipPackageName;
}else{
loadURL+="&itemName=Arena Season Set";
loadURL+="&equipPackageName="+equipPackageName;
}

$.ajax({
		type: "POST",
		url: loadURL,
		success: function(msg){	
	      var equipContent=msg.split("+++");
	      $("#btn_First_page_content").html(equipContent[1]);
	      $("#btn_Last_page_content").html(equipContent[1]);
	      $("#loadeffect").hide("slow");
	      $("#tokenInfoBox").html(equipContent[0]);
	      $("#tokenInfoBox").fadeIn("slow");
		}
	});
}


function  searchingItemEquipPack(){
$("#tokenInfoBox").hide();
$("#loadeffect").show("slow");
var  currentPage="1";
var  loadURL="Arena_Sets_View/loadingArenaSets.jsp?currentPage="+currentPage;
var  equipPackageName="";
var  radioName=document.getElementsByName("season8");
for(var i=0;i<radioName.length;i++){
   if(radioName[i].checked){
     equipPackageName=radioName[i].value;
   }
}
if(equipPackageName=="Arena Season 8 Weapons"){
loadURL+="&itemName=Season Weapons";
loadURL+="&equipPackageName="+equipPackageName;
}else{
var equipEquipClass=trim($("#selectClassBar").text());
if(equipEquipClass!="All"||equipEquipClass!=""){
loadURL+="&equipEquipClass="+equipEquipClass;
}
loadURL+="&itemName=Arena Season Set";
loadURL+="&equipPackageName="+equipPackageName;
}
var selectSlotBar="selectSlotBar";
if(equipPackageName=="Arena Season 9 Set"){
selectSlotBar="selectSecondSlotBar";
}
var selectTypeBar="selectTypeBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectTypeBar="selectSecondTypeBar";
}
var selectLevelBar="selectLevelBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectLevelBar="selectSecondLevelBar";
}
var equipEquipName="equipEquipName";
if(equipPackageName=="Arena Season 8 Weapons"){
equipEquipName="equipSecondEquipName";
}
var  equipEquipSlot=trim($("#"+selectSlotBar).text());
if(equipEquipSlot!="All"){
loadURL+="&equipEquipSlot="+equipEquipSlot;
}

var  equipEquipType=trim($("#"+selectTypeBar).text());
if(equipEquipType!="All"){
loadURL+="&equipEquipType="+equipEquipType;
}
var  equipName=trim($("#"+equipEquipName).val());
if(equipName!=""){
loadURL+="&equipName="+equipName;
}
var  itemLevel=trim($("#"+selectLevelBar).text());
if(itemLevel!="All"){
loadURL+="&itemLevel="+itemLevel;
}
$.ajax({
		type: "POST",
		url: loadURL,
		success: function(msg){
	      var equipContent=msg.split("+++");
	      $("#btn_First_page_content").html(equipContent[1]);
	      $("#btn_Last_page_content").html(equipContent[1]);
	      $("#loadeffect").hide("slow");
	      $("#tokenInfoBox").html(equipContent[0]);
	      $("#tokenInfoBox").fadeIn("slow");
		}
	});
}

function changePage(page){
$("#tokenInfoBox").hide();
$("#loadeffect").show("slow");
var  currentPage=page;
var  loadURL="Arena_Sets_View/loadingArenaSets.jsp?currentPage="+currentPage;
var  equipPackageName="";
var  radioName=document.getElementsByName("season8");
for(var i=0;i<radioName.length;i++){
   if(radioName[i].checked){
     equipPackageName=radioName[i].value;
   }
}
if(equipPackageName=="Arena Season 8 Weapons"){
loadURL+="&itemName=Season Weapons";
loadURL+="&equipPackageName="+equipPackageName;
}else{
var equipEquipClass=trim($("#selectClassBar").text());
if(equipEquipClass!="All"||equipEquipClass!=""){
loadURL+="&equipEquipClass="+equipEquipClass;
}
loadURL+="&itemName=Arena Season Set";
loadURL+="&equipPackageName="+equipPackageName;
}
var selectSlotBar="selectSlotBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectSlotBar="selectSecondSlotBar";
}
var selectTypeBar="selectTypeBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectTypeBar="selectSecondTypeBar";
}
var selectLevelBar="selectLevelBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectLevelBar="selectSecondLevelBar";
}
var equipEquipName="equipEquipName";
if(equipPackageName=="Arena Season 8 Weapons"){
equipEquipName="equipSecondEquipName";
}
var  equipEquipSlot=trim($("#"+selectSlotBar).text());
if(equipEquipSlot!="All"){
loadURL+="&equipEquipSlot="+equipEquipSlot;
}

var  equipEquipType=trim($("#"+selectTypeBar).text());
if(equipEquipType!="All"){
loadURL+="&equipEquipType="+equipEquipType;
}
var  equipName=trim($("#"+equipEquipName).val());
if(equipName!=""){
loadURL+="&equipName="+equipName;
}
var  itemLevel=trim($("#"+selectLevelBar).text());
if(itemLevel!="All"){
loadURL+="&itemLevel="+itemLevel;
}
$.ajax({
		type: "POST",
		url: loadURL,
		success: function(msg){	
	      var equipContent=msg.split("+++");
	      $("#btn_First_page_content").html(equipContent[1]);
	      $("#btn_Last_page_content").html(equipContent[1]);
	      $("#loadeffect").hide("slow");
	      $("#tokenInfoBox").html(equipContent[0]);
	      $("#tokenInfoBox").fadeIn("slow");
		}
	});

}
function  sortEquip(orderBy){
$("#tokenInfoBox").hide();
$("#loadeffect").show("slow");
var  currentPage="1";
var  loadURL="Arena_Sets_View/loadingArenaSets.jsp?currentPage="+currentPage;
var  equipPackageName="";
var  radioName=document.getElementsByName("season8");
for(var i=0;i<radioName.length;i++){
   if(radioName[i].checked){
     equipPackageName=radioName[i].value;
   }
}
if(equipPackageName=="Arena Season 8 Weapons"){
loadURL+="&itemName=Season Weapons";
loadURL+="&equipPackageName="+equipPackageName;
}else{
var equipEquipClass=trim($("#selectClassBar").text());
if(equipEquipClass!="All"||equipEquipClass!=""){
loadURL+="&equipEquipClass="+equipEquipClass;
}
loadURL+="&itemName=Arena Season Set";
loadURL+="&equipPackageName="+equipPackageName;
}
var selectSlotBar="selectSlotBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectSlotBar="selectSecondSlotBar";
}
var selectTypeBar="selectTypeBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectTypeBar="selectSecondTypeBar";
}
var selectLevelBar="selectLevelBar";
if(equipPackageName=="Arena Season 8 Weapons"){
selectLevelBar="selectSecondLevelBar";
}
var equipEquipName="equipEquipName";
if(equipPackageName=="Arena Season 8 Weapons"){
equipEquipName="equipSecondEquipName";
}
var  equipEquipSlot=trim($("#"+selectSlotBar).text());
if(equipEquipSlot!="All"){
loadURL+="&equipEquipSlot="+equipEquipSlot;
}

var  equipEquipType=trim($("#"+selectTypeBar).text());
if(equipEquipType!="All"){
loadURL+="&equipEquipType="+equipEquipType;
}
var  equipName=trim($("#"+equipEquipName).val());
if(equipName!=""){
loadURL+="&equipName="+equipName;
}
var  itemLevel=trim($("#"+selectLevelBar).text());
if(itemLevel!="All"){
loadURL+="&itemLevel="+itemLevel;
}
if(orderBy!=""&&orderBy!=null){
if($("#"+orderBy).attr("class")=="current"){
$("#"+orderBy).attr("class","");
orderBy=orderBy+" desc";
}else if($("#"+orderBy).attr("class")==""){
$("#"+orderBy).attr("class","current")
orderBy=orderBy+" asc";
}
loadURL+="&orderBy="+orderBy;
$("#orderBy").val(orderBy);
}
$.ajax({
		type: "POST",
		url: loadURL,
		success: function(msg){	
	      var equipContent=msg.split("+++");
	      $("#btn_First_page_content").html(equipContent[1]);
	      $("#btn_Last_page_content").html(equipContent[1]);
	      $("#loadeffect").hide("slow");
	      $("#tokenInfoBox").html(equipContent[0]);
	      $("#tokenInfoBox").fadeIn("slow");
		}
	});
}


function  addToCart(itemName,equipId){
$("#shopping_cart").css("display","block");
var  loadCartUrl="Arena_Sets_View/addToCart.jsp?equipEquipId="+equipId+"&itemName="+itemName;
$("#butCartList").fadeOut("slow");
$.ajax({
		type: "POST",
		url: loadCartUrl,
		success: function(msg){	
		   if(msg.indexOf("This item already exists")!=-1){
	          alert(msg);
	        }else{
	        $("#butCartList").html(msg);
	        }
	        $("#butCartList").toggle("slow");
	       
		}
	});
}

function reducingNumber(equipId,number){
if(parseInt(number)==1||parseInt(number)<=0){
alert("The number of items can not be reduced!");
}else{
$("#butCartList").fadeOut("slow");
var  loadreduceUrl="Arena_Sets_View/reduceNumber.jsp?equipEquipId="+equipId+"&currentNumber="+number;
$.ajax({
		type: "POST",
		url: loadreduceUrl,
		success: function(msg){	
	        $("#butCartList").html(msg);
	        $("#butCartList").toggle("slow");
		}
	});
}
}
function addingNumber(equipId,number){
if(parseInt(number)>=90){
alert("This item can no longer increase the number of!");
}else{
$("#butCartList").fadeOut("slow");
var  loadreduceUrl="Arena_Sets_View/addNumber.jsp?equipEquipId="+equipId+"&currentNumber="+number;
$.ajax({
		type: "POST",
		url: loadreduceUrl,
		success: function(msg){	
	        $("#butCartList").html(msg);
	        $("#butCartList").toggle("slow");
		}
	});
}
}

function removeCart(removeEquipIndex){
$("#butCartList").fadeOut("slow");
var  loadUrl="Arena_Sets_View/removeCart.jsp?removeEquipIndex="+removeEquipIndex;
$.ajax({
type:"post",
url:loadUrl,
success:function(msg){
	      if(msg.indexOf("completely empty!")!=-1){
	          alert("Shopping cart has been completely empty!");
	          $("#shopping_cart").css("display","none");
	        }else{
	           $("#butCartList").html(msg);
	           $("#butCartList").toggle("slow");
	        }
}
});
}

function cilckNowBuy(){
document.equipListForm.submit();
}

function showCurrentItem(currentValue){
        $("#selectSecondSlotText").hide();
        $("#selectSecondLevelText").hide();
        $("#selectSecondTypeText").hide();
        $("#selectClassText").hide();
        $("#selectSlotText").hide();
        $("#selectLevelText").hide();
        $("#selectTypeText").hide();
    if(currentValue.indexOf("Arena Season")!=-1&&currentValue.indexOf("Set")!=-1){
       $("#seasonWeaponsINFO").hide();
       $("#seasonSetsINFO").attr("class","seasonNONE");
       $("#seasonSetsINFO").show();
      }else if(currentValue.indexOf("Arena Season")!=-1&&currentValue.indexOf("Weapons")!=-1){
        $("#seasonSetsINFO").hide();
        $("#seasonWeaponsINFO").attr("class","seasonNONE");
        $("#seasonWeaponsINFO").show();
        initSecond();
      }
       loadingItemEquipPack();
}



function initSecond(){
$("#selectSecondSlotArrow").click(function(){ 
          $("#selectSecondSlotText").show("slow");
           if($("#selectSecondLevelText").css("display")=="block"){
             $("#selectSecondLevelText").hide();
          }
             if($("#selectSecondTypeText").css("display")=="block"){
             $("#selectSecondTypeText").hide();
          }
          $("#selectSecondSlotList li").each(function(){
          $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectSecondSlotBar").html($(this).text());
             $("#selectSecondSlotText").hide();
          });
       });
});

$("#selectSecondLevelArrow").click(function(){ 
          $("#selectSecondLevelText").show("slow");
          if($("#selectSecondSlotText").css("display")=="block"){
             $("#selectSecondSlotText").hide();
          }
            if($("#selectSecondTypeText").css("display")=="block"){
             $("#selectSecondTypeText").hide();
          }
      $("#selectSecondLevelList li").each(function(){
           $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectSecondLevelBar").html($(this).text());
             $("#selectSecondLevelText").hide();
            });
      });
});
$("#selectSecondTypeArrow").click(function(){ 
          $("#selectSecondTypeText").show("slow");
          if($("#selectSecondSlotText").css("display")=="block"){
             $("#selectSecondSlotText").hide();
          }
          if($("#selectSecondLevelText").css("display")=="block"){
             $("#selectSecondLevelText").hide();
          }
       $("#selectSecondTypeList li").each(function(){
          $(this).click(function(){
             $(this).addClass("current").siblings().removeClass("current");
             $("#selectSecondTypeBar").html($(this).text());
             $("#selectSecondTypeText").hide();
          });
       });
});
}

function hiddenItemList(){
if($("#butCartList").css("display")=="none"){
   $("#butCartList").show(1000);
   $("#expandImg").attr("src","images/index/ico_hidden.gif");
}else if($("#butCartList").css("display")=="block"){
   $("#butCartList").hide(1000);
   $("#expandImg").attr("src","images/index/ico_add.gif");
}
}
