var type=0;
function gettype(value){
	type=value;
}

function checkform(){
	var value=$("#mainnavtext").val();
	if(type==0){
		alert("请选择类别");
		return false;
	}
	if(value==''){
		alert("请输入搜索的内容");
		return false;
	}
	window.location.href="../search/index.jsp?sortcode="+type+"&key="+encodeURI(value,"utf-8");

}

$(function(){
	$("#mainnav_right").html('<div id="mainnav_righttext"><form id=formsearch name=formsearch><div id="mainnav_rightform"><span style="float:left;line-height:24px;">搜索:&nbsp;&nbsp;</span><div style="float:left;padding-top:2px;"><dl id="sample" class="dropdown1"><dt><span>&nbsp;选择类别</span></dt><dd><ul><li><a href="#" onclick=gettype(21) >&nbsp;共享阳光</a></li><li><a href="#" onclick=gettype(22)>&nbsp;时尚资讯</a></li><li><a href="#" onclick=gettype(23)>&nbsp;楼层导航</a></li><li><a href="#" onclick=gettype(24)>&nbsp;VIP尊享</a></li><li><a href="#" onclick=gettype(25)>&nbsp;阳光礼品</a></li></ul></dd></dl></div>&nbsp;<input type="text" id="mainnavtext" class="mainnavtext" value=""/><input type="button" class="mainnavbutton" onclick="checkform();"/></div></form></div><div id="mainnav_rightfont">搜索热词：会员日 国际 春装 新品 积分 </div>');
	$(".dropdown dt").click(function() {
			$(".dropdown dd ul").toggle();
	});		
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$(".dropdown dd ul").hide();
	});
	
	$(".dropdown1 dt").click(function() {
			$(".dropdown1 dd ul").toggle();
	});		
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown1"))
			$(".dropdown1 dd ul").hide();
	});
	 $(".dropdown1 dt a").click(function() {
	   $(this).closest('dt').siblings('dd').find('ul').toggle();
	 });

	 $(".dropdown1 dd ul li a").click(function() {
	   var text = $(this).text();
	
	   $(this).closest('dd').siblings('dt').find('span').text(text);
	
	   $(this).closest('ul').hide();
	 });

});



function login(){
	if(location.href.indexOf("Returnurl")<0){
		if(location.href.indexOf("regist.jsp")<0){
			location.href = "../mall/login.jsp?Returnurl=" + encodeURI(location.href); return false; 
		}else{
		  location.href = "../mall/login.jsp";return false;
		}
	}else{
		location.href = "../mall/login.jsp" ;return false;
	}
}
function indexlogin(){
	if(location.href.indexOf("Returnurl")<0){
		if(location.href.indexOf("regist.jsp")<0){
			location.href = "mall/login.jsp?Returnurl=" + encodeURI(location.href); return false; 
		}else{
		  location.href = "mall/login.jsp";return false;
		}
	}else{
		location.href = "mall/login.jsp" ;return false;
	}
}


