function CreateHttpRequest()
{
  if(window.XMLHttpRequest)
    return   new   XMLHttpRequest();   
  try{   
    return   new   ActiveXObject('MSXML2.XMLHTTP.4.0');   
  }catch(e){
  	try{   
      return   new   ActiveXObject('MSXML2.XMLHTTP.3.0');   
  }catch(e){
  	try{   
      return   new   ActiveXObject('MSXML2.XMLHTTP.2.6');   
  }catch(e){
  	try{   
      return   new   ActiveXObject('MSXML2.XMLHTTP');   
  }catch(e){
  	try{   
      return   new   ActiveXObject('Microsoft.XMLHTTP');   
  }catch(e){
  	return   null;
  	}}}}}   
}

function GetADList(t) 
{
  var url = '/ad_show.asp?t=' + t +'&rnd='+(new  Date()).getTime();

  var xmlhttp = CreateHttpRequest();
  if(xmlhttp ==null)
    return '';

  try 
  {   
     xmlhttp.open('GET', url, false); 
     xmlhttp.send(null);
     if ( xmlhttp.status == 200 ) 
     { 
         return xmlhttp.responseText;
     } 
     throw '';  
    xmlhttp =null;
  } 
  catch(e) 
  {
  //alert(e);
    xmlhttp =null;
       return ''; 
  }
  xmlhttp =null;
}

function GetSSValue(s)
{
  var url = '/get_ssvalue.asp?s=' + s +'&rnd='+(new  Date()).getTime();

  var xmlhttp = CreateHttpRequest();
  if(xmlhttp ==null)
    return '';

  try 
  {   
     xmlhttp.open('GET', url, false); 
     xmlhttp.send(null);
     if ( xmlhttp.status == 200 ) 
     { 
         return xmlhttp.responseText;
     } 
     throw '';  
    xmlhttp =null;
  } 
  catch(e) 
  {
    xmlhttp =null;
       return ''; 
  }
  xmlhttp =null;
}

function GetSSValue2(s)
{
  var url = '/get_ssvalue.asp?s=' + s;

  var xmlhttp = CreateHttpRequest();
  if(xmlhttp ==null)
    return '';

  try 
  {   
     xmlhttp.open('GET', url, false); 
     xmlhttp.send(null);
     if ( xmlhttp.status == 200 ) 
     { 
         return xmlhttp.responseText;
     } 
     throw '';  
    xmlhttp =null;
  } 
  catch(e) 
  {
    xmlhttp =null;
       return ''; 
  }
  xmlhttp =null;
}

function SetFrom(r)
{
  var url = '/set_from.asp?r=' + r;

  var xmlhttp = CreateHttpRequest();
  if(xmlhttp ==null)
    return '';

  try 
  {   
    xmlhttp.open('GET', url, false); 
    xmlhttp.send(null);
    xmlhttp =null;
  }
  catch(e) 
  {
    xmlhttp =null;
  }
  xmlhttp =null;
  return ''; 
}

function show_ad(name)
{
    document.write(GetSSValue2(name));
  //if(name=="ad_detail_a")
    //document.write(GetSSValue('ad_detail_a'));
  //if(name == "ad_detail_b")
    //document.write(GetSSValue('ad_detail_b'));
}

function FriendlyDisplayForSearch()
{
    var url = new UrlBuilder(document.referrer);
    if ( url.m_Success )
    {
         var host = url.m_Host.toLowerCase();
         var keywords;
         if ( host.indexOf('.google.') != -1 )
         {
             keywords = url.GetValue('q', 'UTF8');
         }
         else if ( host.indexOf('.baidu.') != -1 )
         {
             keywords = url.GetValue('wd', 'GB2312');
         }
         else
             keywords = url.GetValue('keyword', 'GB2312');
         
         if ( keywords )
         {
              var ht = new HighlightText();
              ht.Execute(keywords);
         }
    }   
}

function HighlightText(range)
{
    if ( range )
    {
         this.m_Range = range;
    }
    else
    {
         this.m_Range = document.body.createTextRange();
    }     
    this.m_Keyword = '';
    
    this.toString = function()
    {
         return '[class HightlightText]';
    };       
}
HighlightText.prototype.Execute = function(keyword)
{
     if ( keyword )
     {
          this.m_Keyword = keyword;
     }
     if ( this.m_Range && this.m_Keyword )
     {
         var separater = ' ';
         if ( this.m_Keyword.indexOf(' ') == -1 ) 
         {
              separater = '+';
         }   
         var keywords = this.m_Keyword.split(separater); 
         var bookmark = this.m_Range.getBookmark();             
         for ( var i=0 ; i < keywords.length ; ++i )
         {
             var keyword = keywords[i];
             if ( keyword && keyword.length > 1 )
             { 
                 while(this.m_Range.findText(keywords[i]))
                 {
                      this.m_Range.execCommand('ForeColor', 'false', 'highlighttext');
                      this.m_Range.execCommand('BackColor', 'false', 'highlight'); 
                      this.m_Range.collapse(false);
                 }
                 this.m_Range.moveToBookmark(bookmark);
             }
         }
     }
}

function UrlBuilder(url)
{
    this.m_Href = null;
    this.m_Host = null;
    this.m_Hostname = null; 
    this.m_Port = null;
    this.m_Protocol = null;
    this.m_Path = null;
    this.m_Search = null;
    this.m_Hash = null;
    this.m_Params = null; 
    this.m_Sucess = false; 
    if ( url ) this.Parse(url);
   
    this.toString = function()
    {
         return '[class UrlBuilder]';
    };     
}

UrlBuilder.prototype.Parse = function(url)
{
    var m = url.match(/(\w{3,5}:)\/\/([^\.]+(?:\.[^\.:/]+)+)(?::(\d{1,5}))?\/?/);
    if ( m )
    {
         this.m_Protocol = m[1];
         this.m_Hostname = m[2]; 
         this.m_Port = m[3]; 
         if ( this.m_Port ) 
         {
             this.m_Host = this.m_Hostname + ':' + this.m_Port;
         }
         else
         {  
             this.m_Host = m[2];
         }
         var indexHash = url.indexOf('#');
         if ( indexHash != -1 )
         {
             this.m_Hash = url.substr(indexHash);
         }
         else
         {
             this.m_Hash = '';
         }        
         var indexParams = url.indexOf('?');
         if ( indexParams != -1 )
         {
             if ( indexHash != -1 )
             {
                  this.m_Search = url.substring(indexParams, indexHash);
             }
             else
             { 
                  this.m_Search = url.substr(indexParams);
             }
             this.m_Path = url.substr(indexParams);
         }
         else
         {
             this.m_Search = '';
         }
         this.m_Success = true; 
         this.m_Params = null; 
         this.m_Href = url;
    }
};

UrlBuilder.prototype.GetValue = function(key, encoding)
{
    if ( !this.m_Params )
    {
         if ( this.m_Search )
         {
             this.m_Params = {}; 
             var search = this.m_Search.substring(1);
             var keyValues = search.split('&');
             for ( var i=0 ; i < keyValues.length ; ++i )
             {
                  var keyValue = keyValues[i];
                  var index = keyValue.indexOf('=');
                  if ( index != -1 )
                  {
                       this.m_Params[keyValue.substring(0, index)] = keyValue.substr(index+1);
                  }
                  else
                  {
                       this.m_Params[keyValue] = '';
                  }
              }  
         }
    }
    if (!this.m_Params)
      return '';
      
    encoding = encoding || ''; 
    switch(encoding.toUpperCase())
    {
         case 'UTF8' :
         {
              return decodeURI(this.m_Params[key]);
         }
         case 'UNICODE' :
         {
              return unescape(this.m_Params[key]);
         }
         case 'GB2312' : // need VBScript function Chr()
         default :
         {
              return this.m_Params[key];
         }
    }  
}

function t001(i, s)
{
  var url = '/t001.asp?i=' + i +'&s='+s;

  var xmlhttp = CreateHttpRequest();
  if(xmlhttp ==null)
    return '';

  try 
  {   
     xmlhttp.open('GET', url, false); 
     xmlhttp.send(null);
     if ( xmlhttp.status == 200 ) 
     { 
         return xmlhttp.responseText;
     } 
     throw '';  
    xmlhttp =null;
  } 
  catch(e) 
  {
    xmlhttp =null;
       return ''; 
  }
  xmlhttp =null;
}

function gg_translate(id, intro)
{
  try
  {
    //t001(id, 'del');
    google.language.translate(intro, "zh", "en", function(result)
    {
      if (!result.error)
      {
        t001(id, result.translation);
      }
      else
      {
        document.write('err!!!');
      }
    });
  }
  catch(e)
  {
        t001(id, 'err');
  }
}

