jQuery(document).ready(function(){
  jQuery("#topKeywords").suggest(_frontPath+"/AutoComplete",{minchars:1,fn:'submitSearchForm()'});
});
function showProBox(){
  var obj=document.getElementById("proBox");
  obj.className="prohover";
  obj.setAttribute("class","prohover");
  document.getElementById("showProBox").style.display="block";
}
function hideProBox(){
  var obj=document.getElementById("proBox");
  obj.className="pro";
  obj.setAttribute("class","pro");
  document.getElementById("showProBox").style.display="none";
}
_sortType=1;
function selectedProBox(curr,num){
  var obj=document.getElementById("proBox");
  obj.className="pro";
  obj.setAttribute("class","pro");
  obj.innerHTML=curr.innerHTML;
  document.getElementById("showProBox").style.display="none";
  _sortType=num;
  if(num==1){
    document.getElementById("SortCid").value="603";
    document.getElementById("searchform").setAttribute("action", _frontPath+"/ProductList.do");
  }else{
    document.getElementById("InfoCid").value="904";
    document.getElementById("searchform").setAttribute("action", _frontPath+"/InfoCenter/InfoList.do");
  }
  document.getElementById("allBox").innerHTML="所有分类";
}
function showAllBox(){
  document.getElementById("allBox").className="other";
  document.getElementById("showAllBox"+_sortType).style.display="block";
  
}
function hideAllBox(){
  document.getElementById("allBox").className="othertwo";
  document.getElementById("showAllBox"+_sortType).style.display="none";
}
  function addTopEventHandler(target,eventType,func){
    if(target!=undefined){
      if(target.addEventListener){//dom
        target.addEventListener(eventType,func,false);
      }else if(target.attachEvent){//IE
        target.attachEvent("on"+eventType,func);
      }else{//Other
        target["on"+eventType]=func;
      }
    }
  }

  function onloadtop() {
	  var topdiv = document.getElementById("topdiv");
	  var topclose = document.getElementById("topclose");
		var allBox = document.getElementById("allBox");
	if (_webURL!="/index.jsp"){
		var showAllBox1 = document.getElementById("showAllBox1");
		addTopEventHandler(allBox, "mouseover", showAllBox);
		addTopEventHandler(allBox, "mouseout", hideAllBox);
		addTopEventHandler(showAllBox1, "mouseover", showAllBox);
		addTopEventHandler(showAllBox1, "mouseout", hideAllBox);
		allBox.className="other";
		showAllBox1.style.display = "none";
		addTopEventHandler(topdiv, "mouseover", overtopdiv1);
		addTopEventHandler(topdiv, "mouseout", outtopdiv1);
	addTopEventHandler(topclose, "click", outtopdiv1);
	}else{
		allBox.className="index";
		addTopEventHandler(topdiv, "mouseover", overtopdiv2);
		addTopEventHandler(topdiv, "mouseout", outtopdiv2);
	addTopEventHandler(topclose, "click", outtopdiv2);
	}
}

_defaultsortTop =3;
_defaultsortStep = 40;
_tempsortCid = 1;
function showtopdiv(cid,idx){
	  var sortLayer=document.getElementById("topdiv");
	  var topicon=document.getElementById("top_icon");
	  /*if(cid==57218){
		  if(window.XMLHttpRequest){
			  sortLayer.style.top="288px";
			  topicon.style.top=_defaultsortTop+_defaultsortStep*(idx-1)-112+"px";
		   }else {    
		 	sortLayer.style.top="298px"; 
		 	topicon.style.top=_defaultsortTop+_defaultsortStep*(idx-1)-118+"px";
		   } 
		  
	  }else{
		  sortLayer.style.top="";
		  topicon.style.top=_defaultsortTop+_defaultsortStep*(idx-1)+"px";
	  }*/
      sortLayer.style.top="";
      topicon.style.top=_defaultsortTop+_defaultsortStep*(idx-1)+"px";
	  sortLayer.style.display="block";
	 
	  document.getElementById("subCol_"+cid).style.display="block";
	  _tempsortCid=cid;
	}
function hidetopdiv(){
	  var obj=document.getElementById("allBox");
	  document.getElementById("subCol_"+_tempsortCid).style.display="none";
	  document.getElementById("topdiv").style.display="none";
}
function overtopdiv1(){
	 document.getElementById("allBox").className="other";
	var curr = document.getElementById("topdiv");
	curr.style.display="block";
	  var sort=document.getElementById("topsort_"+_tempsortCid);
      sort.className="cur";
	  document.getElementById("subCol_"+_tempsortCid).style.display="block";
	  document.getElementById("topdiv").style.display="block";
	  document.getElementById("showAllBox1").style.display="block";
}
function outtopdiv1(){
	document.getElementById("allBox").className="othertwo";
	var curr = document.getElementById("topdiv");
	curr.style.display="block";
     var sort=document.getElementById("topsort_"+_tempsortCid);
     sort.className="";
	  document.getElementById("subCol_"+_tempsortCid).style.display="none";
	  document.getElementById("topdiv").style.display="none";
	  document.getElementById("showAllBox1").style.display="none";
}
function overtopdiv2(){
	var curr = document.getElementById("topdiv");
	curr.style.display="block";
	  var sort=document.getElementById("topsort_"+_tempsortCid);
      sort.className="cur";
	  document.getElementById("subCol_"+_tempsortCid).style.display="block";
	  document.getElementById("topdiv").style.display="block";
	  document.getElementById("showAllBox1").style.display="block";
}
function outtopdiv2(){
	var curr = document.getElementById("topdiv");
	curr.style.display="block";
     var sort=document.getElementById("topsort_"+_tempsortCid);
     sort.className="";
	  document.getElementById("subCol_"+_tempsortCid).style.display="none";
	  document.getElementById("topdiv").style.display="none";
	  document.getElementById("showAllBox1").style.display="block";
}
function selectedAllBox(curr,id){
  var obj=document.getElementById("allBox");
  obj.className="all";
  obj.setAttribute("class","all");
  obj.innerHTML=curr.innerHTML;
  document.getElementById("showAllBox"+_sortType).style.display="none";
  if(_sortType==1)document.getElementById("SortCid").value=id;
  else document.getElementById("InfoCid").value=id;
}
function showTopCartBox(count){
  if(count>0)document.getElementById("cartOpen").style.display="";
}
function hideTopCartBox(){
  document.getElementById("cartOpen").style.display="none";
}
function showSaleBox(count){
  if(count>0)document.getElementById("featureOpen").style.display="";
}
function hideSaleBox(){
  document.getElementById("featureOpen").style.display="none";
}
function checkTopSearchForm(){
  var keyword=jQuery("#topKeywords");
  if(_sortType==1){
    if(keyword.val()!=""){
      jQuery("#thKeywords").val(jQuery.trim(keyword.val()));//+",title,content"
    }else{
      alert("请输入搜索关键字！");
      keyword.focus();
      return false;
    }
  }else{
    if(keyword.val()!=""){
      jQuery("#infoKeyword").val(jQuery.trim(keyword.val()));
    }else{
      alert("请输入搜索关键字！");
      keyword.focus();
      return false;
    }
  }
  return true;
}
function submitSearchForm(){
  if(!checkTopSearchForm())return false;
  document.getElementById("searchform").submit();
}
var scrollInterval=0;
function sideCartScroll (id,_top){
  var me=id.charAt?document.getElementById(id):id,d1=document.body,d2=document.documentElement;
  d1.style.height=d2.style.height='100%';
  me.style.top=_top?_top+'px':0;//me.style.left=_left+"px";//[(_left>0?'left':'left')]=_left?Math.abs(_left)+'px':0;
  intervalSideCart(me,d1,d2,_top);
  return arguments.callee;
}
function intervalSideCart(me,d1,d2,_top){
  scrollInterval=setInterval(function (){
    me.style.top=parseInt(me.style.top)+(Math.max(d1.scrollTop,d2.scrollTop)+_top-parseInt(me.style.top))*0.1+'px';
  },10+parseInt(Math.random()*20));
}
function showSideCart(id){
  clearInterval(scrollInterval);
  var top=document.getElementById(id).offsetTop;
  var sideCart=jQuery("#scroll");
  sideCart.css("top",top+"px").slideDown(10);
}
function hideSideCart(){
  var sideCart=document.getElementById("scroll");
  sideCart.style.display="none";
}
function overSideCart(){
  clearInterval(scrollInterval);
  var sideCart=document.getElementById("scroll");
  sideCart.style.display="block";
}
function outSideCart(){
  var sideCart=document.getElementById("scroll");
  sideCart.style.display="none";
  var me=document.getElementById("sideScroll"),d1=document.body,d2=document.documentElement;
  intervalSideCart(me,d1,d2,185);
}
_sideCartBoxTop=0,_currIdx=1;
function sideCartUp(){
  if(_currIdx==1)return;
  var box=document.getElementById("sideCartBox");
  _sideCartBoxTop+=50;
  _currIdx--;
  box.style.top=_sideCartBoxTop+"px";
}
function sideCartDown(count){
  if(_currIdx+2>=count)return;
  var box=document.getElementById("sideCartBox");
  _sideCartBoxTop-=50;
  _currIdx++;
  box.style.top=_sideCartBoxTop+"px";
}
function loginOutSNS(snsLoginConn){
//  if(snsLoginConn=="yes"){
//    jQuery.ajax({timeout:2000,type:"GET",dataType:"script",url:_snsUrl+"emall/exitControl.jsp",cache:false,complete:function(){window.location=_frontPath+"/Member/Exit.do";},error:function(){window.location=_frontPath+"/Member/Exit.do";}});
//  }else{
//    window.location=_frontPath+"/Member/Exit.do";
//  }
//  window.location.href=_frontPath+"/clearFrontendSessionForSNS.jsp?emallUrl="+_snsUrl+"emall/exitControl.jsp";
}
