
// Set cookie variables
pathname = location.pathname;
myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
// Set cookie expiration date to 1 year from now.
var largeExpDate = new Date ()
largeExpDate.setTime(largeExpDate.getTime() + (365 * 24 * 3600 * 1000));

function showFixedWidthWarning() {
  
   if (document.newpost.fwcheck.checked) {
     Msg = "Note: If you are going to use the 'Fixed Width Font' option, "
     Msg = Msg + "you must manually press RETURN at the end of each line "
     Msg = Msg + "instead of letting the words wrap automatically.  This is "
     Msg = Msg + "because the 'Fixed Width Font' option displays both SPACEs and "
     Msg = Msg + "RETURNs exactly as you type them.  If you type a long line "
     Msg = Msg + "without RETURNs, it may look all right on this screen, but "
     Msg = Msg + "when posted, it will come out as one long line with "
     Msg = Msg + "no breaks.  Of course, you always get the opportunity to "
     Msg = Msg + "fix your message if it does not look right in the Preview."
     alert (Msg)
   }
}

function validateFields() {

  with (document.newpost) {
    // Check for required fields.
    if (name.value == "") {
      alert ("You must enter your name or call sign in the Name/Call box in order to post a message.")
      return false
    }

    if (email.value == "") {
      alert ("You must enter a valid e-mail address in order to post a message.")
      return false
    }

    if (subject.value == "") {
      alert ("You must have to enter a Subject for the message that you want to post.")
      return false
    }

    if (body.value == "") {
      alert ("You have to enter something in the 'Message to Post' box.")
      return false
    } else {
      //body.value = body.value.replace(/</g,"&lt;")
      //body.value = body.value.replace(/>/g,"&gt;")
      //subject.value = subject.value.replace(/</g,"&lt;")
      //subject.value = subject.value.replace(/>/g,"&gt;")
    }

    if (link.value == "http://") {
      link.value = ""
    }

    if (picture.value == "http://") {
      picture.value = ""
    }

    // If they type a link name without a link URL, give them an error message.
    if ((linkname.value != "") && (link.value == "")) {
      alert ("If you entered a Link Name, then you have to enter something for the Link URL.")
      return false
    }

    if (fwcheck.checked) {
      fixedwidth.value = "true"
    } else {
      fixedwidth.value = ""
    }

    if (srcheck.checked) {
      sendreply.value = "true"
    } else {
      sendreply.value = ""
    }
  
    SetCookie('QRPFDefaultName',name.value,largeExpDate,myDomain)
    SetCookie('QRPFDefaultEmail',email.value,largeExpDate,myDomain)
  }

  return true
}
    
function setDefaultFields() {

  with (document.newpost) {
    QRPFDefaultName = getCookieValue("QRPFDefaultName")
    if ((QRPFDefaultName != NULL_VALUE) && (name.value == "")) name.value = QRPFDefaultName
    name.value = unescape(name.value)
    
    QRPFDefaultEmail = getCookieValue("QRPFDefaultEmail")
    if ((QRPFDefaultEmail != NULL_VALUE) && (email.value == "")) email.value = QRPFDefaultEmail
    email.value = unescape(email.value)

    if (link.value == "") link.value = "http://"
    if (picture.value == "") picture.value = "http://"
  }
}
   
var QRPFCookie = ""
var LastSeenNum = 0
var HighNum = 0
var CurDate = ""

function GetCurrentDate(CutoffHour) {

  var CurYear = 0
  var CurMonth = 0
  var CurMonthStr = ""
  var CurDay = 0
  var CurDayStr = ""
  var RightNow = new Date()
  var CurDateString = ""

  if (RightNow.getHours() < CutoffHour) {
    RightNow.setTime(RightNow.getTime() - (24 * 3600 * 1000))
  }
  CurYear =  RightNow.getYear()
  if ((CurYear >= 0) && (CurYear <= 1000)) CurYear = CurYear + 1900
  CurMonth = RightNow.getMonth() + 1
  CurMonthStr = CurMonth.toString()
  if (CurMonthStr.length == 1) CurMonthStr = "0" + CurMonthStr
  
  CurDay = RightNow.getDate()
  CurDayStr = CurDay.toString()
  if (CurDayStr.length == 1) CurDayStr = "0" + CurDayStr

  CurDateString = CurYear.toString() + CurMonthStr + CurDayStr

  return CurDateString
}

function CFNP(MessageNum) {

  // CFNP stands for "Check For New Picture"

  if (QRPFCookie == "") {

    QRPFCookie = getCookieValue("QRPFTempCookie")
    if ((QRPFCookie != NULL_VALUE) && (Number(QRPFCookie) != -1)) {

      // If TempCookie exists, then use it because we're still
      // in the same session.  TempCookie will go away when
      // the user exits the browser.
      //alert("QRPFTempCookie = " + QRPFCookie)
      LastSeenNum = Number(QRPFCookie) 

    } else {    
      
      // If TempCookie doesn't exist, then we need to check the date
      // to see if this is the first visit of the day.  If it is,
      // we will copy CurMsgCookie to Permanent cookie and reset 
      // the day to today.

      // If QRPFDateCookie doesn't exist, then set the date cookie
      // to today's date.
      QRPFDateCookie = getCookieValue("QRPFDateCookie")
      if (CurDate == "") CurDate = GetCurrentDate(4)
      //alert("CurDate = " + CurDate)
      if (QRPFDateCookie != NULL_VALUE) {
        //alert("QRPFDateCookie = " + QRPFDateCookie)
        if (CurDate != QRPFDateCookie) {
      	  QRPFCurMsgCookie = getCookieValue("QRPFCurMsgCookie")
          if (QRPFCurMsgCookie != NULL_VALUE) {
            //alert("QRPFCurMsgCookie = " + QRPFCurMsgCookie)
            SetCookie('QRPFPermanentCookie',QRPFCurMsgCookie,largeExpDate,myDomain)
            SetCookie('QRPFDateCookie',CurDate,largeExpDate,myDomain)
          } else {
            SetCookie('QRPFCurMsgCookie','0',largeExpDate,myDomain)
          }
        }
      } else {
        SetCookie('QRPFDateCookie',CurDate,largeExpDate,myDomain)
      }

      QRPFCookie = getCookieValue("QRPFPermanentCookie")
      //alert("QRPFPermanentCookie = " + QRPFCookie)

      if (QRPFCookie != NULL_VALUE) {
        // If PermanentCookie exists, use it.  Then set
        // the new TempCookie to the same value.  TempCookie
        // will not change until it disappears when the user
        // exits their browser even though PermanentCookie
        // will continue to be updated every time the page 
        // is visited.  I hope that makes sense.
        LastSeenNum = Number(QRPFCookie) 
        document.cookie = 'QRPFTempCookie='+QRPFCookie
      } else {
        LastSeenNum = 0 
        document.cookie = 'QRPFTempCookie=0'
      }
    }
  }

  if (MessageNum > HighNum) { HighNum = MessageNum }

  if ((MessageNum > LastSeenNum) && (LastSeenNum > 0)) {
    document.write('<IMG SRC="new.gif" BORDER=0>')
  }
}

function WriteQRPFCookie() {
  
  // The CurMsgCookie is updated every time the page is loaded
  // and the expiration date is set for a year from today.  But
  // the CurMsgCookie is only copied to the PermanentCookie when
  // the day changes.  The rest of the time, TempCookie
  // is used.  That way, all the "New" graphics don't disappear
  // when the user goes to read a message and then comes back to
  // the page later in the same session.  Sneaky, huh?
   
  //alert("QRPFCurMsgCookie = " + HighNum.toString())
  SetCookie('QRPFCurMsgCookie',HighNum.toString(),largeExpDate,myDomain)
  
  QRPFPermCookie = getCookieValue("QRPFPermanentCookie")
  //alert("QRPFPermanentCookie = " + QRPFPermCookie)

  if (QRPFPermCookie == NULL_VALUE) {
    SetCookie('QRPFPermanentCookie',HighNum.toString(),largeExpDate,myDomain)
    document.cookie = 'QRPFTempCookie=-1'
    QRPFCookie = ""
  }

  return true
}
  
function ResetCookie(newmsg, newdate) {
  // This is a little routine I use during testing.  Ignore it :)

  SetCookie('QRPFPermanentCookie',newmsg,largeExpDate,myDomain)
  SetCookie('QRPFCurMsgCookie',(Number(newmsg)+5).toString(),largeExpDate,myDomain)
  SetCookie('QRPFDateCookie','200310'+newdate,largeExpDate,myDomain)
  document.cookie = "QRPFTempCookie=-1"

  document.resetform.newmsg.value = ""
  document.resetform.newdate.value = ""
  return false
}

// This routine isn't used anymore - I don't think!

function fixFields() {

  with (document.newpost) {
    body.value = body.value.replace(/&lt;/g,"<")
    body.value = body.value.replace(/&gt;/g,">")
    subject.value = subject.value.replace(/&lt;/g,"<")
    subject.value = subject.value.replace(/&gt;/g,">")

    //alert("body.value="+body.value+"   subject.value="+subject.value);
  }

  return true
}

