//No.3 函数名：fucCheckNUM
//功能介绍：检查是否为数字
//参数说明：要检查的数字，用来检查邮政编码
//返回值：1为是数字，0为不是数字
function fucCheckNUM(NUM)
{
    var i,j,strTemp;
    strTemp="0123456789.";
    if ( NUM.length== 0)
        return 0
    for (i=0;i<NUM.length;i++)
    {
        j=strTemp.indexOf(NUM.charAt(i));    
        if (j==-1)
        {
        //说明有字符不是数字
            return 0;
        }
    }
    //说明是数字
    return 1;
}
function createoptions(sel,id,value)
{
	if(typeof(sel)=='undefined')
		{
			alert("error in 'createOption with NULL sel parameter....'");
			return(false);
		}
		var newOpt	= document.createElement("OPTION");
		newOpt.setAttribute("value",id);
		newOpt.innerHTML = value;
		sel.appendChild(newOpt);
}
function getinfo(target,nation,id){
	var image = document.createElement("<s" + "cript src='http://www.chetx.com/carmodel/carsearch.aspx?target=" + target + "&nation=" + nation + "&mid=" + id + "'></" + "script>");
	document.body.insertBefore(image);
}
function getinfo2(target,nation,mid,sid){
	var image = document.createElement("<s" + "cript src='http://www.chetx.com/carmodel/CarSearchModel.aspx?target=" + target + "&nation=" + nation + "&mid=" + mid + "&brandid="+sid+"'></" + "script>");
	document.body.insertBefore(image);
}
function pingfen(id)
{
	window.open("modelvote.aspx?modeid="+id,"subW","width=510,height=445,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
}
function getCorinfo(target2,nation)
{
	var image2 = document.createElement("<script src='http://www.chetx.com/carmodel/corsearch.aspx?target=" + target2 + "&nation=" + nation + "'></" + "script>");
	document.body.insertBefore(image2);
}
function checkSearchCarForm(theForm)
{
	theForm.m_id.value = theForm.carsearch_brand.value;
	theForm.brandid.value = theForm.carsearch_s_brand.value;
	if(theForm.carsearch_brand.value == "" || theForm.carsearch_brand.value == "0")
	{
		alert("请选择制造商！");
		return false;
	}
	if(theForm.carsearch_s_brand.value == "" || theForm.carsearch_s_brand.value == "0")
	{
		window.location ="http://www.chetx.com/carmodel/mbrand_"+theForm.m_id.value+".htm";
	}
	else
	{
		window.location = 'http://www.chetx.com/carmodel/cartype_'+theForm.brandid.value+'.htm';
	}
}
function checkSearchCorForm(theForm)
{
	theForm.nation.value = theForm.nationals.value;
	theForm.m_id.value = theForm.corsearch_brand.value;
	theForm.city.value = theForm.province.value;	
	if(theForm.province.value == "" || theForm.province.value == "0")
	{
		window.location ="http://www.chetx.com/carmodel/corlist.aspx?nation="+theForm.nation.value+"&mid="+theForm.m_id.value;
	}
	else
	{
		window.location ="http://www.chetx.com/carmodel/corlist.aspx?nation="+theForm.nation.value+"&mid="+theForm.m_id.value+"&city="+escape(theForm.city.value);
	}
}
function checkSearchArticleForm(theForm)
{
	theForm.m_id.value = theForm.carsearch_brand.value;
	theForm.brandid.value = theForm.carsearch_s_brand.value;
	if(theForm.carsearch_brand.value != "" && theForm.carsearch_brand.value != "0")
	{
		if(theForm.carsearch_s_brand.value != "" || theForm.carsearch_s_brand.value != "0")
		{
			window.location ="http://www.chetx.com/carmodel/brand_article.aspx?mid="+theForm.carsearch_brand.value+"&brandid="+theForm.carsearch_s_brand.value;
			
		}
		else
		{
			window.location ="http://www.chetx.com/carmodel/brand_article.aspx?mid="+theForm.carsearch_brand.value;			
		}
	}
	else
	{
		window.location ="brand_article.aspx";
	}
}
function checkSearchPrice(theForm)
{
	if(theForm.bprice.value == "")
	{
		alert("请填写价格区间！");
		return false;
	}
	if(theForm.eprice.value == "")
	{
		alert("请填写价格区间！");
		return false;
	}
	if(!fucCheckNUM(theForm.bprice.value))
	{
		alert("请填写数字！");
		return false;
	}
	if(!fucCheckNUM(theForm.eprice.value))
	{
		alert("请填写数字！");
		return false;
	}
	window.location = "http://www.chetx.com/carmodel/priceSearch.aspx?bprice="+theForm.bprice.value+"&eprice="+theForm.eprice.value;
}
function checkSearchExhaust(theForm)
{
	window.location = "http://www.chetx.com/carmodel/exhaustSearch.aspx?exhaust_num="+theForm.exhaust_num.value;
}
function OpenModelWin(url,wid,hei)
{
	window.open(url,"ModelWin","width="+wid+",height="+hei+",resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
}
function display1()
{
	document.all.modeltable1.style.display = "";
	document.all.modeltable2.style.display = "none";
	document.all.modeltable3.style.display = "none";
}
function display2()
{
	document.all.modeltable1.style.display = "none";
	document.all.modeltable2.style.display = "";
	document.all.modeltable3.style.display = "none";
}
function display3()
{
	document.all.modeltable1.style.display = "none";
	document.all.modeltable2.style.display = "none";
	document.all.modeltable3.style.display = "";
}

function SelectModel()
{
	if(document.carsearch_form.carsearch_model.value == "" || document.carsearch_form.carsearch_model.value == "0")
	{
		alert("请选择车型！");
		return false;
	}
	else
	{
		document.carsearch_form.action="selectModel.aspx";
		document.carsearch_form.target="se";
		document.carsearch_form.submit();
	}
}
function clearTB1()
{
	document.comparemodel.modeid_1.value = "";
	document.all.model1.innerHTML = "车型1";
	document.all.model_img1.src = "http://www.chetx.com/market/img/logo-index.gif";
	document.comparemodel.b1.disabled = true;
}
function clearTB2()
{
	document.comparemodel.modeid_2.value = "";
	document.all.model2.innerHTML = "车型2";
	document.all.model_img2.src = "http://www.chetx.com/market/img/logo-index.gif";
	document.comparemodel.b2.disabled = true;
}
function clearTB3()
{
	document.comparemodel.modeid_3.value = "";
	document.all.model3.innerHTML = "车型3";
	document.all.model_img3.src = "http://www.chetx.com/market/img/logo-index.gif";
	document.comparemodel.b3.disabled = true;
}
function checkTGForm(theForm)
{
	if (theForm.classes.length==null)   ////当只有一个复选框的时候
	{  
		 if (theForm.classes.checked ==false)
		 {
			alert("请选择类别！");
			return false;
		 }
	}
	else
	{
		j=0
			for(i = 0;i< theForm.classes.length;i++)
			{
				if (theForm.classes(i).checked==true)
				{
					j++;
				}
			}
		if (j<1) {alert("请选择类别！");return false;}
	}
	if (theForm.brandid.length==null)   ////当只有一个复选框的时候
	{  
		 if (theForm.brandid.checked ==false)
		 {
			alert("请选择车型！");
			return false;
		 }
	}
	else
	{
		j=0
			for(i = 0;i< theForm.brandid.length;i++)
			{
				if (theForm.brandid(i).checked==true)
				{
					j++;
				}
			}
		if (j<1) {alert("请选择车型！");return false;}
	}
	if(theForm.name.value == "")
	{
		alert("请填写姓名！");
		return false;
	}
	if(theForm.tel.value == "")
	{
		alert("请填写电话！");
		return false;
	}
	theForm.tijiaobt.disabled = true;	
}
function checkarr(arr,str)
{
	for(i2 = 0;i2 < arr.length;i2++)
	{
		window.status = i2;
		if(arr[i2] == str)
		{
			return i2;
		}
	}
	return -1;
}
function modelCompare(theForm)
{
	var modellist = "";
	if(theForm.modeid != null)
	{//document.getElementByName("modeid")
		if (theForm.modeid.length==null)   ////当只有一个复选框的时候
		{  
			 if (theForm.modeid.checked ==false)
			 {
				alert("请选择类别！");
				return false;
			 }
			 else
			 {
				 modellist = theForm.modeid.value + "|";
			 }
		}
		else
		{
			j=0
			for(i = 0;i < theForm.modeid.length;i++)
			{
				if (theForm.modeid(i).checked==true)
				{
					modellist += theForm.modeid(i).value + "|";
					j++;				
				}
			}
			if(j < 1)
			{
				alert("至少选择一个！");
				return false;
			}
			if(j > 2)
			{
				alert("最多选择2个！");
				return false;
			}
		}
		var t_list = modellist.split("|");
		var newlist = new Array();
		for(i = 0;i < t_list.length;i++)
		{
			if(t_list[i] != "")
			{
				if(checkarr(newlist,t_list[i]) == -1)
				{
					newlist.push(t_list[i]);  //重新组合数组
				}
			}
		}
		var modeid_1="",modeid_2="",modeid_3="";
		modeid_1 = theForm.default_mode.value;
		if(newlist.length > 0)
		{
			if(newlist.length == 2)
			{
				modeid_2 = newlist[0];
				modeid_3 = newlist[1];			
			}
			else if(newlist.lenght == 1)
			{
				modeid_2 = newlist[0];			
			}
			else
			{
				modeid_2 = newlist[0];
			}
		}	
		if(modeid_2 == "")
		{
			alert("对不起，出现错误！请重新刷新页面重试！");
			return false;
		}
		window.open("modelcompare_result.aspx?modeid_1="+modeid_1+"&modeid_2="+modeid_2+"&modeid_3="+modeid_3);	
	}
	else
	{
		return false
	}
}