var
        inifn:TIniFile;
	ItemLst,ItemValLst,LotteryValue:TStrings;
	Tempi:integer;
	LotteryHint, 
	LotteryTag:string; //彩票字母标识


procedure GetLotteryTag;
var s:string;
begin
  s:=inifn.ReadString('Item0','BitmapName','.\images\ssq.png');
  LotteryTag:=StrBetween(s,'images\','.png');
end;

function GetLotteryName(value:string):string;
begin
  case value of
    'sd':  result:='福彩3D';
    'pls': result:='排列三';
    'plw': result:='排列五';
    'qxc': result:='七星彩';
    'qlc': result:='七乐彩';
    'eexw':result:='22选5';
    'syxq':result:='31选7';
    'ssq': result:='双色球';
    'dlt': result:='超级大乐透';
  else
    result:='';
  end;
end;

//计算要显示的文字/球的数量和颜色
procedure ShowLottery(value:string);
var
  lst:TStrings;
  s,s1,s2:string;
  i,j,recti:integer;
begin
{ sd  :8,0,7
  pls :7,9,0
  plw :7,9,0,6,3
  qxc :4,2,6,0,1,1,3
  qlc :05,06,08,14,16,28,30|03
  eexw:02,12,13,19,21
  slxq:06,09,16,26,27,36|07
  ssq :10,14,22,28,29,33|02
  ejxq:06,09,11,18,19,26,27|14
  dlt :03,07,20,33,35|04,07    }
  
  if Pos('|',value)>0 then 
    begin
    s1:=copy(value,1,Pos('|',value)-1);
    s2:=copy(value,Pos('|',value)+1,Length(value)-Pos('|',value));
    end; 
  lst:=TStringList.create;
  StrToStrings(s1+','+s2,lst,',');
  recti:=0;
  try
    if lst.count>0 then 
      case LotteryTag of
        'sd'  :begin
        StrToStrings('1,1,1,0,0,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'pls' :begin
        StrToStrings('1,1,1,0,0,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'plw' :begin
        StrToStrings('1,1,1,1,1,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'qxc' :begin
        StrToStrings('1,1,1,1,1,1,1,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'qlc' :begin
        StrToStrings('1,1,1,1,1,1,1,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'eexw':begin
        StrToStrings('1,1,1,1,1,0,0,0,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'syxq':begin
        StrToStrings('1,1,1,1,1,1,1,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	  end;
	end;
        'ssq' :begin
        StrToStrings('1,1,1,1,1,1,0,1,0,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    //showmessage(IntToStr(74+33*recti));
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	   
	  end;
	end; 
        'dlt' :begin
        StrToStrings('1,1,1,1,1,0,0,1,1,',ItemValLst,',');
        for Tempi:=0 to Itemlst.count-1 do 
	  begin
          inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
	  if ItemValLst[Tempi]='1' then
	    begin
	    inifn.WriteString(Itemlst.strings[Tempi],'Rect',IntToStr(74+33*recti)+'/33/23/23');
            inc(recti);
	    end;
	  if (Tempi<=(lst.count-1)) then
	    s:=lst.strings[Tempi]
	    else
	    s:='';
          inifn.WriteString('Item11','Item'+IntToStr(Tempi),s);
	   
	  end;
	  
	end; 
      end; 
    
  finally
    lst.free; 
  end;
end;

//分析彩票网页
procedure ParseString;
var
  lst:TStrings;
  i:integer;
  s,sVal:string;
begin
  //sVal:=GetHttpStr('http://lottery.sports.sohu.com/open/'); 	
  sVal:=SendURL22('http://lottery.sports.sohu.com/open/'); 	
  lst:=TStringList.create;
  try
    if sVal<>'' then
    begin
    lst.text:=sVal; 
    if lst.count>0 then
      for i:=0 to lst.count-1 do
      begin
        if pos('formatResult('''+LotteryTag,lst.strings[i])>0 then  
        begin
          s:=StrBetween(lst.strings[i],',''',''');');  
          LotteryHint:='彩票：'+GetLotteryName(LotteryTag)+
	               ' 期数：'+StrBetween(lst.strings[i-3],'center">','期</td>')+
		       ' 日期：'+StrBetween(lst.strings[i-2],'center">','</td>');
        
          ShowLottery(s);
          inifn.WriteString('Item0','hint',LotteryHint);
          
        end;
      end;
    end;
  finally
    lst.free;
  end;
end;


begin
  try 
    inifn:=TIniFile.create(SkinFileName);
    Itemlst:=TStringList.create; 
    ItemValLst:=TStringList.create; 
    LotteryValue:=TStringList.create; 
    StrToStrings('Item1,Item2,Item3,Item4,Item5,Item6,Item7,Item8,Item9,',Itemlst,',');
    StrToStrings('0,0,0,0,0,0,0,0,0,',ItemValLst,',');
    StrToStrings(',,,,,,,,,',LotteryValue,',');
    for Tempi:=0 to Itemlst.count-1 do 
      begin
      inifn.WriteString(Itemlst.strings[Tempi],'Enable',ItemValLst[Tempi]);
      inifn.WriteString('Item11','Item'+IntToStr(Tempi),LotteryValue[Tempi]);
      end;
    GetLotteryTag;
    ParseString;
    
  finally
    inifn.free; Itemlst.free; ItemValLst.free; LotteryValue.free;
    RefreshSkin(true);
  end;
 
end.