/*
//js:享客中国游戏
Namespace = new Object();
// 全局对象仅仅存在register函数，参数为名称空间全路径，如"Grandsoft.GEA"
Namespace.register = function(fullNS){
    var nsArray = fullNS.split('.');var sEval = "";var sNS = "";
    for (var i = 0; i < nsArray.length; i++){
        if (i != 0) sNS += ".";sNS += nsArray[i];sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();";
    }if (sEval != "") eval(sEval);
}
/********************************************************************************/
/************************************ DateTime **********************************/
/******************************************************************************** /
Namespace.register("Common");
Common.DateTime = function(){}
Common.DateTime.prototype.Now = function(){return new Date();}
Common.DateTime.prototype.ToString = function(d,_format){
	var _this = this;
	var Year = d.getFullYear();	
	var Month = _this.FormatNum(d.getMonth() + 1);
	var Day = _this.FormatNum(d.getDate());
	var Hour = _this.FormatNum(d.getHours());
	var Minute = _this.FormatNum(d.getMinutes());
	var Second = _this.FormatNum(d.getSeconds());	
	_format = _format.replace("yyyy",Year);
	_format = _format.replace("MM",Month);
	_format = _format.replace("dd",Day);
	_format = _format.replace("HH",Hour);
	_format = _format.replace("mm",Minute);
	_format = _format.replace("ss",Second);
	return _format;
}

Common.DateTime.prototype.FormatNum = function(_n){
	if(_n<10) return "0"+_n;else return _n;
} 
Common.DateTime.Now = function() {
	var od = new Common.DateTime();
	return od.ToString(od.Now(),"yyyy-MM-dd HH:mm:ss");
}
Common.Ajax = function(_Type,_Url,_data,_success,_error,_dataType){
	jQuery.ajax({"type": (_Type?_Type:"POST"),"url": (_Url?_Url:""),"data": (_data?_data:""),success: (_success?_success:null),error: (_error?_error:null),"dataType":(_dataType?_dataType:"html")});
}
//设置指定项闪动效果
Common.SetActiveBackGroundColor =  function(o,ActiveColor,DefaultColor){
	var x = o.css("background-color");o.css("background-color",ActiveColor);
	o.fadeTo("1",0.4,function(){o.css("background-color",x);//.css("color","red");
	if(jQuery.browser.msie) o.css("filter","");else o.fadeTo("100",1);});
}
Common.getCookie = function (name){
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null){if (unescape(arr[2]) == null){return ;}else{return unescape(arr[2]);}}else{return ;}
}
Common.delCookie = function (name){
	var exp = new Date();exp.setTime(exp.getTime() - 1);var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}


/********************************************************************************/
/************************************ Game3 *************************************/
/********************************************************************************/
Namespace.register("GameGroup.Game3");
GameGroup.Game3.Item = function(_GameType,_id){
	var _this = this;
	_this.GameType = _GameType
	_this.ID = _id;
	_this.InitTime = Common.DateTime.Now();//默认启动时间
	_this.Seconds = 0;//计时秒数 
	_this.SaledCount = 0;
	_this.TotalCount = 0;
	_this.UserId = 0;
	_this.UserNickName = "";
	_this.LuckyNumber = "";
	_this.CreateTime = "";
	_this.RealStopTime = "";
	_this.VendueState = 0;
	
	//jQueryDiv
	_this.oID = null;
	_this.oSeconds = null;//计时秒数 
	_this.oSaledCount = null;
	//_this.oTotalCount = null;
	_this.oUserId = null;
	_this.oUserNickName = null;
	_this.oUserNickNameTitle = null;//当成交时修改该标题名称
	_this.oLuckyNumber = null;
	_this.oCreateTime = null;
	_this.oBtn = null;
	_this.oVendueState = null;
	_this.CheckObject();
}

GameGroup.Game3.Item.prototype.CheckObject = function(){
	var _this = this;
	if(_this.oSeconds==null){_this.oSeconds = jQuery("#Seconds_"+ _this.ID);}
	if(_this.oSaledCount==null){_this.oSaledCount = jQuery("#SaledCount_"+ _this.ID);}
	if(_this.oUserNickName==null){_this.oUserNickName = jQuery("#UserNickName_"+ _this.ID);}	
	if(_this.oUserNickNameTitle==null){_this.oUserNickNameTitle = jQuery("#UserNickNameTitle_"+ _this.ID);}	
	if(_this.oCreateTime==null){_this.oCreateTime = jQuery("#CreateTime_"+ _this.ID);}		
	if(_this.oLuckyNumber==null){_this.oLuckyNumber = jQuery("#LuckyNumber_"+ _this.ID);}			
	if(_this.oBtn==null){_this.oBtn = jQuery("#btn_"+ _this.ID);}	
	if(_this.oSpanTip==null){_this.oSpanTip = jQuery("#spanTip_"+ _this.ID);}
	if(_this.oVendueState == null){_this.oVendueState = jQuery("#VendueState_"+ _this.ID);}	


}

GameGroup.Game3.Person = function(_name){
	this.GameType = 3,//游戏类型
	this.PointType = 1,//使用点的类型(1收费,2免费,3体验)
	this.SeMilli = 10,
	this.MinMilli = this.SeMilli * 60 ,//每分钟多少毫秒
	this.HrMilli = this.MinMilli * 60 ,//每小时多少毫秒
	this.DayMilli = this.HrMilli * 24 ,//
	this._Hour = new Date().getHours(),//判断游戏运行时间间隔
	this.UserId =0,//当前会员编号
	this.Url = ["/thread_3.aspx","/thread_3.aspx","/thread_3.aspx","/thread_3.aspx"],//tid=1251,1,7,6,9,1253,19,15,14,13,12,11
	this.VendueList="", //所有时间项
	this.DivList = [];
	this.AjaxDataAll = null//总数据:是否有改动;所有数据;
	this.timer = null ,
	this.timerTmp = [],
	this.ArrTimer=[],
	this.oAjaxHistory = null,
	this.oAjaxMyHistory = null
		
}
GameGroup.Game3.Person.prototype.Ajax=function(_Type,_Url,_data,_success,_error,_dataType){
	jQuery.ajax({"type": (_Type?_Type:"POST"),"url": (_Url?_Url:""),"data": (_data?_data:"")
		,success: (_success?_success:null),error: (_error?_error:null),"dataType":(_dataType?_dataType:"html")});
}
//********************* 取数据部分S ***
//取数据,每秒一次OK
GameGroup.Game3.Person.prototype.GetData = function(){
	var _this = this;
	_Hour = new Date().getHours();
	if( _Hour>=0 && _Hour<9){this.timer = setTimeout(function(){_this.GetData()},60000);}
	else if(this.VendueList.length<1){this.timer = setTimeout(function(){_this.GetData()},30000);}
	else{
		Common.Ajax(
			"GET",
			_this.Url[_this.GameType],
			//参数:编号列表,点类型,
			{"tid":_this.VendueList,"PointType":_this.PointType,"tt":new Date().getTime()},
			function(dt){//有新数据后才进行数据整体更新
				_this.AjaxDataAll = dt;if(_this.AjaxDataAll["IsNewData"]==1){}
				_this.Fill();
			},
			function(msg){}
			,"json"
		);
		_this.timer = setTimeout(function(){_this.GetData()},1000);	
	}
}
//所有数据填充OK
GameGroup.Game3.Person.prototype.Fill = function(){
	//填充数据有:
	var _this = this;
	var _item = null;
	if(_this.AjaxDataAll==null) return ;	
	for(var i=0;i<_this.AjaxDataAll["NewData"].length;i++){
		
		_item = _this.DivList["Bid_"+ _this.AjaxDataAll["NewData"][i]["ID"]];
		if(_item==null) continue;
		_item.VendueState = _this.AjaxDataAll["NewData"][i]["VendueState"];
		//_this.AjaxDataAll["NewData"][i]["InitTime"];		
		_item.InitTime = _item.oSeconds.attr("title");//此方法可保证数据有效
		_item.SaledCount = _this.AjaxDataAll["NewData"][i]["SaledCount"];
		_item.TotalCount = _this.AjaxDataAll["NewData"][i]["TotalCount"];
		_item.UserId = _this.AjaxDataAll["NewData"][i]["UserId"];
		_item.UserNickName = _this.AjaxDataAll["NewData"][i]["UserNickName"];
		_item.LuckyNumber = _this.AjaxDataAll["NewData"][i]["LuckyNumber"];
		_item.CreateTime = _this.AjaxDataAll["NewData"][i]["CreateTime"];
		_item.RealStopTime = _this.AjaxDataAll["NewData"][i]["RealStopTime"];
		
		if(_item.VendueState!="3"){ //未成交
			_item.Seconds = _this.GetSecond(_item.InitTime);//经过计算而得;也可不用
			_item.oSeconds.css("color","#676767");
			_item.oUserNickNameTitle.html("最近享乐者：").css("color","#676767");
			_item.oVendueState.hide();
			_item.oBtn.show();
		}
		else{
			_item.Seconds = _this.GetSecond(_item.InitTime,_item.RealStopTime);//经过计算而得;也可不用
			_item.oSeconds.css("color","#ff0000");
			_item.oUserNickNameTitle.html("幸运享乐者：").css("color","red");
			_item.oVendueState.show();
			_item.oBtn.hide();
		//	_this.Remove(_item.ID);
		}
	//	if(_item.TotalCount<1)_item.oBtn.hide();
		_item.oSeconds.html(_item.Seconds);
		_item.oSaledCount.html(_item.SaledCount);
		_item.oUserNickName.html(_item.UserNickName);
		_item.oCreateTime.html(_item.RealStopTime);
		_item.oLuckyNumber.html(_item.LuckyNumber);
		//_this.FillEveryTime();
	}
	
}

/*
//每秒填充和计算OK
GameGroup.Game3.Person.prototype.FillEveryTime = function(){
	var _this = this;var _item = null;
	if(_this.DivList==null) return ;var n;
	for(n in _this.DivList){_item = _this.DivList[n];
		if(_item.VendueState<3) _item.oSeconds.html(_this.GetSecond(_item.InitTime));
	}
	//_this.ArrTimer[0] = window.setTimeout(function(){_this.FillEveryTime();},1000);
}
*/
//生成秒数OK
/*
GameGroup.Game3.Person.prototype.GetSecond = function(_time){
	var arr = _time.split(/[-|\x20|:]/);
	var d = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1,parseInt(arr[2],10),	parseInt(arr[3],10),parseInt(arr[4],10),parseInt(arr[5],10));	 
	var a = d.getTime();var b = new Date().getTime();var t = b-a;t =parseInt( t /1000,10);
	return t;
}*/

GameGroup.Game3.Person.prototype.GetSecond = function(_time,_time2){
	if(_time2==null)
	{
	var arr = _time.split(/[-|\x20|:]/);
	var d = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1,parseInt(arr[2],10),	parseInt(arr[3],10),parseInt(arr[4],10),parseInt(arr[5],10));	 
	var a = d.getTime();var b = new Date().getTime();var t = b-a;t =parseInt( t /1000,10);
	return t;		
	}
	else
	{
	var arr = _time.split(/[-|\x20|:]/);
	var d = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1,parseInt(arr[2],10),	parseInt(arr[3],10),parseInt(arr[4],10),parseInt(arr[5],10));	 
	arr = _time2.split(/[-|\x20|:]/);
	var d2 = new Date(parseInt(arr[0],10),parseInt(arr[1],10)-1,parseInt(arr[2],10),	parseInt(arr[3],10),parseInt(arr[4],10),parseInt(arr[5],10));	 
	var a = d.getTime();var b = d2.getTime();var t = b-a;t =parseInt( t /1000,10);
	return t;
	}
}
GameGroup.Game3.Person.prototype.AjaxHistoryFill = function(id)
{
	var _this = this;
	Common.Ajax(
		"GET",
		"/Auction/ajaxhistory.aspx",
		//参数:编号列表,点类型,?topnum=2&vendueid=2
		{"TopNum":8,"VendueId":id,"DataType":"0","tt":new Date().getTime()},
		function(dt){//有新数据后才进行数据整体更新
			_this.oAjaxHistory.html(dt);	
		},
		function(msg){}
	);
	if(_this.VendueList.length>0){
		_this.ArrTimer[1] = setTimeout(function(){_this.AjaxHistoryFill(id);},3000);//启动1/10计时器,
	}	
	else{
		clearInterval(this.ArrTimer[1]);
	}
	
	
}

GameGroup.Game3.Person.prototype.AjaxMyHistoryFill = function(id)
{
	var _this = this;
	Common.Ajax(
		"GET",
		"/Auction/ajaxhistory.aspx",
		//参数:编号列表,点类型,?topnum=2&vendueid=2
		{"TopNum":0,"VendueId":id,"DataType":"1","tt":new Date().getTime()},
		function(dt){//有新数据后才进行数据整体更新
			_this.oAjaxMyHistory.html(dt);	
		},
		function(msg){}
	);
}

//********************* 取数据部分E ***

//********************* 初始化部分S ***
//OK
GameGroup.Game3.Person.prototype.Add = function(id){
	var _this = this;if(_this.VendueList.length>0) _this.VendueList +=","+ id;else _this.VendueList = id;
	_this.DivList["Bid_"+ id] = new GameGroup.Game3.Item(_this.GameType,id);
}

//OK
GameGroup.Game3.Person.prototype.Remove = function(id){
	var _this = this;var list = "";
	var arr = _this.VendueList.toString().split(",");	
	for(var n=0;n<arr.length;n++){
		if(arr[n]==id){	_this.DivList["Bid_"+ id] = null;}
		else{if(list.length<1) list=arr[n];else list +=","+arr[n];}
	}
	_this.VendueList = list;	

}
//开始托管程序OK?
GameGroup.Game3.Person.prototype.Start = function () {
	var _this = this; _this.GetData();
	//_this.ArrTimer[0] = setTimeout(function(){_this.FillEveryTime();},1000);//启动1/10计时器
}
//停止托管程序OK
GameGroup.Game3.Person.prototype.Stop = function () {
	clearInterval(this.timer);clearInterval(this.ArrTimer[0]);
}	
//OK
GameGroup.Game3.Person.prototype.Bid = function(id){
	//单击事件
	var _this = this;
	//_islogined is not defined
	var _isLogined = Common.getCookie("islogin");
	if(!_isLogined){
	//	alert("请您登陆.");return false;
	}
	
	var _item = _item = _this.DivList["Bid_"+ id];
	if(_item && _item.TotalCount<1)
	{
		alert("对不起,该彩票没有可用的号(剩余可用号数量无效),请通知客服.");
		return false;
	}
	
	Common.Ajax(
		"GET",
		"/index.aspx?s=/Game3/dobid",
		{"tid":id,"GameType":_this.GameType,"PointType":_this.PointType},
		//_this.Bid_Ajax_Success,
		function(msg){
			//alert("成功" + msg);
			_this.BidSuccess(id,msg);
		},
		_this.Bid_Ajax_Error	
	);
}
//OK
GameGroup.Game3.Person.prototype.Bid_Ajax_Success = function(msg){
	//alert("成功" + msg);
	var _this = this;
	_this.BidSuccess()
}
//OK
GameGroup.Game3.Person.prototype.Bid_Ajax_Error = function(msg){
	ShowErrorMsg("err:" + msg.responseText);
}

GameGroup.Game3.Person.prototype.BidSuccess = function(id,msg){
	var _this = this;
	//_this.AjaxMyHistoryFill(id);
			//window.status = msg;
			////1正常,0操作失败,2没登陆,3值不够,4已出过价,5游戏已结束,6封盘 #ff0000  #339900
			if(msg==0)
			{
				_this.ShowBidTip(id,"您刚才投币无效.","#339900");
			}
			if(msg==1)
			{
				//我的投注.
				_this.AjaxMyHistoryFill(id);
				_this.ShowBidTip(id,'您投币成功',"#339900");
			}else if(msg==0){
				//_this.ShowBidTip(id,'您出价失败，请重试');
			}else if(msg==2){
				//AjaxLoginBox();
				_this.ShowBidTip(id,'请先登录',"#339900");
			}else if(msg==3){
				_this.ShowBidTip(id,'您的余额不足，请充值!()');//<a href="javascript:paycountnow();" title="充值，获取闪点">【马上充值】</a>');
			}else if(msg==4){
				_this.ShowBidTip(id,'您已出价，无需重复',"#FF0000");
				//var msg = '<div class="tc"><span class="button"><span class="first-child"><button onclick="removeDialogbox(\'#userAway\');" type="button">您已出价，无需重复!</button></span></span></div>';
				//addDialogbox("#userAway","拍拍网提示",10010,300);
				//jQuery("#userAway .dialogboxContent").html(msg);
			}else if(msg==5){
				_this.ShowBidTip(id,'商品已成交',"#339900");
			}else if(msg==6){
				_this.ShowBidTip(id,'现已经到达封盘时段（00:00 - 09:00），请于开盘时再竞拍');
			}else if(msg==7){
				ShowBidTip(id,'您的资金账号已被冻结，请与我们的客服联系！',"#FF0000");
			}else if(msg==8){
				_this.ShowBidTip(id,'您的用户账号已被冻结，请与我们的客服联系！',"#FF0000");
				Fast_Logout(true);//用户冻结之后马上退出
			}else if(msg==9){
				_this.ShowBidTip(id,'已达到4周获得游戏封顶',"#FF0000");
				//delCookie('topboxopen');
				//opentopbox();//控制打开个人获得的浮动层
			}else if(msg==10){
				_this.ShowBidTip(id,'您已获得过商品，此为新人竞拍商品',"#FF0000");
			}else if(msg==11){
				_this.ShowBidTip(id,'您出价太快，请放松',"#FF0000");
			}else if(msg==12){
				_this.ShowBidTip(id,'此为新人竞拍商品，请先进行账户安全认证',"#FF0000");
			}else if(msg==13){
				_this.ShowBidTip(id,'检测点击频率太快，暂停出价30秒',"#FF0000");
			}else if(msg==14){
				_this.ShowBidTip(id,'您已设置分身进行竞拍，请取消或者等待分身出价结束后再操作！',"#FF0000");
			}else if(msg==15){
				_this.showBidTip(id,'您已达到出价次数的上限！',"#FF0000");
			}else if(msg==100){
				_this.ShowBidTip(id,'游戏类型不一致');
			}else if(msg==101){
				_this.ShowBidTip(id,'游戏每次投币消耗币数未设置,请与网站客服联系.');				
			}else{
				_this.ShowBidTip(id,'出价信息到达服务器时竞拍已经结束，下次请提早出价！',"#FF0000");
			}

}
GameGroup.Game3.Person.prototype.ShowBidTip = function(id,content,FontColor,Second){
	var _this = this;
	if(!Second)Second=1500;
	
	var o ;
	//o = jQuery("#spanTip_"+id);
	PaiPaiCMS.DialogBox.ShowSimpleTip(content+"","bold",FontColor,15,"center",200,o);
	//_this.timerTmp["ShowBidTip_"+id] = setTimeout(function(){PaiPaiCMS.DialogBox.CloseSimpleTip(o);clearInterval(_this.timerTmp["ShowBidTip_"+ id]);},Second);
}

//********************* 初始化部分E ***

//测试
GameGroup.Game3.Person.prototype.Show = function()
{
	alert(this.name);
}

//展示
//var pp = new PaiPaiJS.Game3.Person("zd");
//pp.Show();
/*
返回JSON

[
	"IsNewData":0,
	"NewData":
	{
		[
			"id":0,
			"InitTime":"2011-03-12 14:00:00",
			"SaledCount":0,
			"TotalCount":100,
			"UserId":1,
			"UserNickName":"小风",
			"LuckyNumber":"1035647",
			"CreateTime":"2011-03-12 17:00:00"
		]
	}
]
--------------------------------------------------------------------
[
	"IsNewData":"0",
	"NewData":
	{
		[
			"ID":1,
			"InitTime":"2011-3-9 17:54:37",
			"SaledCount":0,
			"TotalCount":333,
			"UserId":"25",
			"UserNickName":"111111",
			"LuckyNumber":"",
			"CreateTime":"2011-3-7 17:56:20"
		],
		[
			"ID":2,
			"InitTime":"2011-3-3 17:54:37",
			"SaledCount":0,
			"TotalCount":9999,
			"UserId":"19",
			"UserNickName":" 机器人1",
			"LuckyNumber":"",
			"CreateTime":"2011-3-7 18:05:31"
		],
		[
			"ID":3,
			"InitTime":"2011-3-9 17:47:53",
			"SaledCount":0,
			"TotalCount":0,
			"UserId":"0",
			"UserNickName":"",
			"LuckyNumber":"",
			"CreateTime":"2011-3-9 17:47:56"
		]
	}
]
--------------------------------------------------------------------
{
	"IsNewData":"0",
	"NewData":
	[
	{
		"ID":1,
		"InitTime":"2011-3-9 17:54:37",
		"SaledCount":0,
		"TotalCount":333,
		"UserId":"25",
		"UserNickName":"111111",
		"LuckyNumber":"",
		"CreateTime":"2011-3-7 17:56:20"
	},{
		"ID":2,
		"InitTime":"2011-3-3 17:54:37",
		"SaledCount":0,
		"TotalCount":9999,
		"UserId":"19",
		"UserNickName":"机器人1",
		"LuckyNumber":"",
		"CreateTime":"2011-3-7 18:05:31"
	},{
		"ID":3,
		"InitTime":"2011-3-9 17:47:53",
		"SaledCount":0,
		"TotalCount":0,
		"UserId":"0",
		"UserNickName":"",
		"LuckyNumber":"",
		"CreateTime":"2011-3-9 17:47:56"
	}]
};



*/