// JavaScript Document
//call method
// onLoad="init(); window.setTimeout('show_secs()',1);"

         var ap_name = navigator.appName;
         var ap_vinfo = navigator.appVersion;
         var ap_ver = parseFloat(ap_vinfo.substring(0,ap_vinfo.indexOf('(')));
         var time_start = new Date();
         var clock_start = time_start.getTime();
         var dl_ok=false;
		 var flag=0;
		 var flag2=0;
		 
         function init ()
         {
              if(ap_name=="Netscape" && ap_ver>=3.0)
               dl_ok=true; 
               return true;
        }
		
        function get_time_spent ()
        { 
              var time_now = new Date();
              return((time_now.getTime() - clock_start)/1000); 
        }
		
         function show_secs () // show the time user spent on the side
        { 
                var i_total_secs = Math.round(get_time_spent()); 
                var i_secs_spent = i_total_secs % 60;
                var i_mins_spent = Math.round((i_total_secs-30)/60); 
                var s_secs_spent = "" + ((i_secs_spent>9) ? i_secs_spent : "0" + i_secs_spent);
                var s_mins_spent ="" + ((i_mins_spent>9) ? i_mins_spent : "0" + i_mins_spent);

               //document.fm0.time_spent.value = s_mins_spent + ":" + s_secs_spent;
			   //document.getElementById('joketext').innerHTML =s_mins_spent + ":" + s_secs_spent;
			   
			   if  (s_secs_spent>10 )
				 {
					//执行一次---------------------------------------------------
					if (flag==0)
					{
						get_joke_text();
					    flag=1; 
					}
				 }
				 
               if  (s_secs_spent>50)
			      {
					  flag2=1;
					  document.getElementById('joketext').innerHTML ='';
				  }
			 
			   if (flag2==0) 
			      window.setTimeout('show_secs()',1000); 
				   
         }
		 
		
	  function get_joke_text()
      {
       
		var retstr;
		var readflag;
		var newsubstr='';
		var newsublen=0;
		
		var url;
	    url=window.location.href;
        //alert(window.location.href);
        var point;
	    point=url.lastIndexOf('/')+1;
        var strstr= url.substring(0,point);
        //url 除过最后的文件------------------
	    //alert(str);
		
		
		infoBoard=document.getElementById("joketext"); 
        infoBoard.innerText='查询中...'; 
        myurl=strstr+"get_joke_text.php?rand="+Math.random()*10000
       
        retstr=openUrl2(myurl); 
        //alert("服务器返回值："+retstr);
		readflag=retstr.substring(0,1);
		//alert(newretcode);
		
		newsublen=strlen(retstr);
		//alert(newsublen);
		newsubstr=retstr.substring(1,newsublen); 
		//alert(newsub);
		
						
        switch(readflag){ 
        
        case "1": 
                infoBoard.innerHTML='<font color=green size=-1>'+newsubstr+'</font>';break; 
        case "0": 
                infoBoard.innerHTML='<font color=#000000> none！</font>'; break; 
	    default: 
                infoBoard.innerHTML='<font color=red>!</font>,查询失败';break; 	
						
       } 
       return; 
     } 

   function strlen(str) 
   {
        var len = 0;
        for (var i = 0; i<str.length;i++)
	   {
          if (str.charCodeAt(i)>255) len+= 2; 
	      else 
	       len ++;
        }
       return len;
    }


function openUrl2(url)
 
 { 
    var objxml=new ActiveXObject("Microsoft.XMLHttp") 
    objxml.open("GET",url,false); 
    objxml.send(); 
	
    retInfo=objxml.responseText; 
    //-----------------------最重要，将%20 解码成空格，Visit W3School!") ==》Visit%20W3School%21
	retInfo=unescape(retInfo);
    if (objxml.status=="200")
	{ 
      return retInfo; 
    } 
    else
	{ 
      return "-2"; 
     } 
} 