/* This function is used to open a popup window from links added via a content widget */
function openPopupWindow(url,width,height) {
	// Set defualts for the width and height in case they're not specified
	sWidth = 640;
	sHeight = 480;

	if (width != "") {
		sWidth = width;
	}

	if (height != "") {
		sHeight = height;
	}

	window.open(url,"popupWindow","width=" + sWidth + ",height=" + sHeight + ",directories=no,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes");
}

/* This function clears the text "Search" from the appropriate search field */
function setFocus(search_id) {
	var search_field = document.getElementById(search_id);

	if (search_field.value == "Search")
		search_field.value = "";
}

/* This function is used to validate data entered on the sign up page and the tell a friend module */
function validation(buttonID) {
	if (buttonID != "signup-btn") { // Sign up form submission
		oFullName = document.getElementById("full_name");
		oEmailAddress = document.getElementById("email_address");
		oEmailConfirm = document.getElementById("email_confirm");
		oEmailRegEx = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/; // Email address must be in user@host.domain format

		sErrMsg = "";
		sErrID = "";

		if (oFullName.value == "") {
			sErrMsg = "name";
			sErrID = "full_name";
		}
		else if (!oEmailRegEx.test(oEmailAddress.value)) {
			sErrMsg = "email address";
			sErrID = "email_address";
		}
		else if (!oEmailRegEx.test(oEmailConfirm.value)) {
			sErrMsg = "email address confirmation";
			sErrID = "email_confirm";
		}
		else if (oEmailConfirm.value != oEmailAddress.value) {
			sErrMsg = "The email and confirmation email addresses must match.";
			sErrID = "email_match";
		}
	}
	else { // Tell a friend form submission
		oEmailAddress = document.getElementById("email-address_wide");
		oEmailRegEx = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/; // Email address must be in user@host.domain format

		sErrMsg = "";
		sErrID = "";

		if (!oEmailRegEx.test(oEmailAddress.value)) {
			sErrMsg = "email address";
			sErrID = "email-address_wide";
		}
	}

	if (sErrMsg != "") {
		if (sErrID != "email_match") {
			document.getElementById(sErrID).focus();
		}
		else {
			document.getElementById("email_address").focus();
		}

		if (sErrID == "email-address_wide" || sErrID == "email_address" || sErrID == "email_confirm") {
			document.getElementById(sErrID).select();
			alert("Please enter a valid " + sErrMsg + ".");
		}
		else if (sErrID == "email_match") {
			alert(sErrMsg);
		}
		else {
			alert("Please enter a " + sErrMsg + ".");
		}

		return false;
	}

	return true;
}