var ballonselectclassname = "ball_b"; //球被选中样式
var ballunselectclassname = "ball_r"; //球未选中样式
var zhushu = 0; 

var codeshowspliter = "\r\n";
var codesreg = /\r\n/g;
var codesfinallyspliter = "$";



var	topindex = parent;


var login = parent.iframe_login;
var tradetop = parent.iframe_dg_top;
var middle = parent.iframe_dg;
var bottom = parent.iframe_dg_bottom;
var todayopen = parent.iframe_todayopencode;

var lottype;
var playtype;
var username;
var usertypename;
var usermoney;

var beishutdindex=0;

//
var EndOverSecond=0;
//var TouzhuExpectType = 1;



function show_money()
{//统计选择的期号数、每期投注金额、总金额并显示	
	SetExpectBeishu();
	var singlezhushu = parent.iframe_dg.zhushu;
	if(singlezhushu==null)
	{
		singlezhushu = 0;
	}
	if (parent.iframe_dg.document.getElementById("singlezhushushow")!=null)
	{
		parent.iframe_dg.document.getElementById("singlezhushushow").innerText = singlezhushu;
	}
	if (parent.iframe_dg.document.getElementById("singlemoneyshow")!=null)
	{
		parent.iframe_dg.document.getElementById("singlemoneyshow").innerText = singlezhushu*2;
	}
	
	var expectlistsuc1 = parent.iframe_dg.document.all("expectlistsuc1").value;
	var expectlistsuc2 = parent.iframe_dg.document.all("expectlistsuc2").value;
	var expectlistsuc3 = parent.iframe_dg.document.all("expectlistsuc3").value;
	var beishulistsuc1 = parent.iframe_dg.document.all("beishulistsuc1").value;
	var beishulistsuc2 = parent.iframe_dg.document.all("beishulistsuc2").value;
	var beishulistsuc3 = parent.iframe_dg.document.all("beishulistsuc3").value;
	
	var expectlistsuc=JoinExpect(expectlistsuc1,expectlistsuc2,expectlistsuc3);
	var beishulistsuc=JoinBeishu(beishulistsuc1,beishulistsuc2,beishulistsuc3)
	
	var expectlistsucArr = expectlistsuc.split(",");
	var beishulistsucArr = beishulistsuc.split(",");
	//alert(expectlistsuc+"|"+beishulistsuc+"haha");
	var expectnum = 0;
	var allmoney = 0;
	if(expectlistsuc.length>0)
	{
		expectnum = expectlistsucArr.length;
	}
	var expectmoneyshow = parent.iframe_dg_bottom.document.all("expectmoneyshow");
	var expect_hidden = parent.iframe_dg_bottom.document.all("expect_hidden");
	var beishu_show = parent.iframe_dg_bottom.document.all("beishu_show");
	if(expect_hidden!=null)
	{
		for(var i=0;i<expect_hidden.length;i++)
		{
			var expectmoney = beishu_show[i].value*2*singlezhushu;
			expectmoneyshow[i].value = expectmoney;
		}
	}
	for(var i=0;i<expectlistsucArr.length;i++)
	{
		var expectmoney = beishulistsucArr[i]*2*singlezhushu;
		allmoney = allmoney+expectmoney;
	}
	
	if (parent.iframe_dg.document.all("expectnumshow")!=null)
	{
		parent.iframe_dg.document.all("expectnumshow").innerText = expectnum;
	}
	if (parent.iframe_dg.document.all("allmoneyshow")!=null)
	{
		parent.iframe_dg.document.all("allmoneyshow").innerText = allmoney;
	}
	return;
}

function SetIsStop()
{//根据是否追号设置中奖后是否停止追号
	 var IsZhuihao = parent.iframe_dg.document.all("IsZhuihao");
	 var ZjCut = parent.iframe_dg.document.all("ZjCut");
	 if(IsZhuihao.checked)
	 {
		if(!topindex.CustomIsSetNotStop)
		{
			ZjCut.checked = true;
		}
		ZjCut.disabled = false;
	 }
	 else
	 {
		 ZjCut.checked = false;
		 ZjCut.disabled = true;
	}
}
function CustomSetNotStop()
{
	 var ZjCut = parent.iframe_dg.document.all("ZjCut");
	 if(!ZjCut.checked)
	 {
		 topindex.CustomIsSetNotStop = true;
	 }
	 else
	 {
		 topindex.CustomIsSetNotStop = false;
	 }
}
function SetIsZhuihao()
{
	var IsZhuihao = parent.iframe_dg.document.all("IsZhuihao");
	var ZjCut = parent.iframe_dg.document.all("ZjCut");
	if(IsZhuihao.checked)
	{
		if(!topindex.CustomIsSetNotStop)
		{
			ZjCut.checked = true;
		}
		ZjCut.disabled = false;
	}
	else
	{
	 	ZjCut.checked = false;
	 	ZjCut.disabled = true;
		clear_expectbeishu();
		topindex.FirstLoadTouzhuExpect = true;
		//topindex.SelectTouzhuExpectType(1);
	}
}

function SystemSetIsZhuihao()
{
	var IsZhuihao = middle.document.all("IsZhuihao");
	 var ZjCut = middle.document.all("ZjCut");
	 if(IsZhuihao.checked)
	 {
		ZjCut.checked = true;
		ZjCut.disabled = false;
	 }
	 else
	 {
		ZjCut.checked = false;
		ZjCut.disabled = true;
	 }
}


function check_fsdg()
{//提交检测
     if(parent.strlogin!="ok"){
        alert("您还没有登录,请在登陆之后继续代购！");
		return;
	//	parent.loginer.richlogin.account.focus();
		
	}
	/*if(!topindex.ExpectIsSale)
	{
		alert(topindex.ExpectStateInfo);
		return;
	}*/

	if (!middle.document.all("confirmxy").checked)
	{
		alert("同意《用户合买代购协议》才能投注");
		return;
	}
	var codes = get_codeshow();
	middle.document.all("codes").value=codes;
	//var texts = get_codeshow_text();	
	if(codes=="")
	{
		alert("您还没有选择号码");
		return;
	}
	if(middle.expectnumshow.innerText=="0"){
		alert("您还没有选择期数");
		return;
	}
	if((codes.length-codes.replace(/\;/g,"").length)>=5)
	{
		alert("投注内容不能超过5行");
		return;
	}
	if(Number(middle.zhushu)<=0)
	{
		alert("您选择的号码不正确");
		return;
	}

	var IsZhuihao = middle.document.all("IsZhuihao");
	if(IsZhuihao.checked) {
		IsZhuihao.value="1";
	}else {
		IsZhuihao.value="0";
	}
	var ZjCut=middle.document.all("ZjCut");
	if(ZjCut.checked) {
		ZjCut.value="1";
	}else {
		ZjCut.value="0";
	}
	var allmoney = middle.allmoneyshow.innerText;
	middle.document.all("shares").value=middle.singlezhushushow.innerText;
	var obj_bet_rid=bottom.document.all("checkbeishu");
	var value_bet_rid="";
	var obj_beishu=bottom.document.all("beishu_show");
	var value_beishu="";
	if(obj_bet_rid.length>0){
		for(var i=0;i<obj_bet_rid.length;i++){
			 if(obj_bet_rid[i].checked){
				value_bet_rid+=obj_bet_rid[i].value+"|";
				value_beishu+=obj_beishu[i].value+"|";
			}
 		}
	}else{
	 	  value_bet_rid+=obj_bet_rid.value+"|";
		  value_beishu+=obj_beishu.value+"|";
	}

	
	middle.document.all("bet_rid").value=value_bet_rid.substring(0,value_bet_rid.length-1);
	middle.document.all("beishu").value=value_beishu.substring(0,value_beishu.length-1);
	//alert("请确认您的投注信息\n\r\n\r选号内容："+codes+"\n\r\n\r\n\r总金额："+allmoney+"元"+middle.document.all("bet_rid").value+"<==>"+middle.document.all("beishu").value);
	
	var mode = middle.document.form1.tzfangshi.value;//投注方式
	if(mode == 1) {//复式投注
		middle.document.form1.action="../member/sslCgCommit.do?IsZhuihao="+IsZhuihao.value+"&ZjCut="+ZjCut.value;
	} else if(mode == 2) {
		middle.document.form1.action="../member/sslHzCommit.do?IsZhuihao="+IsZhuihao.value+"&ZjCut="+ZjCut.value;
	} else if(mode == 3) {
		middle.document.form1.action="../member/sslBhCommit.do?IsZhuihao="+IsZhuihao.value+"&ZjCut="+ZjCut.value;
	}
	middle.document.form1.target="iframe_ssl";
	middle.document.form1.submit(); 
	clear_all();
	
	/*var buymode = 0;
	if(texts.indexOf("自选")>0 && texts.indexOf("机选")>0)
	{
		buymode=8;
	}
	else if(texts.indexOf("自选")>0)
	{
		buymode=0;
	}
	else if(texts.indexOf("机选")>0)
	{
		buymode=1;
	}
	else
	{
		alert("参数错误：购买方式");
		return;
	}
	
	var expectlistsuc1 = middle.document.all("expectlistsuc1").value;
	var expectlistsuc2 = middle.document.all("expectlistsuc2").value;
	var expectlistsuc3 = middle.document.all("expectlistsuc3").value;
	var beishulistsuc1 = middle.document.all("beishulistsuc1").value;
	var beishulistsuc2 = middle.document.all("beishulistsuc2").value;
	var beishulistsuc3 = middle.document.all("beishulistsuc3").value;
	var expectlistsuc=JoinExpect(expectlistsuc1,expectlistsuc2,expectlistsuc3);
	var beishulistsuc=JoinBeishu(beishulistsuc1,beishulistsuc2,beishulistsuc3)
	//alert(expectlistsuc+"|"+beishulistsuc);
	if(expectlistsuc=="" || beishulistsuc=="")
	{
		alert("请选择您要投注的期号");
		return;
	}
	//alert(expectlistsuc+","+beishulistsuc);
	var playname = middle.document.all("playname").value;
	var allmoney = middle.allmoneyshow.innerText;
	var expectnum = middle.document.all("expectnumshow").innerText;
	
	
	if(confirm("请确认您的投注信息\n\r\n\r玩法："+playname+"\n\r期数：共"+expectnum+"期\n\r总金额："+allmoney+"元"))
	{
		middle.document.all("Submit").disabled = true;
		var playtype = middle.document.all("playtype").value;
		var ZjCut=0;
		if (middle.document.all("ZjCut")!=null)
		{
			if (middle.document.all("ZjCut").checked)
			{
				ZjCut=1;
			}
		}
		//alert(ZjCut);
		var url,addurl;
		var tmp = new Date();
		tmp = tmp.toString();
		var buyExpect = "";
		if(tradetop.document.all("buyExpectShow")!=null)
		{
			buyExpect = tradetop.document.all("buyExpectShow").innerText;
		}
		//alert(buyExpect);
		addurl = "buyExpect="+buyExpect+"&codes="+codes+"&expectlistsuc="+expectlistsuc+"&beishulistsuc="+beishulistsuc+"&buymode="+buymode+"&playtype="+playtype+"&ZjCut="+ZjCut+"&tmp="+tmp;
		//alert(addurl);
		//return;
		url = "/b_trade/sl/trade/step_suc_new.asp";
		//open(url,"","");

		var ajaxobj=new AJAXRequest(); 
		ajaxobj.url=url;
		ajaxobj.content = addurl;
		ajaxobj.callback=function(xmlobj)
		{
			var result = gb2utf8(xmlobj.responseBody);
			if (result=="0")
			{
				if(expectnum>1)
				{
					alert("成功发起追号任务");
				}
				else
				{
					alert("成功发起方案");
				}
				
				//清空
				middle.zhushu = 0;//注数清0
				clear_expectbeishu();//清空倍数期号
				middle.clear_selectedball();//投注号码清除
				clear_codesshow();//投注内容清空
				//selectallbeishu(false);//清空倍数显示
				topindex.FirstLoadTouzhuExpect = true;
				topindex.SelectTouzhuExpectType(1);
				show_money();//统计显示
				
				topindex.SetCostHTML();
				
				//topindex.ShowMyTouzhu();
				
				if(expectnum>1)
				{
					topindex.touzhu.document.location.href = "/info/ssl/zhuhaomy.asp";
					//topindex.touzhu.document.location.reload();
				}
				else
				{
					topindex.touzhu.document.location.href = "/info/ssl/touzhumy.asp";
					//topindex.touzhu.src = "/info/ssl/touzhumy.asp";
				}
				//alert(topindex.touzhu.src);
				topindex.document.all("selectallbieshu").value = 1;
				
				middle.document.all("Submit").disabled = false;
			}
			else
			{
				alert(result);
				middle.document.all("Submit").disabled = false;
			}

		}
		ajaxobj.send();
	}*/
}

function showcode()
{
	var tbobj=event.srcElement.parentElement.parentElement.parentElement.parentElement;
	var alltbobj=document.all("tb_code");
	if(alltbobj[0]==null)
	{
		if(alltbobj.rows[0].style.display=="")
		{
			alltbobj.rows[0].style.display="none";
			alltbobj.rows[1].style.display="";
			//alltbobj.rows[1].cells[0].className="codeshow";
		}
		else
		{
			alltbobj.rows[0].style.display="";
			alltbobj.rows[1].style.display="none";
		}
	}
	for(var i=0;i<alltbobj.length;i++)
	{
		if(alltbobj[i]!=tbobj)
		{
			alltbobj[i].rows[0].style.display="";
			if(alltbobj[i].rows[1]!=null)
			{
				alltbobj[i].rows[1].style.display="none";
			}
		}
		else
		{
			if(alltbobj[i].rows[0].style.display=="")
			{
				alltbobj[i].rows[0].style.display="none";
				alltbobj[i].rows[1].style.display="";
				//alltbobj[i].rows[1].cells[0].className="codeshow";
			}
			else
			{
				alltbobj[i].rows[0].style.display="";
				alltbobj[i].rows[1].style.display="none";
			}
		}
	}
}

function ViewTouzhuOrZhuihao(str)
{
	if(str=="zhuihao")
	{
		topindex.touzhu.document.location.href = "/info/ssl/zhuhaomy.asp";
	}
	else if(str=="touzhu")
	{
		topindex.touzhu.document.location.href = "/info/ssl/touzhumy.asp";
	}
}

function getRndNum(min,max)
{//生成一个min到max的随机整数
	return Math.round((max-min)*Math.random()+min);
}

function get_codeshow()
{
	codesshow = middle.document.all("codesshow");
	var codes = "";
	for (var i=0; i<codesshow.options.length; i++)
	{
		var option = codesshow.options[i];
		var code = option.value;
		codes = codes+code+";"
	}
	codes = codes.substr(0,codes.length-1);
	return codes;
}
function get_codeshow_text()
{
	codesshow = middle.document.all("codesshow");
	var codes = "";
	for (var i=0; i<codesshow.options.length; i++)
	{
		var option = codesshow.options[i];
		var code = option.text;
		codes = codes+code+";"
	}
	codes = codes.substr(0,codes.length-1);
	alert("++++++++"+codes);
	return codes;
}

function clear_codesshow()
{//清空投注内容
	middle.document.all("codesshow").length = 0;
	return;
}
function f_frameStyleResize(targObj)
{
	var targWin = targObj.parent.document.all[targObj.name];
	if(targWin != null) 
	{
		var HeightValue = targObj.document.body.scrollHeight
		/*if(HeightValue < 50)
		{
			targObj.location.reload();
		}*/
		targWin.style.pixelHeight = HeightValue;
	}
}

function BeforePaste()
	{//禁止粘贴功能
		return clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''));
	}



function del_tabdata2(tabdata)
{
//删除tabdata_fu中的全部数据
	var	row_all = tabdata.rows.length;
	if (row_all > 1)
	{
		for(var i = 1;i<= row_all - 2;i++)
		{
			tabdata.deleteRow(1) ;
		}
	}
}
function get_todaystring()
{
	var year,month,day;
	var jt = new Date();
	year=jt.getUTCFullYear ();
    if((parseInt(jt.getMonth())+1).toString().length<2)
	{
	month="0"+(jt.getMonth() + 1);
	}
	else
	{
	month=jt.getMonth() + 1;
	}
	if(jt.getDate().toString().length<2) 
	{
	day="0"+jt.getDate();
	}
	else
	{
	day=jt.getDate();
     }
	 
	 return year.toString()+month.toString()+day.toString();
}
function del_tabdata(tabdata,startiline)
{
//删除tabdata_fu中的全部数据
	var	row_all = tabdata.rows.length;
	if (row_all > startiline)
	{
		for(var i = startiline;i<= row_all - 1;i++)
		{
			tabdata.deleteRow(startiline) ;
		}
	}
}


function select_singleball_byobj(obj,playname)
{
	var code = obj.innerText;
	if (code=="")
	{
		return;
	}
	select_singleball_bynum(code,playname);
}

function select_singleball_bynum(num,playname)
{
	//var obj = middle.document.all("ball")[num];
	//select_singleball(obj);
	//add_line_self();
	add_line_coldcode(num,playname);
}


//日期转化为字符串格式： yyyy-mm-dd
function DateToStr(dt){
var str="";
if(dt.getFullYear){
  var y,m,d;
  y=dt.getFullYear();
  m=dt.getMonth()+1;  //1-12
  if(m<10)
	{
	  m = "0"+m.toString();
	}
 
  d=dt.getDate();
  if(d<10)
	{
	  d = "0"+d.toString();
	}
  str=""+y+"-"+m+"-"+d;
}
return str;

}

function returnchild(zcid)
{
	if(!confirm("您确定要取消该期追号吗？"))
	{
		return;
	}
	var url = "/b_trade/sl/trade/returnchild.asp?zcid="+zcid;
	//alert(url);
	var ajaxobj=new AJAXRequest(); 
	ajaxobj.url=url;
	ajaxobj.callback=function(xmlobj)
	{
		var result = gb2utf8(xmlobj.responseBody);
		if (result=="0")
		{
			//$(spanid).innerHTML="已撤单"; 
			alert("撤单成功");
			document.location.reload();
		}
		else
		{
			alert(result);
		}
	}
	ajaxobj.send();
}

function returnmain(zmid)
{
	if(!confirm("您确定要终止整个追号任务吗？"))
	{
		return;
	}
	var url = "/b_trade/sl/trade/returnmain.asp?zmid="+zmid;
	//alert(url);
	var ajaxobj=new AJAXRequest(); 
	ajaxobj.url=url;
	ajaxobj.callback=function(xmlobj)
	{
		var result = gb2utf8(xmlobj.responseBody);
		if (result=="0")
		{
			//$(spanid).innerHTML="已撤单"; 
			alert("成功终止任务");
			document.location.reload();
		}
		else
		{
			alert(result);
		}
	}
	ajaxobj.send();
}

function SelectColdCode()
{
}

function DateAdd(interval,number,date){ 
// date 可以是时间对象也可以是字符串，如果是后者，形式必须为: yyyy-mm-dd hh:mm:ss 其中分隔符不定。"2006年12月29日 16点01分23秒" 也是合法的
    number = parseInt(number);
    if (typeof(date)=="string"){
        date = date.split(/\D/);
        --date[1];
        eval("var date = new Date("+date.join(",")+")");
    }
    if (typeof(date)=="object"){
        var date = date
    }
    switch(interval){
        case "y": date.setFullYear(date.getFullYear()+number); break;
        case "m": date.setMonth(date.getMonth()+number); break;
        case "d": date.setDate(date.getDate()+number); break;
        case "w": date.setDate(date.getDate()+7*number); break;
        case "h": date.setHours(date.getHour()+number); break;
        case "n": date.setMinutes(date.getMinutes()+number); break;
        case "s": date.setSeconds(date.getSeconds()+number); break;
        case "l": date.setMilliseconds(date.getMilliseconds()+number); break;
    } 
    return date;
}

//去左空格; 
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
} 
//去左右空格; 
function trim(s){ 
return rtrim(ltrim(s)); 
}

function submit_href(urlStr,imgName){
	var imgSrc1=["img/tz_zx_1.gif","img/tz_z6_1.gif","img/tz_z3_1.gif","img/tz_q1_1.gif","img/tz_h1_1.gif","img/tz_q2_1.gif","img/tz_h2_1.gif"];
	var imgSrc2=["img/tz_zx_2.gif","img/tz_z6_2.gif","img/tz_z3_2.gif","img/tz_q1_2.gif","img/tz_h1_2.gif","img/tz_q2_2.gif","img/tz_h2_2.gif"];
	var heightNum=[370,265,265,370,370,370,370];
	var heightNum1=[160,265,265,160,160,160,160];
	var num=Number(imgName.substring(imgName.length-1,imgName.length));
	for(var i=1;i<=7;i++){
		if(i==num){
			document.all("Image0"+i).src=imgSrc1[i-1];
		}else{
				document.all("Image0"+i).src=imgSrc2[i-1];
		}
	}
	document.all("iframe_dg").src=urlStr;
	document.all("iframe_dg").height=heightNum[num-1];
	document.all("iframe_dg_bottom").height=heightNum1[num-1];
	document.all("iframe_dg").location;
}

function submit_parent_href(urlStr,re){
	if("sslzhix_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=370;
		parent.document.all("iframe_dg_bottom").height=160;
	}
	else if("sslzhix_hz.jsp"==urlStr){
		parent.document.all("iframe_dg").height=300;
		parent.document.all("iframe_dg_bottom").height=230;
	}
	else if("sslzhix_bh.jsp"==urlStr){
		parent.document.all("iframe_dg").height=270;
		parent.document.all("iframe_dg_bottom").height=260;
	}
	else if("sslzux6_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=265;
		parent.document.all("iframe_dg_bottom").height=265;
	}
	else if("sslzux6_hz.jsp"==urlStr){
		parent.document.all("iframe_dg").height=295;
		parent.document.all("iframe_dg_bottom").height=235;
	}
	else if("sslzux3_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=265;
		parent.document.all("iframe_dg_bottom").height=265;
	}
	else if("sslzux3_hz.jsp"==urlStr){
		parent.document.all("iframe_dg").height=285;
		parent.document.all("iframe_dg_bottom").height=245;
	}
	else if("sslqian1_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=370;
		parent.document.all("iframe_dg_bottom").height=160;
	}
	else if("sslhou1_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=370;
		parent.document.all("iframe_dg_bottom").height=160;
	}
	else if("sslqian2_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=370;
		parent.document.all("iframe_dg_bottom").height=160;
	}
	else if("sslqian2_bh.jsp"==urlStr){
		parent.document.all("iframe_dg").height=270;
		parent.document.all("iframe_dg_bottom").height=260;
	}
	else if("sslhou2_fs.jsp"==urlStr){
		parent.document.all("iframe_dg").height=370;
		parent.document.all("iframe_dg_bottom").height=160;
	}
	else if("sslhou2_bh.jsp"==urlStr){
		parent.document.all("iframe_dg").height=270;
		parent.document.all("iframe_dg_bottom").height=260;
	}
	if(re){
		parent.document.all("iframe_dg").src=urlStr;
		parent.document.all("iframe_dg").location;
	}
}