dqzh_Object = {
	_MaxPerNum : 100,
	_PeriodMoney : [],
	_form_name : 'dqzh_form',
	SetPeriodCount  : function(){
		var theform = $(dqzh_Object._form_name);
		dqzh_Object._PeriodMoney = [];
		var ddlSMType		= theform.addtype;//平追/加倍：
		var ddlSMutiType	= theform.mutitype;//加倍方式：		
		var MutiNew			= parseInt(theform.startmultiple1.value);//新加第一注倍数
		var Muti			= parseInt(theform.startmultiple2.value);//第二注倍数						
		var intervalPeriod	= parseInt(theform.intervalperiods.value);//间隔多少期加倍
		var mutiNum			= parseFloat(theform.doublemultiplecount.value);//乘法/加法加倍里的数		
		var tempInterval	= intervalPeriod;		
		var MutiArrNew  = new Array(dqzh_Object._MaxPerNum+1);//第一注倍数数组(?)
		var MutiArr		= new Array(dqzh_Object._MaxPerNum+1);//第二注倍数数组(?)				
		var hidNumList1	= theform.balls1;					//第一个选择号码
		var hidNumList2	= theform.balls2;					//第二个选择号码			
		var txtPerNum	= theform.periodscount;
		if (txtPerNum.value !="")
				{
					dqzh_Object._MaxPerNum	= parseInt(txtPerNum.value);
				}
				else
				{
					dqzh_Object._MaxPerNum = 1;
				}		
				
				for(i=1;i<=dqzh_Object._MaxPerNum;i++)
				{
					MutiArrNew[i]	= 0;
					MutiArr[i]		= 0;
				}
				//计算倍数
				var curStepMulti=0;
				var incNum=0;
				for(i=1;i<=dqzh_Object._MaxPerNum;i++)
				{	
					if (ddlSMType.value == "0")	//0为平追
					{
						//第一注不为空
						if(hidNumList1.value !="")
						{
							MutiArrNew[i] = MutiNew ; 
						}
						
						//第二注都不为空
						if(hidNumList2.value !="")
						{
							MutiArr[i]	  = Muti	;
						}				
					}
					else//乘法和加法加倍
					{
						//计算递增数
						if (i%intervalPeriod==0)
						{
							incNum=parseInt(i/intervalPeriod);
						}
						else
						{
							incNum=parseInt(Math.ceil(i/intervalPeriod));
						}
						
						if (ddlSMutiType.value == "1")//加法
						{
							//第一注都不为空
							if(hidNumList1.value !="")
							{
								curStepMulti=parseInt(MutiNew)+parseInt(Math.round((incNum-1)*mutiNum));
								MutiArrNew[i]=curStepMulti;
							}
							//第二注都不为空
							if(hidNumList2.value !="")
							{
								curStepMulti=parseInt(Muti)+parseInt(Math.round((incNum-1)*mutiNum));
								MutiArr[i]=curStepMulti;
							}							
						}
						else//乘法
						{
							//第一注都不为空
							if(hidNumList1.value !="")
							{
								curStepMulti=Math.round(MutiNew*Math.pow(mutiNum,incNum-1));
								MutiArrNew[i]=curStepMulti;
							}
							//第二注都不为空
							if(hidNumList2.value !="")
							{
								curStepMulti=Math.round(Muti*Math.pow(mutiNum,incNum-1));
								MutiArr[i]=curStepMulti;
							}		
						}						
					}
					dqzh_Object._PeriodMoney.push(MutiArr[i] * 2 + MutiArrNew[i] * 2);
				}//for结束
				dqzh_Object._MaxPerNum = dqzh_Object._PeriodMoney.length;
				
	},
	SetLabel : function(){
		var theform = $(dqzh_Object._form_name);
		var txtPerNum	= theform.periodscount;
		var totalMoney = 0;//统计钱数			
		if(theform.balls1.value!='' || theform.balls2.value!=''){
			dqzh_Object._PeriodMoney.each(function(money){
				totalMoney += money;
			});
		}
		Element.update('dqzh_ChipinMoney',totalMoney);
		theform.totalprice.value = totalMoney;
	},
	form_changed : function(element,value){
		if(Common.detect.isInteger(element.periodscount.value) && 
				(Common.detect.isInteger(element.startmultiple1.value)) && 
				(Common.detect.isInteger(element.startmultiple2.value))
			 ){
			//Element.update('dqzh_spanProNum',element.periodscount.value);
			dqzh_Object.SetPeriodCount();
			dqzh_Object.SetLabel();			
		}
	},
	periodscount_changed : function(element,value){
		if(Common.detect.isInteger(element.value)){
			Element.update('dqzh_spanProNum',element.value);
		}
	},
	validate : function(theform){
		if(theform.ProjectName.value==""){
			alert('方案名称不能为空');
			Common.setFocus(theform.ProjectName);
			return false;
		}
		if(Common.detect.isEmpty(theform.balls1.value) && Common.detect.isEmpty(theform.balls2.value)){
			alert('至少要选择一注');
			Common.setFocus(theform.balls1);			
			return false;
		}
		if(theform.starttype.value=="0"){
		}else if(theform.starttype.value=="1"){
			//判断小时和 分 是否为有效的数字和范围内
			if(!Common.detect.isInteger(theform.starthour.value)){
				alert('输入的时不是有效的小时数');
				Common.setFocus(theform.starthour);			
				return false;
			}
			var n_hour = parseInt(theform.starthour.value);
			var startHour	= parseInt(Config.startTime.split(':')[0]);
			var endHour		= parseInt(Config.endTime.split(':')[0]);
			if(n_hour<startHour || n_hour >endHour){
				alert('小时数必须在{0}-{1}之间！！'.format(startHour,endHour));
				Common.setFocus(theform.starthour);			
				return false;
			};
			if(!Common.detect.isInteger(theform.startminute.value)){
				alert('输入的分钟不是有效的分钟');
				Common.setFocus(theform.startminute);			
				return false;
			};
			var n_minute = parseInt(theform.startminute.value);
			if(n_minute>60){
				alert('输入的分钟必须在0-60之间！！');
				Common.setFocus(theform.startminute);			
				return false;
			}
		}else if(theform.starttype.value=="1"){
			if(!Common.detect.isInteger(theform.startperiod.value)){
				alert('开始期号不是有效的整数');
				Common.setFocus(theform.startperiod);			
				return false;
			};
		}
		if(!Common.detect.isInteger(theform.periodscount.value)){
			alert('追号期数不是整数');
			Common.setFocus(theform.periodscount);
			return false;
		}
		if(theform.EndCondition.value=="1"){
			if(!Common.detect.isDouble(theform.doublemultiplecount.value)){
				alert('累计奖金不是有效的数字');
				Common.setFocus(theform.periodscount);
				return false;
			}
		}
		if(theform.addtype.value=='1')
		{
			if(!Common.detect.isDouble(theform.doublemultiplecount.value)){
				alert('倍数倍数不是整数');
				Common.setFocus(theform.doublemultiplecount);
				return false;
			}
		}
		if(Common.detect.isEmpty(theform.dealpassword.value)){
			alert('请输入操作密码');
			Common.setFocus(theform.dealpassword);
			return false;
		}
		if(!theform.AcceptAgreement.checked){
			alert(Config.unDelegateRule);
			return false;
		}
		//如果是中得头奖：
		if (theform.EndCondition.value=="0")
		{
			var tt=theform.balls1.value!=""?theform.balls1.value:theform.balls2.value;
			theform.endawardlevel.value=tt.split("|").length+''+tt.split("|").length;
		}
		return true;
	}
}

bind_dqzh_event = function(){
	FormSubmit({
		theform : 'dqzh_form',
		checkf : dqzh_Object.validate,
		callback : function(result){
			alert(result);
		}
	});
};
dqzh_Submit = function(value){
	$('dqzh_form').draft.value = value;
	bind_dqzh_event();
}
MutiTypeChange=function(value){
	if (value=="0")//乘法
	{
		$('dqzh_mutiSympol').innerHTML = "×";		
	}
	else
	{
		$('dqzh_mutiSympol').innerHTML = "＋";
	}
}
dqzh_Chipin = function(){
	if($('chipin_tr').style.display=='none')
	{
		var chipinframe = $('chipinframe');
		if(chipinframe.src=="blank.htm"){
				chipinframe.src = "chipin_frame.htm";
		}
		Element.show('chipin_tr');
	}else{
		Element.hide('chipin_tr');
	}
}
winfm = null;
hxfa_Object = {
	_MaxPerNum : 100,
	_form_name : 'hxfa_form',
	SetPeriodCount  : function(){
		var theform = $(hxfa_Object._form_name);
		var txtPerNum	= theform.periodscount;
		if(txtPerNum.value != "")
		{
			if(Config.surperiods<parseInt(txtPerNum.value))
			{
				alert("超过当天的生意运营期数，请重新选择");
				hxfa_Object._MaxPerNum = 1;
				return;
			}
			else
				hxfa_Object._MaxPerNum = parseInt(txtPerNum.value);
		}
		else
		{
			hxfa_Object._MaxPerNum = 1;
		}
		if(theform.addtype.value=='1' && theform.mutitype.value=='1'){
			if(!/^\d+(\.[0]+)?$/.test(theform.doublemultiplecount.value)){
				alert('如果加倍方式选择了加法，倍数必须是整数');
				theform.doublemultiplecount.value = 1;
				return;
			}
		}
		
		var totalMoney = hxfa_Object.GetMoney(hxfa_Object._MaxPerNum);		
		
		Element.update('hxfa_ChipinMoney',totalMoney);
		theform.totalprice.value = totalMoney;		
	},
	GetMoney : function(maxPerNum){
		var theform = $(hxfa_Object._form_name);
		
		var __PeriodMoney = [];
		var addtype = theform.addtype.value;
		var mutitype = theform.mutitype.value;
		var intervalPeriod		= parseInt(theform.intervalperiods.value);//间隔多少期加倍
		var startMuti			= parseInt(theform.startmultiple1.value);//起始倍数
		var mutiNum			= parseFloat(theform.doublemultiplecount.value);//乘法/加法加倍里的数			
		var curStepMulti=0;
		var incNum=0;
		var totalMoney = 0;//统计钱数	
		for(i=1;i<=maxPerNum;i++)
		{	
			/*if (addtype == "0")//平追
			{
				curStepMulti = startMuti;
			}
			else
			{
				if (i%intervalPeriod==0)
				{
					incNum = i/intervalPeriod;
				}
				else
				{
					incNum = parseInt(Math.ceil(i/intervalPeriod));
				}
				if (mutitype == "1")//加法
				{
					curStepMulti=startMuti+parseInt(Math.round((incNum-1)*mutiNum));
				}
				else//乘法
				{
					curStepMulti=Math.round(startMuti*Math.pow(mutiNum,incNum-1));		
				}						
			}
			totalMoney += curStepMulti * 2;*/
			totalMoney += hxfa_Object.GetStepMulti(i,addtype,mutitype,startMuti,intervalPeriod,mutiNum) * 2;

		}	
		return totalMoney;
	},
	GetStepMulti : function(pernum,addtype,mutitype,startMuti,intervalPeriod,mutiNum){
		return 1;
		var curStepMulti = 0;
		var incNum = 0;

		if (addtype == "0")//平追
		{
			curStepMulti = startMuti;
		}
		else
		{
			if (pernum%intervalPeriod==0)
			{
				incNum = pernum/intervalPeriod;
			}
			else
			{
				incNum = parseInt(Math.ceil(pernum/intervalPeriod));
			}
			if (mutitype == "1")
			{
				curStepMulti=startMuti+parseInt(Math.round((incNum-1)*mutiNum));
			}
			else
			{
				curStepMulti=Math.round(startMuti*Math.pow(mutiNum,incNum-1));		
			}						
		}
		return curStepMulti;
	},
	form_changed : function(element,value){
		if(Common.detect.isInteger(element.periodscount.value) && 
				(Common.detect.isInteger(element.c_min.value)) && 
				(Common.detect.isInteger(element.c_max.value))
			 ){
			hxfa_Object.SetPeriodCount();
			if(typeof(winfm)!='undefine' && $('dialogBox') && $('dialogBox').style.display!='none')
			{
				winfm.updateHtml(getShouyi());
			}
			
		}
	},
	periodscount_changed : function(element,value){
		if(Common.detect.isInteger(element.value)){
			Element.update('hxfa_spanProNum',element.value);
		}
	},
	validate : function(theform){
		if(theform.ProjectName.value==""){
			alert('方案名称不能为空');
			Common.setFocus(theform.ProjectName);
			return false;
		};
		if(!Common.detect.isInteger(theform.c_min.value)){
			alert('您输入的含羞次数的最小值不是有效的整数');
			Common.setFocus(theform.min);
			return false;
		}
		if(!Common.detect.isInteger(theform.c_max.value)){
			alert('您输入的含羞次数的最大值不是有效的整数');
			Common.setFocus(theform.c_max);
			return false;
		}
		if(!Common.detect.isInteger(theform.maxnumbers.value)){
			alert('您输入的最多执行次数不是整数');
			Common.setFocus(theform.maxnumbers);
			return false;
		}
		if(!Common.detect.isInteger(theform.periodscount.value)){
			alert('追号期数不是整数');
			Common.setFocus(theform.periodscount);
			return false;
		}
		/*if(theform.avoidnumbers.value!=''){
			if(){
				
			Common.setFocus(theform.avoidnumbers);
				return false;
			}
		}*/
		if(theform.addtype.value=="1"){
			if(!Common.detect.isDouble(theform.doublemultiplecount.value)){
				alert('您输入的加倍方式里的倍数不是有效的数字');
				Common.setFocus(theform.doublemultiplecount);
				return false;
			}
		}
		if(Common.detect.isEmpty(theform.dealpassword.value)){
			alert('请输入操作密码');
			Common.setFocus(theform.dealpassword);
			return false;
		}
		if(!theform.AcceptAgreement.checked){
			alert(Config.unDelegateRule);
			return false;
		}
		return true;
	}
}
bind_hxfa_event = function(){
	FormSubmit({
		theform : hxfa_Object._form_name,
		checkf : hxfa_Object.validate,
		callback : function(result){
			alert(result);
		}
	});
};
hxfa_Submit = function(value){
	$('hxfa_form').draft.value = value;
	bind_hxfa_event();
}

//SetCustomMutil = function(form_name){
////alert('SetCustomMutil')
//	var maxPeriodNum;
//	//var theform = $(hxfa_Object._form_name);
//	var theform = $(form_name);
//	var txtPerNum	= theform.periodscount;
//	var addtype = theform.addtype.value;
//	var mutitype = theform.mutitype.value;
//	var intervalPeriod		= parseInt(theform.intervalperiods.value);//间隔多少期加倍
//	var startMuti			= parseInt(theform.startmultiple1.value);//起始倍数
//	var mutiNum			= parseFloat(theform.doublemultiplecount.value);//乘法/加法加倍里的数	

//	if(txtPerNum.value==""){
//		alert("请先输入加倍期数");
//		return;
//	}
//	if(Config.surperiods<parseInt(txtPerNum.value))
//	{
//		alert("超过当天的生意运营期数，请重新选择");
//		return;
//	}
//	else
//		maxPeriodNum = parseInt(txtPerNum.value);
//	
//	var thisHTML = "";
//	thisHTML = "\
//	<table width='120' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>\
//	<tr bgcolor='#E1E1E1'>\
//	<td width='20%' height='17' align=center>追期序号</td>\
//	<td width='80%' align=center>投注倍数</td>\
//	</tr>\
//	";
//	
//	var startMuti			= parseInt(theform.startmultiple1.value);//起始倍数
//	var _maxPerNum = 1;
//	var addtype = theform.addtype.value;
//	var bgcolor;
//	var __addtype;
//	if(addtype=="0"){
//		__addtype = "平追";
//	}else{
//		__addtype = "{0}{1}{2}".format(theform.intervalperiods[theform.intervalperiods.selectedIndex].text,(theform.mutitype.value=='1'?'＋':'×'),theform.doublemultiplecount.value);
//	}
//	
//	//alert(maxPeriodNum);
//	var totalChipinMoney = 0;
//	for(var i=1;i<=(maxPeriodNum+3);i++)
//	{	
//		//__addtype = GetStepMulti(i,addtype,mutitype,startMuti,intervalPeriod,mutiNum)
//		//var currentChipinMoney = GetStepMulti(i,addtype,mutitype,startMuti,intervalPeriod,mutiNum) * 2;
//		//__addtype=1;
//		//var currentChipinMoney=0;
//		
//		//totalChipinMoney += currentChipinMoney;
//		if(i > maxPeriodNum && i <= (maxPeriodNum+3))
//		{
//			bgcolor = '#efefef';
//		}
//		else if(i == maxPeriodNum)
//		{
//			bgcolor = '#ff9900';
//		}
//		else {
//			bgcolor = '#FFFFFF';
//		}
//		thisHTML += "\
//			<tr bgcolor='"+ bgcolor +"'>\
//			<td height='20' valign='top' align='center'>第 " + i + " 期</td>\
//			<td valign='top' align='center'>" + startMuti + "</td>\
//			</tr>\
//		";
//	}
//	thisHTML +=  "</table>";
//	//alert(thisHTML)
////				<td valign='top' align='right'>" + __addtype + "</td>\
////			<td valign='top' align='right'>" + currentChipinMoney + "</td>\
////			<td valign='top' align='right'>" + totalChipinMoney + "</td>\
////			<td valign='top' align='right'>" + currentChipinMoney*2 +  "</td>\
////			<td align='right' valign='top'>" + (currentChipinMoney*2 - totalChipinMoney) + "</td>\
//	return thisHTML;
//}

//showCustomWinForm = function(innerTxt,periodcount,x,y){
//	//alert(innerTxt)
//	if(winfmCus && $('dialogBoxBGMutil').style.display != 'none')
//	{
//		winfmCus.close();
//		winfmCus = null;
//		return;
//	}
//	alert("adas")
//	winfmCus = new winForm("dialogBoxBGMutil");
//	winfmCus.custom1('自定义倍数', innerTxt,null,periodcount*25,x,y);
//}

//setCustomWinForm = function(innerTxt,periodcount){
//	//alert(periodcount);
//	if(winfmCus)
//	{
//		var height = periodcount*25;
//		if(height>275)
//			height = 275;
//		winfmCus.set('content',innerTxt);
//		winfmCus.set('bodyheight',height);
//		winfmCus.set('dialogHeight',height);
//		winfmCus.set('height',height);
//	}
//}


getShouyi = function(form_name){
	
	var maxPeriodNum;
	//var theform = $(hxfa_Object._form_name);
	var theform = $(form_name);
	var txtPerNum	= theform.periodscount;
	var addtype = theform.addtype.value;
	var mutitype = theform.mutitype.value;
	var intervalPeriod		= parseInt(theform.intervalperiods.value);//间隔多少期加倍
	var startMuti			= parseInt(theform.startmultiple1.value);//起始倍数
	var mutiNum			= parseFloat(theform.doublemultiplecount.value);//乘法/加法加倍里的数	
	var agenttype=($("agenttype").value==4?4:1);
	if(txtPerNum.value==""){
		alert("请先输入加倍期数");
		return;
	}
	if(Config.surperiods<parseInt(txtPerNum.value))
	{
		alert("超过当天的生意运营期数，请重新选择");
		return;
	}
	else
		maxPeriodNum = parseInt(txtPerNum.value);
	
	var thisHTML = "";
	thisHTML = "\
	<table width='420' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>\
	<tr bgcolor='#E1E1E1'>\
	<td width='16%' height='17' align=center>中奖出现</td>\
	<td width='13%'>起始倍数</td>\
	<td width='13%' align=center>投注倍数</td>\
	<td width='20%' align=center>本期投入</td>\
	<td width='13%' align=center>累积投入</td>\
	<td width='13%' align=center>中奖奖金</td>\
	<td width='12%' align=center>收益值</td>\
	</tr>\
	";
	var startMuti			= parseInt(theform.startmultiple1.value);//起始倍数
	var _maxPerNum = 1;
	var addtype = theform.addtype.value;
	var bgcolor;
	var __addtype;
	if(addtype=="0"){
		__addtype = "平追";
	}else{
		__addtype = "{0}{1}{2}".format(theform.intervalperiods[theform.intervalperiods.selectedIndex].text,(theform.mutitype.value=='1'?'＋':'×'),theform.doublemultiplecount.value);
	}
	var totalChipinMoney = 0;
	for(var i=1;i<=(maxPeriodNum+3);i++)
	{	
		__addtype = GetStepMulti(i,addtype,mutitype,startMuti,intervalPeriod,mutiNum)
		var currentChipinMoney = GetStepMulti(i,addtype,mutitype,startMuti,intervalPeriod,mutiNum) * 2;
		//__addtype=1;
		//var currentChipinMoney=0;
		
		totalChipinMoney += currentChipinMoney;
		if(i > maxPeriodNum && i <= (maxPeriodNum+3))
		{
			bgcolor = '#efefef';
		}
		else if(i == maxPeriodNum)
		{
			bgcolor = '#ff9900';
		}
		else {
			bgcolor = '#FFFFFF';
		}
		thisHTML += "\
			<tr bgcolor='"+ bgcolor +"'>\
			<td height='20' valign='top' align='center'>第 " + i + " 期</td>\
			<td valign='top' align='center'>" + startMuti + "</td>\
			<td valign='top' align='right'>" + __addtype + "</td>\
			<td valign='top' align='right'>" + currentChipinMoney + "</td>\
			<td valign='top' align='right'>" + totalChipinMoney + "</td>\
			<td valign='top' align='right'>" + currentChipinMoney*2*agenttype +  "</td>\
			<td align='right' valign='top'>" + (currentChipinMoney*2*agenttype - totalChipinMoney) + "</td>\
			</tr>\
		";
	}
	thisHTML +=  "</table>";
	return thisHTML;
}
showWinForm = function(innerTxt,periodcount,x,y){
	if(winfm && $('dialogBoxBG').style.display != 'none')
	{
		winfm.close();
		winfm = null;
		return;
	}
	winfm = new winForm();
	winfm.custom1('收益计算器', innerTxt,null,periodcount*25,x,y);
}
setWinForm = function(innerTxt,periodcount){
	if(winfm)
	{
		var height = periodcount*25;
		if(height>275)
			height = 275;
		winfm.set('content',innerTxt);
		winfm.set('bodyheight',height);
		winfm.set('dialogHeight',height);
		winfm.set('height',height);
	}
}
rhzz_Object = {
	_MaxPerNum : 100,
	_PeriodMoney : [],
	_form_name : 'rhzz_form',
	_Surperiods : 145,
	SetPeriodCount  : function(){
		var theform = $(rhzz_Object._form_name);
		rhzz_Object._PeriodMoney = [];
		var ddlSMType		= theform.addtype;//平追/加倍：
		var ddlSMutiType	= theform.mutitype;//加倍方式：		
		var Muti					= parseInt(theform.startmultiple1.value);//起始倍数
		var intervalPeriod		= parseInt(theform.intervalperiods.value);//间隔多少期加倍
		var mutiNum			= parseFloat(theform.doublemultiplecount.value);//乘法/加法加倍里的数		
		var tempInterval	= intervalPeriod;
		var MutiArr = new Array(rhzz_Object._MaxPerNum+1);	
		var txtPerNum	= theform.periodscount;
		if(txtPerNum.value != "")
		{
			if(parseInt(rhzz_Object._Surperiods)<parseInt(txtPerNum.value))
			{
				alert("超过当天的生意运营期数，请重新选择");
				rhzz_Object._MaxPerNum = 1;
				return;
			}
			else
				rhzz_Object._MaxPerNum = parseInt(txtPerNum.value);
		}
		else
		{
			rhzz_Object._MaxPerNum = 1;
		}
		if(theform.addtype.value=='1' && theform.mutitype.value=='1'){
			if(!/^\d+(\.[0]+)?$/.test(theform.doublemultiplecount.value)){
			//if(!Common.detect.isInteger(theform.doublemultiplecount.value)){
				alert('如果加倍方式选择了加法，倍数必须是整数');
				theform.doublemultiplecount.value = 1;
				return;
			}
		}
		var curStepMulti=0;
		var incNum=0;
		for(i=1;i<=rhzz_Object._MaxPerNum;i++)
				{	
					if (ddlSMType.value == "0")//平追
					{
						MutiArr[i] = Muti;
					}
					else
					{
						if (i%intervalPeriod==0)
						{
							incNum=parseInt(i/intervalPeriod);
						}
						else
						{
							incNum=parseInt(Math.ceil(i/intervalPeriod));
						}
						if (ddlSMutiType.value == "1")//加法
						{
							curStepMulti=parseInt(Muti)+parseInt(Math.round((incNum-1)*mutiNum));
						}
						else//乘法
						{
							curStepMulti=Math.round(Muti*Math.pow(mutiNum,incNum-1));		
						}						
						MutiArr[i]=curStepMulti;
					}
					rhzz_Object._PeriodMoney.push(MutiArr[i] * 2);
				}
			rhzz_Object.SetLabel();		
	},
	SetLabel : function(){
		var totalMoney = 0;				
		var theform = $(rhzz_Object._form_name);
		var txtPerNum	= theform.periodscount;
		var totalMoney = 0;//统计钱数			
		rhzz_Object._PeriodMoney.each(function(money){
			totalMoney += money;
		});
		Element.update('rhzz_ChipinMoney',totalMoney);
		theform.totalprice.value = totalMoney;
	},
	form_changed : function(element,value){
		if(Common.detect.isInteger(element.periodscount.value) && 
				(Common.detect.isInteger(element.c_min.value)) && 
				(Common.detect.isInteger(element.c_max.value))
			 ){
			rhzz_Object.SetPeriodCount();			
		}
	},
	periodscount_changed : function(element,value){
		if(Common.detect.isInteger(element.value)){
			Element.update('rhzz_spanProNum',element.value);
		}
	},
	validate : function(theform){
		if(theform.ProjectName.value==""){
			alert('方案名称不能为空');
			Common.setFocus(theform.ProjectName);
			return false;
		};
		if(!Common.detect.isInteger(theform.c_min.value)){
			alert('您输入的含羞次数的最小值不是有效的整数');
			Common.setFocus(theform.min);
			return false;
		}
		if(!Common.detect.isInteger(theform.c_max.value)){
			alert('您输入的含羞次数的最大值不是有效的整数');
			Common.setFocus(theform.c_max);
			return false;
		}
		if(!Common.detect.isInteger(theform.maxnumbers.value)){
			alert('您输入的最多执行次数不是整数');
			Common.setFocus(theform.maxnumbers);
			return false;
		}
		if(!Common.detect.isInteger(theform.periodscount.value)){
			alert('追号期数不是整数');
			Common.setFocus(theform.periodscount);
			return false;
		}
		/*if(theform.avoidnumbers.value!=''){
			if(){
				
			Common.setFocus(theform.avoidnumbers);
				return false;
			}
		}*/
		if(theform.addtype.value=="1"){
			if(!Common.detect.isDouble(theform.doublemultiplecount.value)){
				alert('您输入的加倍方式里的倍数不是有效的数字');
				Common.setFocus(theform.doublemultiplecount);
				return false;
			}
		}
		if(Common.detect.isEmpty(theform.dealpassword.value)){
			alert('请输入操作密码');
			Common.setFocus(theform.dealpassword);
			return false;
		}
		if(!theform.AcceptAgreement.checked){
			alert(Config.unDelegateRule);
			return false;
		}
		return true;
	}
}
bind_rhzz_event = function(){
	FormSubmit({
		theform : rhzz_Object._form_name,
		checkf : rhzz_Object.validate,
		callback : function(result){
			alert(result);
		}
	});
};
rhzz_Submit = function(value){
	$('rhzz_form').draft.value = value;
	bind_rhzz_event();
};

var currentListType = 'qbfa';
getPlanDetail = function(PlanID,id){
	var pars = "PlanID=" + PlanID + "&t=" + Math.random();
	$.updater('plandetail','Plan/planDetail.aspx',pars,function(){
				cur_plandetail_id = id;
				toggle(id,'plandetail');
	});	
};
getHistoryList = function(planID,page){
	var pars = "PlanID=" + planID + '&page=' + page + '&t=' + Math.random();
	$.updater('jobhistorylist','Plan/jobhistorylist.aspx',pars,function(){
				toggle(currentListType + '_list','jobhistorylist');
	});		

};
getJobDetail = function(jobid,page){
	var pars = "jobid=" + jobid + '&=page' + page;
	$.updater('jobdetaillist','Plan/planChipinDetail.aspx',pars,function(){
				toggle('jobhistorylist','jobdetaillist');
	});	
};
planDelete = function(planid){
	if(!confirm('确定要删除该方案吗？')){
		return;
	}
	var url = '/Happy8/V2/plan/planDel.aspx';
	var pars = 'planid=' + planid;
	$.request(url,pars,function(req){
				var result = req.responseText;
				parseResult(result,function(re){
						var hash = re.toQueryParams();
						if(hash['result']=='001'){
							alert(hash['msg']);
						}
						else
						{
							alert('操作成功');
							$.updater(currentListType + '_list','/Happy8/V2/Plan/allPlanList.aspx?t=' + Math.random(),1);
						}
				});
	});
};
planCopy = function(planid){
	$.updater('c1012_5','/Happy8/V2/consign.aspx?cmd=dqzh&id=' + planid,'',function(){
				toggle(currentListType + '_list','c1012_5');
	});	
};
changePlanStatus = function(planid,orignalstatus){
		var url = '/Happy8/V2/plan/planDetail.aspx?action=update&status=' + orignalstatus + '&planid=' + planid + '&t=' + Math.random();
		alert(url);
		new Ajax.Request(
				url,
				{
					method: 'get',
					parameters: '',
					onComplete: function(req){
						var result = req.responseText;		
						parseResult(result,function(res){
							alert(res);
							if(res.substring(0,10) == 'result=001'){
								var h = res.toQueryParams();
								alert(h['msg']);
							}else{
								alert('操作成功');
								var file = (currentListType == 'qbfa' ? 'allPlanList':'availplanlist.aspx');
								$.updater(currentListType + '_list','Plan/' + file + '.aspx?t=' + Math.random(),1);
								toggle('plandetail',currentListType + '_list');
							}
						});
					}
				}
		);
	}
	
GetStepMulti=function(pernum,addtype,mutitype,startMuti,intervalPeriod,mutiNum)
{
	var curStepMulti = 0;
	var incNum = 0;

	if (addtype == "0")//平追
	{
		curStepMulti = startMuti;
	}
	else
	{
		if (pernum%intervalPeriod==0)
		{
			incNum = pernum/intervalPeriod;
		}
		else
		{
			incNum = parseInt(Math.ceil(pernum/intervalPeriod));
		}
		if (mutitype == "1")
		{
			curStepMulti=startMuti+parseInt(Math.round((incNum-1)*mutiNum));
		}
		else
		{
			curStepMulti=Math.round(startMuti*Math.pow(mutiNum,incNum-1));		
		}						
	}
	return curStepMulti;
}



var patrn	= /^\d{1,2}$/;
//检验是否是两位数字和1-80之间的数
function CheckNum(num)
{
	var min = 1;
	var max = 80;
	var res = num + "|";
	if(!patrn.exec(num))
	{	
		res = "";
	}
	else if(parseFloat(min) > parseFloat(num) || parseFloat(max) < parseFloat(num))
	{	
		res = "";
	}
	if(res == "")
		return res;
	if(num.length == 1)
	{
		res = "0" + num +"|";
	}
	return res;
}
//检查有没有重复数字
function CheckRepeat(numbers)
{
	var i,j;
	var s = numbers.split('|');
	var res = "";
	var IsRepeat = false;
	for(i=0;i<s.length;i++)
	{
		IsRepeat = false;
		for(j=i+1;j<s.length;j++)
		{
			if(parseFloat(s[i])==parseFloat(s[j]))
			{	
				IsRepeat = true;
				break;
			}
		}
		if(!IsRepeat)
		{
			res += s[i] + "|";
		}
	}
	res = res.substring(0,res.length-1);
	return res;
}
//数字排序
function SortNumber(values)
{
	var arr = values.split('|');
	arr.sort();
	return arr.join('|');
}
