﻿//设置开始
var arenasettings ={
    enable3dview:true,                                  //是否允许查看3D模型
    modelviewerbaseurl:"http://www.wowdb.tw/",               //3D模型所在站点的URL
    modelviewercontentPath:"http://www.wowdb.tw/3D/",        //3D模型所在站点的目录URL
    iconurl:"http://www.wowdb.tw",                      //提供物品图片的站点URL
    raceids:[1, 3, 4, 7, 11, 2, 5, 6, 8, 10],
    classids:[1, 2, 3, 4, 5, 6, 7, 8, 9, 11]
};
var __BattleGroupOption = {
	        regionindex:-1,
	        groupindex:-1,
	        currentregion:'all',
	        currentgroup:'all',
	        currentrealm:'all'
}
function createplayerclassicon(classid){
    return "<img src=\"/images/class/"+classid+".gif\" border=\"0\" align=\"absmiddle\" alt=\""+getchrclassennamebyid(classid)+"\" title=\""+getchrclassennamebyid(classid)+"\" class=\"playerclassicon\"/>"
}
function createplayerraceicon(raceid,gender){
    return "<img src=\"/images/race/"+raceid+"-"+gender+".gif\" border=\"0\" align=\"absmiddle\" alt=\"\" class=\"playerraceicon\"/>"
}
function cr(classid,raceid,gender){
   document.write(" "+createplayerclassraceicon(classid,raceid,gender));
}
function createplayerclassraceicon(classid,raceid,gender){
    var s=createplayerclassicon(classid) + createplayerraceicon(raceid,gender);
    return s;
}
function createplayertalentsicon(classid,t1,t2,t3){
    var n=getchrclassennamebyid(classid);
    var s=" ";
    if ((n!=""&&checkint(t1)&&checkint(t2)&&checkint(t3))&&(t1>0||t2>0||t3>0)){
        s = "<img src=\"/images/talents/trees/"+n+"0.gif\" alt=\"\" align=\"absmiddle\" class=\"playertalenticon\" />"+t1+"&nbsp;"
        s = s + "<img src=\"/images/talents/trees/"+n+"1.gif\" alt=\"\" align=\"absmiddle\" class=\"playertalenticon\" />"+t2+"&nbsp;"
        s = s + "<img src=\"/images/talents/trees/"+n+"2.gif\" alt=\"\" align=\"absmiddle\" class=\"playertalenticon\" />"+t3+"&nbsp;"
    }
    return s;
}
function initindexteamrating(objid){
    showplayerclassicon(objid);
    showteamwinpercent(objid);
}
function showplayerclassicon(objid){
    jQuery("#"+objid+" .teammake").each(function(){
        if(this.innerHTML!=""){
            try {
	            eval("var l="+this.innerHTML+";");
                var s="";
                var d="<table class=\"teamdetailtable\" border=\"1\"><tr class=\"td_header\"><td class=\"td_race\">"+ScriptLangTrans["common_word_class"]+"</td><td class=\"td_name\">"+ScriptLangTrans["common_word_name"]+"</td><td class=\"td_talents\">"+ScriptLangTrans["common_word_talent"]+"</td><td class=\"td_rating\">"+ScriptLangTrans["common_title_playercontribution"]+"</td><td class=\"td_matches\">"+ScriptLangTrans["common_title_matches"]+"</td><td class=\"td_guild\">"+ScriptLangTrans["common_word_guild"]+"</td></tr>";
                for(i=0;i<l[1].length;i++){
                    if (i<l[0][4]){
                        s = s + createplayerclassicon(l[1][i][1]);
                    }
                    d = d + createteamplayerdetail(l[1][i],l[0]);
                }
                d = d + "</table>";
                this.innerHTML = s;
                jQuery("#teamdetail"+l[0][0]).html(d);
            }
            catch (e){
	            //alert(e.name + ": " + e.message);
            }
        }
    })
    
}
function ajaxopenpt(id){
   opentd(id);
   if (jQuery("#teamdetail"+id).html()==''){
        jQuery("#teamdetail"+id).html("Loading.....");
        jQuery("#teamdetail"+id).load("/AjaxLoad.aspx?action=teamofplayer&id=" +id);
    }
}
function showteamwinpercent(objid){
    jQuery("#"+objid+" .matches").each(function(){
        eval("var i="+this.innerHTML+"*100;");
        this.innerHTML = this.innerHTML + " <font size=1 color=#cccccc>("+ i.toFixed(1) +"%)</font>";
    })
}
function createteamplayerdetail(a,b){
    return "<tr class=\"td_item\"><td class=\"td_race\">"+createplayerraceicon(a[2],a[3])+createplayerclassicon(a[1])+"</td><td class=\"td_name\"><a href=\"/player/"+b[1]+"/"+b[3]+"/"+a[4]+"/\" >"+a[4]+"</td><td class=\"td_talents\">"+createplayertalentsicon(a[1],a[5],a[6],a[7])+"</td><td class=\"td_rating\">"+a[8]+"</td><td class=\"td_matches\">"+a[9]+"/"+a[10]+" <font size=1 color=#cccccc>("+getpercent(a[9],a[10])+")</td><td class=\"td_guild\"><a href=\"/guild/"+b[1]+"/"+b[3]+"/"+a[11]+"/\" >"+a[11]+"</a></td></tr>";
}
function opentd(id){
    jQuery("#teamdetail"+id).toggle();
    var o=jQuery("#toggle"+id);
    if (o.attr("src")=="/images/tdon.gif"){
        o.attr("src","/images/tdoff.gif");
    }
    else{
        o.attr("src","/images/tdon.gif");
    }
}
function tdtoggleall(i){
    jQuery("#teamrating .teamdetail").each(function(){
       if(i==0){
            jQuery(this).hide();
       }
       else{
            jQuery(this).show();
       }
    })
    jQuery("#teamrating .tdicon").each(function(){
       if(i==0){
            this.src="/images/tdoff.gif";
       }
       else{
            this.src="/images/tdon.gif";
       }
    })
}
function pdtoggleall(i){
    if(i==0){
        jQuery("#playerrating .teamdetail").hide();
    }
    else{
        jQuery("#playerrating .tdicon").click();
    }
}
function getchrclassennamebyid(classid){
     switch(classid) 
   {
    case 1:
        return "warrior";
    case 2:
        return "paladin";
    case 3:
        return "hunter";
    case 4:
        return "rogue";
    case 5:
        return "priest";
    case 6:
        return "deathknight";
    case 7:
        return "shaman";
    case 8:
        return "mage";
    case 9:
        return "warlock";
    case 11:
        return "druid";
    default:
        break;
    }
}
function lcase(value){
    return value.toLowerCase();
}
function checkint(value){
   if (isNaN(parseInt(value))){
        return false;
   }
   else{
        return true;
   }
}
function getpercent(v1,v2){
    if (checkint(v1)&&checkint(v2)){
        if (v2>0){
            return (v1/v2*100).toFixed(1)+"%";
        }
        else{
            return "0%";
        }
    }
}
function findswf(movieName) {
      if (navigator.appName.indexOf("Microsoft")!= -1) {
        return window[movieName];
      } else {
        return document[movieName];
      }
}
function loadflashchartdata(objid,datavalue)
{
  var tmp = findSWF(objid);
  var x = tmp.load(JSON.stringify(datavalue));
}
function do_resetteamcriteria(){
    window.location = "/rank/";
}
function do_resetplayercriteria(){
    window.location = "/players/";
}
function do_search(obj){
    var keyword=obj.KeyWord;
    var searchType=obj.SearchType;
    var s='/query.aspx?q='+encodeURIComponent(keyword.value)+'&t='+searchType.options[searchType.selectedIndex].value;
    if (keyword!=null){
        if (keyword.value!='') {
            window.location = s;
        }
        else{
            alert(ScriptLangTrans["search_alert_keyword_null"]);
        }
    }
}
function e_RegionListchange(){
    __BattleGroupOption.currentregion=jQuery("#RegionList").val();
    bindBattleGroupList();
  	bindRealmList();
}
function e_BattleGroupListchange(){
    __BattleGroupOption.currentgroup=jQuery("#BattleGroupList").val();
    jQuery("#RealmList").val('all');
}
function e_RealmListchange(){
    __BattleGroupOption.currentrealm=jQuery("#RealmList").val();
    jQuery("#BattleGroupList").val('all');
}
function initteamcriteriaevent(sBracketList,sRegion,sBattleGroup,sRealm,sFaction,sSetupclass){
    jQuery("#RegionList").change(function(){
        e_RegionListchange();
    });
    jQuery("#BattleGroupList").change(function(){
        e_BattleGroupListchange();
    });
    jQuery("#RealmList").change(function(){
        e_RealmListchange();
    });
    jQuery("#BracketList,#RegionList,#BattleGroupList,#RealmList,#FactionList,#setupclass1,#setupclass2,#setupclass3,#setupclass4,#setupclass5").change(function(){
        do_teamquery(this);
    });
    //回溯队伍类型
    jQuery("#BracketList").val(sBracketList);
    //回溯服务器设置
    __BattleGroupOption.currentregion=sRegion;
    __BattleGroupOption.currentgroup=sBattleGroup;
    __BattleGroupOption.currentrealm=sRealm;
    bindGroupAndRealmDefault();
    //回溯阵营设置
     jQuery("#FactionList").val(sFaction);
   //回溯职业设置
    var a=sSetupclass.split(',');
    for(var i=0;i<a.length;i++){
        jQuery("#setupclass"+(i+1)).val(a[i]);
    }
}
function initplayercriteriaevent(sPlayerclass,sRegion,sBattleGroup,sRealm,sFaction){
    jQuery("#RegionList").change(function(){
        e_RegionListchange();
    });
    jQuery("#BattleGroupList").change(function(){
        e_BattleGroupListchange();
    });
    jQuery("#RealmList").change(function(){
        e_RealmListchange();
    });
    jQuery("#RegionList,#BattleGroupList,#RealmList,#FactionList,#playerclass").change(function(){
        do_playerquery(this);
    });
    //回溯职业设置
    jQuery("#playerclass").val(sPlayerclass);
    //回溯服务器设置
    __BattleGroupOption.currentregion=sRegion;
    __BattleGroupOption.currentgroup=sBattleGroup;
    __BattleGroupOption.currentrealm=sRealm;
    bindGroupAndRealmDefault();
    //回溯阵营设置
    jQuery("#FactionList").val(sFaction);
}
function do_teamquery(obj){
   var b=jQuery("#BracketList").val();
   if (b==0){
        b="all";
   }
   else{
        b=b+""+b;
   }
   var s="/rank/"+b+"/"+jQuery("#RegionList").val()+"/"+jQuery("#BattleGroupList").val()+"/"+jQuery("#RealmList").val()+"/"+jQuery("#FactionList").val()+"/"+jQuery("#setupclass1").val()+"/"+jQuery("#setupclass2").val()+"/"+jQuery("#setupclass3").val()+"/"+jQuery("#setupclass4").val()+"/"+jQuery("#setupclass5").val()+"/";
   jQuery("#BracketList,#RegionList,#BattleGroupList,#RealmList,#FactionList,#setupclass1,#setupclass2,#setupclass3,#setupclass4,#setupclass5").attr("disabled","true");
   window.location = cutrankurl(s);
}
function do_playerquery(obj){
   var s="/players/"+jQuery("#playerclass").val()+"/"+jQuery("#RegionList").val()+"/"+jQuery("#BattleGroupList").val()+"/"+jQuery("#RealmList").val()+"/"+jQuery("#FactionList").val()+"/";
   jQuery("#playerclass,#RegionList,#BattleGroupList,#RealmList,#FactionList").attr("disabled","true");
   window.location = cutrankurl(s);
}
function showlangs(){
    jQuery("#langs").show();
}
function hidelangs(){
    jQuery("#langs").css("display","none");
}
function showproperty(index){
    jQuery(".playerproperty th").each(function(i){
       jQuery(this).removeClass("active");
       if(index==i){
            jQuery(this).addClass("active");
       }
    })
    jQuery(".propertyinfo").each(function(i){
       jQuery(this).hide();
       if(index==i){
            jQuery(this).show();
       }
    })
}
function initplayersrating(objid){
     jQuery("#"+objid+" .playericon").each(function(){
        if(this.innerHTML!=""){
            try {
	            eval("var l="+this.innerHTML+";");
                this.outHTML = createplayerclassraceicon(l[0],l[1],l[2]);
           }
            catch (e){
	            alert(e.name + ": " + e.message);
            }
        }
    })
}
function bindBattleGroupList(){
    jQuery.each(realmsdata, function(i, n){
      if (n.area==__BattleGroupOption.currentregion){__BattleGroupOption.regionindex=i;return false;}
    });
    jQuery("#BattleGroupList").empty();
    var s = "<option value='all'>"+ScriptLangTrans["index_dropdownlist_battlegroup_option_all"]+"</option>";
    if (__BattleGroupOption.regionindex>-1){
        jQuery.each(realmsdata[__BattleGroupOption.regionindex].battlegroup,function(j,b){
		    s += "<option value='" + b.name.replace("/","@") + "'>" + b.name + "</option>\n";
	    });
	}
    jQuery("#BattleGroupList").html(s);
//    if (__BattleGroupOption.currentgroup!=''&&__BattleGroupOption.currentgroup!='all'){
//        setTimeout(function(){jQuery("#BattleGroupList").val(__BattleGroupOption.currentgroup);},100);
//    }
    s='';
}
function bindRealmList(){
    jQuery("#RealmList").empty();
    var s = "<option value='all'>"+ScriptLangTrans["index_dropdownlist_realm_option_all"]+"</option>";
    if (__BattleGroupOption.regionindex>-1){
        jQuery.each(realmsdata[__BattleGroupOption.regionindex].battlegroup, function(k, p){
            s+="<optgroup label='===== "+p.name+" =====' value='all'></optgroup>";
            jQuery.each(realmsdata[__BattleGroupOption.regionindex].battlegroup[k].realm,function(j,n){
                    s += "<option value='" + n + "'>" + n + "</option>\n";
	        });
      });
    }
    jQuery("#RealmList").html(s);
//    if (__BattleGroupOption.currentrealm!=''&&__BattleGroupOption.currentrealm!='all'){
//        setTimeout(function(){jQuery("#RealmList").val(__BattleGroupOption.currentrealm);},100);
//    }
    s='';
}
function bindGroupAndRealmDefault(){
    bindBattleGroupList();
    bindRealmList();
    if (__BattleGroupOption.currentregion!='all'&&__BattleGroupOption.currentregion!=''){
        jQuery("#RegionList").val(__BattleGroupOption.currentregion);
    }
    if (__BattleGroupOption.currentgroup!='all'&&__BattleGroupOption.currentgroup!=''){
        setTimeout(function(){jQuery("#BattleGroupList").val(__BattleGroupOption.currentgroup.replace("/","@"));},100);
    }
    if (__BattleGroupOption.currentrealm!='all'&&__BattleGroupOption.currentrealm!=''){
        setTimeout(function(){jQuery("#RealmList").val(__BattleGroupOption.currentrealm);},100);
    }
}
function cutrankurl(url){
    while (url.substring(url.length-5,url.length)=='/all/'){
		url=url.substring(0,url.length-4)
	}
	return url;
}
function getchrraceennamebyid(raceid){
        switch(raceid) 
       {
        case 1:
            return "human";
        case 2:
            return "orc";
        case 3:
            return "dwarf";
        case 4:
            return "nightelf";
        case 5:
            return "scourge";
        case 6:
            return "tauren";
        case 7:
            return "gnome";
        case 8:
            return "troll";
        case 10:
            return "bloodelf";
        case 11:
            return "draenei";
        default:
            return "";
        }
}
function getchrgenderennamebyid(gender){
        switch(gender) 
       {
        case 1:
            return "female";
        case 0:
            return "male";
        default:
            return "male";
        }
    }
var modelviewer = new function(){
    this.modelviewerloaded = false;
    this.view3d = function(race,gender,equiplist,width,height){
        var V,J,X;
        J=getchrraceennamebyid(race)+""+getchrgenderennamebyid(gender);
		V=16;
		X=equiplist;
		var h={model:J,modelType:V,blur:"1",contentPath:arenasettings.modelviewercontentPath,equipList:X.join(",")};
		//wmode:"transparent"
	    var g={quality:"high",wmode:"opaque",allowscriptaccess:"always",menu:false,bgcolor:"#181818"};
	    var Y={};
	    this.modelviewerloaded=true;
	    swfobject.embedSWF(arenasettings.modelviewerbaseurl+"js/ModelView.swf","wow3d_modelviewer",width,height,"10.0.0",arenasettings.modelviewerbaseurl+"/js/expressInstall.swf",h,g,Y);
    }
}