/**
 * <script type="text/javascript" src="/search/script/classic.js">
 *      searchbar.leftimg=false;
 *      searchbar.init(); 
 * </script>
 * @param {Object} $sid
 */
var searchbar = {
    values: new Array(),
	leftimg:true,
	
    g: function($sid){
        return document.getElementById($sid);
    },
    
    init: function(){
        this.values["dictionary"] = new Array('权威、完整的电子百科词典，阅读专业文章必查', 'http://www.eefocus.com/dict/', '_blank');
        this.values["site"] = new Array('电子业界资讯搜索', 'http://www.eefocus.com/search/', '_blank');
        this.values["Datasheet"] = new Array('元器件数据手册一网搜尽', 'http://www.eefocus.com/datasheet/', '_blank');
        this.values["cndzz"] = new Array('电路、资料、方案一网搜尽', 'http://www.cndzz.com/search/', '_blank');
		
        var tpl = this.tpl();
        document.write(tpl);
    },
    
    check: function(){
        var k = this.g("searchselect").value;
        if (this.values[k][0] == this.g('keyword').value || this.g('keyword').value == '') {
            alert("请填写搜索关键字！");
            return false;
        }
        return true;
    },
    
    start: function(){
        if (this.g('keyword').value == this.values[this.g("searchselect").value][0]) {
            this.g('keyword').value = '';
            this.g('keyword').style.color = 'black';
            return;
        }
        if (this.g('keyword').value == '') {
            this.g('keyword').value = this.values[this.g("searchselect").value][0];
            this.g('keyword').style.color = 'gray';
            return;
        }
    },
    tab: function(id){
        var s = new Array("dictionary", "site", "Datasheet", "cndzz");
	    var v = s[id];
	    for (i = 0; i < s.length; i++) {
	        if (i == id) {
	            this.g("tab_btn" + i).className = "eiki_he";
	        }
	        else {
	            this.g("tab_btn" + i).className = "eiki_he1";
	        }
	    }
	    this.g("searchselect").value = v;
		this.g("searchform").action = this.values[v][1];
		this.g("searchform").target = this.values[v][2];
		    
	    if (this.eiki_check()) {
	        this.g("keyword").value = this.values[v][0];
	    }
    },
    
    eiki_check: function(){
        if (this.g("keyword").value == '') {
            return true;
        }
        var s = new Array("dictionary", "site", "Datasheet", "cndzz");
        for (i = 0; i < s.length; i++) {
            if (this.g("keyword").value == this.values[s[i]][0]) {
                return true;
            }
        }
        return false;
    },
    
    tpl: function(){
        var tpl = '';
		tpl += '<div class="eiki_so">';
		if(this.leftimg){
			tpl += '    <div class="eiki_so_left">';
	        tpl += '    	<img src="/images/basic/eefocus/so.gif" width="6" height="71" />';
	    	tpl += '    </div>';
		}
        tpl += '    <div class="eiki_so_enter">';
        tpl += '        <div class="eiki_he1" onclick="searchbar.tab(0)" id="tab_btn0">';
        tpl += '            <span class="eiki">术语辞典</span>';
        tpl += '        </div>';
        tpl += '        <div class="eiki_he1" onclick="searchbar.tab(1)" id="tab_btn1">';
        tpl += '            <span class="eiki">主题文章</span>';
        tpl += '        </div>';
        tpl += '        <div class="eiki_he" onclick="searchbar.tab(2)" id="tab_btn2">';
        tpl += '            <span class="eiki">数据手册</span>';
        tpl += '        </div>';
	    tpl += '        <div class="eiki_he1" onclick="searchbar.tab(3)" id="tab_btn3">';
        tpl += '            <span class="eiki">电子电路</span>';
        tpl += '        </div>';
        tpl += '        <div id="eiki_he2">';
        tpl += '            <a href="http://123.eefocus.com" target="_blank" style="color:#F00;">实用导航</a>';
        tpl += '    		| <a href="http://www.eefocus.com/corp/map.html" target="_blank">网站地图</a>';
        tpl += '            | <a href="http://www.eefocus.com/content/service/searchhelp.php" target="_blank">搜索帮助</a>';
        tpl += '        </div>';
        tpl += '        <div class="eiki_he1_form" id="tab_div0">';
        tpl += '            <form name="searchform" id="searchform" method="get" action="http://www.eefocus.com/datasheet/" target="_blank" onSubmit="return searchbar.check();">';
        tpl += '                <input name="keyword" id="keyword" type="text" value="元器件数据手册一网搜尽" onfocus="searchbar.start();" onblur="if(this.value==\'\')searchbar.start();"/>';
		tpl += '                <input type="hidden" name="searchselect" id="searchselect" value="Datasheet" />';
		tpl += '                <input type="submit" name="search" id="search" value="搜  索" />';
        tpl += '            </form>';
        tpl += '        </div>';
        tpl += '    </div>';
        tpl += '    <div class="eiki_so_left"></div>';
        tpl += '</div>';
        
        return tpl;
    }
}
