function newsLetterPopup(formy)
{
	if (formy.newsletter_email.value)
	{
		if (validEmail(formy.newsletter_email.value))
		{
			emailURL = 'http://lists.ipcmedia.com/cgi-bin/subscribe.cgi/1?email_addr=' + formy.newsletter_email.value;
			window.open(emailURL, "emailPopup", 'height=300,width=550,top=100,left=100,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no');
			return true;
		}
	}
    alert("Please enter a valid email address.");
    formy.newsletter_email.focus();
    formy.newsletter_email.select();
    return false;
}

function nmeExtraPopup(formy)
{
	if (formy.newsletter_email_extra.value)
	{
		if (validEmail(formy.newsletter_email_extra.value))
		{
			emailURL = 'http://lists.ipcmedia.com/cgi-bin/subscribe.cgi/1?email_addr=' + formy.newsletter_email_extra.value;
			window.open(emailURL, "emailPopup", 'height=300,width=550,top=100,left=100,status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no');
			return true;
		}
	}
    alert("Please enter a valid email address.");
    formy.newsletter_email_extra.focus();
    formy.newsletter_email_extra.select();
    return false;
}

function popupform(myform, windowname)
{
  var email = document.getElementById('emailaddress');
  if (email) {
    if (validate_email(email.value || '')) {
      window.open('', windowname, '');
      myform.target = windowname;
      return true;
    } else {
      alert('Please enter a valid email address.');
    }
  }
  return false;
}

function validate_email(email_address) {
  var reg = /^[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-\.]+\.([A-Za-z]{2,4})$/;
  var domain = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/i;
  reg.lastIndex = 0;
  domain.lastIndex = 0;

  var m = reg.exec(email_address);
  if (m) {
    m = m[1];
    if (m.length == 2 || (m.length > 2 && m.match(domain))) {
      return true;
    }
  }
  return false;
}

function enableField()
{
document.form2.submit.disabled=false;
}

function validEmail(email)
{
	invalidChars = " /:,;"

	if (email == "") {						// cannot be empty
		return false
	}
	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			// there must be one "@" symbol
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					// and at least one "." after the "@"
		return false
	}
	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	domainName = email.substring(atPos+1, periodPos)
	if (domainName.length < 2) {			// Cannot have a domain less than 2 characters long
		return false
	}
	return true
}
	/** cookie functions 
	*/
function getCookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+'='+escape( value ) +
		( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) 
{
	if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}