﻿$(document).ready(function(){

	

	var searchType = $('#searchType').attr("value");

	

	if (searchType == "searchName"){

		//alert ("searchName");

		$("input[@name=radiobutton2][@value=searchName]").attr("checked",true);

	}

	else if (searchType == "searchDescription"){

		//alert ("searchDescription");

		$("input[@name=radiobutton2][@value=searchDescription]").attr("checked",true);

	}

	

	/* */

	var loadType = $('#loadType').attr("value");

	var typeValue = $('#typeValue').attr("value");

	

	if (loadType=="SEARCH")

	{

		loadProduct(1,10);

	}

	else if (loadType=="FREEPRODUCT")

	{

		loadFreeProduct(1,10);

	}

	else if (loadType=="MIDDLEWARE")

	{

		var middleware_id = $('#typeKey').attr("value");

		var middleware_name = $('#typeValue').attr("value");

		loadProductByMiddleware(middleware_id,middleware_name,1,10);

	}

	else if (loadType=="DEVELOP")

	{

		var develop_id = $('#typeKey').attr("value");

		var develop_name = $('#typeValue').attr("value");

		loadProductByDevelop(develop_id,develop_name,1,10);

	}

	else if (loadType=="FUNCTION")

	{

		var function_id = $('#typeKey').attr("value");

		var function_name = $('#typeValue').attr("value");

		loadProductByFunction(function_id,function_name,1,10);

	}

	else {

		$('#showProductCatalog').show();

	}

	/* */

		

	

});



function loadProduct(currentPage,countPerPage){

	

	var productName = $('#productName').attr("value");

	if (!productName) {

		alert ("请输入产品名称！");

		return;

	}

	

	//

	var searchType;

	$("input[name='radiobutton2']").each(function(){  

		if (this.checked){  

			searchType = this.value;

		}  

	});

	//alert(searchType);

	

	//

	var childOption;

	$("input[name='radiobutton']").each(function(){  

		if (this.checked){  

			

			childOption = this.value;

			

			if (!childOption)

				childOption = "searchAll";



		}  

	});

	//alert(childOption);

	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search.php?productName='+encodeURIComponent(productName)+'&childOption='+childOption+'&searchType='+searchType,

			type:'GET',

			data:{currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc = '<h4>没有找到相关产品……</h4>';

					

					$('#showProductCatalog').show();

				}

					

				$('#showProduct').html(cc);

				

				

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//

				

			}

		});

	

}



function loadProductByMiddleware(middleware_id,middleware_name,currentPage,countPerPage){

	

	$('#searchChild').attr("value","middleware_id="+middleware_id);

	$('#searchChildName').html(middleware_name);

	$('#showChildOption').show();	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search_middleware.php',

			type:'GET',

			data:{middleware_id:middleware_id,middleware_name:middleware_name,currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						//cc = cc+'<h3>'+data.products[i].name+'</h3>';

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc='<h4>没有找到相关产品……</h4>';

				}

					

				$('#showProduct').html(cc);

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//				

			}

		});

	

}



function loadProductByDevelop(develop_id,develop_name,currentPage,countPerPage){

	

	$('#searchChild').attr("value","develop_id="+develop_id);

	$('#searchChildName').html(develop_name);

	$('#showChildOption').show();	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search_develop.php',

			type:'GET',

			data:{develop_id:develop_id,develop_name:develop_name,currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						//cc = cc+'<h3>'+data.products[i].name+'</h3>';

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc='<h4>没有找到相关产品……</h4>';

				}

					

				$('#showProduct').html(cc);

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//				

			}

		});

	

}



function loadProductByWintool(wintool_id,wintool_name,currentPage,countPerPage){

	

	$('#searchChild').attr("value","wintool_id="+wintool_id);

	$('#searchChildName').html(wintool_name);

	$('#showChildOption').show();	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search_wintool.php',

			type:'GET',

			data:{wintool_id:wintool_id,wintool_name:wintool_name,currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						//cc = cc+'<h3>'+data.products[i].name+'</h3>';

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc='<h4>没有找到相关产品……</h4>';

				}

				

				$('#showProduct').html(cc);

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//				

			}

		});

	

}



function loadProductByFunction(function_id,function_name,currentPage,countPerPage){

	

	$('#searchChild').attr("value","function_id="+function_id);

	$('#searchChildName').html(function_name);

	$('#showChildOption').show();	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search_function.php',

			type:'GET',

			data:{function_id:function_id,function_name:function_name,currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						//cc = cc+'<h3>'+data.products[i].name+'</h3>';

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc='<h4>没有找到相关产品……</h4>';

				}

				

				$('#showProduct').html(cc);

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//				

			}

		});

	

}



function loadFreeProduct(currentPage,countPerPage){

	

	$('#searchChild').attr("value","freeProduct=1");

	$('#searchChildName').html("免费产品");

	$('#showChildOption').show();	

	

		$('#showProductCatalog').hide();

	

		$.ajax({

			url: 'product_search_free.php',

			type:'GET',

			data:{currentPage:currentPage,countPerPage:countPerPage},

			dataType:'json',

			success:function(data)

			{

				var bb = data.pagination;

				$('#loadPagination').html(bb);

				$('#loadPagination2').html(bb);

				

				var cc = '';

				if (data.products.length>0)

				{

					for (i = 0; i < data.products.length; i++)

					{

						cc = cc+'<div class="myroundedbox"><div class="myroundedbox-outer"><div class="myroundedbox-inner"><div class="myroundedbox-title">';

				

						//cc = cc+'<h3>'+data.products[i].name+'</h3>';

						cc = cc+'<h3><a href="product_detail.php?product_id='+data.products[i].id+'">'+data.products[i].name+'</a></h3>';

						cc = cc+'<p>星级评价：<span class="star" val="'+data.products[i].rate+'"></span>('+data.products[i].number+')</p>';

						cc = cc+'<p>'+data.products[i].shortdescription+'<a href="product_detail.php?product_id='+data.products[i].id+'">查看详细信息</a></p>';

						

						cc = cc+'</div></div></div></div>';

					}

				}

				else

				{

					cc='<h4>没有找到相关产品……</h4>';

				}

				

				$('#showProduct').html(cc);

				

				//等级显示

				var images=["./images/grey.gif","./images/red.gif"];		

				var options = { 

					img: images,

					enable: false

				};

				$('.star').jStar(options);

				//				

			}

		});

	

}
