// $Revision: #15 $

/* Translate key chars to HTML entities */
function html_esc(str)
{
    var entity = {
        '\'' : '&apos;',
        '"'  : '&quot;',
        '<'  : '&lt;',
        '>'  : '&gt;'
    };

    for (var e in entity)
    {
        str = str.replace(new RegExp(e, 'g'), entity[e]);
    }

    return str;
}

/* check a max length after html-escaping */
function esc_length_ok(str, len)
{
    return (html_esc(str).length <= len);
}

/* validate an email's syntax */
function checkEmail(email)
{
  if (!email) return true;
  
  if (email.value == "") {
    alert("Please enter your email address.");
    email.focus();
  } else if (/^\w+([\.-]\w+)*@\w+([\.-]\w+)*\.\w{2,}$/.test(email.value)) {
    return true;
  } else {
    alert("Please enter a valid email address.");
    email.focus();
  }
  return false; 
}

/* Open new pop-up window */
function amz_js_PopWin(url, name, options) {
  var winHelp = window.open(url, name, options);
  if( winHelp ){
    winHelp.opener = this;
    winHelp.focus();
  }
}
