function GetParam(name)
{
   var start=location.search.indexOf("?"+name+"=");
   if (start<0) start=location.search.indexOf("&"+name+"=");
   if (start<0) return '';
   start += name.length+2;
   var end=location.search.indexOf("&",start)-1;
   if (end<0) end=location.search.length;
   var result=location.search.substring(start,end);
   var result='';
   for(var i=start;i<=end;i++) {
      var c=location.search.charAt(i);
      result=result+(c=='+'?' ':c);
   }
   return unescape(result);
}
function GetParamOld(name)
{
   var start;
   var cParm;
   cParm=location.search.toLowerCase();
   start=cParm.indexOf("?"+name.toLowerCase()+"=");
   if (start<0) start=cParm.indexOf("&"+name+"=");
   if (start<0) return '';
   start += name.length+2;
   var end=cParm.indexOf("&",start)-1;
   if (end<0) end=cParm.length;
   var result=cParm.substring(start,end);
   var result='';
   for(var i=start;i<=end;i++) {
      var c=cParm.charAt(i);
      result=result+(c=='+'?' ':c);
   }
   return unescape(result);
}

function SetMember(name)
{
  var cName = GetParam(name);
  var cMember;
  var cSubject = GetParam('subject');
  var cBody = GetParam('body');
  var i;
  for (i = 0; i < document.forms[0].To_Member.options.length; i++) {
     cMember = document.forms[0].To_Member.options[i].text;
     if (cMember.indexOf(cName) >= 0) {
        document.forms[0].To_Member.options[i].selected = true;
     }
  }
  document.forms[0].subject.focus();
  if ( cSubject != '' ) {
    document.forms[0].subject.value = cSubject;
    document.forms[0].Message.focus();
  }
  if ( cBody != '' ) {
    document.forms[0].Message.value = cBody;
    document.forms[0].Resident_Name.focus();
  }
  return;
}

function SetMemberN(name)
{
  var nopt = GetParam(name);
  if (nopt < document.forms[0].To_Member.length){
     document.forms[0].To_Member.options[nopt].selected = true
  }
  document.forms[0].subject.focus()
  return
}
function SetRecipient()
{
  var cRecipient = "";
  var i;
  for (i = 0; i < document.forms[0].To_Member.options.length; i++) {
     if ( document.forms[0].To_Member.options[i].selected ) {
         if( cRecipient == ''){
            cRecipient = document.forms[0].To_Member.options[i].value;
         }
         else {
            cRecipient = cRecipient + "; " + document.forms[0].To_Member.options[i].value;
         }
     }
  }
  document.forms[0].recipients.value = cRecipient;
  SetSubject();
}

function SetSubject()
{
  if (document.forms[0].subject.value == '') {
     document.forms[0].subject.value = "General Query";
  }
}

function SetAlertGet()
{
  var arg = document.forms[0].good_url.value + "?email=" + document.forms[0].email.value;
  document.forms[0].good_url.value = arg;
}

function fnOpenModal(URL){
  window.showModalDialog(URL, "center:yes; edge:sunken")
}

function GetSelValue( element ) {
  var cValue = "";
  var n;

  for (n = 0; n < element.options.length; n++) {
    if (element.options[n].selected) {
      cValue = element.options[n].value;
    }
  }
  return cValue;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function SetNominating()
{
alert("Nominating");
}

function SetCandidate()
{
  alert("Candidate");
}
function Dummy()
{
}
function Set_EesVndReg()
{
  var success;
  if (document.forms[0].Food_or_Drink[0].checked || document.forms[0].Food_or_Drink[1].checked) {
    success = true;
  }
  else {
    alert("Please complete the Food/Drink question");
    success = false;
  }
  if ( success ) {
    if ( ReviewContent("Comments") ) {
      document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
    }
    else {
      alert("Comments contain unacceptable content.\r\nPlease revise.");
      success = false;
    }
  }
  return success;
}
function Set_EesVolReg()
{
  var success = ReviewContent("Comments");
  if ( success ) {
    document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
  }
  else {
    alert("Comments contain unacceptable content.\r\nPlease revise.");
  }
  return success;
}
function LandParks()
{
  var success = ReviewContent("Details");
  if ( success ) {
    document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
  }
  else {
    alert("Details contain unacceptable content.\r\nPlease revise.");
  }
  return success;
}
function VacWatch()
{
  var success = ReviewContent("Comments");
  var cText;
  if ( success ) {
    cText = document.forms[0].subject.value + " - " + document.forms[0].Resident_Name.value + " - " + document.forms[0].Date_Depart.value + " to " + document.forms[0].Date_Return.value;
    document.forms[0].subject.value = cText;
    document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
  }
  else {
    alert("Comments contain unacceptable content.\r\nPlease revise.");
  }
  return success;
}

function RegisterEmail(pAction)
{
  var success = false;

  if ( typeof(pAction) == "undefined" ) {
     pAction = "send";
  }
  success = EditForm(pAction);
  if ( success ) {
    SetAlertGet();
    document.forms[0].recipients.value = "webmaster@pid6.org";
    document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
  }
  return success;
}

function CodeBlueForm()
{
  //document.forms[0].recipients.value = "codeblue@pid6.org";
  document.forms[0].recipients.value = "webmaster@pid6.org";
  document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
  return true;
}
function ReviewContent(cField)
{
  var success = true;
  var nope = 0;
  var msg = "";
  if ( cField == "Message" ) {
    msg = document.forms[0].Message.value.toLowerCase();
  }
  if ( cField == "Comments" ) {
    msg = document.forms[0].Comments.value.toLowerCase();
  }
  if ( cField == "Details" ) {
    msg = document.forms[0].Details.value.toLowerCase();
  }
  nope += msg.indexOf("href=") + 1;
  nope += msg.indexOf("http:") + 1;
  nope += msg.indexOf("javascript:") + 1;
  nope += msg.indexOf("vbscript:") + 1;
  nope += msg.indexOf("on*") + 1;
  nope += msg.indexOf("data*") + 1;
  nope += msg.indexOf("dynsrc") + 1;
  nope += msg.indexOf("<a href") + 1;
  nope += msg.indexOf("<applet") + 1;
  nope += msg.indexOf("<base") + 1;
  nope += msg.indexOf("<bgsound") + 1;
  nope += msg.indexOf("<blink") + 1;
  nope += msg.indexOf("<body") + 1;
  nope += msg.indexOf("<div") + 1;
  nope += msg.indexOf("<embed") + 1;
  nope += msg.indexOf("<frame") + 1;
  nope += msg.indexOf("<head") + 1;
  nope += msg.indexOf("<html") + 1;
  nope += msg.indexOf("<iframe") + 1;
  nope += msg.indexOf("<ilayer") + 1;
  nope += msg.indexOf("<img") + 1;
  nope += msg.indexOf("<layer") + 1;
  nope += msg.indexOf("<link") + 1;
  nope += msg.indexOf("<meta") + 1;
  nope += msg.indexOf("<object") + 1;
  nope += msg.indexOf("<script") + 1;
  nope += msg.indexOf("<span") + 1;
  nope += msg.indexOf("<style") + 1;
  nope += msg.indexOf("<title") + 1;
  nope += msg.indexOf("<xml") + 1;
  nope += msg.indexOf("<bgsound") + 1;
  if (nope > 0) {
    success = false;
  }
  return success;
}

function CheckContent(pAction)
{
  var success = true;

  if ( typeof(pAction) == "undefined" ) {
     pAction = "send";
  }
  success = EditForm(pAction);
  if ( success ) {
    success = ReviewContent("Message");
    if ( success ) {
      SetRecipient();
      document.forms[0].action = "http://www.pid6.org/script/fmdirect.php";
    }
    else {
      alert("Message contains unacceptable content.\r\nPlease revise.");
    }
  }
return success;
}

function EditForm(pAction)
{
  var success = true;
  var nope = 0;
  var i = 0;
  var msg = "";
  var str = "";
  var areqfield = new Array();
  var areqtext = new Array();

  if ( typeof(pAction) == "undefined" ) {
     pAction = "send";
  }
  areqfield = document.forms[0].required.value.split(",");
  areqtext = document.forms[0].reqtext.value.split(",");

  for (i=0; i < areqfield.length; i++) {
    if ( areqfield[i] == "email" ) {
      areqfield[i] = "From_Email";
    }
    str = document.getElementById(areqfield[i]);
    //alert("reqtext " + i + " " + areqtext[i] + " " + str.value);
    if ( str.value ) {
    }
    else {
       if ( msg == "" ) {
          msg = "Cannot " + pAction + " because of errors:\r\n\r\n";
       }
       msg += areqtext[i] + " is a required field\r\n";
    }
  }

  if ( msg != "" ) {
     alert(msg);
     nope += 1;
  }
  if (nope > 0) {
    success = false;
  }
  return success;
}



