
function adjustForm()
{
	var f = document.getElementById('subscribe');
//	alert("hi");

	if (f.sub_type.value == 'P')
	{
		hideRow('address1Row');
		hideRow('address2Row');
		hideRow('stateRow');
		hideRow('cityRow');
		hideRow('provinceRow');
		hideRow('zipRow');
	}
	else
	{
		showSubscribeRow('address1Row');
		showSubscribeRow('address2Row');
		showSubscribeRow('stateRow');
		showSubscribeRow('cityRow');
		showSubscribeRow('provinceRow');
		showSubscribeRow('zipRow');
	
		if (f.country_code.value == 'US')
		{
			showSubscribeRow('stateRow');
			showSubscribeRow('zipRow');
			hideRow('provinceRow');
			
		}
		else
		{
			hideRow('stateRow');
			//hideRow('zipRow');
			showSubscribeRow('provinceRow');
		}

	}	
}


function updateTopics()
{
//		alert(getCheckValue(document.subscribe.topic_id));
	document.subscribe.topic_id_all.checked = false;
}

function updateAffiliations()
{
//	document.subscribe.affiliation_id_all.checked = false;
}

function setAllTopics()
{
	for (var i = 0; i < document.subscribe.topic_id.length; i++)
	{
		document.subscribe.topic_id[i].checked = false;
	}
	document.subscribe.topic_id_all.checked = true;
}

function setAllAffiliations()
{
	for (var i = 0; i < document.subscribe.affiliation_id.length; i++)
	{
		document.subscribe.affiliation_id[i].checked = false;
	}
}

function validateMe()
{
	var f = document.subscribe;
//	var f = document.getElementById('subscribeForm');
	var allGood = true;
	var messages = "";
	var sub_type = f.sub_type.value;
	
	if (f.fname.value.length == 0)
	{
		messages = messages + "First name may not be empty.\n";
		allGood = false;
	}
	if (f.lname.value.length == 0)
	{
		messages = messages + "Last name may not be empty.\n";
		allGood = false;
	}

	if (sub_type == 'B' || sub_type == 'M')
	{
		if ((f.address1.value.length == 0) || (f.city.value.length == 0))
		{
			messages = messages + "Address and City are required for this subscription type.\n";
			allGood = false;		
		}

		if ((f.country_code.value == 'US') && ((f.zip.value.length < 5) || f.state_code.value == ''))
		{
			messages = messages + "For a U.S. address you must choose a state and enter a valid zip code.\n";
			allGood = false;	
		}
	}
	
	if (f.email.value.length == 0 || !checkEmail(f.email.value))
	{
		messages = messages + "Email address must be valid.\n";
		allGood = false;
	}
	
	
	if (!allGood)
	{
		alert("The following errors must be corrected before we can process your request:\n" + messages);
	}
	
	return allGood;
}

function safeSubmit(thisObj)
{
	thisObj.disabled = true;
	if (validateMe())
	{
		document.subscribe.submit();
		thisObj.disabled = false;
//		alert("would submit");
	}
	else
	{
		thisObj.disabled = false;
	}
		
}

function showSubscribeRow(rowId)
{
	document.getElementById(rowId).className = 'row';
}