var flResident = true;
var flOnline = false;
var alertMsg = "Sorry - Within Lunenburg and Queens counties, you must subscribe to the hard copy editon of the Bulletin or the Progress Enterprise to gain access to the online edition.";
var finishMsg = "Please indicate a subscription type.";
function GetSubscription()
{
	var i; 

	for( i=0; i<document.subForm.product_end.length; ++i)//this will return the first checked item in the form - sloppy
		if( document.subForm.product_end[i].checked)
			return document.subForm.product_end[i].value;

	// default (non selected)
	return -1;
}

function checkForSubscription() { 
	var i;

	for( i=0; i<document.subForm.product_end.length; ++i) {//this will return the first checked item in the form - sloppy
		if( document.subForm.product_end[i].checked) {
			return true;
			}
		}//document.subForm.product_end[i].value;

	// default (non selected)
	return false;
}

function GetPublication()
{
	var theIndex = document.subForm.product_start.selectedIndex;
	return document.subForm.product_start.options[theIndex].value;
}

function residentState(fl) {
	flResident = fl;
}

function onlineState(fl) {
	flOnline = fl;
}

function validate() {
	
	if (flOnline && flResident) {
		alert(alertMsg);
		return false;
	} else {
		var flSubscriptionChecked = false;
		flSubscriptionChecked = checkForSubscription();
		if (!flSubscriptionChecked) {
			alert(finishMsg);
			return false;
		}
		ps = GetPublication();
		pe = GetSubscription();
		document.subForm.product.value =  GetPublication() + ", " + GetSubscription();
		var thePrice;
		switch (pe) {
			case "Nova Scotia New":
				thePrice = "55.20";
				break;
			case "Nova Scotia Renewal":
				thePrice = "50.12";
				break;
			case "Rest of Canada":
				thePrice = "76.33";
				break;
			case "US":
				thePrice = "156";
				break;
			case "International":
				thePrice = "199";
				break;
			case "Online Edition":
				thePrice = "27.60";
				break;
		}
		document.subForm.price.value = thePrice;
		return true;
	}
	return false;
}

