﻿var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}

function hide_popup() {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById("em_popup")');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.getElementById("em_popup")');
  else
      document.poppedLayer = eval('document.layers["em_popup"]');
     
  document.poppedLayer.style.visibility = "hidden";
}

function show_popup() {

  //alert("Entering...");
  if (browserType == "gecko") {
      document.poppedLayer = eval('document.getElementById("em_popup")');
      document.maillink = eval('document.getElementById("emaillink")');
  }
  else if (browserType == "ie") {
      document.poppedLayer = eval('document.getElementById("em_popup")');
      document.maillink = eval('document.getElementById("emaillink")');
  }
  else {
      document.poppedLayer = eval('document.layers["em_popup"]');
      document.maillink = eval('document.layers["emaillink"]');
  }

  var posX = document.maillink.offsetTop - 320;
  var posY = document.maillink.offsetLeft - 100;

  //alert("Top: " + posX.toString() + "\n Left: " + posY.toString());
  
  document.poppedLayer.style.left = posY.toString() + "px";
  document.poppedLayer.style.top = posX.toString() + "px";
  document.poppedLayer.style.visibility = "visible";
  document.email_form.friend_email.value = "  <enter your friend's email here>";
  document.email_form.from_email.value = "  <enter your email here>";
  document.email_form.em_msg.value = "";
}

function enable_Fld(inputFld) {

    inputFld.value = "";
    inputFld.readOnly = false;
    inputFld.select();
    inputFld.focus();
}

// validate email address
function validate_email(inputFld) {
    var em = inputFld.value;
    if (em=="") {
        alert('\nYou must enter an email address.');
        enable_Fld(inputFld);
        return false;
    }
    else if (!goodEmail(em)) {
        alert('You must enter a valid email address.  You entered: ' + em);
        enable_Fld(inputFld);
        return false;
    }		
    return true;
}

//validate email form
function validate_em_form() {

    if (validate_email(document.email_form.friend_email) == false) return false;
    if (validate_email(document.email_form.from_email) == false) return false;
    
    return true;
}

//submit email form
function submit_em_form() {

    if (validate_em_form()) {
        document.email_form.submit();
        hide_popup();
        return true;
    }
    else return false;
}
            
