/*+++++++++++++++++++++++++++++++++++++
+ 功能:每天投票类
+ 研发:宗帝
+ 时间:2011-06-30
+ 
+++++++++++++++++++++++++++++++++++++*/
Namespace.register("Wisdom.PollDay");
Wisdom.PollDay = function(){
	var _this = this;
	this.DayCount = 3;
	this.MultiOptionCount =1;
	this.CheckBoxPrefix = "CheckBox_";//CheckBox_0_OptionId
	//this.__cookieName = "UserOnLine";
	this.timer = null;
	this.init=function(_DayCount,_MultiOptionCount){
	//	var _this = this;
		_DayCount = parseInt(_DayCount,10);if(isNaN(_DayCount)) _DayCount=3;if(_DayCount<1) _DayCount = 3;_this.DayCount = _DayCount;
		_MultiOptionCount = parseInt(_MultiOptionCount,10);if(isNaN(_MultiOptionCount)) _MultiOptionCount=1;if(_MultiOptionCount<1) _MultiOptionCount =1;_this.MultiOptionCount = _MultiOptionCount;
		
		var key = "";
		key = _this.CheckBoxPrefix ;
		jQuery("input[id^='"+ key +"']").click(function(){//alert(jQuery(this).parent().parent().parent().find("input").length);
			if(_this.MultiOptionCount<2){//jQuery(this).parent().parent().parent().find("input").removeAttr("checked");this.checked=true;
				var dayIndex = this.id.substr(key.length,1);var _currentchecked = this.checked;
				jQuery("input[id^='"+ key + dayIndex +"']").removeAttr("checked");if(_currentchecked) this.checked=true;
			}
			else{
				var dayIndex = this.id.substr(key.length,1);var _currentchecked = this.checked;
				var n = jQuery("input[id^='"+ key + dayIndex +"']:checked").length;
				if(n>_this.MultiOptionCount){alert("您只能同时选中"+ _this.MultiOptionCount +"项。"); this.checked =false;}
			}
		});
		jQuery("#PollDayBtnSubmit").click(function(){_this.CheckBeforeAjaxSubmit();});
		
	};

	this.CheckBeforeAjaxSubmit=function(){
		//数据验证
	
		var IsOK = true;
		var i =0;
		var j = 0;
		for(i=0;i<_this.DayCount;i++){j = jQuery("input[id^='"+ _this.CheckBoxPrefix + i +"']:checked").length;if(j<1){ IsOK=false;}}
		if(IsOK) this.AjaxSubmit();	else {alert("每天的投票您都需要选择一项。");}

	};
	this.AjaxSubmit = function(){
		//验证通过后的数据提交
		var url = "/Auction/pollday.aspx?IsAdd=21";
		
		var s ="";
		var i=0;
		var j=0;
		for(i =0;i<_this.DayCount;i++){
			var o = jQuery("input[id^='"+ _this.CheckBoxPrefix + i +"']:checked");
			var x = "";
			for(j=0;j<o.length;j++)	{ var optionid = o[j].id.substr(_this.CheckBoxPrefix.length+2);x+=optionid+"," }
			if(x.length>1) x = x.substr(0,x.length-1);
			s +=(i+"="+ x );
			if(i+1<_this.DayCount) s+="|";
		}
		var data = {"optionid":s};
		Common.Ajax("POST",url,data
			,function(msg){	if(msg>0) alert("感谢您的投票,祝您玩的愉快."); else alert("服务器异常，您的投票未成功记录。");
				
			},function(msg){alert("网络或服务器异常，请稍候再提交。");}
			);
	
	};
	this.AddDialogBox = function(MsgTitle){
		//不存在，则弹出层
		var _this = this;
		//var msg = '<input type="button" value="关闭" id="BtnCookieOnLineClose" > - <input type="button" id="BtnCookieOnLineContinue" value="继续" >';
		
		var msg = '\
<div class="tipBox">\
	<div class="tipLeft"></div>\
	<div class="tipContent">\
		<div class="tipTitle">\
		</div>\
		<div class="tipText">\
			<div class="divcontent">'
			+ MsgTitle +
			'</div>\
		</div>\
		<div class="tipButton">\
			<span class="btn_ok" ><a href="#"  id="BtnCookieOnLineContinue">继续</a></span>\
		</div>\
	</div>\
	<div class="tipRight">\
	</div>\
</div>\
	';
		var w = 381;
		var h = 195;
		AddDialogbox("CookieUseronLine","",61000,w,"",60000,false,msg);
		jQuery("#BtnCookieOnLineContinue").click(function(){_this.RemoveDialogBox();});
			
	};
	this.RemoveDialogBox = function(){RemoveDialogbox("CookieUseronLine");return false;};
	
	
	this.init();
		
}
