﻿var select = function(pid,ptb,gn){
    var color = $("#tpcolor").val();
    var fgnum = $("#tpnum").val();
    var tppid = pid.split(",");
    for(var j=0;j<tppid.length;j++)
    {
        var tptr = $("#"+tppid[j]);
        tptr.children("td.stwhite,td.styellow").each(function(i){
            $(this).click(function(){selectML(this,i,color,fgnum,ptb,gn)});
        });
    }
    if(!gn)
    {$("#lotcid").val("-1");}
}
var selectML = function(obj,i,color,fgnum,ptb,gn){
    var tptd = $(obj);
    var tpcolor = color.split(",");
    var tpnum = fgnum.split(",");
    var tpval;
    for(var j=0;j<tpnum.length;j++)
    {
        if(i<parseInt(tpnum[j]))
        {
            if(tptd.html().length<10)
            {
                tpval = tptd.html();
                if(ptb==0)
                {
                    tptd.html("<div class=\"selectNum" + tpcolor[j] + "\">" + tpval + "</div>");
                }
                else
                {
                    tptd.html("<div class=\"selectBK" + tpcolor[j] + "\">" + tpval + "</div>");
                }
            }
            else
            {
                tpval = tptd.children("div").text();
                tptd.html(tpval);
            }
            break;
        }
    }
    if(gn)
    {getMLvalue(obj,fgnum);}
}
var getMLvalue = function(obj,fgnum){
    $("#cll").removeAttr("disabled");
    var tptr = $(obj).parent();
    var tptd = tptr.children("td.stwhite,td.styellow");
    var tpnum = fgnum.split(",");
    var liminti = 0;
    var lotid = $("#lotcid").val();
    for(var i=0;i<tpnum.length;i++)
    {
        var T_number = "";
        var numval = $("#" + tptr.attr("id") + "num");
        if(i==0)
        {
            for(var j=0;j<parseInt(tpnum[i]);j++)
            {
                var tp = tptd.eq(j);
                if(tp.html().length>9)
                {
                    liminti++;
                    T_number = T_number.length > 0 ? T_number + "," + tp.children("div").text() : tp.children("div").text(); 
                }
            }
            if(lotid==4&&liminti>20)
            {$("#cll").attr("disabled","disabled");alert("双色球每组模拟选号红球最多只能选20个号码！");return;}
            if(lotid==12&&liminti>20)
            {$("#cll").attr("disabled","disabled");alert("大乐透每组模拟选号前区最多只能选20个号码！");return;}
            numval.val(T_number);
        }
        else
        {
            for(var j=parseInt(tpnum[i-1]);j<parseInt(tpnum[i]);j++)
            {
                var tp = tptd.eq(j);
                if(tp.html().length>9)
                {
                    liminti++;
                    T_number = T_number.length > 0 ? T_number + "," + tp.children("div").text() : tp.children("div").text(); 
                }
            }
            numval.val(numval.val() + "|" + T_number);
        }
        if(lotid==3&&liminti>30)
        {$("#cll").attr("disabled","disabled");alert("排列5每组模拟选号最多只能选30个号码！");return;}
        if(lotid==19&&liminti>40)
        {$("#cll").attr("disabled","disabled");alert("七星彩每组模拟选号最多只能选40个号码！");return;}
    }
}
var pgoucai = function(purl){
    var postform = $("#pcform");
    postform.attr("action",purl);
    postform.submit();
}
