function safeMail (psTLD, psDomain, psName)
{
   document.location = "mailto:" + psName + "@" + psDomain + psTLD;

   return false;
}

function openWin (psURL, pnWidth, pnHeight, psOptions, psTarget)
{
   var sWidth = "";
   var sHeight = "";
   var sOptions = "";
   var sComma1 = "";
   var sComma2 = "";

   if (pnWidth == undefined)
      pnWidth = 750;

   if (pnHeight == undefined)
      pnHeight = 550;

   if (pnWidth > 0)
      sWidth = "width=" + pnWidth.toString();

   if (pnHeight > 0)
      sHeight = "height=" + pnHeight.toString();

   if (sWidth != ""  &&  sHeight != "")
      sComma1 = ",";

   if (psOptions != undefined) {
      if (psOptions != "none")
         sOptions = "left=20,top=20,menubar=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes";
   }

   if (sOptions == "")
      sOptions = "menubar=yes,location=yes,toolbar=yes,scrollbars=yes,resizable=yes";

   if (sOptions != "" && (sWidth != ""  ||  sHeight != ""))
      sComma2 = ",";

   if (psTarget == undefined)
      psTarget = "_maint";

   var wWin = window.open (psURL, psTarget, sWidth + sComma1 + sHeight + sComma2 + sOptions);

   wWin.focus ();

   if (!wWin.opener)
         wWin.opener = self;

   self.name = "_openWinX";

   return wWin;
} // openWin


function locationTo (psTarget, poSelObj, pnRestore, pnScrollVertical)
{
   eval (psTarget + ".location='" + poSelObj.options[poSelObj.selectedIndex].value + "'");

   if (pnRestore)
      poSelObj.selectedIndex = 0;

   window.scrollBy (0, pnScrollVertical);

} // locationTo


function viewImage (psFilepath, pnWidth, pnHeight)
{
   if (pnWidth == undefined)
      pnWidth = 750;
   if (pnHeight == undefined)
      pnHeight = 550;

   var wWin = window.open ("", "_image", "width=" + pnWidth.toString() + ",height=" + pnHeight.toString() +
      ",left=20,top=20,menubar=no,location=no,toolbar=no,scrollbars=yes,status=no,resizable=yes");

   wWin.document.write ("<html><head><title>Image Preview</title></head>\n");
   wWin.document.write ("<body bgcolor=white text=black link=blue vlink=black alink=red>\n");
   wWin.document.write ("<font face=\"Arial, Helvetica, sans-serif\"><center>\n");
   wWin.document.write ("<a href='javascript:parent.close()'>\n");
   wWin.document.write ("<h3>" + psFilepath + "</h3>\n");
   wWin.document.write ('<img src="' + psFilepath + '"><br>\n&nbsp;<br>\n');
   wWin.document.write ("<big><b>Close Image Preview</b></big></a><br>\n&nbsp;<br>\n");
   wWin.document.write ("</center></font>\n");
   wWin.document.write ("</body></html>");
   wWin.document.close ();

   wWin.focus ();

   return;
} // viewImage


function toUpper (psTextField)
{
    psTextField.value = psTextField.value.toUpperCase();
    return;
} // toUpper


function toLower (psTextField)
{
    psTextField.value = psTextField.value.toLowerCase();
    return;
} // toLower


try {
   Window.prototype.qsValue = function (pstrName, pvarDefault)
   {
      pvarDefault = (pvarDefault == void 0) ? false : pvarDefault;

      var regexParser = new RegExp ("(?:\\?|&)" + pstrName + "=([^&]+)", "gi");

      if (regexParser.test (location.search))
         return unescape (RegExp.$1);

      else
         return pvarDefault;
   } // Window.prototype.qsValue

} catch (eErr) {  // for silly ol' IE (Internet Explorer)
   window.qsValue = function (pstrName, pvarDefault)
   {
      pvarDefault = (pvarDefault == void 0) ? false : pvarDefault;

      var regexParser = new RegExp ("(?:\\?|&)" + pstrName + "=([^&]+)", "gi");

      if (regexParser.test (location.search))
         return unescape (RegExp.$1);

      else
         return pvarDefault;
   } // window.qsValue
} // try-catch


function sureDelete (psDesc, psItem) {

   if (confirm ("Are you certain?  Do you really want to delete " + psItem + " " + psDesc + "?"))
      return true;

   else
      return false;
} // sureDelete


function highlightText (peFormInput, pnSelectionStart, pnSelectionEnd) {
   if (peFormInput.setSelectionRange) {
      peFormInput.focus();
      peFormInput.setSelectionRange (pnSelectionStart, pnSelectionEnd);

   } else if (peFormInput.createTextRange) {
      var rRange = peFormInput.createTextRange();
      rRange.collapse (true);
      rRange.moveEnd ("character", pnSelectionEnd);
      rRange.moveStart ("character", pnSelectionStart);
      rRange.select();

   } else {
      peFormInput.focus();
   }

   return;
} // highlightText


function selectColorizer (peSelect, psColorData)
{
// example:  selectColorizer(this,',#000,#f80,N,#fff,#f00,X,#000,#fff,Y,#000,#fff');

   var aValues = psColorData.split (",");
   var nGroup = 0;

   if (aValues[0] == "") {    // first blank is default
      peSelect.style.color = aValues[1];
      peSelect.style.backgroundColor = aValues[2];
      nGroup = 3;
   }

   while (nGroup < aValues.length) {

      if (peSelect.value == aValues[nGroup]) {
         peSelect.style.color = aValues[nGroup + 1];
         peSelect.style.backgroundColor = aValues[nGroup + 2];
      }

      nGroup += 3;

   }

   return;
}


function suppCheckColorizer (peCheckbox)
{
   var sID = peCheckbox.id;   // classification_X

   var aLabelID = sID.split ("_");
   var sLabelID = "class_label_" + aLabelID[1];
   var eLabel = document.getElementById (sLabelID);   // class_label_X
   var sClass = eLabel.className;

   if (peCheckbox.checked) {
      if (sClass == "supp_class_default_")
         eLabel.className = "supp_class_selected";

      if (sClass == "supp_class_unchecked")
         eLabel.className = "supp_class_default_checked";

   } else {    // unchecked
      if (sClass == "supp_class_selected")
         eLabel.className = "supp_class_default_";

      if (sClass == "supp_class_default_checked")
         eLabel.className = "supp_class_unchecked";
   }

   return;
}


try {
   String.prototype.trim = function()
   {
       return this.replace (new RegExp ("^\\s+|\\s+$", "gi"), "");
   } // Trims leading and trailing spaces from a string; added as a new String method

} catch (eErr) {  // for silly ol' IE (Internet Explorer)
   // ignore it
} // try-catch


function sentenceCase (psText)
{
   sText = psText.toLowerCase();

   var aSentences = sText.split (/([.?!] )|\n/);
   var nSentences = aSentences.length;
   var sResult = "";

   for (var ii = 0;  ii < nSentences;  ++ii) {

      sSentence = aSentences[ii].trim();  // requires string prototype trim function

      if (sSentence == ""  ||  sSentence == "."  ||  sSentence == "!"  ||  sSentence == "?") {
         if (sSentence == "")
            sSentence = "\n";

         else
            sSentence += " ";    // restore space

         sResult += sSentence;

      } else {
         sResult += sSentence.charAt (0).toUpperCase() + sSentence.substr (1);
      }

   } // for

   sResult = sResult.replace (/\n\n/g, "\n")   // fix end of line duplications
   sResult = sResult.replace (/ i /g, " I ");   // fix I pronouns

   return sResult;
} // sentenceCase -- Capitalize all sentences in the text (assumes space character after . or ! or ?)


function textFormatter (psText)
{
   sText = psText;

   sText = sText.replace (/([.!?,;:])/g, "$1 ");      // make sure there is a space after punctuation
   sText = sText.replace (/([.!?,;:]) +/g, "$1 ");    // fix any that already had spaces, and reduce to one

   sText = sText.replace (/ +([.!?,;:])/g, "$1");     // make sure there is no space before punctuation

   sText = sText.replace (/wtc/g, "WTC");             // fix WTC uppercasing
   sText = sText.replace (/WTC1/g, "WTC 1");          // fix WTC 1 spelling
   sText = sText.replace (/WTC2/g, "WTC 2");          // fix WTC 2 spelling
   sText = sText.replace (/WTC7/g, "WTC 7");          // fix WTC 7 spelling
   sText = sText.replace (/911/g, "9/11");            // fix 9/11 spelling

   sText = sText.replace (/twin towers/g, "Twin Towers");         // fix capitalization
   sText = sText.replace (/iraq/g, "Iraq");                       // fix capitalization
   sText = sText.replace (/iran/g, "Iran");                       // fix capitalization
   sText = sText.replace (/israel/g, "Israel");                   // fix capitalization
   sText = sText.replace (/pearl harbor/g, "Pearl Harbor");       // fix capitalization
   sText = sText.replace (/new york/g, "New York");               // fix capitalization

   return sText.trim();    // requires string prototype trim function
} // textFormatter -- Help out with some extra formatting (generic and AE911Truth specific)


function formTextFormat (peText, psFormatType)
{
   var nStart = peText.selectionStart;
   var nEnd = peText.selectionEnd;

   if (nStart == nEnd) {
      alert ("No text selected to format!");

   } else {
      var sBefore = (peText.value).substr (0, nStart);
      var sText = (peText.value).substring (nStart, nEnd)
      var sAfter = (peText.value).substr (nEnd);
      //alert (sBefore+"_\n_"+sText+"_\n_"+sAfter+"\n");

      switch (psFormatType.toUpperCase()) {

      case "CAP":

         sText = sText.charAt (0).toUpperCase() + sText.substr (1).toLowerCase();

      break;

      case "LC":

         sText = sText.toLowerCase();

      break;

      case "UC":

         sText = sText.toUpperCase();

      break;

      } // switch

      peText.value = sBefore + sText + sAfter;
      peText.selectionStart = nStart;
      peText.selectionEnd = nEnd;
      peText.focus();
   }

   return;
} // formTextFormat -- Format text box and area text: Parm 2 = CAP, LC, UC

