var price_policy = {
	"bzjz200_0907" :	{ "1y" : 598,	"2y" : 1076,	"3y" : 1435,	"4y" : 1674,	"5y" : 2093,	"mbox" : "embox" },
	"bzjz500_0907" :	{ "1y" : 798,	"2y" : 1436,	"3y" : 1915,	"4y" : 2234,	"5y" : 2793,	"mbox" : "embox" },
	"bzjz800_0907" :	{ "1y" : 998,	"2y" : 1796,	"3y" : 2395,	"4y" : 2794,	"5y" : 3493,	"mbox" : "embox" },
	"bzjz1000_0907" :	{ "1y" : 1198,	"2y" : 2156,	"3y" : 2875,	"4y" : 3354,	"5y" : 4193,	"mbox" : "embox" },
	"swjz200_0907" :	{ "1y" : 798,	"2y" : 1436,	"3y" : 1915,	"4y" : 2234,	"5y" : 2793,	"mbox" : "gmbox" },
	"swjz500_0907" :	{ "1y" : 998,	"2y" : 1796,	"3y" : 2395,	"4y" : 2794,	"5y" : 3493,	"mbox" : "gmbox" },
	"swjz800_0907" :	{ "1y" : 1198,	"2y" : 2156,	"3y" : 2875,	"4y" : 3354,	"5y" : 4193,	"mbox" : "gmbox" },
	"swjz1000_0907" :	{ "1y" : 1398,	"2y" : 2516,	"3y" : 3355,	"4y" : 3914,	"5y" : 4893,	"mbox" : "gmbox" },
	"full" :			{
		"com" :			{ "new" : 68,	"renew" : 68 },
		"cn" :			{ "new" : 28,	"renew" : 58 },
		"embox" :		{ "1" : 100, "10" : 90, "20" : 80, "30" : 70, "50" : 60, "100" : 50 },
		"gmbox" :		{ "1" : 150, "10" : 135, "20" : 120, "30" : 105, "50" : 90, "100" : 75 }
		},
	"com" :				{ "new" : 50,	"renew" : 60 },
	"cn" :				{ "new" : 6,	"renew" : 45 },
	"embox" :			{ "1" : 95, "10" : 86, "20" : 76, "30" : 67, "50" : 57, "100" : 48 },
	"gmbox" :			{ "1" : 135, "10" : 122, "20" : 108, "30" : 95, "50" : 81, "100" : 68 }
};

var updprc = function(prdcode) {
	var prdform = document.forms[prdcode];
	var prdprcfield = document.getElementById(prdcode + "_ttlprc");
	var prdprcsaving = document.getElementById(prdcode + "_saving");
	var prcidx = 0;
	
	var domain = "";
	for (var i = 0; i < prdform.elements["domain"].length; i++) {
		if (prdform.elements["domain"][i].checked) {
			domain = prdform.elements["domain"][i].value;
			break;
		}
	}
	var mboxnum = prdform.elements["emailcnt"].value;
	var nodomain = prdform.elements["nodomain"].checked;
	var noemail = prdform.elements["noemail"].checked;
	var yearcnt = prdform.elements["yearcnt"].options[prdform.elements["yearcnt"].selectedIndex].value;
	
	var ttlprc = price_policy[prdcode][yearcnt + "y"];
	var full_ttlprc = parseInt(price_policy[prdcode]["1y"]) * parseInt(yearcnt);
	if (!nodomain && !/^\s*$/.test(domain)) {
		ttlprc += price_policy[domain]["new"] + price_policy[domain]["renew"] * parseInt(yearcnt - 1);
		full_ttlprc += price_policy["full"][domain]["new"] + price_policy["full"][domain]["renew"] * parseInt(yearcnt - 1);
	}
	if (!noemail && /^[0-9]+$/.test(mboxnum)) {
		prcidx = parseInt(parseInt(mboxnum) / 10) * 10;
		if (prcidx == 0) {
			prcidx = 1;
		}
		ttlprc += price_policy[price_policy[prdcode]["mbox"]][prcidx.toString()] * parseInt(mboxnum) * parseInt(yearcnt);
		full_ttlprc += price_policy["full"][price_policy[prdcode]["mbox"]][prcidx.toString()] * parseInt(mboxnum) * parseInt(yearcnt);
	}
	prdprcfield.innerHTML = ttlprc;
	prdprcsaving.innerHTML = full_ttlprc - ttlprc;
	
	// check email number and domain radios
	if (noemail) { prdform.elements["emailcnt"].value = "0"; }
	if (nodomain) {
		for (var i = 0; i < prdform.elements["domain"].length; i++) {
			prdform.elements["domain"][i].checked = false;
		}
	}
}

var submitform = function(formname) {
	document.forms[formname].submit();
}

