var zQuery=function(ele,tagName,className){ //核心对象   
    if ( window == this ) return new zQuery(ele,tagName,className);   
    if(!arr){var arr=new Array;}   
    if(ele){   
        if(ele.constructor!=zQuery){   
            var elem=typeof(ele)=="object"?ele:document.getElementById(ele);   
            if(!tagName){   
                arr.push(elem);   
            }else{   
                var tags=elem.all&&!window.opera?tagName=="*"?elem.all:elem.all.tags(tagName):elem.getElementsByTagName(tagName);   
                if(!className){   
                    for(var i=0, l=tags.length; i<l; i++){   
                        arr.push(tags[i]);   
                    }   
                }else{   
                    var reClassName=RegExp("(^|\\s+)"+className+"($|\\s+)");   
                    for(var i=0, l=tags.length; i<l; i++){   
                        if(reClassName.test(tags[i].className)){   
                            arr.push(tags[i]);   
                        }   
                    }   
                }   
            }   
        }else{   
            for(var i=0, l=ele.length; i<l; i++){   
                arr=arr.concat(Array.prototype.slice.call(zQuery(ele[i],tagName,className)));   
            }   
        }   
    }   
    return this.setArray(arr); //借鉴jQuery方法，这里返回zQuery对象原型（一个DOM集合对象），不再是返回单纯的DOM数组对象   
}   
zQuery.prototype.setArray = function( arr ) {   
    this.length = 0;   
    Array.prototype.push.apply( this, arr ); //这里的概念非常重要，zQuery方法对象执行了Array原型的push()方法   
    return this;   
}   
zQuery.fn=zQuery.prototype;   
var $=zQuery;   
  
//取select的绝对位置、高、宽   
function Offset(obj){   
    var t = obj.offsetTop;   
    var l = obj.offsetLeft;   
    var w = obj.offsetWidth;   
    var h = obj.offsetHeight-2;   
    //var h=obj.style.height;   
    while(obj=obj.offsetParent)   
    {   
        t+=obj.offsetTop;   
        l+=obj.offsetLeft;   
    }   
    return {   
        top : t,   
        left : l,   
        width : w,   
        height : h   
    }   
}   
//模拟select   
function instSelect(obj){   
    var offSet=Offset(obj);   
    obj.style.display="none";   
    var sDiv=document.createElement("div");   
    sDiv.id="div"+obj.name;   
    sDiv.className="divSlt";   
    sDiv.style.width=offSet.width+"px";   
    //sDiv.style.height=offSet.height+"px";   
    sDiv.style.left=offSet.left+"px";   
    sDiv.style.top=offSet.top+"px";   
    document.body.appendChild(sDiv);   
    var sSpan=document.createElement("span");   
    var spanId=obj.options[obj.selectedIndex].value;   
    var spanText=obj.options[obj.selectedIndex].text;   
    sSpan.id=spanId;   
    sSpan.style.lineHeight=offSet.height+"px";   
    sTxt=document.createTextNode(spanText);   
    sSpan.appendChild(sTxt);   
    sDiv.appendChild(sSpan);   
    sSpan.onclick=function(){
		
        if($("div"+obj.name,"ul").length==0){   
            var sUl=document.createElement("ul");   
            sDiv.appendChild(sUl);   
            var optLen=obj.options.length;   
            var tmp=document.createDocumentFragment();   
            for(var j=0;j<optLen;j++){   
                var sltVal=obj.options[j].value;   
                var sltTxt=obj.options[j].text;   
                var sLi=document.createElement("li");   
                sLi.id=sltVal;   
                sLi.appendChild(document.createTextNode(sltTxt));   
                sLi.onmouseover=function(){   
                    this.style.background="#181818";   
                    this.style.color="#b8b0a7";   
                }   
                sLi.onmouseout=function(){   
                    this.style.background="#181818";   
                    this.style.color="#b8b0a7";   
                }   
                sLi.onclick=function(){
					if(this.getAttribute('id')>400){
						 try{
						smartAjaxRequest('./ajax_home.php','type='+this.getAttribute('id'),'get',taocan);
						 }catch(e){}
						}else{
						try{
							home_type_change(this.getAttribute('id'));
							}catch(e){}
						}
										//alert(this.id);
					//window.location.href=this.id;
					//window.open(this.id);
                    sSpan.innerHTML=this.innerHTML;   
                    obj.value=this.id;   
                    sUl.style.display="none";   
                }   
                tmp.appendChild(sLi);   
            }   
            sUl.appendChild(tmp);   
            if(optLen>3){   
                sUl.style.overflowY="none";   
                sUl.style.height="100%";   
            }   
        }   
        else{   
            if($("div"+obj.name,"ul")[0].style.display=="none") $("div"+obj.name,"ul")[0].style.display="block";   
            else $("div"+obj.name,"ul")[0].style.display="none";   
        }   
    }   
}   
//取得slect的个数，并且对每个select执行函数   
function initSelect(){   
    //var slt=$("slt1");   
    //var sltLen=slt.length;   
	//alert(sltLen);
	var sltLen=4;
    for(var i=1;i<sltLen;i++){   
	    var slt=$("slt"+i);
		if(slt){
       instSelect(slt[0]);
		}
    }   
}   
  
window.onload=initSelect;   
document.onclick=function(){   
    var evt=getEvent();   
    var element=evt.srcElement || evt.target;   
    var s=$("slt1");
	try{
    if((element.parentNode.parentNode==null||element.parentNode.parentNode.className!="divSlt")&&element.nodeName!="SPAN"){   
        for (var i=0; i<s.length; i++) {   
            if(!$("div" + s[i].name,"ul")[0]) continue;   
            $("div" + s[i].name,"ul")[0].style.display="none";   
        }   
    } 
	}catch(e){};
}   

function getEvent(){   
     //同时兼容ie和ff的写法   
     if(document.all)    return window.event;   
     func=getEvent.caller;   
     while(func!=null){   
         var arg0=func.arguments[0];   
         if(arg0){   
             if((arg0.constructor==Event || arg0.constructor ==MouseEvent)   
                || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){       
                return arg0;   
              }   
         }   
          func=func.caller;   
        }   
        return null;   
		
		
		
		
		
} 



function taocan(o){
	document.getElementById('taocan').innerHTML=o.responseText;
	document.body.removeChild(document.getElementById('divfrm[kfinfo_id]'));
	home_type_change(document.getElementById('slt3').options[document.getElementById('slt3').selectedIndex].value);
       instSelect($('slt3')[0]);
	}

