// 页面加载后，执行分类目录展示，从后台直接拿到html代码
function getTypeMenuTreeTableAndData(id) {
	var searchType = $("#searchType").val();
	$.getJSON("getTypeMenuDetail.htm", {
		typeMenu : searchType,
		currId : id
	}, function(data) {
		$("#navBarArea").show();
		$("#hereViewNavBar").empty();
		$("#hereViewNavBar").html(data.navData);
		$("#hereViewTypeMenuTable").empty();
		$("#hereViewTypeMenuTable").html(data.tableData);
		$("#currId").val(id);
		
		//郭海斌修改（非最后一级也能查到结果2011-03-15）
		//if (data.endFlag == "Y") {
			searchByTypeMenu(searchType);
		//}
	});
}

// 通过分类目录查询
function searchByTypeMenu(searchType) {
	var csSearchData = {
		currId : $("#currId").val(),
		searchType : searchType
	};
	if (searchType == "searchByHS" || searchType == "searchByChinaFieldType"
			|| searchType == "searchByForeignFieldType"
			|| searchType == "searchByProdType"
			|| searchType == "searchByCallingType") {
		doSearchProdRequest(csSearchData);
	} else {
		doSearchCorpRequest(csSearchData);
	}
}

$(function() {
	// 页面加载结束时检查是否需要调用数据查询
	getTypeMenuTreeTableAndData($("#currId").val());
});

// 发送企业查询ajax请求
function doSearchCorpRequest(csSearchData) {
	$('#csPagenum').pagination(
			{
				src : "getDataListByTypeMenu.htm",
				number : 6,
				data : csSearchData
			},
			function(item) {
				var areaval = '';
				if (item.cityname != '')
					areaval = '('+item.cityname+')';
				var html = '<li><h4><a href="coDetail.htm?corpId='+item.epuserid+'" target="_blank">' 
						+ item.epname + areaval + '</a>'
						+ '</span></h4><p class="intro"><b>企业简介：</b>'
						+ item.epintro + '</p></li>';
				return html;
			});
	$('#csResult').show();
	$('#psResult').hide();
}

// 发送产品查询ajax请求
function doSearchProdRequest(psSearchData) {
	$('#psPagenum').pagination(
			{
				src : "getDataListByTypeMenu.htm",
				number : 6,
				data : psSearchData
			},
			function(item) {
				var html = '<li><p class="info"><b>产品名称：</b><a href="coDetail.htm?prodId=' +item.id + '" target="_blank">' 
						+ item.epprodname + '</a>'
						+ '<br/><b>产品供应方：</b><a href="coDetail.htm?corpId=' + item.epcorpid + '" target="_blank">' 
						+ item.epprodmanufacturer + '</a>'
						+ '<br/><b>产品简介：</b>' + item.epprodintro + '</p></li>';
				return html;
			});
	$('#psResult').show();
	$('#csResult').hide();
}

function showTypeMenuRoot() {
	$('#typeMenuRootTable').show();
	$('#typeMenuChildTable').hide();
	$("#navBarArea").hide();
	$("#hereViewTypeMenuTable").empty();

}

