/**
 * ==========================================
 * main.js
 * Copyright (c) 2010 wwww.96654.com.cn
 * Author: cai@115.com
 * ==========================================
 */
/*$("#date").el.innerHTML = Calendar.show();//显示日期*/

//search

var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0)
var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸")
var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥")
var cmStr = new Array('日','正','二','三','四','五','六','七','八','九','十','冬','腊')
var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十')
var now;var SY;var SM;var SD
function cyclical(num) { return(Gan[num%10]+Zhi[num%12]) }
function lYearDays(y) {
var i, sum = 348
for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0
return(sum+leapDays(y))}
function leapDays(y) {
   if(leapMonth(y))  return((lunarInfo[y-1900] & 0x10000)? 30: 29)
   else return(0)}
function leapMonth(y) { return(lunarInfo[y-1900] & 0xf)}
function monthDays(y,m) { return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 )}
function Lunar(objDate) {
var i, leap=0, temp=0
var baseDate = new Date(1900,0,31)
var offset   = (objDate - baseDate)/86400000
this.dayCyl = offset + 40
this.monCyl = 14
for(i=1900; i<2050 && offset>0; i++) {
temp = lYearDays(i)
offset -= temp
this.monCyl += 12}
if(offset<0) {
offset += temp;
i--;
this.monCyl -= 12}
this.year = i
this.yearCyl = i-1864
leap = leapMonth(i)
this.isLeap = false
for(i=1; i<13 && offset>0; i++) {
if(leap>0 && i==(leap+1) && this.isLeap==false)
{ --i; this.isLeap = true; temp = leapDays(this.year); }
else
{ temp = monthDays(this.year, i); }
if(this.isLeap==true && i==(leap+1)) this.isLeap = false
offset -= temp
if(this.isLeap == false) this.monCyl ++}
if(offset==0 && leap>0 && i==leap+1)
if(this.isLeap)
{ this.isLeap = false; }
else
{ this.isLeap = true; --i; --this.monCyl;}
if(offset<0){ offset += temp; --i; --this.monCyl; }
this.month = i
this.day = offset + 1}
function YYMMDD() {    return(''+SY+'年'+(SM+1)+'月'+SD+'日')}
function weekday(){
    var cl = '';
    return(cl+'星期'+nStr1[now.getDay()]+'');
}
function cDay(m,d){
var nStr2 = new Array('初','十','廿','卅','　');var s
s= cmStr[m]+'月'
switch (d) {
  case 10:s += '初十'; break;
  case 20:s += '二十'; break;
  case 30:s += '三十'; break;
  default:s += nStr2[Math.floor(d/10)]; s += nStr1[Math.round(d%10)];
}return(s)}
function solarDay(){
var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758)
var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至")
var lFtv = new Array("0101*春节","0115 元宵节","0505 端午节","0707 七夕","0715 中元节","0815 中秋节","0909 重阳节","1208 腊八节","1224 小年","0100*除夕")
var sFtv = new Array("0101*元旦","0214 情人节","0308 妇女节","0312 植树节","0401 愚人节","0501 劳动节","0504 青年节","0512 护士节","0601 儿童节","0701 建党节","0801 建军节","0910 教师节","1001*国庆节","1101 万圣节","1108 记者日","1225 圣诞节","0513 母亲节","0617 父亲节")
  var sDObj = new Date(SY,SM,SD);
  var lDObj = new Lunar(sDObj);
  var lDPOS = new Array(3)
  var festival='',solarTerms='',solarFestival='',lunarFestival='',solarTerms='',tmp1,tmp2;

  for(i in lFtv)
  if(lFtv[i].match(/^(\d{2})(.{2})([\s\*])(.+)$/)) {
   tmp1=Number(RegExp.$1)-lDObj.month;
   tmp2=Number(RegExp.$2)-lDObj.day;
   if(tmp1==0 && tmp2==0) lunarFestival=RegExp.$4;}
  if(lunarFestival=='') {
  for(i in sFtv)
  if(sFtv[i].match(/^(\d{2})(\d{2})([\s\*])(.+)$/)){
   tmp1=Number(RegExp.$1)-(SM+1);
   tmp2=Number(RegExp.$2)-SD;
   if(tmp1==0 && tmp2==0) solarFestival = RegExp.$4;}
  if(solarFestival =='') {
	  tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2+1]*60000)+Date.UTC(1900,0,6,2,5))
  tmp2 = tmp1.getUTCDate()
  if (tmp2==SD) solarTerms = solarTerm[SM*2+1]
  tmp1 = new Date((31556925974.7*(SY-1900)+sTermInfo[SM*2]*60000)+Date.UTC(1900,0,6,2,5))
  tmp2= tmp1.getUTCDate()

  if (tmp2==SD) solarTerms = solarTerm[SM*2]
	if(solarTerms=='') sFtv='';else sFtv=solarTerms
  } else sFtv=solarFestival
  } else sFtv=lunarFestival
  if(sFtv=='')
	sTermInfo=cyclical(lDObj.year-1900+36)+'年 '+cDay(lDObj.month,lDObj.day)
  else sTermInfo=cDay(lDObj.month,lDObj.day)+' '+sFtv+''
  return(sTermInfo)
}
  function solarDay2(){
    	
        var lDObj = new Lunar(new Date(SY, SM, SD));
        var tt = cyclical(lDObj.year-1900+36)+'年 '+cDay(lDObj.month, lDObj.day);
        return (tt)
    }

function CurentTime()
{
	var now=new Date();
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getTime()%60000;	
	ss=(ss-(ss%1000))/1000;	
	if(hh==0&&mm==0&&ss==0)showcal(1)
	var clock=hh+':';	
	if(mm<10)clock+='0';	
	clock+=mm;
	return (clock)
}
function refreshCalendarClock(){
	
}
function showcal(t){
	now=new Date();
	SY=now.getFullYear();
	SM=now.getMonth();
	SD=now.getDate();	
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getTime()%60000;	
	ss=(ss-(ss%1000))/1000;
	hh+=':'
	if(mm<10)hh+='0'
	hh+=mm
	var str='<p><a href="javascript:rili()" target=_self>今天是：<b>'+YYMMDD()+'</b></a></p><p><a href="javascript:rili()" target=_self>'+solarDay2()+'</a></p><p><div class="rl_week"><a href="javascript:rili()" target=_self>'+weekday()+'</a></div><div class="tixin"><a href="javascript:clock()" target=_self  title=点击设置闹钟>闹钟</a></div><div class="hangli"><a href="javascript:rili()" target=_self  title=点击查看日历>日历</a></div></p>';	
	if(t==1)document.getElementById('rili').innerHTML=str;
	else document.write(str);
}
function clock(){
	window.open(dhpath+'tool/time/clock.htm','time','left='+(screen.width-380)+',height=310,width=310,status=no,toolbar=no,menubar=no')
}
function rili(){
	window.open(dhpath+'tool/calendar/index.htm','hangli','left='+(screen.width-500)+',height=512,width=412,status=no,toolbar=no,menubar=no')
}
if(typeof(isclock)!="undefined"){
	showcal(1);
	setInterval('refreshCalendarClock()',1000)
}



Date.prototype.format = function(format){
	var o = {
		"M+" : this.getMonth()+1, //month
		"d+" : this.getDate(),    //day
		"h+" : this.getHours(),   //hour
		"m+" : this.getMinutes(), //minute
		"s+" : this.getSeconds(), //second
		"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
		"S" : this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format)){
		format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}
	for(var k in o){
		if(new RegExp("("+ k +")").test(format)){
			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
		}
	}
	return format;
}
$("#jp_today,#jd_fromDate,#jd_toDate").each(function(el){
	el.value = new Date(new Date().getTime()+3600*24*1000).format("yyyy-MM-dd");
});

var qucikSearch = (function(){
    var Q = $("#q_int");
    var I = $("#q_int input");
    var R = $("#qs-result");
    var Btn = false;
    var defaultValue = I.el.value = "请输入网站名或拼音";
    var inputState = 0; //0 普通  1 focus
    var sendDelay, countDelay,timer = 200;
    var lastValue;
    
    I.on("focus", function(el){
        Q.el.className = "f";
        if (el.value == defaultValue) {
            el.value = "";
        }
        inputState = 1;
    });
    
    I.on("keyup", function(el){
        if (el.value == "") {
            closeSearch();
            return;
        }
        if (lastValue && el.value == lastValue) {
            return; //无改变
        }
        if (!Btn) {
            Q.create("a", {
                id: "qs-btn",
				rel:'nr',
                href: "javascript:void(0);",
                target: "_parent",
                title: "关闭"
            }, function(el){
                el.onclick = function(){
                    inputState = 0;
                    closeSearch();
                }
                this.append(el);
            });
            Btn = true;
        }
        if (el.value!="") {
            if (sendDelay) {
                window.clearTimeout(sendDelay);
            }
			if (countDelay) {
                window.clearTimeout(countDelay);
            }
            send(el.value);
        }
        
    })
    
    I.on("blur", function(el){
        Q.el.className = "n";
        if (el.value == "") {
            el.value = defaultValue;
        }
        
    });
    
    function closeSearch(clear){
        R.hide();
        if (Btn) {
            Q.el.removeChild($("#qs-btn").el);
            Btn = false;
        }
        if (inputState == 0 || clear == true) {
            I.el.value = defaultValue;
            //K.el.blur();
        }
        cache.remove("HAS_SHOW_QS");
    }
    function send(query){
		if(query==""){return}
        lastValue = query;
        sendDelay = window.setTimeout(function(){
			R.show();
            cache.set("HAS_SHOW_QS", true);
            R.el.innerHTML = '<ul><li>正在搜索中...</li></ul>';
            var api = './search.php?keyword=' + encodeURIComponent(query) ;
			//var api = 'search.txt?k=1';
			Ajax(api+ '&rd=' + new Date().getTime(), callback);
        }, timer);
		
        countDelay = window.setTimeout(function(){
			KeywordCount({
			type: "qs",
			word: query,
			url: window.location.href
			}, "http://www.tjj.com/click.php");
		},1000);
        
        function callback(xhr){
            if (xhr.responseText == '') {
                R.el.innerHTML = '<ul><li>没有搜索到相关站点!</li></ul>';
            }
            else {
                R.el.innerHTML = '<ul class="clearfix">' + xhr.responseText + '</ul>';
            }
        }
        
    }
    return {
        close: closeSearch
    }
})();//网址快速搜索



var Suggest = (function(){
    var K , S = $("#suggest"), Query,//输入值
 currentKey = -1, dataScript = null,//数据脚本
 dataResult,//结果数据
 KeywordItems, //li
 mouseSelect = false, stopRequest = false, Hidestate = false, isClose = false;
var KEL;
	$(".sstb .sskbg").each(function(el){
		K = $(el);
		
		
		K.el.onkeydown = function(e){
			var e = e || window.event;
			if (isClose) {
				return;
			}
			KEL = this
			switch (e.keyCode) {
				case 38:
					if (Hidestate) {
						if (this.value == "") 
							return;
						S.show();
						Hidestate = false;
					}
					else {
						currentKey--
					}
					selectItem();
					break;
				case 40:
					if (Hidestate) {
						if (this.value == "") 
							return;
						S.show();
						Hidestate = false;
					}
					else {
						currentKey++
					}
					selectItem();
					break;
				case 27:
					this.value = Query;
					hideSuggest();
					break;
				case 13:
					hideSuggest();
					break;
				default:
					//stopRequest = false;
					break;
			}
		}

    K.el.onkeyup = function(e){
        var e = e || window.event;
        if (isClose) {
            return;
        }
        
		var myKey = Number(this.getAttribute("index"));
		for(var j = 0, jlen = inputTxtArr.length; j < jlen; j++){
			var oKey = Number(inputTxtArr[j].getAttribute("index"));
			if(oKey != myKey){
				inputTxtArr[j].value = this.value;
			}
		}
        Query = this.value;
       
        switch (e.keyCode) {
            case 38:
                stopRequest = true;
                
                break;
            case 40:
                stopRequest = true;
                break;
            case 8:
                if (this.value == "") {
                    hideSuggest();
                }
                else {
                    requestData();
                }
                break;
            case 27:
                this.value = Query;
                hideSuggest();
            case 13:
                hideSuggest();
                break;
            default:
                if (Query != "") {
                    requestData();
                }
                
                break;
        }
    }
	
	
	
    K.el.onblur = function(){
        if (!mouseSelect) {
            hideSuggest();
        }
    }
	
    function selectItem(){
        if (!KeywordItems) 
            return;
        var len = KeywordItems.length;
        
        stopRequest = true;
        if (currentKey < 0) {
            currentKey = len - 1;
        }
        else 
            if (currentKey >= len) {
                currentKey = 0;
            }
        for (var i = 0, len = KeywordItems.length; i < len; i++) {
            KeywordItems[i].className = "";
        }
        KeywordItems[currentKey].className = "hover";
        //K.el.value = KeywordItems[currentKey].innerHTML;
		for(var j = 0, jlen = inputTxtArr.length; j < jlen; j++){
			inputTxtArr[j].value = KeywordItems[currentKey].innerHTML;
		}
    }
    
    function showSuggest(){
        if (typeof(dataResult) != "object" || typeof(dataResult) == "undefined") 
            return;
        var html = '<ul>';
        dataResult.forEach(function(el, index, arr){
                html += '<li key="' + index + '">' + el + '</li>';
        });
        html += '</ul><div class="close"><a id="closeSugBtn">关闭</a></div>';
        KeywordItems = S.el.getElementsByTagName("li");
        S.el.innerHTML = html;
        S.show();
        currentKey = -1;
        Hidestate = false;
        mouseHandle();
    }
    function hideSuggest(){
        S.hide();
        Hidestate = true;
        
    }
    
    function closeSuggest(){
        KEL.setAttribute("autocomplete", "on");
        KEL.focus();
        S.hide();
        isClose = true;
    }
    
    function mouseHandle(){
        S.el.onmouseover = function(e){
            var e = e || window.event, target = e.target || e.srcElement;
            
            if (target.tagName.toUpperCase() == "LI") {
                for (var i = 0, len = KeywordItems.length; i < len; i++) {
                    KeywordItems[i].className = "";
                }
                target.className = "hover";
                currentKey = parseInt(target.getAttribute("key"));
                
                $(target).on("mouseout", function(el){
                    el.className = "";
                })
            }
            mouseSelect = true;
        }
        S.el.onmouseout = function(){
            mouseSelect = false;
        }
        
        S.el.onclick = function(e){
            var e = e || window.event, target = e.target || e.srcElement;
            if (target.tagName.toUpperCase() == "LI") {
				for(var j = 0, jlen = inputTxtArr.length; j < jlen; j++){
					inputTxtArr[j].value = target.innerHTML;
				}
                hideSuggest();
               var SF =  KEL.parentNode;
			   //SF.onsubmit();
			   SF.submit();
            }
            if (target.id == "closeSugBtn") {
                closeSuggest();
            }
            
        }
    }

    function requestData(){
        var head = $("head").el;
        if (!Browser.isIE) {
            if (dataScript) {
                head.removeChild(dataScript);
            }
            dataScript = null;
        } // IE不需要重新创建script元素
        if (!dataScript) {
            var script = document.createElement("script");
            script.type = "text/javascript";
			script.charset = "gb2312";
            head.insertBefore(script, head.firstChild);
            dataScript = script;
        }
        var rd = new Date().getTime();
        var key = encodeURIComponent(K.el.value);
        var Url = "http://suggestion.baidu.com/su?wd=" + key + "&sc=114la&rd=" + rd;
       dataScript.src = Url;
    }
	
    //baidu
    window.baidu = {};
    window.baidu.sug = function(O){
        if (typeof(O) == "object" && typeof(O.s) != "undefined" && typeof(O.s[0]) != "undefined") {
            dataResult = O.s;
            showSuggest();
        }
        else {
            hideSuggest();
        }
    };
	
	
	});
})();//搜索自动完成


function KeywordCount(keyword, Counturl){
    if (!keyword || keyword =="") {
        return
    }
    var url = Counturl || "http://www.tjj.com/index";
	
	
    var rd = new Date().getTime()
    var Count = new Image();
    var countVal = "";
	for (var i in keyword) {

			if(i=='u'){
				countVal += ('?'+ i +'=' + encodeURIComponent(keyword[i]));
			}else{
				countVal += ('&' + i +'=' + encodeURIComponent(keyword[i]));
			}
	}
	if(url=="http://www.tjj.com/index"){
		Count.src = url+countVal+'&i='+rd;
	}else{
		Count.src = url + "?i=" + rd + countVal;
	}
}

DOMReady(function(){
	if(Browser.isIE){			  
		
	}
	var setFocus = function(){
		
	}
    $("#f_int input,#q_int input").on("mouseover", function(el){

		if (cache.get(el.id + "GETFOCUS") && el.parentNode.id =="q_int") {
            return;
        }
		if(document.all){
        	Yl.getFocus(el);
		}else{
			el.focus();
		}
    });
/*	$(".tbox .int_b").on('mouseover',function(el){
		el.select();
	});*/
	
    $("#f_int input,#q_int input").on("blur", function(el){
        cache.remove(el.id + "GETFOCUS");
    });

});



function ResumeError(){
    return true
}
window.onerror = ResumeError;
