var url="/cuju/";
var pathApp = "/cuju/";
var pathHtml = "/cuju/html/";
var ajaxEl=null;
var isUnload=1;
var fanType = "";
var outsite = "";

var circle_gray = '<div class="circle_gray_l_t"></div>';
circle_gray += '<div class="circle_gray_l_b"></div>';
circle_gray += '<div class="circle_gray_r_t"></div>';
circle_gray += '<div class="circle_gray_r_b"></div>';

var circle_black ='<div class="circle_black_l_t"></div>';
circle_black +='<div class="circle_black_l_b"></div>';
circle_black +='<div class="circle_black_r_t"></div>';
circle_black +='<div class="circle_black_r_b"></div>';


var circle_black_n = '<div class="circle_black_l_b"></div>';
circle_black_n +='<div class="circle_black_r_t"></div>';
circle_black_n +='<div class="circle_black_r_b"></div>';

var rTop = "<div class='rTop'><div class='col_l'></div><div class='col_r'></div></div>" ;
var rBot = "<div class='rBot'><div class='col_l'></div><div class='col_r'></div></div>" ;
var rContent = "<div class='rContent'></div>";

var imgLoader = new Image();
imgLoader.src = "/cuju/images/web/loadingAnimation.gif";
$A = function(obj)
{
    var ret = [];
    for(var i = 0; i < obj.length; i++)
    {
        ret.push(obj[i]);
    }
    return ret;
}
String.prototype.trim = function(){return this.replace(/(^\s*)|(\s*$)/g,"");} 

String.prototype.gblen = function() {   
    var len = 0;   
    for (var i=0; i<this.length; i++) {   
        if (this.charCodeAt(i)>127 || this.charCodeAt(i)==94) {   
            len += 2;   
        } else {   
            len ++;   
        }   
    }   
    return len;   
};

Function.prototype.bind=function()
{
	
	var method = this;
    var args = $A(arguments);
    var obj = args.shift();
	return function(){
		method.apply(obj,args);
	}
	
}
var childMenuFn = "";
$(function(){
	
	
	
	
	$("#menu>li").hover(
		function(){
			
			if($(this).hasClass("hover")){clearTimeout(setTime1)};
	 		$(this).addClass("hover");
			var offset = $(this).offset();
			$("ul",this).css({"left":offset.left+1,"top":offset.top+36}).show();
			$("body").append($("ul",this));
			
			
		},
		function(){
			
			var self = this;
			childMenuFn = function(){
				
				$(self).removeClass("hover");
				var type = $.trim($(self).text());
				
				var id = type=="NBA" ? 0 : type=="英超" ? 1 : type=="游戏赢家" ? 2 : "";
				
				$(self).append($("#childUl_"+id));
				$("ul",self).hide();
			};
			setTime1 = setTimeout(childMenuFn,20);
			//childMenuFn.call(this);
		}
	);
	 $("#menu>li .menu_select").hover(
		function(){
			clearTimeout(setTime1);
		},
		function(){
			setTime1 = setTimeout(childMenuFn,20);
			
		}
	)
			
	
	$("#top_bar .searchContainer").hover(
		function(){$("ul",this).show()},
		function(){$("ul",this).hide()}
	);
	
	$("#mainForum li").each(function(){
		if($("a",this).eq(2).text().indexOf("竞猜")>-1){
			$(this).hide();
		}
	});
})

/*$(function(){
		 
	/*$("#lobbyMenu li[class!='current']").hover(
		function(){
			
			$(this).find("div").css({"color":"#000","background-position":"0 100%"});
			$(this).find("b").css({"color":"#000","background-position":"right 100%"});
		},
		function(){
			$(this).find("div").css({"color":"#333","background-position":"0 0"});
			$(this).find("b").css({"color":"#333","background-position":"right top"});	
			
		}
	);*/
	/*$("#loginButton,#loginSubmitBtn").hover(
		function(){
			$(this).css("background-position","0 0");	
		},
		function(){
			$(this).css("background-position","0 100%");		
		}
	 );
	
	$("#playerMarketBodyHeader .buildButton1,#enterMarketButton .buildButton1,#lobbyRoom .buildButton1,#msgOKDiv .buildButton2,#msgOKCancelDiv .buildButton2,#dashBoard :button,#buildLockerWrap :button,#createArticle .buildButton2,#createAdviceSubmit .buildButton2,#myWall :button,#myArtAjax :button,#personalSettingsSubmit .buildButton2").hover(
		function(){
			$(this).css("color","#fc3");
		},
		function(){
			$(this).css("color","#fff");
		}
	);

		
})*/
function setSelect(name, selVal, objFlag)
{
	if(objFlag) {
		var selObj = name;
	}else {
		var selObj = document.getElementsByName(name);
		selObj = selObj[0];
	}	
	if (typeof(selVal)=="Array") {
		for (i=0; i<selObj.length; i++) {
			for (j=0; j<selVal.length; j++) {
				if (selObj.options[i].value == selVal[j]) selObj.options[i].selected = true;
			}
		}
	}else {
		for (i=0; i<selObj.length; i++) {
			if (selObj.options[i].value == selVal) selObj.options[i].selected = true;
		}
	}
}
function showLoginWindow()
{
	
	TB_remove();
	
	
	//fanType = fanType!=null ? fanType : "";
	
	
	if(fanType != ""){
		
		TB_show("/cuju/user/loginHtml/fan");
	}else{
		
		TB_show("/cuju/user/loginHtml");	
	}
	setTimeout(function(){$("#TB_window #username").val($.cookie("cuju_loginuser"));$("#TB_window #username").focus()},1000);

	
}
var loadingHTML="<div style='padding:10px 0;text-align:center;color:#333'><img src="+url+"/images/web/loading.gif class=loading align='absbottom'/><span style='margin-left:10px;'>正在加载....</span></div>";


function cujuAddOption(srcSel,optText,optVal,optClass)
{
	var opt = document.createElement("option");
	opt.text = optText;
	if (arguments[2]) {
		if (optVal === true) {
			opt.value = opt.text;
		}else {
			opt.value = optVal;
		}
	}
	if (arguments[3]) {
		opt.className = optClass;
	}
	srcSel.options.add(opt);
}



var cuju={
	//错误提示框
	errorMsg:function(str,func){
		TB_remove();
		
		TB_show("inlineId=msgOK");
		$("#TB_window .buildButton2").attr("disabled",0);
		$("#TB_window #msgOKDiv .msgButton").eq(0).html(str);
		
		//$("#TB_window #OK")[0].onclick=func;
		if(func){
			$("#TB_window .ok")[0].onclick=function(){TB_remove();func()};
			
		};
		$("#TB_window .ok").focus();
		//this.onEnterDown(function(){alert("a");$("#TB_window #OK").click()});
	},
	errorMsg1:function(ajaxDiv,json){
	
		
			
			
			
		var id = "msgOK";
		
		json["html"] = $("#"+id).html();
		cuju.doubleMsg.call(this,ajaxDiv,json);
		$("#TB_window1 .ok")[0].onclick=function(){$("#TB_window1").remove()};
		$("#TB_window1 #msgOKDiv .msgButton").eq(0).html(json.msg);
		
			
		
			
	},
	doubleMsg:function(ajaxDiv,json){
	
				
				
		//$(ajaxDiv).append('<div id="TB_window"></div>');
		if($("#TB_window1")[0]){
			$("#TB_window1")[0].innerHTML = json.html;
		}else{
			var html = '<div id="TB_window1">' + json.html + '</div>';
			$(ajaxDiv).append(html);
		}
		var $el = $("#TB_window");
		var w = $el.width();
		var h = $el.height();
		var top = $el.offset().top;
		var left = $el.offset().left;
		var $wind1 = $("#TB_window1");
		var w1 = $wind1.width();
		var h1 = $wind1.height();
		
		var ch = document.documentElement.clientHeight;
		if(ch<h1) h1 = ch
		$wind1.css({top:(top+h/2)-h1/2,left:(left+w/2) - w1/2}).show();
				
			
		
	},
	//确定框
	okcancelMsg:function(str,func){
		TB_remove();
		
		TB_show("inlineId=msgOKCancel");
		var tb=$("#TB_window");
		$(".buildButton2",tb).attr("disabled",0);

		
		
		//alert($("#TB_window #OK").click)
		
		$("#msgOKCancelDiv .msgButton",tb).get(0).innerHTML=str;
		
		$(".confirm",tb).get(0).onclick=func;
		
		$(".confirm",tb).focus();
		
		//this.onEnterDown(function(){$("#TB_window #OK").click()});
	},
	okcancelMsg1:function(ajaxDiv,json,fn1,fn2){
	
		
			
			
			
		var id = "msgOKCancel";
		
		json["html"] = $("#"+id).html();
		cuju.doubleMsg.call(this,ajaxDiv,json);
		$("#TB_window1 .btn_003")[0].onclick = fn1;
		$("#TB_window1 .btn_003")[1].onclick = fn2;
		$("#TB_window1 #msgOKCancelDiv .msgButton").eq(0).html(json.msg);	
	},
	//可拖动移动窗口
	showInputField:function(t,maxLength,thisEl){
		
		if($("#TB_window").html())return;
		
		//TB_remove();
		if(t=="c")
		{
			TB_show("#TB_inline?height=218&width=466&inlineId=commentWindow");
			$("#TB_window #commentText").focus();
			$("#TB_window #commentText").val("");
		}else if(t=="m"||t=="r"){
			TB_show("#TB_inline?height=218&width=466&inlineId=msgWindow");
			var func=t=="m"?addMsg:addReply.bind(this,thisEl);
			$("#TB_window .buildButton2").get(0).onclick=func;
			$("#TB_window #msgText").focus();
			$("#TB_window #msgText").val("");
		}
		$('#TB_overlay,#TB_HideSelect').remove();
		
		$("#TB_window").jqDrag(".jqDrag");
		
		if(maxLength){
			
			$("#TB_window #commentText")[0].onkeyup=function(){cuju.surplusWord(this,'showErrorId',maxLength)};
			this.surplusWord($("#TB_window #commentText")[0]||$("#TB_window #msgText")[0],'showErrorId',maxLength);
		}else{
			this.surplusWord($("#TB_window #commentText")[0]||$("#TB_window #msgText")[0],'showErrorId',200);
		}
		$("#TB_window .buildButton2").click(function(){this.disabled=1;});
		
	},
	//可输入剩余字数
	surplusWord:function($this,showErrorId,maxLength)
	{
		
		var n=$this.value.gblen();
		var l=parseInt(maxLength)-n;
		if(l<0){
			var str="<span style='color:#f00'>已经超过"+maxLength+"字符</span>";
			$("#add_comment .btn_003").attr("disabled",1).css("color","#ccc");
		}else{
			var str='还可输入<span class="redWord">'+l.toString()+'</span>个字符';
			if($("#add_comment #commentText").val()==""||$("#TB_window #msgText").val()==""){
				$("#add_comment .btn_003").attr("disabled",1).css("color","#ccc");
			}else{
				$("#add_comment .btn_003").attr("disabled",0).css("color","#fff");
			}
		}
		
		$("#"+showErrorId).html(str);
		$("#TB_window #"+showErrorId).html(str);
		

	},
	noLoginSubmitTeam:function(t)
	{
		if(t=="n"){
			var location = "nba_fantasy/fantasy/createFantasyTeam/1";
			var s="nba_fantasy";
		}else{
			var location = "epl_fantasy/fantasy/createFantasyTeam/2";
			var s="epl_fantasy";
		}
		//var location = t=="n"?"nba_fantasy/fantasy/createFantasyTeam/1":"epl_fantasy/fantasy/createFantasyTeam/2";
		$.getJSON(url+s+"/fantasyTeamAjax/createTeamForLogined",function(data){
			
			
			if(data.rcode==0){
				var str="创建球队成功！";
			}else if(data.rcode==1){	
				var str=data.rcode;
			}else{	
				var str=data.rcode;
			}
			
			this.errorMsg(str,function(){window.location=url+location});
		});
	},
	//ESC绑定function
	onEscDown:function(func)
	{
		$(document).one("keydown",function(e){
			keycode=e==null?event.keyCode:e.which;
			if(keycode == 27){ // close
				if(func)func();
				if($("#TB_window #OK").html())$("#TB_window #OK")[0].onclick=TB_remove;
				//TB_remove();
			};
		});
	},
	onEnterDown:function(func)
	{
		
		if(document.all){
			var keycode=window.event.keyCode;
		}else{
			var e=getEvent();
			var keycode=e.which;
		}
		//var e=getEvent();
		//var keycode=window.event.keyCode||e.which;
		//alert(keycode)
		if(keycode == 13){ // close
			func();
		};
			
		
		/*var $el=$("#TB_window").get()?$("#TB_window"):$(document);
		//alert($el.html())
		$el.one("keydown",function(e){
								   alert("Aaa")
			keycode=e==null?event.keyCode:e.which;
			if(keycode == 13){ // close
			//	alert(func)
				func();
			};
		});
		*/
	},
	abortAjax:function()
	{
		if(ajaxEl){
			ajaxEl.abort();
			ajaxEl=null;
		}
	},
	showAdviseInfo:function(thisEl,info)
	{
		if($("#adviseDiv").length==0){
			$(thisEl).addClass("advise_hover");
			$("<div id='adviseDiv'></div>").text(info).css({"left":$(thisEl).offset().left,"top":$(thisEl).offset().top+20}).appendTo("body");
		}
	},
	hideAdviseInfo:function(thisEl)
	{
		$(thisEl).removeClass("advise_hover");
		$("#adviseDiv").remove();
	},
	commentVote:function(ajaxUrl,thisEl)
	{
		var vote=$(thisEl).parent().attr("vote");
		if(vote){
			cuju.errorMsg("你已经投票了，请不要重复投票");
		}else{
			$.getJSON(ajaxUrl,function(json){
			if(json.rcode==0)
			{
				cuju.errorMsg("提交成功,谢谢参与");
				var el=$(thisEl).next();
				
				
				var n=parseInt(el.html().substr(1))+1;
					
				
				el.html("x"+n);
				$(thisEl).parent().attr("vote",1);
			}
			else
			{
				cuju.errorMsg("提交失敗");
			}
			
			});	
		}
		
	},
	doane:function(event)
	{
		var e = event ? event : window.event;
		if(document.all) {
			e.returnValue = false;
			e.cancelBubble = true;
		} else if(e) {
			e.stopPropagation();
			e.preventDefault();
		}
	},
	Void:function(){},
	post:function(url,data,func,func_1){
		cuju.abortAjax();
		if(func_1)func_1();
		
		ajaxEl = $.post(url,data,function(json){
			cuju.callback(json,func);		
		});
	},
	get:function(url,func,func_1){
		cuju.abortAjax();
		if(func_1)func_1();
		
		ajaxEl = $.get(url,function(json){
			cuju.callback(json,func);						
		})
	},
	callback:function(json,func){
		
		var json = eval("(" + json + ")");		
		
		if(json.rcode == 0){
			func(json);
		}else if(json.rcode == -1){
			cuju.errorMsg(json.msg,function(){window.location.reload()});
			nokeydown();	
		}else if(json.rcode == 2){
			if(typeof outsite == "undefined" || outsite == ""){
				showLoginWindow();
				
			}else{
				cuju.errorMsg(json.msg,function(){window.location.reload()});
				nokeydown();	
			}
			
		}else{
			cuju.errorMsg(json.msg);
		}
								 
		
		
	}
	
}

function getEvent()
{
   var func=getEvent.caller;
	
    while(func!=null)
    {
        var arg0=func.arguments[0];
		
        if(arg0)
        {
			
			//KeyboardEvent 键盘 MouseEvent 鼠标 Event
            if(arg0.constructor==KeyboardEvent) // 如果就是event 对象
			{
				
                return arg0;
				
			}
        }
        func=func.caller;
    }
    return null;
}

/*function countDown(){
	var s=$("#TB_window #countDownSpan").html();
	s=s.substr(0,1)!=0?s:s.substr(1);
	if(s!="0"){
		var sec=parseInt(s);
		$("#TB_window #countDownSpan").html("0"+(sec-1).toString());
	}else{
		clearInterval(set_Time);
		TB_remove();
	}
}*/
function msgCancel()
{
	if(typeof set_Time!="undefined"){
		clearInterval(set_Time);
	};
	TB_remove();
	
}
function openWindow(page)
{
	//$("body").removeAttr("onbeforeunload");
	isUnload=0;
	if(page=="rule"){
		if(fanType=="nba_fantasy"){
			var url='/cuju/html/fanRule_nba.html';
			var w=440;
		}else{
			var url='/cuju/html/fanRule.html';
			var w=520;
		}
	}
	var l=window.screen.width-w;
	var win=window.open (url, 'Cuju', 'height=550, width='+w+', top=0, left='+l+' toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
	win.focus();
	setTimeout(function(){isUnload=1},1000);
	/*try{
		if(pageSort=="c"){
			$("body").attr("onbeforeunload","return '    离开将丢失你在本页面上的数据'");
		}else if(pageSort=="p"){
			$("body").attr("onbeforeunload","return '    离开将丢失你在本页面上修改的阵形'");
		}
	}catch(e){};
*/

}

function randomAd(t)
{
	var n=Math.round(Math.random()*10);
	if(n<5){
		//var href="/cuju/nba_fantasy/fantasy/index/1";
		var src="/cuju/images/ad/nba_fantasy_ad.swf";
		/*if(t=="main"||t=="nba"){
			var href="/cuju/nba_fantasy/fantasy/index/1";
			var src="/cuju/images/ad/nba_fantasy_ad.swf"
		}else{
			var href="/cuju/epl_fantasy/fantasy/index/2";
			var src="/cuju/images/ad/epl_fantasy_ad.swf"
		}*/
	}else if(n>=5&&n<8){
		//var href="/cuju/epl_fantasy/fantasy/index/2";
		var src="/cuju/images/ad/epl_fantasy_ad.swf";
		/*if(t=="main"){
			var href="/cuju/epl_fantasy/fantasy/index/2";
			var src="/cuju/images/ad/epl_fantasy_ad.swf"
		}else if(t=="nba"){
			var href="/cuju/pickem/index/1";
			var src="/cuju/images/ad/epl_arcade_ad.swf"
		}else{
			var href="/cuju/pickemepl/index/2";
			var src="/cuju/images/ad/epl_arcade_ad.swf"
		}*/
	}else{
		//var href="/cuju/pickem/index/1";
		var src="/cuju/images/ad/epl_arcade_ad.swf";
		
	}
	var func=function(){$('#slideDiv').slideUp("slow")};
	var str=' <embed src='+src+' quality=high width=750 height=380 type="application/x-shockwave-flash" wmode="transparent" ></embed> '
	str+="<input class='cross1' type='button' onclick=$('#slideDiv').slideUp('slow') />";
	$("#slideDiv").html(str);
	
}
function isUnloadFunc()
{
	
	if(isUnload==1){
		if(pageSort=="c"){
			
			return '    离开将丢失你在本页面上的数据';
		}else if(pageSort=="p"){
			return '    离开将丢失你在本页面上修改的阵形';
		}
	}


}



jQuery.fn.scrollCont=function(type,arr)
{
	
	var $el = this;
	if($el.get(0).index){
		var current = $el.get(0).index;
	}else{
		var current = 1;
		
		var $li = $("li",$el);
		var li_width = parseFloat($li.css("width")) + parseFloat($li.css("margin-left")) + parseFloat($li.css("margin-right")) + (parseFloat($li.css("border-width"))*2 || 0);
		
		$el.css("width", li_width * $("li",$el).length + "px");
	}
	
	//this = 调用方法的el
	var arr = $.extend({
	
		width:parseInt(this.parent().css("width")),
		items:parseInt(this.parent().css("width"))/parseInt($("li",this).css("width")),
		maxPage:Math.ceil(parseFloat(this.css("width"))/parseInt(this.parent().css("width")))
		
	},arr||{});
	


	
	
	
	
	var func = function(){
		
		/*var space = arr["width"]/(arr["items"]*2);
		arr["items"] *= 2;
			
		var time = setInterval(function(){
			if(arr["items"]){
				
				var l = parseFloat($el.css("left"))	;
				
				
				var speed = type == "next" ? l - space : l + space;
				$el.css("left", speed + "px");		 
			}else{
			
				clearInterval(time);
			}
			arr["items"]--;
			
		},100);*/
		//var l = parseInt($el.css("left"));
		//var speed = type == "next" ? l - arr.width : l + arr.width;
	
		var speed = (current - 1) * arr["width"];
		speed =  speed * -1 ;
		
		$el.animate({marginLeft: speed + "px"},500);
		
		
	}
	
	
	if(type){
		if(current < arr["maxPage"]){
			$el.parent().prev().removeClass("disabled");
			
			current++;
			func();
			
			$el.get(0).index = current;
			
		}
	}else{
		if(current>1){
			$el.parent().next().removeClass("disabled");
			current--;
			func();
			
			$el.get(0).index = current;
		}
	}
	
	
	if(current == arr["maxPage"]){
		$el.parent().next().addClass("disabled");
	}else if(current == 1){
		$el.parent().prev().addClass("disabled");
	}
	
	
}

function getRank(el,period,game)
{
	el.disabled = 1;
	var id = $(el).val();
	var i = period == "month" ? 2 : 3 ;
	
	if(game){
		//pickem_url
		//i = pickType == "pickemepl" ? i - 1 : i; 
		var league_id = pickType == "pickem" ? 1 :2 ;
		var url = "/cuju/" + pickType + "/getUserRank/" + league_id + "/" + period + "/" + id ;
	}else{
		//i = fanType == "epl_fantasy" ? i - 1 : i; 
		var url = "/cuju/" + fanType + "/fantasyTeamAjax/queryRank/" + period + "/" + id ;
	}
	$.getJSON(url,function(json){
		if(json.rcode==0){
			var rows = $("#rankData tbody tr")	;
			rows.eq(1).find("td").eq(i).text(json.current_rank);
			rows.eq(2).find("td").eq(i).text(json.current_point);
		}else{
			alert(json.msg);
		}
		el.disabled = 0;
	});
	
	
}
function show_all(name)
{
	
	var $el = $(name).find("#newsContentBox");
	
	if($el.css("height")=="52px"){
		//el.removeClass("hideCont");
		$el.animate({height:"600px"},500);
		setTimeout(function(){$el.css("height","100%")},550);
		//alert($(name).find(".show_all a").css("background-image"));
		$(name).find(".show_all a").css("background","url(/cuju/images/web/btn_017.png) no-repeat");
		
		$(name).find(".show_all a").text("缩小");
	}else{
		//el.addClass("hideCont");
		$el.animate({height:"52px"},500);
		//setTimeout(function(){$el.addClass("hideCont")},500);
		$(name).find(".show_all a").css("background","url(/cuju/images/web/btn_018.png) no-repeat");
		$(name).find(".show_all a").text("打开");
	};
	//window.scroll(0,0);
	
}
//var arr_ajax = [];

function channel_rank(arr,game,portal)
{
		var sels = $("#gameRank select:visible");
		if(!sels.get(1).index){
			
			sels.get(1).index = 1;
			options_html = sels.eq(1).html();
		}
		$("#gameRank .h_status a").removeClass("current").eq(arr.index).addClass("current");
		
		if(!portal)
			sels.eq(1).find("option").eq(0).attr("selected",1);
		
		var arr = $.extend({
			index:0,
			period:sels.eq(0).val(),
			id:sels.eq(1).val()
		},arr||{});
		
		var type = arr.index == 0 ? "leader" :
					  arr.index == 1 ?	"me" :	"friend";
		
		
		if(type == "me"){
			
			sels.eq(1).find(".my_none").remove();
		}else{
			if(!portal)
				sels.eq(1).html(options_html);
		}
		if(game){
			var league_id = pickType == "pickem" ? 1 : 2;
			var ajax_url = "/cuju/" + pickType + "/getPickemRanksNew/" + league_id + "/" + type + "/" + arr.period + "/" + arr.id;
		}else{
			var ajax_url= "/cuju/" + fanType + "/fantasyAjaxHtml/rank/" + type + "/" + arr.period + "/" + arr.id;
		};	
		
		
		
		
		$.getJSON(ajax_url,function(json){
			//arr_ajax[channel] = json.html;
			$("#ajaxDiv").get(0).innerHTML = json.html;
		});
		
		
	/*};
	
	$("#ajaxDiv").get(0).first = "true";
	//alert($("#ajaxDiv").get(0).first)*/
}
function getChannelRankUrl(arr)
{
	var arr = $.extend({
		index:0,
		period:sels.eq(0).val(),
		id:sels.eq(1).val()
	},arr||{});
	
	var type = arr.index == 0 ? "leader" :
				  arr.index == 1 ?	"me" :	"friend";
	
	if(game){
		var league_id = pickType == "pickem" ? 1 : 2;
		var ajax_url = "/cuju/" + pickType + "/getPickemRanksNew/" + league_id + "/" + type + "/" + arr.period + "/" + arr.id;
	}else{
		var ajax_url= "/cuju/" + fanType + "/fantasyAjaxHtml/rank/" + type + "/" + arr.period + "/" + arr.id;
	};	
	return ajax_url;
	
}
function sel_rank(sel,game){
	var i = $("#gameRank .h_status a").index($("#gameRank .current"));
	if(sel == 0){
		
		var period = $("#gameRank select").eq(0).val();
		if(period == "week"){
			$("#sel_month,#sel_season").hide();
			$("#sel_week").show().find("option").eq(0).attr("selected",1);
		}else if(period == "month"){
			$("#sel_week,#sel_season").hide();
			$("#sel_month").show().find("option").eq(0).attr("selected",1);
		}else{
			$("#sel_week,#sel_month").hide();
			$("#sel_season").show().find("option").eq(0).attr("selected",1);
		}
	}/*else{
		var id = $(el).val();
	}*/
	var arr = {index:i};
	channel_rank(arr,game,"sel");
}
function search_type(i)
{
	$("#top_search a").removeClass("current").prev().find("input").attr("checked",0);
	$("#top_search a").eq(i).addClass("current").prev().find("input").attr("checked",1);
						
	
	
}
function top_search()
{
	var search_text = $("#searchField").val();
	if(search_text){
		
	}else{
		window.location = "/sns/network.php?ac=space";
	}
}
function doLoginP()
{
      
		var loginid=$("#TB_window #username").val();
		var password=$("#TB_window #password").val();
		if($("#cookietime").attr("checked")){
			var cookietime = $("#cookietime").val();
		}else{
			var cookietime = 0;
		}
		if(loginid&&password){
			$.post("/cuju/user/login",{"loginid":loginid,"password":password,"cookietime":cookietime},function(data){
					var data=eval('('+data+')');
				
					if(data.rcode=="0"){
						$("body").append(data.synchronization);
						setTimeout(function(){window.location.reload()},500);
					}else{	
						cuju.errorMsg("登入错误");
						$("#TB_window #OK")[0].onclick = showLoginWindow;
					}
				 
			});
		}else{
			
			
			cuju.errorMsg("用户名或密码不能为空喔！",showLoginWindow);
		}
}


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

jQuery.fn.substrmix=function(sub_len)
{
	var str = this.text();
	if(str.gblen() > sub_len){
		var len = 0;
		for (var i=0; i<str.length; i++) {   
			if (str.charCodeAt(i)>127 || str.charCodeAt(i)==94) {   
				len += 2;
				if(len > sub_len) break;
			} else {   
				len ++;  
				if(len > sub_len) break;
			}   
		};
		this.text(str.substr(0,i));
		
	}
	
}
function nokeydown(){
	document.onkeyup = function(e){ 	
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if(keycode == 27){ // close
			
		}	
	};
	
}
function delCujuGameCookie()
{
	
	/*$.getJSON("/cuju/user/delcujugame",function(){
		
	});	
	*/
	
	$.ajax({
	   type: "POST",
	   url: "/cuju/user/delcujugame",
	   async:false
	   
	}); 
	
	/*for(var i = 0;i<10000000;i++){
		
	}*/
	
	
	//window.open("/cuju/user/delcujugame");
	
}
function cmsAddPlayer(id,type){
	if(type == "nba"){
		var ajax_url = "/cuju/nba_fantasy/fantasyTeamAjax/checkUser/" + id + "?" + new Date().getTime();
	}else{
		var ajax_url = "/cuju/epl_fantasy/fantasyTeamAjax/checkUser/" + id + "?" + new Date().getTime();
	}
	$.getJSON(ajax_url,function(json){
		
		if(json.rcode == 0){
			window.open(json.url);
		}else{
			var func = function(){
				TB_remove();
				//delCujuGameCookie();
				window.open(json.url);
			};
			cuju.okcancelMsg(json.msg,func);
		};
	});
	
}
function goToPlayerDetails(player_id, league_hint) {
	window.open(pathApp+league_hint+'_player/details/'+player_id);
}

function goToTeamDetails(team_id, league_hint) {
	window.open(pathApp+league_hint+'_team/details/'+team_id);
}

function get_cuju_ad(file_name,w,h)
{
	var insertstr='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width='+w+' height='+h+'>';
	insertstr+='<param name="movie" value="http://www.cuju2.com/cuju/images/ad/' + file_name + '.swf" />';
	insertstr+='<param name="quality" value="high" />';
	insertstr+='<embed src="http://www.cuju2.com/cuju/images/ad/' + file_name + '.swf"' + ' quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width='+w+' height='+h+'></embed></object>'	;
	
	return insertstr;
	
}
var isDoubleMsg = "0";
function TB_show(url,data,callback)
{
	
	//var arr = str[1].split("&");
	//var w = arr[0].split("=")[1];
	//var h = arr[1].split("=")[1];
	//var arr = url.split(/[;&]/)	;
	
	
	TB_remove();
	isDoubleMsg = 1;
	if(!data){
		data = {};
	}
	if($.isFunction(data)){
		callback = data;
		data = {};
	}
	var scrollTop = document.documentElement.scrollTop;
	var ch = document.documentElement.clientHeight;
	
	var html = '<div id="TB_overlay"></div>';
	html += '<div id="TB_loading"><img src="' + imgLoader.src + '" /></div>';
	$("body").append(html);
	$("#TB_loading").css("top",scrollTop+ch/2);
	$("#TB_loading").show();
	var func = function(ajaxDiv,json){
		
		$("#TB_loading").remove();
		//$(ajaxDiv).append('<div id="TB_window"></div>');
		
		var html = '<div id="TB_window">' + json.html + '</div>';
		$(ajaxDiv).append(html);
		
		/*$("#TB_window").html(json.html);
		$("#TB_window").unload(function(){
				$("#"+id).append($("#TB_window").children());											
		});*/
		
		
		
		var $el = $("#TB_window");
		var w = $el.width()+8;
		var h = $el.height()+8;
		
		if(ch<h)h = ch;
		if(outsite){
			ch = 1000;
		}
		
		//alert(document.body.offsetHeight);
		$el.css({top:scrollTop+ch/2,marginLeft:-(w/2),marginTop:-(h/2)}).show();

		if(callback)
			callback.call(this,ajaxDiv,json);
		
	}
	if(typeof url == "object"){
		var json = url;
		func.call(this,$("body"),json);	
	}else if(url.indexOf("inlineId") == -1){
		
		data["outsite"] = outsite;
		$("body").cujuAjax(url,data,func);
	}else{
		var id = url.split("=")[1];
		var json = {"html":$("#"+id).html()};
		func.call(this,$("body"),json);
		
		
	}
	
}
function TB_remove()
{
	isDoubleMsg = 0;
	$("#TB_overlay,#TB_window").trigger("unload").remove();
	
}
function showLoading()
{
	
	var scrollTop = document.documentElement.scrollTop;
	var ch = document.documentElement.clientHeight;
	var img = "<img src='"+imgLoader.src+"' id='loading' />"
	
	$("body").append(img);
	
	$("#loading").css({top:scrollTop+ch/2,marginTop:-7,marginLeft:-104});
}
jQuery.fn.cujuAjax = function(url,data,callback,errFn)
{
	var $self = this;
	if($.isFunction(data)){
		callback = data;
		data = {};
	}
	if(data==""){
		callback = data;	
		data = {};
	}
	data["outsite"] = outsite;
	if($self[0].tagName != "BODY"){
		
		$self[0].innerHTML = loadingHTML;	
		
	}else if($self[0].tagName == "BODY"){
		
		showLoading();
		
		
	}
	$.post(url,data,function(json){
		if($self[0].tagName == "BODY"){
			$("#loading").remove();	
		}
		var json = eval("(" + json + ")");
		//self[0].innerHTML = json1.html;
		//if(callback)
		if(json.rcode == "0"){
			if(callback){
				callback.call(this,$self[0],json);
			}else if(callback===""){
				
			}else{
				$self[0].innerHTML = json.html
				
			};
		}else if(json.rcode == "1"){
			if(errFn){
				errFn.call(this,$self[0],json);
			}else{
				cuju.errorMsg(json.msg);
			}
		}else if(json.rcode == "2"){
			showLoginWindow(json);
		}else if(json.rcode=="-1"){
			cuju.errorMsg(json.msg,window.location.reload);
		}else if(json.rcode=="-11"){
			cuju.errorMsg(json.msg);
		}
	});
	
	
}
jQuery.fn.cujuAjaxHTML = function(url,data,callback)
{
	var $self = this;
	if($.isFunction(data)){
		callback = data;
		data = {};
	}
	$.post(url,data,function(html){
		//var json = eval("(" + json + ")");
		//self[0].innerHTML = json1.html;
		//if(callback)
		var json = {};
		json["html"] = html;
		if(callback){
			callback.call(this,$self[0],json);
		}else if(callback===""){
				
		}else{
			$self[0].innerHTML = html
			
		}
	});
	
	
}


