function empty(mixed_var) {
	var key;
	if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === false || mixed_var === undefined) {
		return true;
	}
	if (typeof mixed_var == "object") {
		for (key in mixed_var) {
			if (typeof mixed_var[key] !== "function") {
				return false;
			}
		}
		return true;
	}
	return false;
}
	
function validate_form_long(fn) {
	var err = new Array();
	var fcs = new Array();

	if (empty(fn.first_name.value)) {
		err.push("First Name");
		fcs.push("first_name");
	}
	if (empty(fn.last_name.value)) {
		err.push("Last Name");
		fcs.push("last_name");
	}
	if (empty(fn.city.value)) {
		err.push("City");
		fcs.push("city");
	}
	if (fn.state.selectedIndex == 0) {
		err.push("State");
		fcs.push("state");
	}
	if (empty(fn.postal_code.value)) {
		err.push("Postal Code");
		fcs.push("postal_code");
	}
	if (fn.country_code.selectedIndex == 0) {
		err.push("Country");
		fcs.push("country_code");
	}
	if (empty(fn.comments.value)) {
		err.push("Comments");
		fcs.push("comments");
	}

	if (err.length > 0) {
		alert("The following required fields were left blank:\n\n- " + err.join("\n- "));
		if (fcs.length > 0)
			fn.elements[fcs[0]].focus();
		return false;
	} else {
		fn.submit.value = "Sending...";
		fn.submit.disabled = true;
		return true;
	}
}

function validate_form_short(fn) {
	var err = new Array();
	var fcs = new Array();

	if (empty(fn.name.value)) {
		err.push("Name");
		fcs.push("name");
		highlight(fn.name, 1);
	} else {
		highlight(fn.name, 0);
	}

	if (fn.state.selectedIndex == 0 && (fn.country_code.value == "CA" || fn.country_code.value == "US")) {
		if (fn.country_code.value == "US") {
			err.push("State");
		} else {
			err.push("Province");
		}
		fcs.push("state");
		highlight(fn.state, 1);
	} else {
		highlight(fn.state, 0);
	}
	if (fn.country_code.selectedIndex == 0) {
		err.push("Country");
		fcs.push("country_code");
		highlight(fn.country_code, 1);
	} else {
		highlight(fn.country_code, 0);
	}
	if (empty(fn.email.value)) {
		err.push("Email");
		fcs.push("email");
		highlight(fn.email, 1);
	} else if (!is_email(fn.email.value)) {
		err.push("Email not in correct format.");
		fcs.push("email");
		highlight(fn.email, 1);
	} else {
		highlight(fn.email, 0);
	}
	if (empty(fn.comments.value)) {
		err.push("Comments");
		fcs.push("comments");
		highlight(fn.comments, 1);
	} else {
		highlight(fn.comments, 0);
	}

	if (err.length > 0) {
		alert("The following required fields were left blank:\n\n- " + err.join("\n- "));
		if (fcs.length > 0)
			fn.elements[fcs[0]].focus();
		return false;
	} else {
		fn.submit.value = "Sending...";
		fn.submit.disabled = true;
		return true;
	}
}

window.onload = function() {
	var v = document.getElementById("country_code");
	validate_country(document.form_contact.state, v);
}