/*
Power By qingtian
联系QQ：314048526
官方站点：http://www.qingtian.net
*/
var start = (new Date).getTime();
function end_ff(){
	var pageLoad = (new Date).getTime() - start;
	alert(pageLoad)
}

function qtCms_dh_getObj(id){return document.getElementById(id);}
function qtCms_dh_init(){
		var liS=qtCms_dh_getObj("qtCms_dh_selectId").getElementsByTagName("input");
		var j
		j=liS.length;
		for(var i=0;i<j;i++){
			liS[i].lisNum = i;
			liS[i].onclick=function(){qtCms_dh_displayTab(this.id.replace(/se/gi,""),0);}
		}
		 
}


function qtCms_dh_setSearchTab(value){expire = 1000*3600*24*30;qtCms_dh_setCookie(qtCms_dh_getSearchTabCookieName(), value, expire);}

var Const_qtCms_dh_se_tab_str=Const_qtCms_dh_tab_str=""

function  qtCms_dh_displayTab(sNum, tNum){
	
	var tpg=true
	if(sNum==5)
		qtCms_dh_getObj("qtcms_hidden_text_1").innerHTML="0"
	else
		qtCms_dh_getObj("qtcms_hidden_text_1").innerHTML="1"
	
/*	if(qtCms_search_btn_google!=""){
		var qta=qtCms_search_btn_google.split("||")
		qta_1=qta[0] //类型，比如google
		qta_2=qta[1] //是否默认路径
		qta_2=(qta_2=="default"?G_Newqt_Dir+"Ztool/search/s/"+qta_1+".html":G_Newqt_Dir+"template/"+G_Newqt_G_moban+"/images/g_js/"+qta_1+".html")
		if(sNum==1){
			
			Const_qtCms_dh_se_tab_str=qtCms_dh_getObj("qtCms_dh_se_tab").innerHTML
			qtCms_dh_getObj("qtCms_dh_se_tab").innerHTML='<iframe id="qtCms_dh_se_tab_google" src="'+qta_2+'" width="100%" marginwidth="0" height="60" marginheight="0" scrolling="no" allowtransparency="true" frameborder="0"></iframe>'
			Const_qtCms_dh_tab_str=qtCms_dh_getObj("qtCms_dh_tab").innerHTML
			qtCms_dh_getObj("qtCms_dh_tab").innerHTML=""
			tpg=false
			
			var selectWeb = document.getElementsByName("qtCms_dh_searchRadio");
			for(var i=0; i<selectWeb.length; i++)
			{
				if(parseInt(selectWeb[i].id.replace(/se/gi,"")) == sNum) selectWeb[i].checked=true;
				else selectWeb[i].checked=false;
			}
			
			qtCms_dh_setSearchTab(sNum+','+tNum);
			
		}else{
			if(Const_qtCms_dh_se_tab_str!="")
				qtCms_dh_getObj("qtCms_dh_se_tab").innerHTML=Const_qtCms_dh_se_tab_str	
			if(Const_qtCms_dh_tab_str!="")
				qtCms_dh_getObj("qtCms_dh_tab").innerHTML=Const_qtCms_dh_tab_str			
		}
	}*/
	
	if(tpg){
		
		qtCms_dh_getObj('qtCms_dh_suggests').style.display='none'
		qtCms_dh_getObj("qtCms_dh_hidpar").innerHTML = '';
		qtCms_dh_getObj("qtCms_dh_searchForm").action = qtCms_dh_searchs[sNum][tNum][1];
		qtCms_dh_getObj("qtCms_dh_kw1").name = qtCms_dh_searchs[sNum][tNum][2];
		qtCms_dh_getObj("qtCms_dh_searchBtn").value = qtCms_dh_searchs[sNum][tNum][3]+"搜索";
		if(qtCms_dh_getObj("qtCms_dh_seBox").style.backgroundPositionY) 
			qtCms_dh_getObj("qtCms_dh_seBox").style.backgroundPositionY = qtCms_dh_searchs[sNum][tNum][4]+"px";
		else {
			qtCms_dh_getObj("qtCms_dh_seBox").style.backgroundPosition = "0 "+qtCms_dh_searchs[sNum][tNum][4]+"px";
		}
		tabLen = qtCms_dh_searchs[sNum].length;tabStr = '';
		var selectWeb = document.getElementsByName("qtCms_dh_searchRadio");
		for(var i=0; i<selectWeb.length; i++)
		{
			if(parseInt(selectWeb[i].id.replace(/se/gi,"")) == sNum) selectWeb[i].checked=true;
			else selectWeb[i].checked=false;
		}
		for(var i=0; i< tabLen; i++)
		{
			if(i == tNum){tabStr = tabStr + "<b  class='qtCms_dh_bStyle'>"+qtCms_dh_searchs[sNum][i][0]+"</b>";}
			else{tabStr = tabStr + "<b onclick='qtCms_dh_displayTab("+sNum+","+i+")'>"+qtCms_dh_searchs[sNum][i][0]+"</b>";}
			if(i < tabLen-1) tabStr = tabStr + "|";
		}
		if(qtCms_search_hand_d=="1"){
			tabStr+="<b id='qTcms_Search_Hand_2' onclick='qTcms_qTcms_Search_Hand_2_c(this)'>手写功能</b><SUP class='qtH'>New!</SUP>"
		}
		
		qtCms_dh_getObj("qtCms_dh_searchTab").innerHTML = tabStr;
		qtCms_dh_getObj("qtCms_dh_setUrl").href = qtCms_dh_searchs[sNum][tNum][5];
		if(qtCms_dh_searchs[sNum][tNum][6] != null)
		{
			paramArrs = qtCms_dh_searchs[sNum][tNum][6].split(";");
			for(var i=0; i< paramArrs.length; i++)
			{
				pvalue = paramArrs[i].split(":");
				pel = document.createElement("INPUT");
				pel.type = "hidden";
				pel.name = pvalue[0];
				pel.id = pvalue[0];
				pel.value = pvalue[1].replace("#",":");
				qtCms_dh_getObj("qtCms_dh_hidpar").appendChild(pel);
			}
		}
		
		if(sNum == 3 && tNum == 1)
		{
			qtCms_dh_getObj("qtCms_dh_searchForm").onsubmit=function(){if(qtCms_dh_getObj("backUrl")) {qtCms_dh_getObj("backUrl").value="http%3A//search.dangdang.com/search.aspx%3Fkey%3D"+qtCms_dh_getObj("qtCms_dh_kw1").value;return true;}};
	
		}
			  // if(sNum > 1){sNum = 1;tNum = 0;}
			   
			   qtCms_dh_setSearchTab(sNum+','+tNum);
	}
}	
function qtCms_dh_setCookie(name,value){var expire = arguments[2] ? arguments[2] : 365*24*60*60*1000;var exp = new Date();exp.setTime(exp.getTime() + expire);document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();}
function qtCms_dh_getCookie(name){var arr; var reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");if(arr=document.cookie.match(reg)){return unescape(arr[2]);}else{return null;}}
function qtCms_dh_getSearchTabCookieName(){return 'qt_schtab';}
function qtCms_dh_getSearchTabByIndex(){
	var index = arguments[0] ? arguments[0] : 0;
	var schtab = qtCms_dh_getCookie(qtCms_dh_getSearchTabCookieName());
	if( ( schtab==null || schtab=='' ) ){
		if(arguments[1]){
			return arguments[1];
		}else{return 0;}
	}
	schtabs = schtab.split(',');
	return schtabs[index];
}
function qtCms_dh_highlightSearchTab()
{
    var s = qtCms_dh_getSearchTabByIndex(0 , -1);
    if(s == -1){
        s = qtCms_search_default_s;
    }
	
    var t = qtCms_dh_getSearchTabByIndex(1);
    qtCms_dh_displayTab(s, t);
	
}

function qtCms_dh_myhint(event){
	//判断是否屏蔽下拉提示==by qingtian 314048526++++++++++++++
   if(qtCms_search_xiala_display=="0"){
		return false   
   }
   if(qtCms_dh_getObj("qtcms_hidden_text_1").innerHTML=="0")
   		return false
	//--------------------	
   var keyword=qtCms_dh_getObj('qtCms_dh_kw1');
   var h=qtCms_dh_getObj('qtCms_dh_suggests');
   if(!keyword.value || !keyword.value.length || event.keyCode==27 || event.keyCode==13){
       h.style.display='none';
       return;
   }
   if(event.keyCode==38 || event.keyCode==40){
     if(h.style.display=='none') return;
       if(event.keyCode==38){
         if(h._i==-1)h._i=h.firstChild.rows.length-1;
         else{h._i--;} 
      }else{h._i++;} 
    for(var i=0;i<h.firstChild.rows.length;i++)h.firstChild.rows[i].style.background="#FFF";
      if(h._i >= 0 && h._i < h.firstChild.rows.length)with(h.firstChild.rows[h._i]){
        style.background="#E6E6E6";
        keyword.value=cells[0].attributes['_h'].value;
      }else{
        keyword.value=h._kw;
        h._i=-1;
      } 
}else{
      h._i=-1;
      h._kw=keyword.value;
      qtCms_dh_googleHint(keyword.value);
      with(h.style){width=keyword.offsetWidth - 2;}
    } 
}
function qtCms_dh_googleHint(key){
  if(qtCms_dh_getObj('gsuggest'))qtCms_dh_getObj('gsuggest').parentNode.removeChild(qtCms_dh_getObj('gsuggest'));
  var sg=document.body.appendChild(document.createElement('script'));
  sg.language='javascript';
  sg.id='gsuggest';
  sg.charset='utf-8';
  sg.src='http://www.google.cn/complete/search?hl=zh-CN&xhr=f&q=' + encodeURIComponent(key);
}

window.google={};
window.google.ac={};
window.google.ac.h=function(a){
   	if(!a || (a.length<3)) return;
    if(a[0] != qtCms_dh_getObj('qtCms_dh_kw1').value) return;
    var ihtml='';
 	var c = a[1];
    for(var j = 0; j < c.length; j ++) {
        ihtml += '<tr style="cursor:pointer" onmousedown="qtCms_dh_getObj(\'qtCms_dh_kw1\').value=\'' +c[j][0] +'\';javascript:qtCms_dh_searchSubmit(this);" onmouseover="javascript:this.style.background=\'#E6E6E6\'" onmouseout="javascript:this.style.background=\'#FFF\';"><td style="color:#000;font-size:12px;" align="left" _h="'+c[j][0] +'">' +c[j][0] +'</td><td style="color:#090" align="right" style="font-size:11.5px;"></td></tr>';
    }
	ihtml += '<tr><td style="color:#000;font-size:12px;" align="left"></td><td style="color:#666666;cursor:pointer" align="right" style="font-size:11.5px;" onclick="qtCms_dh_setDisplay(\'qtCms_dh_suggests\', 0)">关闭</td></tr>';
    qtCms_dh_getObj('qtCms_dh_suggests').innerHTML='<table width="100%" border="0" cellpadding="0" cellspacing="0">' + ihtml + '</table>';
    qtCms_dh_setDisplay('qtCms_dh_suggests', 1);
};
function qtCms_dh_setDisplay(i, d){qtCms_dh_getObj(i).style.display= d ? "block" : "none";}

function qtCms_dh_searchSubmit(index){
     formInfo = index.parentNode.parentNode.parentNode.parentNode; 
     if(formInfo.tagName == "FORM") {
		if(qtCms_dh_getObj("backUrl")) {
		qtCms_dh_getObj("backUrl").value="http%3A%2F%2Fsearch.book.dangdang.com%2Fsearch.aspx%3Fcatalog%3D01%26SearchFromTop%3D1%26key%3D"+$("qtCms_dh_kw1").value;
		}
	formInfo.submit();
	qtCms_dh_getObj('qtCms_dh_suggests').style.display='none'
	}
}



qtCms_dh_init();
qtCms_dh_highlightSearchTab();

if(qtCms_search_hand_d=="1"){
	document.write("<scrip"+"t src='"+G_Newqt_Dir+"Ztool/search/hand.js'></scri"+"pt>")
}
if(qtCms_search_btn_google==""){
	qtCms_dh_getObj("qtCms_dh_kw1").focus();
}
