
// Detect the browser being used

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
 
function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function Browser() {
 
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari'))  browser = "Safari";
	else if (checkIt('omniweb')) browser = "OmniWeb";
	else if (checkIt('opera'))   browser = "Opera";
	else if (checkIt('webtv'))   browser = "WebTV";
	else if (checkIt('icab'))    browser = "iCab";
	else if (checkIt('msie'))    browser = "Internet Explorer";
	else if (checkIt('mozilla')) browser = "Firefox";
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";
	
	if (!version) version = detect.charAt(place + thestring.length);

   browser = browser + ' v' + version;
   return browser;
	}
	function BrowserName(){	
	   var browser = Browser();	  
	   return browser.slice(0,browser.indexOf(' v'));	// Remove version number
	}
	function BuildHeader(BannerImage){
		document.write('<body>');
		document.write('<table>');
		document.write('	<tr>');
		document.write('		<td width="100" valign="top" align="left">');
		document.write('		   <img border="0" hspace="5" src="Images/New Music City Power Squadron Logo with Shadow.jpg" width="75" style="margin-top:0;">');
		document.write('		</td>');
		document.write('		<td width = "2000" valign="middle" align="center">');

		                     // The banner text images are created in Adobe Photoshop using ant-aliased, 60pt, Stencil BT font  

		document.write('			<img src="' + BannerImage + '">');
		document.write('		</td>');
		document.write('		<td width="100" valign="top" align="right">');
		document.write('		   <IMG alt="" src="Images/USPS Logo.jpg" width=80 border=0 align="right">');
		document.write('		</td>');
		document.write('</table>');
		document.write('<table width=100%>');
		document.write('	<tr>');
		document.write('		<td width=150>');
	}

   function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
        // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
