﻿//请引用jquery
$(document).ready(function() {
	var ckeytip = "请输入关键词";
	$("#txtCKey").val(ckeytip);
	$("#txtCKey").css({ color: "gray" });
	// $("#txtCKey").click(function() { $(this).val(""); });

	$("#txtCKey").blur(function() {
		if ($.trim($(this).val()) == "") {
			$(this).val(ckeytip);
			$("#txtCKey").css({ color: "gray" });
		}
	});
	$("#txtCKey").click(function() {
		if ($(this).val() == ckeytip) {
			$(this).val("");
			$(this).css({ color: "#000" });
		}
	});

	$("input[type=radio][name=radCSearch]").click(function() {
		var type = $(":radio[name=radCSearch]:checked").val();
		if (type == 1 || type == 3) {
			//产品
			$("#hreCSearch").attr("href", "/Search/ProductSearch.aspx");
		}
		else if (type == 2) {
			//企业
			$("#hreCSearch").attr("href", "/Search/CompanySearch.aspx");
		}
	});
	$("#btnCSerach").click(function() {
		var type = $("input[type=radio][name=radCSearch]:checked").val();
		var key =$("#txtCKey").val();
		if ($("#txtCKey").css("color") == "gray") {
			$("#txtCKey").val("");
			if (type == 1) {
				//产品
				window.location.href = "/Search/ProductResult.aspx?SOD=1";
			}
			else if (type == 2) {
				//企业
				window.location.href = "/Search/CompanyResult.aspx";
			}
			else if (type == 3) {
				//求购（买家）
				window.location.href = "/Search/ProductResult.aspx?SOD=2";
			}
			return;
		}
		if (key.length < 2 && key.length > 0) {
			$("#txtCKey").focus();
			alert("您必须输入两个关键字。");
			return;
		}
		if (type == 1) {
			//产品
			window.location.href = "/Search/ProductResult.aspx?KeyWord=" +encodeURIComponent(key) + "&SOD=1";
		}
		else if (type == 2) {
			//企业
			window.location.href = "/Search/CompanyResult.aspx?keyWord=" +encodeURIComponent(key);
		}
		else if (type == 3) {
			//求购（买家）
			window.location.href = "/Search/ProductResult.aspx?KeyWord=" +encodeURIComponent(key) + "&SOD=2";
		}
		else if (type == 4) {
			//联盟
			window.location.href = "/Union/UnionList.aspx?SCAName=" + key;
		}
	});

	
});