// JavaScript Document by yaoqi


function $ID(ID)
{
	return document.getElementById(ID);
}

function AJAXLib()
{

    this.XMLHttpReq = null;						//XML对象
    this.method = "post";						//执行的方法(post/get)
    this.URLString = "";						//异步调用的页面地址
    this.response = "";							//异步返回的响应字符串
    this.responseXML = "";                      //异步返回的响应XML
    this.failed = false;                        //创建对象错误标志
    
    /**
    事件区
    */
	this.onLoading = function() { };            //正在发送请求
	this.onLoaded = function() { };             //已经接收到全部响应内容
	this.onInteractive = function() { };        //正在解析响应内容
	this.onCompletion = function() { };         //响应内容解析完成
	this.onError = function() { };              //异步错误处理事件
	this.onFail = function() { };               //创建对象失败处理世界
    
    /**
    重置所有事件函数
    */
    this.resetFunctions = function() {
		this.onLoading = function() { };
		this.onLoaded = function() { };
		this.onInteractive = function() { };
		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
    };
	
	/**
    初始化函数(构造时自动初始化)
    */
    this.Init = function()
    {
       //对于Mozilla浏览器
        if(window.XMLHttpRequest)
        {
            //直接使用XMLHttpRequest函数来创建XMLHttpRequest对象
            this.XMLHttpReq = new XMLHttpRequest();
        }
        //对于IE浏览器
        else if (window.ActiveXObject)
        {
            try
            {
                this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP");
                }
                catch(e)
                {
                    try
                    {
                        this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e)
                    {
                        try
                        {
                            this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                        } 
                        catch(oc)
                        {
                            this.failed=true;   //创建AJAX对象发生异常
                        }
                    }
                }
            }
//            try
//            {
//                //使用AcitveXObject函数创建浏览器
//                this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
//            }
//            catch (e)
//            {
//                //如果出现异常，再次尝试以如下方式创建XMLHttpRequest对象
//                try
//                {
//                    this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
//                }
//                catch (e)
//                {
//                    this.failed=true;   //创建AJAX对象发生异常
//                }
//            }
        }
    };
    
    /**
    发送请求函数
    @param data 发送的数据
    @example send("id=1");
    */
    this.Send=function(data)
    {
        var self=this;
        //通过open方法取得与服务器的连接
	    if(this.method=="post")
	    {
		    this.XMLHttpReq.open(self.method,self.URLString,true);
	    }
	    else
	    {
		    this.XMLHttpReq.open(self.method,self.URLString+"?"+encodeURI(data),true);
	    }
	    //添加消息响应头
        this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        
        //异步回调函数
        this.XMLHttpReq.onreadystatechange = function()
        {
            //对象未创建
            if (self.failed) {
	            self.onFail();
	            return;
            }
            
            //消息响应标志
            switch (self.XMLHttpReq.readyState) {
	            case 1:
	            {
		            self.onLoading();
		            break;
	            }
	            case 2:
	            {
		            self.onLoaded();
		            break;
	            }
	            case 3:
	            {
		            self.onInteractive();
		            break;
	            }
	            case 4:
	            {
		            if(self.XMLHttpReq.status==200) { 
			            self.response = self.XMLHttpReq.responseText;
			            self.responseXML = self.XMLHttpReq.responseXML;
			            self.onCompletion();
		            }
		            else 
		            { 
			            self.onError();     //执行错误函数
		            }
		            break;
	            }
            }
        };
        
        
        if(this.method=="post")
        {
            this.XMLHttpReq.send(encodeURI(data)); //发送请求
        }
        else
        {
            this.XMLHttpReq.send(); //发送请求
        }
    };
    
    this.Abort=function()
    {
        this.XMLHttpReq.abort();
    }
    
    this.Close=function()
    {
        this.XMLHttpReq=null;
    }
	//初始化AJAX库
    this.Init();
}



var haoCurrHighLight = document.getElementById("haobaidu");
function haoSubSearch(sc){
	changePage(sc);
	imglogo=document.getElementById("imglogo");
	keyWords=document.getElementById("word");
	Btn=document.getElementById("SSBtn");
		if(sc == "google")
		{		
			imglogo.src="link/logo_google.gif";
			imglogo.alt="谷歌";	
			urllogo.href="http://www.google.com";
			f.SSBtn.onclick=function(){window.open("http://www.google.cn/search?domains=www.church114.cn&q="+keyWords.value);};
			return ;
		}
		else if(sc == "youdao")
		{			
			imglogo.src="link/logo_youdao.gif";
			imglogo.alt="有道";	
			urllogo.href="http://www.youdao.com/";
			f.SSBtn.onclick=function(){window.open("http://www.youdao.com/search?keyfrom=www.church114.cn&q="+keyWords.value);};
			return ;
		}
		else if(sc == "baidu")
		{
			imglogo.src="link/logo_baidu.gif";			
			imglogo.alt="百度首页";	
			urllogo.href="http://www.baidu.com/index.php?tn=sitechurch114";
			f.SSBtn.onclick=function(){window.open("http://www.baidu.com/s?tn=www.church114.cn&wd="+keyWords.value);};
			return ;
		}
		else if(sc == "zhidao")
		{
			imglogo.src="link/logo_baiduzhidao.gif";
			imglogo.alt="百度知道";	
			urllogo.href="http://zhidao.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word="+keyWords.value);};
			return ;
		}
		else if(sc == "mp3")
		{
			imglogo.src="link/logo_baidump3.gif";
			imglogo.alt="百度MP3";	
			urllogo.href="http://mp3.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://mp3.baidu.com/m?tn=www.church114.cn&word="+keyWords.value);};
			return ;
		}
		else if(sc == "img")
		{
			imglogo.src="link/logo_baidupic.gif";
			imglogo.alt="百度图片";	
			urllogo.href="http://image.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://image.baidu.com/i?tn=baiduimage&ct=201326592&lm=-1&cl=2&word="+keyWords.value+"&z=0");};
			return ;
		}
		else if(sc == "post")
		{
			imglogo.src="link/logo_baidupost.gif";
			imglogo.alt="百度帖吧";	
			urllogo.href="http://image.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://tieba.baidu.com/f?tn=www.church114.cn&kw="+keyWords.value);};
			return ;
		}
		else if(sc == "news")
		{
			imglogo.src="link/logo_baidunews.gif";
			imglogo.alt="百度新闻搜索";	
			urllogo.href="http://news.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://news.baidu.com/ns?cl=2&rn=20&tn=news&word="+keyWords.value);};
			return ;
		}
		else if(sc == "Video")
		{
			imglogo.src="link/logo_baiduvedio.gif";
			imglogo.alt="百度视频搜索";	
			urllogo.href="http://video.baidu.com/";
			f.SSBtn.onclick=function(){window.open("http://video.baidu.com/v?tn=www.church114.cn&word="+keyWords.value);};
			return ;
		}

}
function searchInit()
{
	keyWords=document.getElementById("word");
	window.open("http://www.baidu.com/s?tn=www.church114.cn&wd="+keyWords.value);
	//changePage("baidu");
}
function changePage(sc){
	if(haoCurrHighLight == null){
		haoCurrHighLight = document.getElementById("haobaidu");
	}
	//alert(haoCurrHighLight.id);
	haoCurrHighLight.className = "searchfod2";
	haoCurrHighLight = document.getElementById("hao"+sc);
	haoCurrHighLight.className = "searchfod1";
	document.f.word.focus()
	 f.word.value="";
}

function AJAXLib()
{

    this.XMLHttpReq = null;						//XML对象
    this.method = "post";						//执行的方法(post/get)
    this.URLString = "";						//异步调用的页面地址
    this.response = "";							//异步返回的响应字符串
    this.responseXML = "";                      //异步返回的响应XML
    this.failed = false;                        //创建对象错误标志
    
    /**
    事件区
    */
	this.onLoading = function() { };            //正在发送请求
	this.onLoaded = function() { };             //已经接收到全部响应内容
	this.onInteractive = function() { };        //正在解析响应内容
	this.onCompletion = function() { };         //响应内容解析完成
	this.onError = function() { };              //异步错误处理事件
	this.onFail = function() { };               //创建对象失败处理世界
    
    /**
    重置所有事件函数
    */
    this.resetFunctions = function() {
		this.onLoading = function() { };
		this.onLoaded = function() { };
		this.onInteractive = function() { };
		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
    };
	
	/**
    初始化函数(构造时自动初始化)
    */
    this.Init = function()
    {
       //对于Mozilla浏览器
        if(window.XMLHttpRequest)
        {
            //直接使用XMLHttpRequest函数来创建XMLHttpRequest对象
            this.XMLHttpReq = new XMLHttpRequest();
        }
        //对于IE浏览器
        else if (window.ActiveXObject)
        {
            try
            {
                this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP");
                }
                catch(e)
                {
                    try
                    {
                        this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e)
                    {
                        try
                        {
                            this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                        } 
                        catch(oc)
                        {
                            this.failed=true;   //创建AJAX对象发生异常
                        }
                    }
                }
            }
//            try
//            {
//                //使用AcitveXObject函数创建浏览器
//                this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
//            }
//            catch (e)
//            {
//                //如果出现异常，再次尝试以如下方式创建XMLHttpRequest对象
//                try
//                {
//                    this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
//                }
//                catch (e)
//                {
//                    this.failed=true;   //创建AJAX对象发生异常
//                }
//            }
        }
    };
    
    /**
    发送请求函数
    @param data 发送的数据
    @example send("id=1");
    */
    this.Send=function(data)
    {
        var self=this;
        //通过open方法取得与服务器的连接
	    if(this.method=="post")
	    {
		    this.XMLHttpReq.open(self.method,self.URLString,true);
	    }
	    else
	    {
		    this.XMLHttpReq.open(self.method,self.URLString+"?"+encodeURI(data),true);
	    }
	    //添加消息响应头
        this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        
        //异步回调函数
        this.XMLHttpReq.onreadystatechange = function()
        {
            //对象未创建
            if (self.failed) {
	            self.onFail();
	            return;
            }
            
            //消息响应标志
            switch (self.XMLHttpReq.readyState) {
	            case 1:
	            {
		            self.onLoading();
		            break;
	            }
	            case 2:
	            {
		            self.onLoaded();
		            break;
	            }
	            case 3:
	            {
		            self.onInteractive();
		            break;
	            }
	            case 4:
	            {
		            if(self.XMLHttpReq.status==200) { 
			            self.response = self.XMLHttpReq.responseText;
			            self.responseXML = self.XMLHttpReq.responseXML;
			            self.onCompletion();
		            }
		            else 
		            { 
			            self.onError();     //执行错误函数
		            }
		            break;
	            }
            }
        };
        
        
        if(this.method=="post")
        {
            this.XMLHttpReq.send(encodeURI(data)); //发送请求
        }
        else
        {
            this.XMLHttpReq.send(); //发送请求
        }
    };
    
    this.Abort=function()
    {
        this.XMLHttpReq.abort();
    }
    
    this.Close=function()
    {
        this.XMLHttpReq=null;
    }
	//初始化AJAX库
    this.Init();
}