// JavaScript Document
var c_AnswerID_ReligiousAffiliation_Other = 22
var c_AnswerID_SpiritualNeedsMet_No = 27
var c_Comments_CharacterLimit = 500

function ChangeCountry(sCountryCode) { 
	var seldivus = document.getElementById('divus');
	var seldivintl = document.getElementById('divintl');	
	
	if (sCountryCode == 'US' || sCountryCode == 'CA') {
		seldivintl.style.display = "none";
		seldivus.style.display = "inline";		
	}
	else {
		seldivus.style.display = "none";
		seldivintl.style.display = "inline";
	}
}

function ChangeAffiliation(iAnswer) { 
	var seldiv = document.getElementById('divaffi');
	
	if (iAnswer == c_AnswerID_ReligiousAffiliation_Other) {
		seldiv.style.display = "inline";		
	}
	else {
		seldiv.style.display = "none";
	}
}

function ChangeSpiritualNeeds(iAnswer) { 
	var seldiv = document.getElementById('divneeds');
	
	if (iAnswer == c_AnswerID_SpiritualNeedsMet_No) {
		seldiv.style.display = "inline";		
	}
	else {
		seldiv.style.display = "none";
	}
}

function CheckComments(e) {
		var keynum;
		var keychar;
		var numcheck;

		if (document.OrderForm.question9.value.length > c_Comments_CharacterLimit) {
			alert("Please limit your comments to " + c_Comments_CharacterLimit + " characters.");
			document.OrderForm.question9.value = document.OrderForm.question9.value.substr(0,c_Comments_CharacterLimit)
		}				
	}

function SubmitLogin(){ 
	var reBlank = /^\s*$/;
  
	var strValue = document.frmLogin.email.value; 
	if (reBlank.test(strValue)){ 
		alert('Please enter your E-mail address.');  
		document.frmLogin.email.focus(); 
		return false; } 
}

function SubmitCheck(sType){ 
	var reBlank = /^\s*$/;
  
	var strValue = document.OrderForm.fname.value; 
	if (reBlank.test(strValue)){ 
		alert('Please enter your First Name.');  
		document.OrderForm.fname.focus(); 
		return false; } 

	var strValue = document.OrderForm.lname.value; 
	if (reBlank.test(strValue)){ 
		alert('Please enter your Last Name.');  
		document.OrderForm.lname.focus(); 
		return false; }

	if (document.OrderForm.country.selectedIndex == 0) {  
		alert('Please select your Country.');  
		document.OrderForm.country.focus(); 
		return false; }

	var selCountryIndex = document.OrderForm.country.selectedIndex; 
	var strCountry = document.OrderForm.country.options[selCountryIndex].value; 
	if ((strCountry == 'US') || (strCountry == 'CA')) {		
		var strValue = document.OrderForm.address1.value; 
		if (reBlank.test(strValue)){
			alert('Please enter your Address 1.'); 
			document.OrderForm.address1.focus(); 
			return false; }

		var strValue = document.OrderForm.city.value; 
		if (reBlank.test(strValue)){ 
			alert('Please enter your City.');  
			document.OrderForm.city.focus(); 
			return false; }

		var selStateIndex = document.OrderForm.state.selectedIndex; 
		var strState = document.OrderForm.state.options[selStateIndex].value; 
		if (strState == '') {  
			alert('Please select your State or Province.');  
			document.OrderForm.state.focus(); 
			return false; }
	
		//var strValue = document.OrderForm.phone.value; 
		//if (reBlank.test(strValue)){ 
		//	alert('Please enter your Telephone Number.');  
		//	document.OrderForm.phone.focus(); 
		//	return false; }

		var strValue = document.OrderForm.zip.value; 
		if (reBlank.test(strValue)){ 
			alert('Please enter your Zip/Postal Code.');  
			document.OrderForm.zip.focus(); 
			return false; }
		else {
			if (strCountry == 'US') {
				if (!(IsValidUSZip(strValue))) { 
					alert('Please enter a valid US Zip Code.');  
					document.OrderForm.zip.focus(); 
					return false; }}}	
	}
	else {
		var strValue = document.OrderForm.addressline1.value; 
		if (reBlank.test(strValue)){
			alert('Please enter your Address Line 1.'); 
			document.OrderForm.addressline1.focus(); 
			return false; }
	}
	
	if (sType == 'o') {
		if (document.OrderForm.agerange.selectedIndex == 0) {  
			alert('Please select your Age Range.');  
			document.OrderForm.agerange.focus(); 
			return false; }
	}
}	

function IsValidUSZip(strZip) { 
	var strChar;  
	if (strZip.length != 5) { return false; } 	
	for (var i=0;i<=4;i++) { 
		strChar = strZip.charAt(i)  
		if (strChar <'0' || strChar >'9' ) { return false; }
	} 
	return	true; 
}