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 SetMember(name)
{
  var cName = GetParam(name);
  var cMember;
  var cSubject = GetParam('subject');
  var cBody = GetParam('body');
  var i;
  if (cName == "") { return; }
  for (i = 0; i < document.forms[0].To_Member.options.length; i++) {
     cMember = document.forms[0].To_Member.options[i].value.toLowerCase();
     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 SetRecipient(defsubject)
{
  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(defsubject);
}

function SetSubject(defsubject)
{
  if (document.forms[0].subject.value == '') {
     if (defsubject == '') {
        document.forms[0].subject.value = 'Resident Query';
     }
     else {
        document.forms[0].subject.value = defsubject;
     }
  }
}

function SetAlertGet()
{
  var arg = document.forms[0].good_url.value + "?email=" + document.forms[0].email.value + "&street=" + document.forms[0].street.value;
  document.forms[0].good_url.value = arg;
  SetRegEmail();
}

function SetRegEmail()
{
  document.forms[0].message.value = "Register address: " + document.forms[0].email.value;
}

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 FindPhase()
  {
  var aStreet = new Array(14);
  var aLoNum = new Array(14);
  var aHiNum = new Array(14);
  var aPhase = new Array(14);
  var cStreet = "";
  var nCell;
  var n;
  var nStreetNo;
  var cPhase = "?";

  aStreet[0] = "Beaver Head Road";
  aLoNum[0] = 7750;
  aHiNum[0] = 7792;
  aPhase[0] = "1";

  aStreet[1] = "Grant Park Avenue";
  aLoNum[1] = 4673;
  aHiNum[1] = 4829;
  aPhase[1] = "2";

  aStreet[2] = "Grant Park Avenue";
  aLoNum[2] = 4621;
  aHiNum[2] = 4672;
  aPhase[2] = "3";

  aStreet[3] = "Park Bend Drive";
  aLoNum[3] = 4729;
  aHiNum[3] = 4835;
  aPhase[3] = "1";

  aStreet[4] = "Park Bend Drive";
  aLoNum[4] = 4700;
  aHiNum[4] = 4728;
  aPhase[4] = "2";

  aStreet[5] = "Park Bend Drive";
  aLoNum[5] = 4640;
  aHiNum[5] = 4868;
  aPhase[5] = "3";

  aStreet[6] = "Park Brook Drive";
  aLoNum[6] = 4816;
  aHiNum[6] = 4928;
  aPhase[6] = "1";

  aStreet[7] = "Park Court";
  aLoNum[7] = 4650;
  aHiNum[7] = 4671;
  aPhase[7] = "2";

  aStreet[8] = "Navajo Court";
  aLoNum[8] = 7751;
  aHiNum[8] = 7783;
  aPhase[8] = "1";

  aStreet[9] = "Park Downs Drive";
  aLoNum[9] = 7751;
  aHiNum[9] = 7855;
  aPhase[9] = "3";

  aStreet[10] = "Park Run Road";
  aLoNum[10] = 7758;
  aHiNum[10] = 7821;
  aPhase[10] = "3";

  aStreet[11] = "Park Trails Drive";
  aLoNum[11] = 7755;
  aHiNum[11] = 7824;
  aPhase[11] = "1";

  aStreet[12] = "Silver Sage Drive";
  aLoNum[12] = 7758;
  aHiNum[12] = 7820;
  aPhase[12] = "2";

  aStreet[13] = "Teal Drive";
  aLoNum[13] = 7762;
  aHiNum[13] = 7824;
  aPhase[13] = "1";

  nCell = aStreet.length + 1;
  cStreet = GetSelValue( CcrPhase.cboStreetName );
  nStreetNo = CcrPhase.txtStreetNo.value - 0;

  if (cStreet.length > 0) {
    for (n = 0; n < aStreet.length; n++) {
      if (cStreet == aStreet[n]) {
        if (nStreetNo >= aLoNum[n]) {
           if (nStreetNo <= aHiNum[n]) {
              nCell = n;
              break;
           }
        }
      }
    }
  }
  if (nCell <= aStreet.length) {
     cPhase = aPhase[nCell];
  }
  else {
     cPhase = cStreet;
  }
  return cPhase;
}

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 CodeBlueForm()
{
  document.forms[0].recipients.value = "webmaster@myppna.com";
  document.forms[0].action = "http://www.myppna.com/scripts/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()
{
  var success = ReviewContent("Message");
  if ( success ) {
    SetRecipient();
    document.forms[0].action = "http://www.myppna.com/scripts/fmdirect.php";
  }
  else {
    alert("Message contains unacceptable content.\r\nPlease revise.");
  }
return success;
}

function ContactEditor(pAction)
{
  var success = true;

  if ( typeof(pAction) == "undefined" ) {
     pAction = "send";
  }
  success = EditForm(pAction);
  if ( success ) {
    success = ReviewContent("Message");
    if ( success ) {
      SetSubject("PPNA Newsletter Query");
      document.forms[0].action = "http://www.myppna.com/scripts/fmdirect.php";
    }
    else {
      alert("Message contains unacceptable content.\r\nPlease revise.");
    }
  }
return success;
}

function ContactPPNA(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.myppna.com/scripts/fmdirect.php";
    }
    else {
      alert("Message contains unacceptable content.\r\nPlease revise.");
    }
  }
  return success;
}

function ContactVacation(pAction)
{
  var success = true;

  if ( typeof(pAction) == "undefined" ) {
     pAction = "send";
  }
  success = EditForm(pAction);
  if ( success ) {
    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.myppna.com/scripts/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].action = "http://www.myppna.com/scripts/fmdirect.php";
  }
  return success;
}

function FeedbackForm()
{
  var success = ReviewContent("Message");
  if ( success ) {
    document.forms[0].action = "http://www.myppna.com/scripts/fmdirect.php";
  }
  else {
    alert("Message contains unacceptable content.\r\nPlease revise.");
  }
return success;
}
function OpenNewPage(cboname)
{
  var oSelect = document.getElementById(cboname);
  for (var i = 0; i < oSelect.options.length; i++) {
     if ( oSelect.options[i].selected ) {
        window.open(oSelect.options[i].value);
     }
  }
}
function OpenSamePage(cboname)
{
  var oSelect = document.getElementById(cboname);
  var dest = "";
  var np = -1;
  for (var i = 0; i < oSelect.options.length; i++) {
     if ( oSelect.options[i].selected ) {
        dest = oSelect.options[i].value;
        np = dest.indexOf(".pdf");
        if (np < 0) np = dest.indexOf("http:");
        if ( np < 0 ) {
           location = dest;
        }
        else {
           OpenNewPage(cboname);
        }
     }
  }
}
function LogAction()
{
  var success = true;
  var cName = GetParam("username");
  var cPass = GetParam("userpass");
  cName = document.forms[0].username.value;
  cPass = document.forms[0].userpass.value;
  //alert(cName);
  //alert(cPass);
  if (cName == "") {success = false};
  if (cPass == "") {success = false};
  if ( success ) {
    document.forms[0].action = "http://www.myppna.com/scripts/get_login.php";
  }
  else {
    success = false;
    alert("E-Mail Address or Password missing.\r\nPlease re-enter.");
  }
  return success;
}
function LogError()
{
  var cName = GetParam("username");
  if (cName == "") {
    }
  else {
    document.forms[0].username.value = cName;
    alert("E-Mail Address or Password incorrect.\r\nPlease re-enter.");
  }
}

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;
}

