
var curPopupWindow = null;

function openWindow(url, winName, width, height, center) {

   var xposition = 50; // Postions the window vertically in px
   var yposition = 50; // Postions the window horizontally in px
   var location=0, menubar=0, resizable=1, scrollbars=1, status=0, titlebar=1;

   if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
       xposition = (screen.width - 800) / 2;
       yposition = (screen.height - 600) / 2;
   } 
   
   // Features to specify for a new window
   args = "width=" + width + ","
   + "height=" + height + ","
   + "location=" + location + ","
   + "menubar=" + menubar + ","
   + "resizable=" + resizable + ","
   + "scrollbars=" + scrollbars + ","
   + "status=" + status + ","
   + "titlebar=" + titlebar + ","
   + "toolbar=0,"
   + "hotkeys=0,"
   + "screenx=" + xposition + ","  //NN Only
   + "screeny=" + yposition + ","  //NN Only
   + "left=" + xposition + ","     //IE Only
   + "top=" + yposition;           //IE Only
   
	// Performs the opening of the window (and closing of a window already opened for that page).
	if (curPopupWindow != null) {
		curPopupWindow.close();
	}
	curPopupWindow = window.open(url, winName, args, false);
	curPopupWindow.focus();
}

function ValidateEmail(ctrl)
{
  if(ctrl.value.length==0)
  {
    alert("E-mail address requires a value.");
    ctrl.focus();
    return false;
  }
  if(!LooksLikeEmailAddress(ctrl.value))
  {
    alert("E-mail address is not valid.");
    ctrl.focus();
    return false;
  }
  return true;
}

function LooksLikeEmailAddress (email)
{
	var atpos = email.indexOf("@");
	var dotpos = email.lastIndexOf(".");
	var len = email.length;

	var tld;

	if (len > dotpos+1)
		tld = email.substring (dotpos+1, len);

	if (len == 0)
	{
		return false;
	}
	else if (atpos == -1 || dotpos == -1 || dotpos < atpos || dotpos == atpos + 1 || len < 5 || dotpos >= len-2)
	{
		return false;
	}
	else if (tld.length >= 3 && tld.toUpperCase() != "COM" &&
		tld.toUpperCase() != "EDU" &&
		tld.toUpperCase() != "GOV" &&
		tld.toUpperCase() != "INT" &&
		tld.toUpperCase() != "MIL" &&
		tld.toUpperCase() != "NET" &&
		tld.toUpperCase() != "ORG" &&
		tld.toUpperCase() != "AERO" &&
		tld.toUpperCase() != "BIZ" &&
		tld.toUpperCase() != "COOP" &&
		tld.toUpperCase() != "INFO" &&
		tld.toUpperCase() != "MUSEUM" &&
		tld.toUpperCase() != "NAME" &&
		tld.toUpperCase() != "PRO" &&
		tld.toUpperCase() != "TRAVEL")
	{
		return false;
	}
	return true;
}

