

function showPostalField(val) {
	if (val == 'CA') {
		document.getElementById('PostalLabel').innerHTML = 'Postal Code';
	} else if (val == 'US') {
		document.getElementById('PostalLabel').innerHTML = 'Zip Code';
	} else {
		top.location = '../wheretobuy/index.php?country='+val;
	}
}


function showDistributors(which) {
	var objResultContainer = document.getElementById("distributors");
	switch(which) {
		case "ab":
			objResultContainer.innerHTML = "Results for Alberta";
			break;
		case "bc":
			objResultContainer.innerHTML = "Results for British Columbia";
			break;
		default:
			objResultContainer.innerHTML = "";
	}
}

var intOrderFields = 10;

function toggleOrderFields(whichItem) {
	if (whichItem.checked == true) {
		for (i=1; i<=intOrderFields; i++) {
			document.getElementById("order_" + i).style.display = "inline";
		}
	} else {
		for (i=1; i<=intOrderFields; i++) {
			document.getElementById("order_" + i).style.display = "none";
		}
	}
}

function validateForm(whichForm) {
	var strErrorMessage = "";
	if (whichForm.name == "contactForm") {
		if (whichForm.realname.value == "") {
			strErrorMessage+= "Please enter your full name.\n";
		}
		if (whichForm.company.value == "") {
			strErrorMessage+= "Please enter your company name.\n";
		}
		if (whichForm.address.value == "") {
			strErrorMessage+= "Please enter your full address.\n";
		}
		if (whichForm.city.value == "") {
			strErrorMessage+= "Please enter your city.\n";
		}
		if (whichForm.pcode.value == "") {
			strErrorMessage+= "Please enter your zip/postal code.\n";
		}
		if (!validateEmail(whichForm.email.value)) {
			strErrorMessage+= "Please enter a valid email address.\n";
		}
		if (whichForm.provstate.value == "") {
			strErrorMessage+= "Please enter your province or state.\n";
		}
		if (whichForm.country.value == "") {
			strErrorMessage+= "Please enter your country.\n";
		}
		if (whichForm.phone.value == "") {
			strErrorMessage+= "Please enter your phone number.\n";
		}
	} else if (whichForm.name == "literature") {
		if (whichForm.catalogrequesttype[1].checked) {
			if (whichForm.realname.value == "") {
				strErrorMessage+= "Please enter your full name.\n";
			}
			if (whichForm.company.value == "") {
				strErrorMessage+= "Please enter your company name.\n";
			}
			if (whichForm.address.value == "") {
				strErrorMessage+= "Please enter your full address.\n";
			}
			if (whichForm.city.value == "") {
				strErrorMessage+= "Please enter your city.\n";
			}
			if (whichForm.pcode.value == "") {
				strErrorMessage+= "Please enter your zip/postal code.\n";
			}
			if (!validateEmail(whichForm.email.value)) {
				strErrorMessage+= "Please enter a valid email address.\n";
			}
			if (whichForm.provstate.value == "") {
				strErrorMessage+= "Please enter your province or state.\n";
			}
			if (whichForm.country.value == "") {
				strErrorMessage+= "Please enter your country.\n";
			}
			if (whichForm.phone.value == "") {
				strErrorMessage+= "Please enter your phone number.\n";
			}
		} else {
			if (whichForm.realname.value == "") {
				strErrorMessage+= "Please enter your full name.\n";
			}
			if (whichForm.company.value == "") {
				strErrorMessage+= "Please enter your company name.\n";
			}
			if (!validateEmail(whichForm.email.value)) {
				strErrorMessage+= "Please enter a valid email address.\n";
			}
			if (whichForm.phone.value == "") {
				strErrorMessage+= "Please enter your phone number.\n";
			}
		}
	} else if (whichForm.name == "drawings") {
		if (whichForm.realname.value == "") {
			strErrorMessage+= "Please enter your full name.\n";
		}
		if (whichForm.company.value == "") {
			strErrorMessage+= "Please enter your company name.\n";
		}
		if (!validateEmail(whichForm.email.value)) {
			strErrorMessage+= "Please enter a valid email address.\n";
		}
		if (whichForm.phone.value == "") {
			strErrorMessage+= "Please enter your phone number.\n";
		}
	}
	if (strErrorMessage != "") {
		alert(strErrorMessage);
		return false;
	} else {
		return true;
	}
}

function validateEmail(strValue) {
	var objRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return objRegExp.test(strValue);
}