//create by Siva
//last modified 2011-07-18

var cpdyj = {
	version:'1.0',
	author: 'Siva',
	company: 'starlott.com',
	parent: 'jquery 1.4.2'
};

var $t = cpdyj.trade = {
	loginUri : '/user/login.go',
	isLoginUri : '/user/islogin.go',
	logoutUri : '/user/outlogin.go',
	yzmUri : '/yzm.yzm',
	userMoneyUri : "/user/queryusermoney.go",
	securityRankUri : "/user/fetchusersecurerank.go",

	allProjectUri : "/trade/getallproject.dyj",
	
	allCountUri : "/staticdata/pageinfo/usercount.xml",
	allMoneyUri : "/staticdata/pageinfo/allmoney.xml",

	winnerUri : "/staticdata/pageinfo/winner.xml",

	starHistoryUri : "http://trade.cpdyj.com/trade/user/starhistory.html",

	getAllMoney : function(fn){
		$.get($t.allMoneyUri,function(xmlDoc){
			var allmoney = $(xmlDoc).find("xml>row").attr("allmoney");
			if(typeof fn == "function") fn(allmoney);
		});
	},
	getAllCount : function(fn){
		$.get($t.allCountUri,function(xmlDoc){
			var num = $(xmlDoc).find("xml>row").attr("num");
			if(typeof fn == "function") fn(num);
		});
	},	
	getWinner : function(fn){
		$.get($t.winnerUri,function(xmlDoc){
			var $xml = $(xmlDoc);
			$xml.find("xml>row").each(function(i,e){
				var username = $(e).attr("username");
				var lottname = $(e).attr("lottype");
				var expect = $(e).attr("expect");
				var paymoney = $(e).attr("paymoney");
				if(typeof fn == "function") fn(i,username,lottname,expect,paymoney);
			});
		})
	},
	openStarHistory : function(u,lt,pt){
		showModalDialog($t.starHistoryUri+"?username="+encodeURIComponent(u)+"&lottype="+lt+"&playtype="+pt+"",window,"dialogWidth:620px;dialogHeight:550px;scroll:no;");
	},
	setRegfrom : function(){
		var url=window.location.href.toLowerCase();
		var m = "";
		if(document.domain == "zh.cpdyj.com") m = "zhaohang888";
		else m=cpdyj.tool.getHrefParam(url,"regfrom");
		$.ajax({
			url:"/user/regcpdyj.go",
			type:"POST",
			dataType:"xml",
			data:"regfrom="+encodeURIComponent(m),
			cache:false,
			success:function(xmlDoc){},
			error:function(){}	
		});
	}	
};

cpdyj.tool = {
	setCookies : function(a){
		var l=a.length;
		for(var i=0;i<l;i++){		
			$.cookie(a[i][0],a[i][1],{path:"/",domain:"cpdyj.com"});
		}
	},
	delCookies : function(a){
		var l=a.length;
		for(var i=0;i<l;i++){		
			$.cookie(a[i],null);
		}
	},
	commafy : function(num){ //数字千分号，每3位加,
		num  =  num+"";  
		var  re=/(-?\d+)(\d{3})/  
		while(re.test(num)){  
			num=num.replace(re,"$1,$2")  
		}  
		return  num;  
	},
	getHrefParam : function(s,n){//s url，n 参数名
		var r = new RegExp("[\?\&]"+n+"=([^&?]*)(\\s||$)", "gi");
		var r1=new RegExp(n+"=","gi");
		var m=s.match(r);
		if(m==null){return ""}else{return m[0].split(r1)[1];}
	},
	chkKeyNum : function(e,n){
		e=e||window.event;
		var k=e.KeyCode||e.which||e.charCode;
		return [k==n,k];
	}
};

cpdyj.lott={
	data : [
		[""],
		["胜负彩","任九"],//1
		["进球彩"],//2
		["双色球"],//3
		["七星彩"],//4
		["排列三","排列五"],//5
		["福彩3D"],//6
		["22选5"],//7
		["七乐彩"],//8
		["时时乐"],//9
		[""],//10
		["半全场"],//11
		[""],//12
		["天津15选5"],//13
		[""],//14
		[""],//15
		["时时彩"],//16
		["超级大乐透"],//17
		["36选7"],//18
		[""],//19
		[""],//20
		[""],//21
		[""],//22
		["11选5"],//23
		["快乐123"],//24
		["北京单场"],//25
		[""],//26
		["竞彩足球"],//27
		["南粤风采"],//28
		["即乐彩"],//29
		[""],//30
		["新时时彩"],//31
		["幸运赛车"],//32
		[""],//33
		[""],//34
		["竞彩篮球"]//35
	],
	projectUri : [
		["http://trade.cpdyj.com/trade/index.html"],
		["http://trade.cpdyj.com/trade/index.html?path=/trade/zc/list_ds.html","http://trade.cpdyj.com/trade/index.html?path=/trade/rj/list_ds.html"],//1
		["http://trade.cpdyj.com/trade/index.html?path=/trade/jq/list_ds.html"],//2
		["http://trade.cpdyj.com/trade/index.html?path=/trade/ssq/list_ds.html"],//3
		["http://trade.cpdyj.com/trade/index.html?path=/trade/qx/list_ds.html"],//4
		["排列三","排列五"],//5
		["福彩3D"],//6
		["22选5"],//7
		["七乐彩"],//8
		["时时乐"],//9
		[""],//10
		["半全场"],//11
		[""],//12
		["天津15选5"],//13
		[""],//14
		[""],//15
		["时时彩"],//16
		["http://trade.cpdyj.com/trade/index.html?path=/trade/clt/list_ds.html"],//17
		["36选7"],//18
		[""],//19
		[""],//20
		[""],//21
		[""],//22
		["11选5"],//23
		["快乐123"],//24
		["http://trade.cpdyj.com/trade/dc/spf/index.html"],//25
		[""],//26
		["http://trade.cpdyj.com/trade/jc/spf/index.html"],//27
		["南粤风采"],//28
		["即乐彩"],//29
		[""],//30
		["新时时彩"],//31
		["幸运赛车"],//32
		[""],//33
		[""],//34
		["http://trade.cpdyj.com/trade/jclq/sf/sf_fs.htmlff"]//35
	],
	get : function(l,p){
		var j = 0;
		if(p==5||p==6||p==7||p==8||p==12){j=1}
		return this.data[l][j];
	},
	getProjectUri : function(l,p){
		var j = 0;
		if(p==5||p==6||p==7||p==8||p==12){j=1}
		return this.projectUri[l][j];
	}
};

//tab切换，current:点击的对象id,target:切换的对象id,css:点击对象切换的样式
var showTab = {
	click : function(o){
		$(o.current).bind("click",function(){
		$(this).addClass(o.css).siblings().removeClass(o.css);
		oIndex = $(this).index();
		$(o.target).eq(oIndex).show().siblings().hide();
		});
	},
	mouseover : function(o){
		$(o.current).bind("mouseover",function(){
		$(this).addClass(o.css).siblings().removeClass(o.css);
		oIndex = $(this).index();
		$(o.target).eq(oIndex).show().siblings().hide();
		});
	}
};
