 /*
 * 8684公交查询--by charles
 * mail:flcckwj2005@hotmail.com
 * $Date:2009-5-31$(最后修改)
 * 
 */
var queryType,curCityName,curCityId,cbbCity,cbbProv,cbbStation,cityArray=[],curTime,logoInfo={},adDownOver=false,cityClickTimes=1,linkToSite;
String.prototype.trim= function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
queryType= parseInt(ReadIniEx('user.ini','search','queryType')) || 1;
curCityName= ReadIniEx('user.ini','city','cityName');
curCityId= ReadIniEx('user.ini','city','cityId');
var lastLine=ReadIniEx('user.ini','queryed','lastLine') || '如:27路';
var lastStation=ReadIniEx('user.ini','queryed','lastStation') || '如:火车南站';
var lastTrans1=ReadIniEx('user.ini','queryed','lastTrans1') || '如:红牌楼';
var lastTrans2=ReadIniEx('user.ini','queryed','lastTrans2') || '如:磨子桥'; 
var adCode= readFile( widgetPath+'file\\adInfo.txt');
adCode =(adCode.indexOf('a7c7f2d4487a570dc92c98495ff4b0fd')>0)?adCode:'';
function setQueryType(v){
  queryType=v || 1;
  WriteIniEx('user.ini','search','queryType',queryType);
  LockRefresh;
  switch(queryType){
    case 2:
      edit0.Text=lastStation;
      if(lastStation=='如:火车南站')edit0.fontColor='clSilver'
      else edit0.fontColor='clBlank';
      siteBt.comb3in1ImgSrc="img/selected.png";
      lineBt.comb3in1ImgSrc="img/unselect.png";
      changeBt.comb3in1ImgSrc="img/unselect.png"; 
      edit0.Width=110;
      listBt1.Left=390;
      edit1.Visible=false;
      edit0.Visible=true;
      listBt2.Visible=false;  
      listBt1.Visible=true;
      break;
    case 3:
      edit0.Text=lastTrans1;
      edit1.Text=lastTrans2;
      if(lastTrans1=='如:红牌楼')edit0.fontColor='clSilver'
      else edit0.fontColor='clBlank';
      if(lastTrans2=='如:磨子桥')edit1.fontColor='clSilver'
      else edit1.fontColor='clBlank';
      changeBt.comb3in1ImgSrc="img/selected.png";
      siteBt.comb3in1ImgSrc="img/unselect.png";
      lineBt.comb3in1ImgSrc="img/unselect.png";  
      edit0.Width=45;
      edit1.Width=45;
      listBt1.Left=326;
      listBt2.Left=390;
      edit1.Visible=true;
      edit0.Visible=true;
      listBt2.Visible=true;  
      listBt1.Visible=true;
      break;
    default:  
      edit0.Text=lastLine;        
      if(lastLine=='如:27路')edit0.fontColor='clSilver'
      else edit0.fontColor='clBlank';
      lineBt.comb3in1ImgSrc="img/selected.png";
      siteBt.comb3in1ImgSrc="img/unselect.png";
      changeBt.comb3in1ImgSrc="img/unselect.png"; 
      edit0.Width=110;
      listBt1.Left=390;
      edit1.Visible=false;
      edit0.Visible=true;
      listBt2.Visible=false;  
      listBt1.Visible=true;
      break;
  }
  UnLockRefresh;
  Refresh;      
}
function downStationInfoOver(txt){
  try{
    var objArray=eval(txt);
    if(objArray.length>0){
      var str = TStringList.Create();
      for(i=0;i<objArray.length;i++){
        str.add(objArray[i]); 
      } 
      cbbStation.Items = str;
      cbbStation.Text = "选择城市";
      cbbStation.enabled = true; 
    }     
  }catch(e){
    Print('查询结果异常');
  }    
}
function loadCbbStation(sender){
  var se = pack();
  if(!se)return;
  var u="http://api.8684.cn/openapi.php?secret="+se+"&api_key=49d438b4e353ad2afe3e&format=php&k=sn&cityid="+curCityId+"&arg="+encodeURI(sender.Text)+"&t="+curTime;
  getHttpStrAsync( u ,"downStationInfoOver" );
  /*
  var ajax=new xmlHttp();
  ajax.onfailure=function(e){
    Print('获取查询结果失败');
    return;
  }  
  ajax.onload=function(e){
    Print( e.text);
    try{
      var objArray=eval(e.text);
      if(objArray.length>0){
        var str = TStringList.Create();
        for(i=0;i<objArray.length;i++){
          str.add(objArray[i]); 
        } 
        cbbStation.Items = str;
        cbbStation.Text = "选择城市";
        cbbStation.enabled = true; 
      }     
    }catch(e){
      Print('查询结果异常');
    }    
  }
  
  ajax.get(u);
  print('url:'+u); 
  */
}
function loadLineStyle(txt){
  try{
    var objArray=eval(txt);
    if(objArray.length>0){
      var str = TStringList.Create();
      for(i=0;i<objArray.length;i++){
        str.add(objArray[i]); 
      } 
      cbbStationSign.Items = str;
      cbbStationSign.enabled = true; 
    }     
  }catch(e){
    Print('查询结果异常');
  } 
}
function loadCbbLine(sender){
  var se = pack();
  if(!se)return;
  var u='http://api.8684.cn/openapi.php?secret='+se+'&api_key=49d438b4e353ad2afe3e&format=php&k=pl&t='+curTime+'&cityid='+curCityId+'&arg='+encodeURI(sender.Text);
  getHttpStrAsync( u ,"loadLineOver" );
}
function loadLineOver(txt){
  try{
    var objArray=eval(txt);
    if(objArray.length>0){
      var str = TStringList.Create();
      for(i=0;i<objArray.length;i++){
        str.add(objArray[i]); 
      } 
      cbbStation.Items = str;
      cbbStation.enabled = true; 
    }     
  }catch(e){
    Print('查询结果异常');
  } 
}
function listBt1OnClick(sender)
{
  if(!curCityName){alert('请先选择查询城市');return;};
  var frmList = TForm.create(widget);
  frmList.width = 280;
  frmList.height = 200;
  frmList.Position = poScreenCenter;  
  frmList.font.name='宋体';
  frmList.font.size=9;
  frmList.ShowHint=true;
  frmList.BorderStyle=bsDialog;
  
  switch(queryType){
    case 1:
      var se = pack();
      if(!se)return;
      frmList.caption = '选择公交线路';
      var u='http://api.8684.cn/openapi.php?secret='+se+'&api_key=49d438b4e353ad2afe3e&format=php&k=pt&t='+curTime+'&cityid='+curCityId;
      getHttpStrAsync( u ,"loadLineStyle" );
      cbbStationSign = TComboBox.Create(widget);
      cbbStationSign.parent = frmList;
      cbbStationSign.rc = Rect(15,25,100,50);      
      cbbStationSign.Text = "选择线路种类";
      cbbStationSign.OnSelectEx = 'loadCbbLine';
      cbbStationSign.enabled = false; 
      
      cbbStation = TComboBox.Create(widget);
      cbbStation.parent = frmList;
      cbbStation.rc = Rect(125,25,130,50);      
      cbbStation.Text = "选择线路名称";
      cbbStation.enabled = false;
      break;
    default: 
      frmList.caption = '选择公交站点';
      var stationSign=TStringList.Create();
      stationSign.add('数字');
      for(i=65;i<91;i++){
        stationSign.add(String.fromCharCode(i));      
      }
      cbbStationSign = TComboBox.Create(widget);
      cbbStationSign.parent = frmList;
      cbbStationSign.rc = Rect(15,25,100,50);      
      cbbStationSign.Items = stationSign;
      cbbStationSign.ItemIndex = 0;
      cbbStationSign.Text = "选择分类";
      cbbStationSign.OnSelectEx = 'loadCbbStation';
      
      cbbStation = TComboBox.Create(widget);
      cbbStation.parent = frmList;
      cbbStation.rc = Rect(125,25,130,50);      
      cbbStation.Text = "选择站点";
      cbbStation.enabled = false;
  }       
       
  var img = TImage.Create(widget);
  img.parent = frmList;
  img.rc = Rect(10,55,250,60);
  img.hint = (logoInfo.tip)?logoInfo.tip : '8684全国公交查询';
  img.Cursor =crHandPoint;
  img.stretch = true;
  img.helpKeyWord = (logoInfo.link)?logoInfo.link : 'http:\/\/www.8684.cn';
  img.OnClickEx = 'goLink'; 
  var imgSrc = (adDownOver)?'img\\ad\\ad.bmp' : 'img\\logo.bmp';
  img.Picture.LoadFromFile( widgetPath+imgSrc);  
 
  //img.Cursor = 'crHandPoint';    
  var btOK = TButton.Create(widget);
  btOK.parent = frmList;
  btOK.caption = "确定";
  btOK.rc = Rect(55,130,70,25);
  btOK.ModalResult = 1; 
  
  var btCan = TButton.Create(widget);
  btCan.parent = frmList;
  btCan.caption = "取消";
  btCan.rc = Rect(141,130,70,25); 
  btCan.ModalResult = 2;
  btCan.cancel = true;
      
  if(frmList.ShowModal==1){
    if(cbbStation.ItemIndex>=0 && cbbStationSign.ItemIndex>=0){
      if(sender.name=="listBt1"){
        edit0.fontColor='clBlank';
        edit0.Text= cbbStation.Text;
      }else{
        edit1.fontColor='clBlank';
        edit1.Text= cbbStation.Text;
      }
    }else{
      showTrayHint('8684小工具提示：','您还没有选择任何站点或者线路');
    }  
  }      
  frmList.free;      
}

function goLink(sender){
  OpenLink( sender.helpKeyWord );
}

function searchBtOnClick(sender)
{
  if(!curCityName){alert('请先选择查询城市');return;} 
  if(isDefaultQuery())return;
  var se=pack();
  if(!se)return; 
  switch(queryType){
    case 1:
      var lineName= edit0.Text.trim();
      if(!lineName){
        showTrayHint("鱼鱼温馨提示！","请输入内容后再查询");
        break;        
      }
      lineName=lineName.replace('lu','路'); 
      if(lineName.indexOf('路')<1)lineName+='路';
      startRequest("http://api.8684.cn/openapi.php?secret="+se+"&api_key=49d438b4e353ad2afe3e&format=php&k=p&cityid="+curCityId+"&arg="+lineName+"&t="+curTime);
      linkToSite='http://api.8684.cn/jump.php?k=pp&q='+encodeURI(lineName)+'&cityid='+curCityId;
      showTrayHint("8684小工具提示：","正在查询("+lineName+")车的线路信息...");
      break;
    case 2:
      if(!edit0.Text.trim()){
        showTrayHint("鱼鱼温馨提示！","请输入内容后再查询");
        break;        
      }
      startRequest("http://api.8684.cn/openapi.php?secret="+se+"&api_key=49d438b4e353ad2afe3e&format=php&k=pp&cityid="+curCityId+"&arg="+edit0.Text.trim()+"&t="+curTime);      
      linkToSite='http://api.8684.cn/jump.php?k=p&q='+encodeURI(edit0.Text.trim())+'&cityid='+curCityId;
      showTrayHint("8684小工具提示：","正在查询经过站点("+edit0.Text.trim()+")的公车信息...");
      break;
    case 3:
      if(!edit0.Text.trim() || !edit1.Text.trim()){
        showTrayHint("鱼鱼温馨提示！","请输入内容后再查询");
        break;        
      }      
      startRequest("http://api.8684.cn/openapi.php?secret="+se+"&api_key=49d438b4e353ad2afe3e&format=php&k=p2p&t="+curTime+"&cityid="+curCityId+"&arg="+edit0.Text.trim()+"&arg2="+edit1.Text.trim());      
      linkToSite='http://api.8684.cn/jump.php?k=p2p&q='+encodeURI(edit0.Text.trim())+'&q1='+encodeURI(edit1.Text.trim())+'&cityid='+curCityId;
      showTrayHint("8684小工具提示：","正在查询从("+edit0.Text.trim()+")到("+edit1.Text.trim()+")的乘车方案...");
      break; 
    default:
      showTrayHint("鱼鱼温馨提示！","得不到查询类型，请重试");          
  }
}

function closeBtOnClick(sender)
{
  LockRefresh;
  leftBg.Visible=false;
  closeBt.Visible=false;
  HtmlPanelVisible=false;
  UnLockRefresh;
  Refresh;  
}

function lineBtOnMouseDown(sender)
{
  setQueryType(1);
}

function siteBtOnMouseDown(sender)
{
  setQueryType(2); 
}

function changeBtOnMouseDown(sender)
{
  setQueryType(3); 
}

function startRequest(u){
  var ajax=new xmlHttp();
  Print( u);
  ajax.onfailure=function(e){
    Print('获取查询结果失败');
    return;
  }
  ajax.onload=function(e){
    var res= e.text;
    var detail="<br><a target='_blank' style='float:right; margin-right:10px;' href='"+linkToSite+"'>到8684查看详情<\/a><br>";
    if(res){
      LockRefresh;
      var styleCode='<html><head><style type="text/css">body{margin:0px;padding:0px;font-family:"宋体";font-size:12px;}#main{background-color:#E3F3F4;line-height:18px;margin:0px; padding:0px; width:260px; height:110px; overflow-x: hidden;overflow-y:scroll;}.r{color:red;}.b{color:blue;}<\/style><\/head><body scroll=no><div id="main">';
      switch(queryType){
        case 1:
          try{        
            var obj= eval('['+res+']');      
            var upLine=obj[0].up_line.replace(/\|/img,'<font style="color:blue;">→<\/font>');
            var downLine=obj[0].up_line.replace(/\|/img,'<font style="color:blue;">→<\/font>');
            var lineName=edit0.Text.trim();
            lineName=lineName.replace('lu','路'); 
            if(lineName.indexOf('路')<1)lineName+='路';             
            var s="<span class='r'><a target='_blank'  title='到百度搜索该路线' href='http://www.baidu.com/s?ie=utf-8&wd="+encodeURI(curCityName)+' '+encodeURI(lineName)+"&tn=dmato_pg'>"+lineName+"<\/a><\/span>公交车的行驶路线：<br><span class='r'>上行<\/span>：" +upLine+"<br/><span class='r'>下行<\/span>：<br>&nbsp;&nbsp;"+downLine;        
          }catch(e){                                                                                                                                                                                               
            Print('获取查询结果失败');
            var s="没有查询到数据";            
          }
          leftBg.Visible=true;
          closeBt.Visible=true;
          HtmlPanelVisible=true;
          HtmlPanelHtmlSrc='';           
          var output=styleCode+s+adCode+detail+"<br><\/div><\/body><\/html>";
          HtmlPanelHtmlSrc=output;      
          lastLine=edit0.Text.trim(); 
          WriteIniEx('user.ini','queryed','lastLine',lastLine);    
          break;
        case 2:
          try{
            var obj= eval(res);
            var s="经过<span class='r'><a target='_blank' title='到百度搜索该站点' href='http://www.baidu.com/s?ie=utf-8&wd="+encodeURI(curCityName)+' '+encodeURI(edit0.Text.trim())+"&tn=dmato_pg'>"+edit0.Text.trim()+"<\/a><\/span>的公交车有：<br>&nbsp;&nbsp;"+obj.toString();
          }catch(e){
            Print('获取查询结果失败');
            var s="没有查询到数据";            
          }
          leftBg.Visible=true;
          closeBt.Visible=true;
          HtmlPanelVisible=true; 
          HtmlPanelHtmlSrc=''; 
          var output=styleCode+s+adCode+detail+"<br><\/div><\/body><\/html>";
          HtmlPanelHtmlSrc=output;
          lastStation=edit0.Text.trim();     
          WriteIniEx('user.ini','queryed','lastStation',lastStation);     
          break;
        case 3:
          try{
            var obj=eval(res);
            var s='从"<span class="r"><a target="_blank" title="到百度搜索该站点" href="http://www.baidu.com/s?ie=utf-8&wd='+encodeURI(curCityName)+' '+encodeURI(edit0.Text.trim())+'&tn=dmato_pg">'+edit0.Text.trim()+'<\/a><\/span>"到"<span class="r"><a target="_blank" title="到百度搜索该站点" href="http://www.baidu.com/s?ie=utf-8&wd='+encodeURI(curCityName)+' '+encodeURI(edit1.Text.trim())+'&tn=dmato_pg">'+edit1.Text.trim()+'<\/a><\/span>"你可以这样乘车：<br>&nbsp;&nbsp;'+obj.toString();
          }catch(e){
            Print('获取查询结果失败');
            var s="没有查询到数据";            
          }
          leftBg.Visible=true;
          closeBt.Visible=true;
          HtmlPanelVisible=true; 
          HtmlPanelHtmlSrc=''; 
          var output=styleCode+s+adCode+detail+"<br><\/div><\/body><\/html>";
          HtmlPanelHtmlSrc=output; 
          HtmlPanelVisible=true;
          lastTrans1=edit0.Text.trim();
          lastTrans2=edit1.Text.trim();
          WriteIniEx('user.ini','queryed','lastTrans1',lastTrans1);
          WriteIniEx('user.ini','queryed','lastTrans2',lastTrans2);
          break;
        default:
          showTrayHint("鱼鱼温馨提示！","得不到查询类型，请重试");  
      }
      UnLockRefresh;
      Refresh;
    }
  }
  ajax.get(u);
}

function cityOnMouseDown(sender)
{
 if(cityClickTimes==2){
   DownLoadFileAsync('http://api.8684.cn/openapi.php?secret=78bdb0c4846757c8b545&api_key=49d438b4e353ad2afe3e&format=php&k=c', widgetPath+"file\\cityList.bak","cityListDownOver" ); 
 }else{
   getCityList(true);
 }
 cityClickTimes++; 
}
Object.each=function(o,f){for(var i in o)f(i,o[i])};
Object.join=function(o){var s='';Object.each(o,function(key,value){s+='&'+key+'='+value});return s.slice(1)};
function xmlHttp(){
  this.transport = this.getTransport();
} 
xmlHttp.prototype.getTransport=function(){
  var xmlhttp;
　try {
　　xmlhttp = new XMLHttpRequest();
　} catch (trymicrosoft) {
　　try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch(othermicrosoft) {
　　　try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(failed){xmlhttp = false;}
　　}
　}
  return xmlhttp;
}
xmlHttp.prototype.get=function(u){
  var o =  this.transport;
  var self = this;
  u+=(u.indexOf('?')>-1?'&':'?')+'rn='+Math.random();
  u=encodeURI(u);
  o.open('GET',u,true);
  o.onreadystatechange = function(){self.onState();}  
  o.send(null);           
}
xmlHttp.prototype.onState=function(){
  if(this.transport.readyState==4){
     if(this.transport.status==200){
       if(this.onload){this.onload({text:this.transport.responseText})};              
     }else{if(this.onfailure)this.onfailure({text:''});}           
  }
}
function loadCbbCity(sender){
  var len=cityArray[sender.ItemIndex].cityList.length;  
  if(len>0){    
    var cityStr = TStringList.Create();
    for(i=0;i<len;i++){
      cityStr.add(cityArray[sender.ItemIndex].cityList[i].cityName); 
    }    
    cbbCity.Items = cityStr;
    cbbCity.Text = "选择城市";
    cbbCity.enabled = true;
  }
}
function saveCity(sender){
  curCityName=cityArray[cbbProv.ItemIndex].cityList[sender.ItemIndex].cityName;
  curCityId=cityArray[cbbProv.ItemIndex].cityList[sender.ItemIndex].cityId;
  WriteIniEx('user.ini','city','cityName',curCityName);
  WriteIniEx('user.ini','city','cityId',curCityId); 
}
function loadCityListInfo(){
  var len=cityArray.length;
  if(len>0){
      var provStr = TStringList.Create();
      for(i=0;i<len;i++){
        provStr.add(cityArray[i].provName); 
      }  
      var frmList = TForm.create(widget);
      frmList.width = 230;
      frmList.height = 160;
      frmList.Position = poScreenCenter;  
      frmList.caption = '选择查询城市';
      frmList.font.name='宋体';
      frmList.font.size=9;
      frmList.ShowHint=true;
      frmList.BorderStyle=bsDialog;
       
      cbbProv = TComboBox.Create(widget);
      cbbProv.parent = frmList;
      cbbProv.rc = Rect(15,20,90,50);      
      cbbProv.Items = provStr;
      cbbProv.ItemIndex = 0;
      cbbProv.Text = "选择省份";
      cbbProv.OnSelectEx = 'loadCbbCity';
      
      cbbCity = TComboBox.Create(widget);
      cbbCity.parent = frmList;
      cbbCity.rc = Rect(110,20,100,50);      
      cbbCity.Text = "选择城市";
      cbbCity.enabled = false;
       
      var btOK = TButton.Create(widget);
      btOK.parent = frmList;
      btOK.caption = "确定";
      btOK.rc = Rect(35,85,70,25);
      btOK.ModalResult = 1; 
   
      var btCan = TButton.Create(widget);
      btCan.parent = frmList;
      btCan.caption = "取消";
      btCan.rc = Rect(125,85,70,25); 
      btCan.ModalResult = 2;
      btCan.cancel = true;
      
      if(frmList.ShowModal==1){
        if(cbbProv.ItemIndex>=0 && cbbCity.ItemIndex>=0){
          curCityName=cityArray[cbbProv.ItemIndex].cityList[cbbCity.ItemIndex].cityName;
          curCityId=cityArray[cbbProv.ItemIndex].cityList[cbbCity.ItemIndex].cityId;
          WriteIniEx('user.ini','city','cityName',curCityName);
          WriteIniEx('user.ini','city','cityId',curCityId);
          city.caption=curCityName;           
        }else{
          showTrayHint('8684小工具提示：','您还没有选择任何城市');
        }  
      }      
      frmList.free;      
  }
}
function cityListDownOver(){
  if(fileExists( widgetPath + "file\\cityList.bak")){
    try{
      var str= readFile( widgetPath + "file\\cityList.bak" );
      if(str){
        var obj= eval(str);
        if( obj.length>0){  
          cityArray=obj;        
          loadCityListInfo();          
          copyFile(widgetPath + "file\\cityList.bak" , widgetPath + "file\\cityList.txt");        
        }
      }else{
        return;
      }
    }catch(e){
      Print('读取城市列表出错');
      return;
    }
  }
}
function getCityList(showDialog){
  if(fileExists( widgetPath + "file\\cityList.txt")){
    try{
      var str= readFile( widgetPath + "file\\cityList.txt" );
      if(str){
        var obj= eval(str);
        if( obj.length>0){
          cityArray=obj;
          if(showDialog)
            loadCityListInfo();
          else
            getHttpStrAsync( 'http://www.dmato.com/app/client.php' ,"onGetCurCity" );
        }
      }else{
        Print('城市列表为空');
        return;
      }
    }catch(e){
      Print('读取城市列表出错');
      return;
    }  
  }else{
    DownLoadFileAsync('http://api.8684.cn/openapi.php?secret=78bdb0c4846757c8b545&api_key=49d438b4e353ad2afe3e&format=php&k=c', widgetPath+"file\\cityList.bak","cityListDownOver" );
  }
}
function onGetCurCity(txt){
  var cityStr= txt.substring(txt.indexOf('g="'),txt.indexOf('a="'));
  if(cityStr && cityArray.length>0){
    for(i=0;i<cityArray.length;i++){
      var o=cityArray[i].cityList;
      for(j=0;j<o.length;j++){
        if(cityStr.indexOf(o[j].cityName)>0){
          curCityName=o[j].cityName;
          curCityId=o[j].cityId;
          city.caption=curCityName;
          WriteIniEx('user.ini','city','cityName',curCityName);
          WriteIniEx('user.ini','city','cityId',curCityId);
        }
      }
    }
  }
}
function widgetOnInit()
{
  if(curCityName && curCityId){
    city.caption=curCityName;    
  }else{
    getCityList();
  }
  getTime();
  setQueryType(queryType);
  /* 
  try{
    var aa= new ActiveXObject('pack8684.pack');
  }catch(e){
    if(confirm( '首次使用你必须注册必要的组件,是否立即注册' )){
      regActive(); 
    }else{
      showTrayHint('鱼鱼温馨提示','没有注册组件不能使用该工具，你可以通过右击菜单来实现注册！');
    } 
  } 
  */ 
}

function getTime(){
  var ajax=new xmlHttp();
  ajax.onfailure=function(e){
    Print('获取时间失败');
    return;
  }
  ajax.onload=function(e){
    Print( e.text);
    if(!isNaN(parseInt(e.text))){
      curTime=parseInt(e.text);
      timer0.enabled=true;
    }
  }
  ajax.get('http://api.8684.cn/openapi.php?k=t');
}
function timer0OnTimer()
{
  if(curTime){
    curTime++;
    //Print( curTime );
  }else{
    timer0.enabled=false;
  }
}
function pack(){
  try{
    var aa= new ActiveXObject('pack8684.pack');
    if(curTime.toString()){
      return aa.encode(curTime.toString());
    }else{
      return;
    }
  }catch(e){
    if(confirm( '创建activeX出错,你可能需要注册必要的组件,是否立即注册' )){
      regActive(); 
    }
    return null;
  }
}
function regActive(){
  try{
      if( fileExists(widgetPath+"file\\pack8684.dll")){
          regSvr(widgetPath+"file\\pack8684.dll");
          alert('注册组件成功，你可以通过右击菜单来卸载该组件'); 
          return true;    
      }else{
          alert("缺少组件文件"+widgetPath+"file\\pack8684.dll，此小工具将不能正常运行，请重新下载使用该小工具");
          return false;
      }      
  }catch(e){
      alert("注册组件失败");
      return false;      
  }
}
function unRegActive(){
  try{
      if( fileExists(widgetPath+"file\\pack8684.dll")){
          unRegSvr(widgetPath+"file\\pack8684.dll");
          alert("成功卸载组件，你可以通过右击菜单来注册该组件");
          return true;
      }else{
          alert("缺少组件文件"+widgetPath+"file\\pack8684.dll，此小工具将不能被反注册");
          return false;
      }            
  }catch(e){
      alert("卸载组件失败");
      return false;      
  }
}
function checkInfo(){
  timer1.enabled=false;
  var s = readFile( widgetPath+"file\\adinfo.bak");
  var startIndex=s.indexOf('a7c7f2d4487a570dc92c98495ff4b0fd');
  if(startIndex>0){
    copyFile(widgetPath+"file\\adinfo.bak",widgetPath+"file\\adinfo.txt");
    adCode = s;
    var str= s.substring(startIndex+32,s.indexOf('-->'));    
    try{
      var obj=eval('['+str+']'); 
      logoInfo=obj[0];
      DownLoadFileAsync( logoInfo.src , widgetPath+"img\\ad\\ad.bmp" ,"downImgOver" );
    }catch(e){
      logoInfo={};
    }
  }
}

function downImgOver(){
  adDownOver=true;
}

function timer1OnTimer()
{
  DownLoadFileAsync( 'http:\/\/www.fishdesk.com\/widget\/news\/8684.txt' , widgetPath+"file\\adinfo.bak" ,"checkInfo" );
}
function isDefaultQuery(){
  switch(queryType){
    case 1:
         if(edit0.fontColor=='clSilver'){ 
           alert('请选择查询线路名称');          
           return true;
         }else{
           return false;
         }
         break;
    case 2:
         if(edit0.fontColor=='clSilver'){
           alert('请选择查询站点');
           return true;
         }else{
           return false;
         }
         break;
    default:
         if(edit0.fontColor=='clSilver' || edit1.fontColor=='clSilver'){
           alert('请选择查询站点');
           return true;
         }else{
           return false;
         }
  }
}

function edit0OnChange()
{
  edit0.fontColor='clBlank';
}

function edit1OnChange()
{
  edit1.fontColor='clBlank';
}

function edit0OnKeyDown()
{
  if(keycode==13){
    searchBtOnClick(); 
  }
}

function edit1OnKeyDown()
{
  if(keycode==13){
    searchBtOnClick(); 
  }  
}