﻿if(typeof($d) == "undefined")
{
    $d=function(id){return document.getElementById(id);}
}

function loadSearchBar(name,objDiv){
    var arrItems = new Array();
    arrItems[0] = new Array("供应","请输入要查找的门店关键词","/SupplyList.Shtml");
    this.name = name;
    this.arrItem = arrItems;//数组
    this.currentIndex=0;   //当前显示第几个    this.div=objDiv;
    this.txtObj=null;
    this.btnObj=null;
    this.count=0;
}

loadSearchBar.prototype.initEvents=function()
{
    var currentObj = this;
    if(this.txtObj)
    {
        this.txtObj.onkeypress=function(e){
            var iKeyCode = window.event?event.keyCode:e.which;
            if(iKeyCode==13)
            {
               currentObj.doSearch();
               return false;
            }
            return true;
        }
    }
    if(this.btnObj)
    {   
        this.btnObj.onclick=function(){
            currentObj.doSearch();
            return false;
            }
    }
}

loadSearchBar.prototype.doSearch=function()
{

    var searchUrl = this.arrItem[this.currentIndex][2] +"?k="+ encodeURIComponent(this.txtObj.value) ;
    window.location.href=searchUrl;
}

loadSearchBar.prototype.pressKeyCode=function(e,obj)
{
  var iKeyCode = window.event?e.keyCode:e.which;
    if(iKeyCode==13)
    {
        this.doSearch(e);
        return false;
    }
    return true;
}

window.onload = function(){
    var divObj = $d("divNav") ;
    for(var i=0 ; i <divObj.getElementsByTagName("li").length;i ++)
    {
    var curLink = divObj.getElementsByTagName("li")[i].getElementsByTagName("a")[0].href.toUpperCase();
    var page=  window.location.pathname.toUpperCase() =="/" ? "/index.shtml".toUpperCase() : window.location.pathname.toUpperCase();

        if(curLink.indexOf(page.toUpperCase())!=-1)
        {
            var curPageLi = divObj.getElementsByTagName("li")[i];
            var nextPageLi= divObj.getElementsByTagName("li")[i+1];
            if(curPageLi)
            curPageLi.className="on";
        }
    }
}    
