/*
 * 导航条控制方法集
 * */

//--显示搜索关键字--
function schFocus() {
	var TypeId = this.form.elements["TypeId"].value;
	if (this.value == this.title) {
		if (TypeId == "All" || TypeId == "") {
			this.value = '';
		} else {
			location.href = "listprod.asp?TypeId=" + TypeId;
		}
	}
	this.className = 'SearchFocus';
	//this.parentNode.parentNode.className = 'SearchFocus';
	//showSchPanel();
}

//--隐藏搜索关键字--
function schBlur() {
	//this.parentNode.parentNode.className = '';
	this.className = '';
	if (this.value == '') { this.value = this.title; }
}

//--显示搜索列表--
function showSchPanel() {
	var kw = $(".KeyWord");
	$(".HidePanel").css({left:kw.offset().left, top:kw.offset().top+kw[0].offsetHeight-1 }).show();
}

//--提交搜索--
function doSearch(form) {
	var kw = form.elements["KeyWord"];
	if (kw.value == "" || kw.value == kw.title) { kw.focus(); return false; }
}

//--切换搜索菜单复选框--
function toggleChk(e) {
	var chkbox = this.getElementsByTagName("INPUT")[0];
	var form = chkbox.form;
	var chkall = form.elements["All"];
	var chkids = form.elements["TypeId"];
	var isChkAll = true;
	
	if (e.target.tagName != "INPUT") { chkbox.checked = !chkbox.checked; }
	if (chkbox.name == chkall.name) {
		$(this.parentNode).find(":checkbox").attr("checked", chkall.checked);
	} else {
		for (var i=0;i<chkids.length;i++)
			isChkAll = (isChkAll && chkids[i].checked);
		chkall.checked = isChkAll;
	}
}


$(document).ready(function(){

	//导航菜单子菜单事件
	$("ul.topnav li a").mouseover(function() {
		$(this).parent().find("ul.subnav").css({left:$(this).offset().left, top:$(this).offset().top+this.offsetHeight-1}).slideDown('fast');
		$(this).parent().hover(function(){}, function(){ $(this).parent().find("ul.subnav").slideUp('slow'); });
	});
	
	//搜索面板事件
	//$(".SchPanel").mousemove(showSchPanel).hover(showSchPanel, function(){$(".HidePanel").fadeOut(1500);}).find(".HidePanel").hide();
	//$(".KeyWord").keydown(schFocus).mousedown(schFocus).focus(schFocus).blur(schBlur).blur();
	//$(".HidePanel a").click(toggleChk);
	$(document.forms["SearchForm"].elements["KeyWord"]).keydown(schFocus).mousedown(schFocus).focus(schFocus).blur(schBlur).blur();
});


