
// -----------------------------------------------------
// The centerDialog function is used for pop-up windows. It will automatically center a
// pop-up window, given the file name, window width and height, and any extra
// parameters used to change the window style (for example status bar)
// -----------------------------------------------------
function centerDialog(fileName, dialogWidth, dialogHeight, dialogParams, dialogTitle) {
	if (dialogParams == null) {
	 	dialogParams = "";
	}
	else {
		dialogParams = "," + dialogParams;
	}

	xpos = (screen.width - dialogWidth)/2;
	ypos = (screen.height - dialogHeight)/2;
	var dialogProperties = "left="+xpos+",top="+ypos+",width="+dialogWidth+",height="+dialogHeight;
	
  dialogProperties += dialogParams;
	window.open(fileName,dialogTitle,dialogProperties);
}

// -----------------------------------------------------
// Validation functionality
// -----------------------------------------------------
function validateEmail(emailId) {
  var emailObject = document.getElementById(emailId);
  
  if (emailObject.value == "") {
    alert("Please enter an Email Address in the Newsletter Signup");
    return false;
  }
  
  if (validateEmailAddress(emailObject.value) == false) {
    alert("Please enter a valid Email Address for the Newsletter Signup.");
    return false;
  }

  return true;
}

function validateEmailAddress(email) {
   return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);
}

function validatePhoneNumber(phoneNumber) {
  var stripped = phoneNumber.replace(/[\(\)\.\-\ ]/g, '');
  stripped = parseInt(stripped);
  if (isNaN(stripped)) {
    return false;
  }

  stripped = stripped + "";
  if (!(stripped.length == 10)) {
	  return false;
  }
  
  return true;
}