 /**************************************************************************/
/** Contact - this module handles the field validation for the ContactUs **/
/**           page                                                       **/
/**************************************************************************/

askedForEmail = false;
netscape = false

function checkEmail (field)
{
  with (field)
  {
    if (value == '') return true;

    // Check that the e-mail address is formated correctly. ie: someone@somewhere.something
    atSign = value.indexOf('@');
    dot = value.lastIndexOf('.');
    if ((atSign <= 0) || (dot < 0) || (dot < atSign) || (dot > value.length-2))
    {
      alert("EMail addresses must be of the form <username>@<domain>.<type>");
      field.focus();
      return false;
    }
    return true;
  }
}

function checkMandatory ()
{
  with (document.forms[0])
  {
    if ((EMail.value == '') && (!askedForEmail))
    {
      alert("Please enter an E-Mail address.");
      askedForEmail = true;
      EMail.focus();
      return false;
    }

    if (!checkEmail(EMail))
    {
      EMail.focus();
      return false;
    }

    if ((Subject.value == '') && (Message.value == ''))
    {
      alert("You have not filled in any message");
      Subject.focus();
      return false;
    }


    if (Message.value.length > 700)
    {
      alert("You can only enter 700 characters in this form.\nPlease email info@dmimeetings.com for longer messages.");
      Message.focus();
      return false;
    }
    else if (netscape)
    {
      len = Message.value.length;
      i = 1;
      msg = Message.value;
      Message.value = '';
      mseg = '';
      while (len > 0)
      {
         if (len > 128)
         {
           mseg = msg.substring(0,128);
           msg = msg.substring(128);
           len -= 128;
         }
         else
         {
           mseg = msg;
           len = 0;
         }
         switch (i)
         {
           case 1 : MSG1.value = mseg; break;
           case 2 : MSG2.value = mseg; break;
           case 3 : MSG3.value = mseg; break;
           case 4 : MSG4.value = mseg; break;
           case 5 : MSG5.value = mseg; break;
           case 6 : MSG6.value = mseg; break;
           case 7 : MSG7.value = mseg; break;
         }
         ++i;
      }
    }
  }
  return true;
}

function netscapeBrowser()
{
  return (navigator.appName.indexOf('Netscape') != -1);
}

function netscapeFields ()
{
  if (netscapeBrowser())
  {
    netscape = true;
    with (document)
    {
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG1 VALUE=''>");
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG2 VALUE=''>");
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG3 VALUE=''>");
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG4 VALUE=''>");
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG5 VALUE=''>");
      writeln("   <INPUT TYPE=HIDDEN NAME=MSG6 VALUE=''>");
    }
  }
}

