﻿$(document).ready(function(){
	 LoadJs("/data/24/html/lastest"+$("#drawno").val()+".js","default");
})

function bindDrawlist(listinfo){
   bindlatestDraws(listinfo);
  $("#drawno").change(function(){//添加onchange事件  
  LoadJs("/data/24/html/lastest"+$("#drawno").val()+".js","latest");
$("tr").remove(".uncontent"); 
   $("#hitnum").children().text(0);
  $("#hitnum td:first-child").text("出现次数");
  //$("#hitnum td:first-child").next().text("");
  $("#hitnum td:last-child").text("");
  //alert("/data/1/html/lastest"+$("#drawno").val()+".js")
 })
   
}

function bindlatestDraws(listinfo){
		//$("#bufferImg").hide();
	$("#hitnum").hide();
	var drawSort = new Array();
	var resultSort = new Array();
	var timeSort = new Array();
	for(var i=0;i<listinfo.drawnos.length;i++)
	{
		drawSort.push(listinfo.drawnos[i].drawno);
		resultSort.push(listinfo.drawnos[i].result);
		timeSort.push(listinfo.drawnos[i].drawtime);
	}
	drawSort.sort();
	resultSort.sort();
	timeSort.sort();
    //for(var i=listinfo.drawnos.length-1;i > -1;i--)
	for(var i=0;i<listinfo.drawnos.length;i++)
    {
    var tempRow = $("#bottomLine").clone(); 
						$(tempRow).addClass("uncontent");
            var c =$(tempRow).find("td");
            $(c).empty();
            $(c).removeAttr("style");
             $(c).eq(0).text(listinfo.drawnos[i].drawno);
             if(listinfo.drawnos[i].result!="-")
             {
             	var reg = /[\s+]/;  
             var s = listinfo.drawnos[i].result.split(reg);
            // alert(s);
             for(var j =0;j<s.length;j++)
             {
             	
             	$(c).eq(parseInt(s[j],10)).text(s[j]);
             	//if(j==(s.length-1))
             //	{
             		//$(c).eq(parseInt(s[j],10)).removeAttr("style");
             	// $(c).eq(parseInt(s[j],10)).attr("style","background-color:#005fa2;color:#fff;");
             //	}
             hitnum(0,s[j]);
             	}
             
            }
            $(c).eq(34).text(listinfo.drawnos[i].drawtime);
             $("#headLine").after(tempRow);
    }
   var maxn= 0;
   for(p=1;p<34;p++)
    {
    	
    	var m;
    	if(p<10)
    	{
    		m="0"+p;
    	}
    	else
    	{
    		m=p;
    		}
    	var num = $("#num0"+"_"+m).text();
    	if(num>maxn)
    	maxn=num;
    	}
    for(n=1;n<34;n++)
    {
    	 var m;
    	if(n<10)
    	{
    		m="0"+n;
    	}
    	else
    	{
    		m=n;
    		}
    	var num = $("#num0"+"_"+m).text();

    	//alert($("#num"+0+"_"+n).html());
    	var ht = num/maxn*100+"%";
    	//alert(ht);

     var tb=	"<table id="+"bg0_"+m+" style=\"width:100%; height:"+ht+"; border:0;\""
     +"cellpadding=\"0\" cellspacing=\"0\"><tr><td style=\"background-color:#e62c34;\"></td></tr></table>";
    	
    	$("#num0"+"_"+m).append(tb);
    	
    	}
    	//alert($("#hitnum").html());
    	$("#bufferImg").hide();
	$("#hitnum").show();
}
function hitnum(i,j)
{
	var num = $("#num"+i+"_"+j).text();
	//alert(num);
	//if(num==''||num=='NaN'||num==null||num=="元素文本")
	//{
	//	$("#num"+i+"_"+j).text(1);
 
//}
//else
//{
  $("#num"+i+"_"+j).text(parseInt(num)+parseInt(1));
//}
}
function LoadJs(jspath,bindtype){
	var dt = new Date();
	$.get(jspath,{'dt': dt.toTimeString()},function(data, status){//获取指定js文件的内容
    if(status=='success'){
    var listinfo=eval(data); //字符串转化为json对象 
    if(bindtype=="default"){
       bindDrawlist(listinfo);}
       else if(bindtype=="latest"){
      	  bindlatestDraws(listinfo);}
  }
  else
      alert('指定历史奖期文件不存在！');
})
}
