﻿function LGAjax(onSuccess,timeOut,onTimeOut,onRequesting){var S=onSuccess;var T=onTimeOut;var R=onRequesting;var m=this;var i=0;m.XMLHttp=null;m.TimeOut=8000;m.RequestMethod="GET";m.IsAsync=true;m.PostData=null;m.Requesting=false;if(typeof timeOut=="number")m.TimeOut=timeOut;if(typeof XMLHttpRequest!="undefined"){m.XMLHttp=new XMLHttpRequest();}else if(window.ActiveXObject){var aVersions=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];for(var i=0;i<aVersions.length;i++){try{m.XMLHttp=new ActiveXObject(aVersions[i]);break;}catch(oe){}}};var H=function(){if(m.XMLHttp.readyState==4){m.Requesting=false;clearTimeout(i);if(m.XMLHttp.status==200){if(typeof S=="function")S(m);}else{if(typeof T=="function")T(m);}}};var O=function(){m.XMLHttp.abort();};m.Request=function(url){if(m.Requesting){if(typeof R=="function")R(m);}else{m.XMLHttp.onreadystatechange=H;m.XMLHttp.open(m.RequestMethod.toUpperCase(),url,m.IsAsync);if(m.RequestMethod.toUpperCase()=="POST")m.XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");m.XMLHttp.send(m.PostData);if(m.IsAsync){clearTimeout(i);i=setTimeout(O,m.TimeOut);m.Requesting=true;}}};}

var ajax = new LGAjax(GenCate);
	var isP = true;
	function GenCate()
	{
		var jnCate = eval(ajax.XMLHttp.responseText);
		var slt;
		if(isP)
		{
			slt = document.getElementById("slt_PID");
			isP = false;
		}
		else
		{
			slt = document.getElementById("slt_CID");
		}
		
		slt.options.length = 0;
		slt.options.add(new Option("不选","-1"));
		if(jnCate != null && jnCate.length > 0)
		{
			for(var i = 0;i<jnCate.length;i++)
			{
				slt.options.add(new Option(jnCate[i].Title,jnCate[i].ID));
			}
			slt.selectedIndex = 0;
		}
	}
	window.onload = function()
	{
		ajax.Request("/getcc.ashx?PID=0");
	}
	function RootChange()
	{
		var id = parseInt(document.getElementById("slt_PID").value);
 
		if(id > 0)
		{
			ajax.Request("/getcc.ashx?PID=" + id );
		}
		else
		{
			var slt = document.getElementById("slt_CID");
			slt.options.length = 0;
			slt.options.add(new Option("不选","-1"));
		}
	}
 
	function GoSearch()
	{
		var keyword = document.getElementById("txt_Keyword");
		if(keyword.value == "")
		{
			alert("请输入搜索关键字！");
			keyword.focus();
			return;
		}
		var url = "/Search.aspx?Keyword=" + escape(keyword.value);
		var cid = parseInt(document.getElementById("slt_CID").value);
		if(cid > 0)
		{
			url = url + "&CID=" + cid;
		}
		else
		{
			var pid = parseInt(document.getElementById("slt_PID").value);
			if(pid > 0)
			{
				 url = url + "&PID=" + pid;
			}
		}
		window.location.href = url;
	}