   //快速分类相关begin

   	function showCategory(){
   					jQuery('.product-all a').removeClass("class-products");
   					jQuery('.product-all a b').removeClass("up-b");
   					jQuery('.product-all a b').addClass("down-b");
                  	jQuery('#product-list').show();
                  	
                  }
 	function closeCategory(){
 					jQuery('.product-all a').addClass("class-products");
 					jQuery('.product-all a b').removeClass("down-b");
   					jQuery('.product-all a b').addClass("up-b");
 					jQuery('#product-list').hide();
                  }
    function closeCategoryAgain(m){
    				document.getElementById('category'+m).className='item';
    			 }
    jQuery(function(){
                 jQuery("li.item").hover(
                  		function(){
                  			var height=jQuery(this).find(".categoryList").height();
                  			if(height<262){
								jQuery(this).find(".categoryList").css("height","262px");
					}
                  	}
                  	);
                  })
   //快速分类相关end
   function isMouseLeaveOrEnter(e, handler) {    
        if (e.type != 'mouseout' && e.type != 'mouseover') return false;    
        var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;    
        while (reltg && reltg != handler)    
            reltg = reltg.parentNode;    
        return (reltg != handler);    
    }  
    
//加载验证码
function loadvalidatecode(){
	document.getElementById("codepic").src=basePath+"/validatecode/validatecode.html?temp=" + (new Date().getTime().toString(36));
}
//验证验证码
function checkheadvalidatecode(){
		$.ajax({
				type : "post",
				url : basePath+"/validatecode/checkvalidatecode.html",
				async:false,
				data:{c:$("#check_headcode").val()},
				success : function(data){
				if(data==1){
				$('#head_code').attr('value',1);
				document.getElementById('errorVal').innerHTML ='';
				}else if(data==2){
					$('#head_code').attr('value',2);
					if($('#check_headcode').val()==""){
						document.getElementById('errorVal').innerHTML ='请输入验证码！';
					}else{
						document.getElementById('errorVal').innerHTML ='验证码输入错误';
					}
				}
				}
			});
}
//登录begin
function valAccount(){
	var name ='';
	if(document.getElementById('username')){
	name =document.getElementById('username').value;
	if(name ==''){
		document.getElementById('disMsg2').innerHTML ='账户不为空！';
		
	}else{
		document.getElementById('disMsg2').innerHTML ='';
		document.getElementById('disMsg').innerHTML ='';
	}
	}
}

function gotoNext(){
	if(showValidate){
		$("input[name='check_headcode']").focus();
	}else{
		submit_form();
		return true;
	}
}
function submit_form(){
		var isTrue=false;
		if(showValidate){
			checkheadvalidatecode();
		if($('#head_code').val()==2){
			$("input[name='check_headcode']").focus();
			loadvalidatecode();
			showValidate=true;
			return;
		}else if($('#head_code').val()==1){
			isTrue=true;
		}
		}else{
			isTrue=true;
		}
		if(isTrue){
			var name=jQuery.trim(jQuery("input[name='username']").val());
			if(name=='')
			{
				document.getElementById('disMsg2').innerHTML ='账户不为空！';
				jQuery("input[name='username']").focus();
				return;
			}
			var psw=jQuery.trim(jQuery("input[name='userpass']").val());
			if(psw=='')
			{
				document.getElementById('disMsg').innerHTML ='密码选项不能为空！';
				jQuery("input[name='userpass']").focus();
				return;
			}
		}
		if(head_login_flag)
		{
			$('.login-zc  img').show();
			jQuery("#btn_login").css("cursor","wait");
			head_login_flag=false;
			$.ajax({
              type:"post",
              url:basePath+'/web/memberJqueryAjax/loginByTypeJquery.html',
              data:{name:name,psw:psw},
              dataType:"json",
              success:function(data){
				jQuery("#btn_login").css("cursor","");
				if(data.errorLogin=='0'){
					head_login_flag=true;
					jQuery("input[name='check_headcode']").val("");
					jQuery("input[name='userpass']").val("");
					jQuery("input[name='username']").val(data.userLastLoginName);
					 if(data.userErrorNum>2 && data.userErrorNum<10 ){
						showValidate=true;
						$('.login_field').show();
						var warningNum=10-data.userErrorNum;
						document.getElementById('disMsg').innerHTML ='账户名与密码不匹配，还可以尝试'+warningNum+'次<br>如失败，账户将被冻结2小时';	
						loadvalidatecode();
					}else if(data.userErrorNum ==10){
						document.getElementById('disMsg').innerHTML ='登录失败超过10次，账户已被冻结2小时<br>您可尝试<a href="'+basePath+'/auth/toGetPasswordBack.html">找回密码</a>';	
						showValidate=false;
						$('.login_field').hide();
					}else{
						document.getElementById('disMsg').innerHTML ='账号或密码有误！';	
					}
					jQuery("input[name='userpass']").focus();
					$('.login-zc  img').hide();
				}
				else{
					head_login_flag=false;
					var toUrl=jQuery.trim(jQuery("input[name='toUrl']").val());
					LoginUtil.closeDialog('weizhi');
					showValidate=false;
					window.location.href =toUrl;
				}            
              },
              	error:function(){
              }
            });
		}
}

function clearMeessage(clearId){
	document.getElementById(clearId).innerHTML ='';
	if(document.getElementById('disMsg')){
		if(document.getElementById('disMsg').innerHTML =='账号或密码有误！'){
			document.getElementById('disMsg').innerHTML ='';
		}
	}
	if(document.getElementById("errorVal")){
		document.getElementById('errorVal').innerHTML ='';
	}
}
//登录end
//搜索begin

	$(function(){
		//个人中心-收藏本站-帮助
		$(".personal").hover(function(){
			$(this).removeClass("personal");
			$(this).addClass("personal-c");
		},function(){
			$(this).removeClass("personal-c");
			$(this).addClass("personal");
		})
		$(".collection").hover(function(){
			$(this).removeClass("collection");
			$(this).addClass("collection-c");
		},function(){
			$(this).removeClass("collection-c");
			$(this).addClass("collection");
		})	
		$(".help-header").hover(function(){
			$(this).removeClass("help-header");
			$(this).addClass("help-header-c");
		},function(){
			$(this).removeClass("help-header-c");
			$(this).addClass("help-header");
		})		
	
		//初始化搜索关键下标
		var _searchresultindex=-1;
		//控制关键字
		var _tw='';
		var _tempword=''
		//up
		function keywordAssist(obj,event){
		
			if(event.keyCode==38||event.keyCode==40||event.keyCode==222||obj.value=="\""||obj.value=="%")
			{
				return false;
			}
			_tw=$.trim(obj.value);
			var _word=$.trim(obj.value);
			//搜索类型
			var _type=$.trim($("#searchTypeName").text())
			if(_word=="")
			{
				$("#tags").hide().empty();
			}
			else if(_word==_tempword)
		    {
				$("#tags").show();
			}
			else{
				$("#tags").empty();
				$.ajax({
		              type:"post",
		              url:basePath+"/web/producttags.html",
		              data:{word:_word,type:_type},
		              dataType:"json",
		              success:function(data){
		              $("#tags").empty();
		              	if(data.length>0)
						{
							_searchresultindex=-1;
							for(var i=0;i<data.length;i++){
								$("#tags").append("<li><a href=\"javascript:void(0)\" onclick=\"return false\">"+data[i]+"</a></li>");
							}
							$("#tags").show();
							$("#tags li a").bind("click",function(){
								$("input[name='_searchKey']").val($(this).text());
								$("#tags").hide();
								document.getElementById("searchTypeHidden").value=$("#searchTypeName").text();
								var key =  $(this).text();
								key=encodeURIComponent(key);
								key=encodeURIComponent(key);
								document.searchForm.action=basePath+"/web/search.html?searchKeywords="+key;
								document.searchForm.submit();
							});
						}
						else{
							$("#tags").hide().empty();
						}
		              },
		              error:function(){
		              }
		            });
			}
		}
		
		//down
		function setSrc(obj,event)
		{
			$("input[name='_searchKey']").attr("style","color:#000");
			_tempword=$.trim(obj.value);
			//关键字选择器
			var _key=$("#tags li a");
			//关键字数量
			var _keysize=_key.size();
			var _tempforjs;
			if(_keysize>0){
				if(_searchresultindex==-1){
					_searchresultindex=_keysize;
				}
				//up
				if(event.keyCode==38){
					_key.css("background-color","");
					_searchresultindex=_searchresultindex>0?_searchresultindex-1:_keysize;
				}
				//down
				if(event.keyCode==40){
					_key.css("background-color","");
					_searchresultindex=_searchresultindex<_keysize?_searchresultindex+1:0;
				}
				_tempforjs=_key.get(_searchresultindex);$(_tempforjs).css("background-color","#f9eeda");
				if(event.keyCode!=8){
					if(_searchresultindex==_keysize){
						$("input[name='_searchKey']").val(_tw);}
					else
						$("input[name='_searchKey']").val(_key.eq(_searchresultindex).text());
				}
			}
		}
	
		//初始得到焦点
		$("#_searchKey").focus(function(){
			if($(this).val()=="美容宝"){
				$(this).val("");
			}
		});
		//离开选择
		//弹出四类别选项框
		$(".cate-n li mark.bg-nav").click(function(){
			$(this).next().attr("style","display:block");
			
		})
		//选择某一类别
		$("ol.searchList li a").click(function(){
			var _index=$("ol.searchList li a").index(this);
			$(".cate-n").find("mark").text($(this).text());
			document.getElementById("searchTypeHidden").value=$(this).text();
			$(".searchList").attr("style","display:none");
			$("#tags").hide().empty();
			$("input[name='_searchKey']").val("");
			$("#_searchKey").focus();
		})
		//选择关键字
		$("#tags li a").click(function(){
			$("mark.bg-nav").find("input").attr("value",$(this).text());
			$("#tags").empty();
			$("#tags").attr("style","display:none");
		})
		$("button.bg-nav").click(function(){
			document.searchForm.submit();
		});
		
		$("input[name='_searchKey']")
		.keyup(function(event){
			keywordAssist(this,event);
		})
		.keydown(function(event){
			setSrc(this,event);
		});
	})
	function searchFormSubmit(){
		if($("input[name='_searchKey']").val()==""){
			alert("请输入搜索信息")
			$("input[name='_searchKey']").focus();
			return false;
		}
		document.getElementById("searchTypeHidden").value=$("#searchTypeName").text();
		var key =  $("input[name='_searchKey']").val();
		key=encodeURIComponent(key);
		key=encodeURIComponent(key);
		document.searchForm.action=basePath+"/web/search.html?searchKeywords="+key;
		document.searchForm.submit();
		
	}
	//搜索end
	
	//头部购物车相关begin
	$(function(){
		$(".cart-gw").hover(
          function(){
            $.ajax({
              type:"post",
              url:basePath+"/web/showShoppingCart.html",
              dataType:"text",
              success:function(data){
                  $("#showDiv").html(data);
                  if(parseInt($("span#totalNums").text())>5){
                 	 $("#sc").addClass("gwc-height");
            	  }else{
                 	 $("#sc").removeClass("gwc-height");
            	  }
                  if($("#totalNums").length > 0){
	                  $("#cartSize").text($("#totalNums").text());
                  }else{
	                  $("#cartSize").text('0');
                  }
                  $(".deleteShopingCar").bind("click",function(){
                  		var _shoppingCarIndex= $(".deleteShopingCar").index(this);
                  		var itemId=$(this).attr("id");
                  		$.ajax({
					        type:"post",
					        url:basePath+"/salesShoppingcart/deleteItem.html",
					        data:{itemId:itemId},
					        dataType:"text",
					        success:function(data){
					            if(data==1){
					              $("#sc dl").eq(_shoppingCarIndex).hide();
					              $("#cartSize").text(""+parseInt($("#cartSize").text())-1);
					              if(parseInt($("#cartSize").text())<5){
					            	  $("#sc").removeClass("gwc-height");
					              }
					              if(parseInt($("#cartSize").text())<=5)
					            	  $("#shippingNum").hide();
					              if(parseInt($("span#shoppingCarMark").text())>=1){
						              $("span#shoppingCarMark").text(""+parseInt($("span#shoppingCarMark").text())-1);
					              }else{
					            	  $("span#shoppingCarMark").text("0");
					              }
					              if(parseInt($("#cartSize").text())==0){
					            	   $("#showDiv").html("<h2>您的购物车里暂无产品，赶快选择心爱的产品吧！</h2>");
					              }
					            }
					        }
					      });
                  })
                  
              }
            });
			$(".cart-gw").find("div").fadeIn(300);
		  },
          function(){
            $(this).find("div").fadeOut(300);
          }
       );
       
	})
	//购物车相关end
