﻿// JScript 文件

function $(obj)
{
    return document.getElementById(obj);
}

//设置查询类别
function SetMenuSelected(obj,categoryid)
{
    for(var i=0;i<=12;i++)
    {
        $("menu"+i).className = "#";
    }
    obj.className = "hover"
    $("category").value = categoryid;
}

//首页搜索按钮事件
function SetDetailMenuSelected(categoryid)
{
    for(var i=0;i<=12;i++)
    {
        $("menu"+i).className = "#";
    }
    switch(categoryid)
    { 
        case "all":
             $("menu0").className = "hover";
        break;
        case "A1":
            $("menu1").className = "hover";
        break;
        case "A2":
            $("menu2").className = "hover";
        break;
        case "buy":
            $("menu3").className = "hover";
        break;
        case "supply":
            $("menu4").className = "hover";
        break;
        case "A20":
            $("menu6").className = "hover";
        break;
        case "A15":
            $("menu7").className = "hover";
        break;
        case "company":
            $("menu8").className = "hover";
        break;
        case "A17":
            $("menu9").className = "hover";
        break;
        case "A301":
            $("menu10").className = "hover";
        break;
          case "A16":
            $("menu11").className = "hover";
        break;
        case "book":
            $("menu12").className = "hover";
        break;
    }
}


function SetSearch()
{
    var keyword = $("keyword").value;
    var categoryid = $("category").value;
    
    if(keyword.length == 0)
    {
        alert("请输入关键字！");
        return false;
    }
    if(categoryid.length == 0)
    {
        categoryid = "all";
    }

    url = "/detail_" + encodeURI(keyword) + "_" + categoryid;
	try
	{
        document.form1.action = url;
        document.form1.submit();
    }
    catch(e)
    {
    	window.location.href = url;
    }
    openDialogs("<p>不要着急，休息，休息一下...</p><p align='center'><img src='/images/plzwait.gif'/></p>")
}


function hotKeyword(keyword)
{
    var url = "/detail_" + encodeURI(keyword) + "_all";
    alert(url);
    try
	{
        document.form1.action = url;
        document.form1.submit();
    }
    catch(e)
    {
    	window.location.href = url;
    }
    openDialogs("<p>不要着急，休息，休息一下...</p><p align='center'><img src='/images/plzwait.gif'/></p>")
}



function openDialogs(strHtml)
 {

    new NeatDialog(strHtml, "聪明的一休", false);
}

function NeatDialog(sHTML, sTitle, bCancel)
{
  window.neatDialog = null;
  this.elt = null;
  if (document.createElement  &&  document.getElementById)
  {
    var dg = document.createElement("div");
    dg.className = "neat-dialog";
    if (sTitle)
      sHTML = '<div class="neat-dialog-title"><div>'+sTitle+'</div>'+
                '</div>\n' + sHTML;
    dg.innerHTML = sHTML;

    var dbg = document.createElement("div");
    dbg.id = "nd-bdg";
    dbg.className = "neat-dialog-bg";

    var dgc = document.createElement("div");
    dgc.className = "neat-dialog-cont";
    dgc.appendChild(dbg);
    dgc.appendChild(dg);

    if (document.body.offsetLeft > 0)
      dgc.style.marginLeft = document.body.offsetLeft + "px";

    document.body.appendChild(dgc);
    if (bCancel) document.getElementById("nd-cancel").onclick = function()
    {
      window.neatDialog.close();
    };
    this.elt = dgc;
    window.neatDialog = this;
  }
}

function GetXmlHttp()
{
	var A=null; 
	try { 
		A=new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch(e){ 
		try{ 
			A=new ActiveXObject("Microsoft.XMLHTTP"); 
		}catch(oc){ 
			A=null;
		}
	} 
	if ( !A && typeof XMLHttpRequest != "undefined" ){ 
		A=new XMLHttpRequest() ;
	} 
	return A ;
}

function GetSearchLogXML()
{
    var keyword = $("keyword").value;
    var type = ($("category").value!="")?$("category").value:"all";
    var message = "";
    var xmlhttp = GetXmlHttp();
    if(xmlhttp==null) return;
    var poster = "/searchlogxml.aspx?type=" + encodeURI(type) + "&keyword=" + escape(keyword);
    xmlhttp.open("GET",poster,true,null);
    xmlhttp.onreadystatechange=function(){
	if(xmlhttp.readyState==4&&xmlhttp.status==200){
		var DataXml=xmlhttp.responseXML;
	    var liArray = DataXml.getElementsByTagName('list');
		ClearTable();
		for(var i=0;i<liArray.length;i++){
		    //message = "<tr onmouseover=\"this.bgColor='#0066CC';\" onmouseout=\"this.bgColor='transparent';\"><td class='al'>"+liArray[i].getElementsByTagName("keyword")[0].firstChild.data+"</td><td class='ar'>"+liArray[i].getElementsByTagName("resultcnt")[0].firstChild.data+"</td></tr>";
			//alert(message);
			AddDataRow(liArray[i].getElementsByTagName("keyword")[0].firstChild.data,liArray[i].getElementsByTagName("resultcnt")[0].firstChild.data);
			}			
		//$("autoComplete").innerHTML = message;
		}
	}
	xmlhttp.send (null);
}

function AddDataRow(keyword,resultcnt){
    var otr = $("autoComplete").insertRow(-1);
        otr.onmouseover = setMouseOverStyle; //otr.bgColor="#0066CC";
        otr.onmouseout = setMouseOutStyle;   //otr.bgColor="transparent";
		otr.onclick = SetSearchFromLog;
    var otd1 = document.createElement("td");
	otd1.className = "al";
    otd1.innerText = keyword;
    var otd2 = document.createElement("td");
	otd2.className = "ar";
    otd2.innerText = resultcnt+"条结果";

	otr.appendChild(otd1); 
    otr.appendChild(otd2); 

}

function ClearTable()
{
	var tbl = $("autoComplete");
	var rowscnt = tbl.rows.length;
	for(var i=0;i<rowscnt;i++)
	{
		tbl.deleteRow(0);
	}
}


setMouseOverStyle = function()
{
	this.bgColor = "#0066CC";
	this.style.cursor = "hand";
	this.style.color = "#FFF";
}

setMouseOutStyle = function()
{
	this.bgColor = "transparent";
	this.style.color = "#000";
}

SetSearchFromLog = function()
{
	var keyword = this.getElementsByTagName("td")[0].innerText;
	$("keyword").value = keyword;
	var type = $("category").value;
	//alert(keyword);
	//alert(type);
	SetSearch();
}