//getElementsByClassName函数
var getElementsByClassName = function(searchClass,node,tag) {
    if(document.getElementsByClassName){
        return  document.getElementsByClassName(searchClass)
    }else{   
        node = node || document;
        tag = tag || '*';
        var returnElements = []
        var els =  (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag);
        var i = els.length;
        searchClass = searchClass.replace(/\-/g, "\\-");
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        while(--i >= 0){
            if (pattern.test(els[i].className) ) {
                returnElements.push(els[i]);
            }
        }
        return returnElements;
    }
}
function fg$(id) { return document.getElementById(id); }   
   //标题党展开收缩
   function packUp(parentId,elementId,newElementId,btnId,htmlLength){
	   if(!fg$(parentId))return false;
	   if(!fg$(elementId))return false;
	   if(!fg$(newElementId))return false;
	   if(!fg$(btnId))return false;
       var parentDiv = fg$(parentId),elementDiv = fg$(elementId), newElementDiv = fg$(newElementId),btnSpan = fg$(btnId);
	   var elementHtml= elementDiv.innerHTML;
	   var elementLength= elementHtml.length;
	   if(elementLength > htmlLength){
	        elementDiv.innerHTML=(elementDiv.innerHTML.substr(0,htmlLength)+'...');
			btnSpan.onclick=function(){
				elementDiv.style.display="none";
				btnSpan.style.display="none";
				newElementDiv.style.display="block";
				parentDiv.style.border="1px solid #ccc";
			}
			newElementDiv.onmouseout=function(){
				elementDiv.style.display="";
				btnSpan.style.display="";
				newElementDiv.style.display="none";
				parentDiv.style.border="1px solid #fff";
			}
	   }
	   if(elementLength <= htmlLength){
	       btnSpan.style.display="none"    
	   }
   }
   //餐厅简介展开收缩
   function packUp1(elementId,btnId,htmlLength,className1,className2){
	   if(!fg$(elementId))return false;
	   if(!fg$(btnId))return false;
	   var elementDiv = fg$(elementId),btnSpan = fg$(btnId);
	   var elementHtml= elementDiv.innerHTML;
	   var elementLength= elementHtml.length;
	   if(elementLength > htmlLength){
	        elementDiv.innerHTML=(elementDiv.innerHTML.substr(0,htmlLength)+'...');
			btnSpan.onclick=function(){
				btnSpan.className=btnSpan.className==className1?className2:className1;
				elementDiv.innerHTML=btnSpan.className==className1?elementDiv.innerHTML.substr(0,htmlLength)+'...':elementHtml;
				btnSpan.innerHTML=btnSpan.className==className1?"查看全文":"收起";
			}
	   }
	   if(elementLength <= htmlLength){
	      btnSpan.style.display="none"    
	   }
   }
   //导航显示隐藏
    function HpGlobalMenu(hpMenu,indexMenu,othenMenu,class1,class2,class3){
	     if(!fg$(hpMenu))return false;
	     if(!fg$(indexMenu))return false;
	     if(!fg$(othenMenu))return false;
	     var hpNavWarp = fg$(hpMenu),indexNav = fg$(indexMenu),othenNav = fg$(othenMenu);
		 hpNavWarp.onmouseover=function(){
		     othenNav.style.display="block";
			 hpNavWarp.className=class1;
			 indexNav.className=class2;
		 }
		 hpNavWarp.onmouseout=function(){
		     othenNav.style.display="";
			 hpNavWarp.className="";
			 indexNav.className=class3;
		 }
	}
   //餐厅评分显示更多 隐藏更多
    function showSwitch(showId,hideId,btnId1,btnId2){
	   if(!fg$(showId))return false;
	   if(!fg$(hideId))return false;
	   if(!fg$(btnId1))return false;
	   if(!fg$(btnId2))return false;
	   var showDiv= fg$(showId),hideDiv= fg$(hideId),showBtn= fg$(btnId1),hideBtn= fg$(btnId2);
	   showBtn.onclick=function(){
	      hideDiv.style.display="block"; 
		  showDiv.style.display="none";
	   }
	   hideBtn.onclick=function(){
	      showDiv.style.display="block";
		  hideDiv.style.display="none";  
	   }
	}
//	//点评回复 显示 隐藏
//    function replayCMT(btnClassName,divClassName){
//    var replayButton = getElementsByClassName(btnClassName),showDiv = getElementsByClassName(divClassName); 
//	if(!replayButton)return false;
//	if(!showDiv)return false;
//	function showReplay(i){
//	   replayButton[i].onclick=function(){
//	       showDiv[i].style.display=showDiv[i].style.display=="block"?"none":"block";
//	   }
//	}
//	for(i=0;i<replayButton.length;i++) {
//	   showReplay(i);
//	}
//   }
   //促销信息换边框
   function changeBorder(){
	     if(!fg$("promotions"))return false;
	     if(!fg$("promotionsTop"))return false;
	     if(!fg$("promotionsBottom"))return false;
	     if(!fg$("promotionsBody"))return false;
	     var promotions=fg$("promotions"),promotionsTop=fg$("promotionsTop"),promotionsBottom=fg$("promotionsBottom"),promotionsBody=fg$("promotionsBody");
		 promotions.onmouseover=function(){
		     promotionsTop.style.background="url(http://s1.57575777.com/adentity/images/hpMap.gif) no-repeat -109px -65px";
			 promotionsBottom.style.background="url(http://s1.57575777.com/adentity/images/hpMap.gif) no-repeat -109px -75px";
			 promotionsBody.style.borderLeft="1px solid #FFB681";
			 promotionsBody.style.borderRight="1px solid #FFB681";
		 }
		 promotions.onmouseout=function(){
		     promotionsTop.style.background="url(http://s1.57575777.com/adentity/images/hpMap.gif) no-repeat -109px 0";
			 promotionsBottom.style.background="url(http://s1.57575777.com/adentity/images/hpMap.gif) no-repeat -109px -10px";
			 promotionsBody.style.borderLeft="1px solid #D8D8D8";
			 promotionsBody.style.borderRight="1px solid #D8D8D8";
		 }
	}
	//显示隐藏切换
    function showToggle(btnid1,btnid2,toggleDiv){
		 if(!fg$(btnid1))return false;
		 if(!fg$(btnid2))return false;
		 if(!fg$(toggleDiv))return false;
	     var toggleBtn1=fg$(btnid1),toggleBtn2=fg$(btnid2);toggleDiv=fg$(toggleDiv);
		 toggleBtn1.onclick=function(){
		     this.style.display="none" ;
			 toggleBtn2.style.display="block";  
		     toggleDiv.style.display="block";
		 }
		 toggleBtn2.onclick=function(){
		     this.style.display="none";
			 toggleBtn1.style.display="block";
		     toggleDiv.style.display="none";
		 }
	}
	//
   function showToggle1(btnId,showDivId,class1,class2){
	   if(!fg$(btnId))return false;
	   if(!fg$(showDivId))return false;
       var btn =fg$(btnId),showDiv =fg$(showDivId);
	   btn.onclick=function(){
	       showDiv.style.display=showDiv.style.display==="none"?"block":"none";
		   this.className=showDiv.style.display==="block"?class2:class1;
	   }
   }
   function showToggle2(btnId,showDivId){
	   if(!fg$(btnId))return false;
	   if(!fg$(showDivId))return false;
       var btn =fg$(btnId),showDiv =fg$(showDivId);
	   btn.onclick=function(){
	       showDiv.style.display=showDiv.style.display==="block"?"none":"block";
	   }
   }
  //简易高亮切换
 function easyTab(warpId,typeName,highLightClass,lostFocusClass){
	 if(!fg$(warpId))return false;
     var tabDiv= document.getElementById(warpId);
	 var tabList= tabDiv.getElementsByTagName(typeName);
	 for(i=0;i<tabList.length;i++){
	     tabList[0].className=highLightClass;
         switchClass(i); 
 	 }
	 function switchClass(i){
	     tabList[i].onclick=function(){
		     for(j=0;j<tabList.length;j++){
			     tabList[j].className=j===i?highLightClass:lostFocusClass;
			 }
		 }
	 }
 }
 
