var NS4 = (document.layers);    // Which browser?
var IE4 = (document.all);
var win = window;               // window to search.
var n   = 0;

var i=0;

var strValidLogin = "NO";

var strTransTypes = new Array ( "Member Transfer In", "Added", "Updated", "Deleted" );

var winCouncilWindow,
    winCouncilsWindow,
    winFullYearWindow,
    winMemberListWindow,
    winMemberAddWindow,
    winMembersWindow,
    winMultiMembersWindow;


function doCloseWindows ()
{
  if ( typeof ( winCouncilWindow      ) != "undefined" )
     winCouncilWindow.close     ();

  if ( typeof ( winCouncilsWindow     ) != "undefined" )
     winCouncilsWindow.close    ();

  if ( typeof ( winFullYearWindow     ) != "undefined" )
     winFullYearWindow.close    ();

  if ( typeof ( winMemberListWindow   ) != "undefined" )
     winMemberListWindow.close  ();

  if ( typeof ( winMemberAddWindow    ) != "undefined" )
     winMemberAddWindow.close   ();

  if ( typeof ( winMembersWindow      ) != "undefined" )
     winMembersWindow.close     ();

  if ( typeof ( winMultiMembersWindow ) != "undefined" )
     winMultiMembersWindow.close();
}

var numTotalLoginSel = 43;
var strLoginChoices  = new Array ( "C_OFFICERS",
                                   "C_MEMBERS",
                                   "C_CONTACTINFO",
                                   "C_EDITACT",
                                   "C_CAPTIONS",
                                   "C_TRANSRPT",
                                   "C_ADDRLAB",
                                   "C_RETLAB",
                                   "C_ANNOUNCE",
                                   "C_FLYERS",
                                   "C_EVENTS",
                                   "C_NEWSLTRS",
                                   "C_ROSTER",
                                   "A_OFFICERS",
                                   "A_MEMBERS",
                                   "A_EDITACT",
                                   "S_OFFICERS",
                                   "S_AGENTS",
                                   "S_EDITACT",
                                   "S_CAPTIONS",
                                   "S_EVENTS",
                                   "S_NOTICES",
                                   "S_FRONTPG",
                                   "COUNCILS",
                                   "MEMBERSHIP",
                                   "DEGREES",
                                   "PROLIFE",
                                   "MESSAGES",
                                   "PSDS",
                                   "EXPORT",
                                   "S_COUNCILINFO",
                                   "S_DEMOGRAPHICS",
                                   "TRANSRPT",
                                   "VISITSRPT",
                                   "EMAIL",
                                   "ASSEMBLIES",
                                   "MASTERSTAFF",
                                   "ASSY_MSG",
                                   "ASSY_SCH",
                                   "USERSLIST",
                                   "USERS",
                                   "NL_NEWS",
                                   "APPROVE" );

//
//  FileSystemObject functions
//

// var fso     = new ActiveXObject( "Scripting.FileSystemObject" );

// var newpath     = fso.BuildPath    ( "c:\\tmp", "kuku.txt" );
// var fileBool    = fso.FileExists   ("d:\\old.txt");
// var folderBool  = fso.FolderExists ("d:\\old");
// var tmpName     = fso.GetTempName  ();

// alert(newpath);

var strBase          = "";
var strCurrentFolder = "";

// var dirGalleryBase   = strbase        + "\\Activities";
// var dirBayQueen      = dirGalleryBase + "\\BayQueen";

function DOESfolderExists ( strFolderName )
{
   var fso          = new ActiveXObject( "Scripting.FileSystemObject" );
   strCurrentFolder =     strbase + "\\" + strFolderName;

   return ( fso.FolderExists   ( strCurrentFolder ) );
}

function DOESfileExists ( strFileName )
{
   if ( strCurrentFolder == "" )
      return false;

   var fso            = new ActiveXObject( "Scripting.FileSystemObject" );
   var strCurrentFile =     strCurrentFolder + "\\" + strFileName;

   return ( fso.FileExists   ( strCurrentFile ) );
}

function verifyFile ( strFileName )
{
   return ( true );

   var numResults,
       fso = new ActiveXObject ( 'Scripting.FileSystemObject' );

   if ( fso.FileExists( strFileName ) )
      numResults = true;
   else
      numResults = false;

   return numResults;
}

function FullYear_Spawn ( sPageName, sWindowName, nIndex )
{
   var strURL;
   var strYear = "<%=Year(date)%>";

   // alert ( "FullYear_Spawn " + nIndex );
   strURL = sPageName + "?year=" + strYear + "&show_all=yes" + "&index=" + nIndex;

   winFullYearWindow = window.open ( strURL, sWindowName, 'height=600,width=700,left=20,top=5,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resize=0,resizeable=0');
}

var winObj;

function spawnCouncils ()
{
   winCouncilsWindow = window.open( 'dispCouncils.asp','Councils','width=450,height=550,left=0,top=0,scrollbars=yes,status=yes,resizable=yes');
}

function spawnMemberList ( anchor, windowname, CouncilNumber, AssemblyNumber )
{
   var strURL;

   if( CouncilNumber == "99999" )
      strURL = "showMembers.asp";
   else
      strURL = "showMembers.asp?council=" + CouncilNumber + "&assembly=" + AssemblyNumber;

   document.getdata.MemberList.value = "1";

   winMemberListWindow = window.open ( strURL, windowname, 'height=600,width=500,left=20,top=5,toolbar=0,location=0,directories=0,status=1,scrollbars=1,resize=0,resizeable=0' );

   return;
}

function spawnMemberAdd ( strCouncil, strMembNO, strFNAME, strLNAME )
{
   var strURL = "editMembers.asp?council=" + strCouncil + "&MEMBNO=" + strMembNO + "&FNAME=" + strFNAME + "&LNAME=" + strLNAME;

   winMemberAddWindow = window.open ( strURL, "Newmember", "width=400,height=400,left=5,top=5,scrollbars=yes,resizable=yes" );
}


var LEFTWARDS_ARROW         = 0;
var UPWARDS_ARROW           = 1;
var RIGHTWARDS_ARROW        = 2;
var DOWNWARDS_ARROW         = 3;
var LEFT_RIGHT_ARROW        = 4;
var LEFTWARDS_DOUBLE_ARROW  = 5;
var UPWARDS_DOUBLE_ARROW    = 6;
var RIGHTWARDS_DOUBLE_ARROW = 7;
var DOWNWARDS_DOUBLE_ARROW  = 8;
var LEFT_RIGHT_DOUBLE_ARROW = 9;

var Arrows = new Array ( 0x2190, 0x2191, 0x2192, 0x2193, 0x2194, 0x21d0, 0x21d1, 0x21d2, 0x21d3, 0x21d4 );

function Chr_Arrow ( numArrowCode )
{
	return String.fromCharCode( Arrows[ numArrowCode ] );
}

function getDivObject ( divName )
{
   return ( document.getElementById ( divName ) );
}

//
// This function will remove and reinsert a file input type such that the contents of the text box will be
// empty.  This is needed to be implemented because for ( some reason, document.getdata.file1.value = "";
// will not work!
//

function BlankOut_FileElement ( strFileObj )
{
   var o = document.getElementById( strFileObj );
   var p = o.parentNode;

   p.removeChild ( o );

   var n = document.createElement ( 'input' );

   with (n)
      {
      type     = 'file';
      id       = strFileObj;
      name     = o.name;
      className= o.className;
      size     = o.size;
      onchange = o.onchange;
      }

   p.appendChild ( n );
}

function testDate ( strDate )
{
   if ( strDate.length == 0 )
      return 1;

   cDateSplit = "/";
   if ( strDate.indexOf( cDateSplit ) == -1 )
      {
      cDateSplit = "-";

      if ( strDate.indexOf( cDateSplit ) == -1 )
         {
         cDateSplit = ".";
         }
      }

   dDate    = strDate.split( cDateSplit );

   intMonth = dDate [0];
   intDay   = dDate [1];
   intYear  = dDate [2];

   return ( Test_the_Date ( intMonth, intDay, intYear ) );
}

function formatDate ( dateObject )
{
   replaceSingleQuotes( dateObject );

   var strTemp   = dateObject.value;
   var numLength = strTemp.length;
   var strFinal  = "";
   var flagOK_2_format;

   if ( strTemp == "" )
      return;

   if ( strTemp.charAt(1) == "/" || strTemp.charAt(2) == "/" || strTemp == "" )
      flagOK_2_format = true;
   else
      flagOK_2_format = false;

   if ( flagOK_2_format == false && numLength != 6 && numLength != 8 )
      {
      alert ( "Date Format Error --- Date MUST be in the form mmddyy or mmddyyyy" );

      dateObject.value = "";
      dateObject.select();
      dateObject.focus ();
      }
   else
      {
      //
      //  Check to see if the '/' characters need to be entered
      //
      if ( strTemp.charAt(1) == "/" || strTemp.charAt(2) == "/" || strTemp == "" )
         strFinal = strTemp;
      else
         {
         if ( numLength == 6 )
            strFinal = strTemp.substring(0,2) + "/" + strTemp.substring(2,4) + "/" + strTemp.substring(4,6)
         else
            strFinal = strTemp.substring(0,2) + "/" + strTemp.substring(2,4) + "/" + strTemp.substring(4,8)
         }

      var nResults = testDate ( strFinal );
      if ( nResults == 1 )
         {
         alert ( "Date Format Error: " + strFinal );
         dateObject.value = "";
         dateObject.select ();
         dateObject.focus  ();
         }
      else
         dateObject.value = strFinal;
      }

   return;
}

function showCopyRight ()
{
   document.write ( "<center>" );
   document.write ( "<FONT size=2 color=black>Last updated Oct. 15, 2005" );
   document.write ( "<BR><BR>" );

   document.write ( "This web site is hosted by <a href='http://www.knightsonline.net'><img src='images/Knights_Online.gif' align='absmiddle'></a><br>" );
   document.write ( "<a href='mailto:PaulGScannell@verizon.net' class='blk_links'>Jerry Scannell</a> webmaster" );
   document.write ( "</CENTER>" );

   return true;
}

function floatButton ()
{
   if (document.all)
      {
      document.all.topButton.style.pixelTop = document.body.scrollTop + 20;
      }
   else if (document.layers)
           {
           document.topButton.top = window.pageYOffset;
           }
        else if (document.getElementById)
   	          {
                document.getElementById('topButton').style.top = window.pageYOffset + 'px';
                }
}

function initButton ()
{
   if (document.all)
      {
      document.all.topButton.style.pixelLeft  = 0;
      document.all.topButton.style.visibility = 'visible';
      }
   else if (document.layers)
           {
           document.topButton.left            = 0;
           document.topButton.visibility      = 'show';
           }
        else if (document.getElementById)
               {
               document.getElementById('topButton').style.left       = 0;
               document.getElementById('topButton').style.visibility = 'visible';
               }
}

function findInPage ( str )
{
   var txt, i, found;

   if (str == "")
      return false;             // Dont bother looking for nothing!


   //
   // Netscape
   //
   if (NS4)
      {
      // Look for match starting at the current point. If not found, rewind back to the first match.
      if (!win.find(str))
         while(win.find(str, false, true))
            n++;
      else
            n++;

     if (n == 0)                // If not found in either direction, give message.
        alert("Not found.");
     }


   //
   // Internet Explorer
   //
   if (IE4)
      {
      txt = win.document.body.createTextRange();
      // Find the nth match from the top of the page.
      for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
         {
         txt.moveStart( "character", 1 );
         txt.moveEnd  ( "textedit" );
         }

      // If found, mark it and scroll it into view.
      if (found)
         {
         txt.moveStart     ( "character", -1 );
         txt.findText      ( str );
         txt.select        ();
         txt.scrollIntoView();
         n++;
         }
      else                      // Otherwise, start over at the top of the page and find first match.
         {
         if (n > 0)
            {
            n = 0;
            findInPage(str);
            }
         else                   // Not found anywhere, give message.
            alert("Not found.");
         }
      }
   return false;
}

function Zero_Fill ( strString, numLength )
{
   var strResult = strString;

   while ( strResult.length < numLength )
      strResult = "0" + strResult;

   return strResult;
}

function UpperCase ( String )
{
   var localString = String.toUpperCase();
   return ( localString );
}

function LowerCase ( String )
{
   var localString = String.toLowerCase();
   return ( localString );
}

function jsFloatConvert ( String )
{
   var numRetVal = String * 1.0;

   if ( isNaN ( numRetVal ) )
      numRetVal = 0.0;

   return ( numRetVal );
}

function jsIntegerConvert ( String )
{
   var numRetVal = String * 1;

   if ( isNaN ( numRetVal ) )
      numRetVal = 0;

   return ( numRetVal );
}

function jsStringConvert ( String )
{
   var localString = String;

   if ( String == "null" || String == null || String == "" )
      localString = "";
   else
      localString = String;

   return ( localString );
}

function jsBooleanConvert ( String )
{
   var numRetVal;

   if( String == "true" || String == true )
      numRetVal = true;
   else
      numRetVal = false;

   return ( numRetVal );
}

function jsDateConvert ( dateString )
{
   var strMonth,
       strDay,
       strYear,
       strFinalDate,

       numLength,
       localDate = new Date ( dateString );

   numLength             = dateString.length;
   strMonth              = localDate.getMonth () + 1;
   strDay                = localDate.getDate  ();

   strHour               = localDate.getHours  ();
   strMinute             = localDate.getMinutes();
   strSecond             = localDate.getSeconds();

   if ( isNaN(strMonth) )
      strFinalDate       = "";
   else
      {
      strYear      = dateString.substring ( numLength-4, numLength )
      strFinalDate = strMonth + "/" + strDay + "/" + strYear;
      }

   return ( strFinalDate );
}

function jsTimeConvert ( String )
{
   var strHour, strMinute, strSecond, strFinalTime;

   localTime       = new Date             ( String );

   strHour         = localTime.getHours   () + "";
   strMinute       = localTime.getMinutes () + "";
   strSecond       = localTime.getSeconds () + "";

   if ( isNaN(strHour) )
      strFinalTime = "";
   else
      strFinalTime = Zero_Fill ( strHour, 2 ) + ":" + Zero_Fill ( strMinute, 2 ) + ":" + Zero_Fill ( strSecond, 2 );

   return ( strFinalTime );
}

function jsDateTimeConvert ( dateString )
{
   var strMonth,
       strDay,
       strYear,
       strFinalDate,

       strHour,
       strMinute,
       strSecond,
       strFinalTime,

       numLength,
       localDate = new Date ( dateString );

   numLength             = dateString.length;
   strMonth              = localDate.getMonth () + 1;
   strDay                = localDate.getDate  ();

   strHour               = localDate.getHours  () + "";
   strMinute             = localDate.getMinutes() + "";
   strSecond             = localDate.getSeconds() + "";

   if ( isNaN(strMonth) )
      strFinalDate       = "";
   else
      {
      strYear      = dateString.substring ( numLength-4, numLength )
      strFinalDate = strMonth + "/" + strDay + "/" + strYear;

      strFinalTime = Zero_Fill ( strHour, 2 ) + ":" + Zero_Fill ( strMinute, 2 ) + ":" + Zero_Fill ( strSecond, 2 );

      strFinalDate = strFinalDate + " @ " + strFinalTime
      }

   return ( strFinalDate );
}

/*
 * This routine replaces any occurances of a single quote with
 * a null.
 *   NOTE:  In the calling routine, the form merely places the field's name in the call
 *          Take a look at smld\main.asp for an example.
 */

function replaceSingleQuotes ( strField )
{
   var temp = "" + strField.value;
   var add  = "";

   var pos = 0;

   while ( temp.indexOf("'") > -1 )
      {
      pos  = temp.indexOf( "'" );
      temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + 1), temp.length));
      }

   while ( temp.indexOf('"') > -1 )
      {
      pos  = temp.indexOf( '"' );
      temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + 1), temp.length));
      }

   strField.value = temp;
}

function Test_the_String ( String )
{
   var text   = "[" + String + "]"
   if ( text == "[]" )
      return ( 1 );
   else
      return ( 0 );
}

function Test_the_Date ( intMonth, intDay, intYear )
{
   var Bad_Date = 0;

   if ( intMonth != "" && intDay != "" && intYear != "" )
      {
      if ( intMonth < 1    || intMonth > 12 )
         Bad_Date = 1

      if ( intDay   < 1    || intDay   > 31 )
         Bad_Date = 1

      if ( intYear  < 1900 || intYear  > 2199 )
         Bad_Date = 1
      }

   return ( Bad_Date );
}

function Test_the_Integer ( intData )
{
   var intTemp = intData;

   if ( intTemp == "" )
      return ( false );

   if ( parseInt   ( intData, 10 ) != intTemp )
      return ( true  );
   else
      return ( false );

}

function Test_the_Float ( fltData )
{
   var fltTemp = fltData;

   if ( fltTemp == "" )
      return ( false );

   if ( parseFloat ( fltData ) != fltTemp )
      return ( true  );
   else
      return ( false );

}

function Test_Msg ( msg, form )
{
   if ( msg > "" )
      {
      alert      ( msg );
      return     ( false );
      }

   form.submit();
   return     ( true );
}
