document.FomMain.ProSel1.options[0].selected = true;
document.FomMain.ProSel2.options[0].selected = true;
document.FomMain.CitSel1.options[0].selected = true;
document.FomMain.CitSel2.options[0].selected = true;
document.FomMain.AreSel1.options[0].selected = true;
document.FomMain.AreSel2.options[0].selected = true;

var iX;

for(iX = 0; iX < iP; iX ++)
{
	document.FomMain.ProSel1.options[iX + 1] = new Option(ProSel[iX][1], iX);
	document.FomMain.ProSel2.options[iX + 1] = new Option(ProSel[iX][1], iX);
}

function chanCit1(AreID)
{
	var iE, iNum;
	
	iNum = document.FomMain.CitSel1.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.CitSel1.options.remove(1);
	}
	document.FomMain.CitSel1.options[0].selected = true;
	iNum = document.FomMain.AreSel1.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.AreSel1.options.remove(1);
	}
	document.FomMain.AreSel1.options[0].selected = true;
	if(AreID == "false")
		return;
	iNum = 1;
	for(iE = 0; iE < iC; iE ++)
	{
		if(CitSel[iE][2] > ProSel[AreID][2] && CitSel[iE][3] < ProSel[AreID][3])
		{
			document.FomMain.CitSel1.options[iNum] = new Option(CitSel[iE][1], iE);
			iNum ++;
		}
	}
}

function chanAre1(AreID)
{
	var iE, iNum;
	
	iNum = document.FomMain.AreSel1.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.AreSel1.options.remove(1);
	}
	document.FomMain.AreSel1.options[0].selected = true;
	if(AreID == "false")
		return;
	iNum = 1
	for(iE = 0; iE < iA; iE ++)
	{
		if(AreSel[iE][2] > CitSel[AreID][2] && AreSel[iE][3] < CitSel[AreID][3])
		{
			document.FomMain.AreSel1.options[iNum] = new Option(AreSel[iE][1], AreSel[iE][0]);
			iNum ++;
		}
	}
}

function chanCit2(AreID)
{
	var iE, iNum;
	
	iNum = document.FomMain.CitSel2.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.CitSel2.options.remove(1);
	}
	document.FomMain.CitSel2.options[0].selected = true;
	iNum = document.FomMain.AreSel2.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.AreSel2.options.remove(1);
	}
	document.FomMain.AreSel2.options[0].selected = true;
	if(AreID == "false")
		return;
	iNum = 1;
	for(iE = 0; iE < iC; iE ++)
	{
		if(CitSel[iE][2] > ProSel[AreID][2] && CitSel[iE][3] < ProSel[AreID][3])
		{
			document.FomMain.CitSel2.options[iNum] = new Option(CitSel[iE][1], iE);
			iNum ++;
		}
	}
}

function chanAre2(AreID)
{
	var iE, iNum;
	
	iNum = document.FomMain.AreSel2.options.length;
	for(iE = 1; iE < iNum; iE ++)
	{
		document.FomMain.AreSel2.options.remove(1);
	}
	document.FomMain.AreSel2.options[0].selected = true;
	if(AreID == "false")
		return;
	iNum = 1
	for(iE = 0; iE < iA; iE ++)
	{
		if(AreSel[iE][2] > CitSel[AreID][2] && AreSel[iE][3] < CitSel[AreID][3])
		{
			document.FomMain.AreSel2.options[iNum] = new Option(AreSel[iE][1], AreSel[iE][0]);
			iNum ++;
		}
	}
}

var ProVal1, CitVal1, AreVal1, ProVal2, CitVal2, AreVal2, txtVal;

function checkFomInfo(ProObj1, CitObj1, AreObj1, ProObj2, CitObj2, AreObj2, txtObj)
{
	if(ProObj1.value == "false")
	{
		alert("请选择发件地的省名!");
		ProObj1.focus();
	}
	else if(CitObj1.value == "false")
	{
		alert("请选择发件地的市名!");
		CitObj1.focus();
	}
	else if(AreObj1.value == "false")
	{
		alert("请选择发件地的区/县名!");
		AreObj1.focus();
	}
	else if(ProObj2.value == "false")
	{
		alert("请选择收件地的省名!");
		ProObj2.focus();
	}
	else if(CitObj2.value == "false")
	{
		alert("请选择收件地的市名!");
		CitObj2.focus();
	}
	else if(AreObj2.value == "false")
	{
		alert("请选择收件地的区/县名!");
		AreObj2.focus();
	}
	else if(txtObj.value == "")
	{
		alert("请输入包裹的重量!");
		txtObj.focus();
	}
	else if(parseInt(txtObj.value) > 35000)
	{
		alert("你的包裹超过邮局规定重量!");
		txtObj.value = "";
		txtObj.focus();
	}
	else
	{
		document.FomMain.QueryFom.value = "查询中．";
		ProVal1 = ProObj1.options[ProObj1.selectedIndex].text;
		CitVal1 = CitObj1.options[CitObj1.selectedIndex].text;
		AreVal1 = AreObj1.options[AreObj1.selectedIndex].text;
		ProVal2 = ProObj2.options[ProObj2.selectedIndex].text;
		CitVal2 = CitObj2.options[CitObj2.selectedIndex].text;
		AreVal2 = AreObj2.options[AreObj2.selectedIndex].text;
		txtVal = txtObj.value;
		postRequest(AreObj1.value, AreObj2.value);
	}
}

var http_request;

function postRequest(val1, val2)
{
	var urlstr = "proval.asp";
	var posstr = "val1=" + val1 + "&val2=" + val2;
	
	makePost(urlstr, posstr);
}

function makePost(urlstr, posstr)
{
	http_request = false;
	if(window.XMLHttpRequest)
	{
		http_request = new XMLHttpRequest();
		if(http_request.overrideMimeType)
			http_request.overrideMimeType('text/xml');
	}
	else if(window.ActiveXObject)
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {}
		}
	}
	
	if(!http_request)
	{
		alert("Giving up: Cannot create an XMLHTTP instance...");
		return false;
	}
	http_request.onreadystatechange = alertContentsPost;
	http_request.open('POST', urlstr, true);
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	http_request.send(posstr);
}

function alertContentsPost()
{
	if(http_request.readyState == 4)
	{
		if(http_request.status == 200)
		{
			document.FomMain.QueryFom.value = "立即查询";
			writeTable(http_request.responseText);
		}
		else
		{
			alert("There was a problem with the request.\nError Code: " + http_request.status + "\nPlease find the error code in www.w3c.org.");
		}
	}
}

function writeTable(money)
{
	var tabStr = "";
	var pos, num;
	num = parseInt(txtVal);
	if(num % 500 == 0)
		num = num / 500;
	else
		num = parseInt(num / 500) + 1;
	pos = parseFloat(money) * num / 2;
	pos = parseFloat(pos.toFixed(1) );
	tabStr += "<table width='650' border='0' cellspacing='0' cellpadding='0' id='posTable'>\n"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th height='20' colspan='3' align='left' scope='col'>由 <font color='#FF0000'>" + ProVal1 + CitVal1 + AreVal1 + "</font> 到 <font color='#FF0000'>" + ProVal2 + CitVal2 + AreVal2 + "</font> 重量 <font color='#FF0000'>" + txtVal + "</font>克 所需邮费：</th>"
	tabStr +=	"  </tr>"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th width='153' height='20' align='right' scope='col'>普通邮费(必须)：</th>"
	tabStr +=	"    <th colspan='2' align='left' scope='col'><font color='#FF0000'>" + pos + "</font> ￥</th>"
	tabStr +=	"  </tr>"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th height='20' align='right' scope='col'>挂号费(必须)&nbsp;&nbsp;：</th>"
	tabStr +=	"    <th colspan='2' align='left' scope='col'><font color='#FF0000'>3.0</font> ￥</th>"
	tabStr +=	"  </tr>"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th height='20' align='right' scope='col'>回执费(可选)&nbsp;&nbsp;：</th>"
	tabStr +=	"    <th colspan='2' align='left' scope='col'><font color='#FF0000'>3.0</font> ￥</th>"
	tabStr +=	"  </tr>"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th height='20' align='right' scope='col'>保价费(可选)&nbsp;&nbsp;：</th>"
	tabStr +=	"    <th width='228' align='left' scope='col'><font color='#FF0000'>1.0</font> ￥</th>"
	tabStr +=	"    <th width='269' align='left' scope='col'>合计费用：<font color='#FF0000'>" + (pos + 3) + "</font>(必须) + <font color='#FF0000'>4.0</font>(可选) = <font color='#FF0000'>" + (pos + 3 + 4) + " ￥</font></th>"
	tabStr +=	"  </tr>"
	tabStr +=	"  <tr>"
	tabStr +=	"    <th colspan='3' align='left' scope='col'>&nbsp;</th>"
	tabStr +=	"  </tr>"
	tabStr +=	"</table>"
	document.getElementById("posTable").outerHTML = tabStr;
}