// JavaScript Document

function drawSearch(iType){

	switch(iType){
		case 1:
			document.writeln("<table border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">");
			document.writeln("<tr>");
			document.writeln("<form name=\"searchForm\" method=\"post\" target=\"_blank\" style=\"MARGIN: 1px\" onsubmit=\"return searchInAll(this);\">");
			document.writeln("<td width=\"70\">");
			document.writeln("<img src=\"/resources/images/tool.jpg\" />");
			document.writeln("</td>");
			document.writeln("<td>");
			document.writeln("<span id=\"part1\">");
			document.writeln("<INPUT onfocus=\"if(this.value.substring(0,3)=='请输入'){this.value='';}\" maxLength=100 size=30 value=请输入产品名称 name=keywords>");
			document.writeln("</span>");
			document.writeln("<span id=\"part2\" style=\"display:none\">");
			document.writeln("价格区间：");
			document.writeln("<INPUT size=\"8\" value=\"\" name=\"pricefrom\" id=\"pricefrom\" >");
			document.writeln("至");
			document.writeln("<INPUT size=\"8\" value=\"\" name=\"priceto\" id=\"priceto\" >");
			document.writeln("</span>");
			document.writeln("<SELECT name=\"IndexArea\" onchange=setinput(this)>");
			document.writeln("<OPTION value=productname selected>产品名称</OPTION>");
			document.writeln("<OPTION value=productnum>产品编号</OPTION>");
			document.writeln("<OPTION value=productprice>产品价格</OPTION>");;
			document.writeln("</SELECT>");
			document.writeln("<INPUT type=submit value=\"找一下\" name=\"submit\">");
			document.writeln("</form>");
			document.writeln("</td>");
			document.writeln("</tr>");
			document.writeln("</table>");
		break;
		case 2:
			document.writeln("<form name=\"searchForm\" method=\"post\" target=\"_blank\" style=\"MARGIN: 1px\" onsubmit=\"return searchInAll(this);\">");
			document.writeln("<span id=\"part1\">");
			document.writeln("<INPUT onfocus=\"if(this.value.substring(0,3)=='请输入'){this.value='';}\" maxLength=100 size=25 value=请输入产品名称 name=keywords>");
			document.writeln("</span>");
			document.writeln("<span id=\"part2\" style=\"display:none\">");
			document.writeln("<INPUT size=\"8\" value=\"\" name=\"pricefrom\" id=\"pricefrom\" >");
			document.writeln("至");
			document.writeln("<INPUT size=\"8\" value=\"\" name=\"priceto\" id=\"priceto\" >");
			document.writeln("</span>");
			document.writeln("<SELECT name=\"IndexArea\" onchange=setinput(this)>");
			document.writeln("<OPTION value=productname selected>产品名称</OPTION>");
			document.writeln("<OPTION value=productnum>产品编号</OPTION>");
			document.writeln("<OPTION value=productprice>产品价格</OPTION>");
			document.writeln("<OPTION value=infotitle>饰品资讯</OPTION>");
			document.writeln("</SELECT>");
			document.writeln("<INPUT type=submit value=\"找一下\" name=\"submit\">");
			document.writeln("</form>");
		break;
	}
}

//描绘表单
function setinput(obj){
	switch(obj.value){
		case "productname":
			document.getElementById("part1").style.display="";
			document.getElementById("part2").style.display="none";
			document.forms["searchForm"].keywords.value="请输入产品名称";
			break;
		case "productnum":
			document.getElementById("part1").style.display="";
			document.getElementById("part2").style.display="none";
			document.forms["searchForm"].keywords.value="请输入产品编号";
			break;
		case "productprice":
			document.getElementById("part1").style.display="none";
			document.getElementById("part2").style.display="";
			break;
		case "infotitle":
			document.getElementById("part1").style.display="";
			document.getElementById("part2").style.display="none";
			document.forms["searchForm"].keywords.value="请输入关键字";
			break;
	}
}
//结果筛选
function searchInAll(obj) {

	var selectedValue = "";var keywords = "";var url = "";
	if (obj.IndexArea){
		selectedValue = obj.IndexArea.options[obj.IndexArea.selectedIndex].value;
	}

	if (obj.keywords){
		keywords = obj.keywords.value;
	}
	
	if(selectedValue=="productprice"){
		pricefrom=obj.pricefrom.value;
		priceto=obj.priceto.value;
		if(testVal("pricefrom","Money")==false || testVal("priceto","Money")==false){
			alert("请正确输入价格区间，正确格式为：1.01")
			return false;
		}
		if(parseFloat(priceto)<=parseFloat(pricefrom)){
			alert("请正确输入价格区间，后者价格必须高于前者价格")
			return false;	
		}
	}else{
    	if ((keywords == "") || (keywords.length <= 1) || (keywords == "输入关键字") || (keywords.substring(0,3) == "请输入")) {
    		alert("请输入关键字，至少两个字符！");
    		return false;
  		}
	}
			
	switch(selectedValue){
	case "productname":
		url="/Product/List_0_0_0_p1.html?field="+selectedValue+"&value="+keywords;
		obj.method = "post";
		obj.action = url;
		obj.target = "_blank";
		break;
	case "productnum":
		url="/Product/List_0_0_0_p1.html?field="+selectedValue+"&value="+keywords;
		obj.method = "post";
		obj.action = url;
		obj.target = "_blank";
		break;
	case "productprice":
		url="/Product/List_0_0_0_p1.html?field="+selectedValue+"&value="+pricefrom+"-"+priceto;
		obj.method = "post";
		obj.action = url;
		obj.target = "_blank";
		break;
	case "infotitle":
		url="/Info/Search.asp?keywords="+keywords;
		obj.method = "post";
		obj.action = url;
		obj.target = "_blank";
		break;
	}
}