var submitted = false;

function validateSubmit() {
	if (submitted) {
		return false; // don't submit form
	} else {
		submitted = true;
		return true; // submit form
	}
}

function popup(url) {
	window.open(url, 'new', 'scrollbars=yes, width=560, height=375');
}

function isEmpty(element) {

	var isChecked;

	for (i = 0; i < element.length; i++) {
		if (element[i].checked == true) {
			return false;
		}
	}

	return true;
}

function clearNoneOfTheAboveBox() {
	var n = document.getElementById("noneOfTheAbove");
	if (n != null) {
		n.checked = false;
	}
}

function clearOtherBoxes(obj) {
	var elements = document.forms[0].elements;
	var i = 0;

	while (elements[i]) {
		if (elements[i] == obj && elements[i].checked == true) {
			elements[i].checked = true;
		} else {
			elements[i].checked = false;
		}
		i++;
	}
}

function checkAgreeTerms() {
	if (!document.registrationForm.rules.checked) {
		alert('To complete your registration, please check the box and agree to the Terms and Conditions and Privacy Policy.');
		return false;
	} else {
		return true;
	}
}

function changeDisplay(id, visibility, display) {
	obj = document.getElementsByTagName("div");
	if (obj[id] != null) {
		obj[id].style.visibility = visibility;
		obj[id].style.display = display;
	}
}

function showObject(form) {
	var i = 0;
	if (document.registrationForm.country_id != null)
		i = document.registrationForm.country_id.options.selectedIndex;

	if (i == "2") {
		changeDisplay('province', 'visible', 'block');
		changeDisplay('postal_code', 'visible', 'block');
		changeDisplay('state', 'hidden', 'none');
		changeDisplay('zip', 'hidden', 'none');
	} else if (i == "1") {
		changeDisplay('state', 'visible', 'block');
		changeDisplay('zip', 'visible', 'block');
		changeDisplay('province', 'hidden', 'none');
		changeDisplay('postal_code', 'hidden', 'none');
	} else {
		changeDisplay('state', 'visible', 'block');
		changeDisplay('zip', 'visible', 'block');
		changeDisplay('province', 'hidden', 'none');
		changeDisplay('postal_code', 'hidden', 'none');
		return false;
	}
}

function terminateScreener(form) {
	var s = document.registrationForm.occupation_id.options.selectedIndex;
	if (s == "6") {
		window.location = "/register/register_screenout.html";
	}
}

function terminateScreenerEmployment(form) {
	var s = document.registrationForm.employment_id.options.selectedIndex;
	if ((s == "2") || (s == "4") || (s == "5") || (s == "6")) {
		window.location = "/register/register_screenout.html";
	}
}

function terminateScreenerPurchaseProcess(form) {
	var s = document.registrationForm.purchase_process_id.options.selectedIndex;
	if (s == "8") {
		window.location = "/register/register_screenout.html";
	}
}

function updatePostalCode() {
	if (document.registrationForm.postal_code1.value != "" && document.registrationForm.postal_code2.value != "")
	{
		document.registrationForm.postal_code.value = document.registrationForm.postal_code1.value + document.registrationForm.postal_code2.value;
		return true;
	}
}