var toUrl = 'http://www.takungpao.com:8080/searchserver/search.xhtml?method=search&';
//var toUrl = 'http://192.168.1.19:8080/searchserver/search.xhtml?method=search&';
//首页搜索
function maingotosearch(){
var key =$("#vkey").val();
 if(key== "请输入关键字")
  {
     key = "";
   }
 if(key=='請輸入關鍵字'){
	 
	  key = "";
 }
            
//var	key=$("#vkey").val();
 var radomwindow=Math.floor(Math.random()*100)+'updateXX';	
window.open ('http://www.takungpao.com/hotsearch.html?key='+key,radomwindow);
}
function opensearch(key){
//$("#key").val(key);
	 var radomwindow=Math.floor(Math.random()*100)+'updateXX';
window.open ('http://www.takungpao.com/hotsearch.html?key='+key,radomwindow);
	//$("#key").val(key);
	//$("#vkey").val(key);
	//hostsearch(key);
	
}

//热搜进入页面执行
function hotfirstsearch(){
	//var key= window.opener.document.getElementById('key').value;
	var key=getArgs()['key'];
	$("#sgkey").val(key);
	$("#vkey").val(key);
	hostsearch(key);
}
  function getArgs( ) {
     var args = new Object( );
     var query = location.search.substring(1);      // Get query string
     var pairs = query.split("&");                  // Break at ampersand
     for(var i = 0; i < pairs.length; i++) {
         var pos = pairs[i].indexOf('=');           // Look for "name=value"
         if (pos == -1) continue;                   // If not found, skip
         var argname = pairs[i].substring(0,pos); // Extract the name
         var value = pairs[i].substring(pos+1);     // Extract the value
         value = decodeURIComponent(value);         // Decode it, if needed
         args[argname] = value;                     // Store as a property
     }
     return args;                                   // Return the object
}
//热搜
function hostsearch(key){
               document.title="搜索关于 '"+key+ "'的新闻";
                  key=encodeURI(encodeURI(key));
              $.getJSON(toUrl+"keyWord="+key+"&format=json&jsoncallback=?",
	          function(json){
	          var continents =json.content;
                 var datahtml=continents[0].body;
                 $('#pindao-l').html(datahtml); 
                 }); 
}

//频道搜索	 
             function gotosearch(){  
           var    key= $("#vkey").val();
            if(key == "请输入关键字"){
                    key = "";
                } else if(key=="請輸入關鍵字"){
                	key = "";
                	}else{
                if(key.length>20){
                key=key.substring(0,20)
                }
                }
              $("#sgkey").val(key);
              $("#key").val(key);
               document.title="搜索关于 '"+key+ "'的新闻";
                  key=encodeURI(encodeURI(key));
              $.getJSON(toUrl+"keyWord="+key+"&format=json&jsoncallback=?",
	          function(json){
	          var continents =json.content;
                 var datahtml=continents[0].body;
                 $('#pindao-l').html(datahtml); 
                 }); 
             }
             
             
         //文章下面搜索框
        function gotosearchbotm(){  
         var    key = $("#vkeybotm").val();
            if(key== ""){
                 key = "";
                } else{
               var key=$("#vkeybotm").val();
                if(key.length>20){
                key=key.substring(0,20)
                }
                }
            $("#sgkey").val(key);
               document.title="搜索关于 '"+key+ "'的新闻";
                key=encodeURI(encodeURI(key));
              $.getJSON(toUrl+"keyWord="+key+"&format=json&jsoncallback=?",
	          function(json){
	          var continents =json.content;
                 var datahtml=continents[0].body;
                 $('#pindao-l').html(datahtml); 
                 }); 
             }
             
            
           function    gotoPage(v){
        	  var key=$("#sgkey").val();
        	   if(typeof(key)== "undefined"){
        		 key=$("#key").val();
        	 }
                 key=encodeURI(encodeURI(key));
              $.getJSON(toUrl+"page="+v+"&keyWord="+key+"&format=json&jsoncallback=?",
	          function(json){
	          var continents =json.content;
                 var datahtml=continents[0].body;
                 $('#pindao-l').html(datahtml); 
                 }); 
           
           }
             function BindEnter(event) {
        var button = document.getElementById('serachbutton');
        if (event.keyCode == 13) {
            button.click();
            event.returnValue = false;
        }
    }
     document.onkeydown=function(event) 
{ 
 var button = document.getElementById('serachbutton');
 var mbutton = document.getElementById('mainserachbutton');
 
e = event ? event :(window.event ? window.event : null); 
if(e.keyCode==13){ 
//执行的方法 
	if(mbutton==null||""==mbutton){
		button.click();
	}else{
		mbutton.click();
	}
	
e.returnValue = false;
} 
} 
//topbanner.gif
$(document).ready(function (){
  var url=this.location.href;
  if(url.length>'http://www.takungpao.com/'.length){
if(url=='http://www.takungpao.com/travel/'){
 var html='<a href="http://www.lastminute.com.hk" target="_blank"><img src="http://www.takungpao.com/images/h20110408_1.gif" width="650" height="90" /></a>';
 $("#topbanner").html(html);
}else if(url=='http://www.takungpao.com/hm/'){
var html='<a href="http://www.takungpao.com/health/treatment/2012-01-14/1057321.html" target="_blank"><img src="http://www.takungpao.com/images/banner01aa.gif" width="650" height="90" /></a>';
 $("#topbanner").html(html);
}else{
  var html='<a href="http://jp.takungpao.com/" target="_blank"><img src="http://www.takungpao.com/images/daikomo.jpg" width="650" height="90" /></a>';
  $("#topbanner").html(html);
  }
}else{window.setInterval("jsFlash()",2000);}
 cjReplace();
});
function cjReplace() {
     var  link = document.getElementsByTagName("a")
     for(i=0;i<link.length;i++)
     {
      if(link[i].href=='http://www.dagong888.com/'){
       link[i].href='http://finance.takungpao.com/';
      }
      if(link[i].href=='http://www.takungpao.com/chinese/buddhism/'){
       link[i].href='http://bodhi.takungpao.com/';
      }
    }
 } 
 
 //js index top flah 
var img1='http://www.takungpao.com/images/tkpled.gif';
//var img2='http://www.takungpao.com.hk/images/2011select1.jpg';
var img2='http://www.takungpao.com.hk/images/whjdyxj1.jpg';
var url1='http://www.takungpao.com.hk/led/index.htm';
//var url2='http://source.takungpao.com/inc/special/2011select/index.asp';
var url2='http://www.takungpao.com.hk/inc/special_new.asp?catalog_id=whjdyxj&c=%A4%E5%A4%C6%B8g%A8%E5%C4%A3%AD%BB%A6%BF';
var chTag=true; 
function jsFlash(){
if(chTag){
$("#tkpTopIndex1").attr("src",img2);
$("#topImageUrl").attr("href",url2);
chTag=false;
return;
}else{
$("#tkpTopIndex1").attr("src",img1);
$("#topImageUrl").attr("href",url1);
chTag=true;
return;
}
}
 
(function($){  
$.fn.extend({  
	Scroll:function(opt,callback){  
			if(!opt) var opt={};  
			var _this=this.eq(0).find("ul:first");  
			var        lineH=_this.find("li:first").height(), 
					line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), 
					speed=opt.speed?parseInt(opt.speed,10):500,   
					timer=opt.timer?parseInt(opt.timer,10):3000;  
			if(line==0) line=1;  
			var upHeight=0-line*lineH;  
			scrollUp=function(){  
					_this.animate({  
							marginTop:upHeight  
					},speed,function(){  
							for(i=1;i<=line;i++){  
									_this.find("li:first").appendTo(_this);  
							}  
							_this.css({marginTop:0});  
					});  
			}  
			_this.hover(function(){  
					clearInterval(timerID);  
			},function(){  
					timerID=setInterval("scrollUp()",timer);  
			}).mouseout();  
	}         
	})  
})(jQuery);

