function WinPop(pageAddress,winName,iWidth,iHeight) {
 if (iWidth == null) {iWidth = 680;}
 if (iHeight == null) {iHeight = 280;}
 if (navigator.appName == 'Netscape') {
   iWidth = iWidth+20;
   iHeight = iHeight+20; }
  else {
   iWidth = iWidth+0;
   iHeight = iHeight+0;
 }
 window.open(pageAddress,null,'resizable=no,toolbar=no,menubar=no,location=no,height='+iHeight+',width='+iWidth);
}

function browserDetect() {return navigator.appVersion}

function deviceType() {
 var uagent = navigator.userAgent.toLowerCase();
 if (uagent.search('android') > -1) return 'mobileWeb';
 if (uagent.search('blackberry') > -1) return 'mobileWeb';
 if (uagent.search('windows ce') > -1) return 'mobileWeb';
 if (uagent.search('iphone') > -1) return 'mobileWeb';
 if (uagent.search('ipod') > -1) return 'mobileWeb';
 if (uagent.search('ipad') > -1) return 'mobileWeb';
 if (uagent.search('series60') > -1) return 'mobileFeature';
 if (uagent.search('symbian') > -1) return 'mobileFeature';
//  if (uagent.search('webkit') > -1) return 'WebKit';
 if (uagent.search('palm') > -1) return 'mobileFeature';
 return '';
}

function Write_eMail(strUser,strDomain,strPrompt,strSubject,strBody) {
 // this script hides the email address from web bots and spiders
  if (strUser=='office' && strDomain.length==0) {
    strDomain = 'q.com';
    strUser = 'sermonmc';
  }
  var strRecipient = strUser + "@" + strDomain;
  if (strRecipient=='@') {
    strRecipient = '';
  }
  if (strPrompt.length==0) {
    var strPrompt = strRecipient;
  }
  if (strBody.length > 0) {
    if(navigator.appVersion.indexOf("PPC") != -1) {
      var strSubject = strBody;
      var strBody = '' }
     else {
      var strBody = '&body='+strBody
    } }
   else {
    var strBody = ''
  }
  document.write('<a href="mailto:' + strRecipient + '?subject=' + strSubject + strBody + '" onmouseover="window.status=\'Send an e-mail\'; return true" onmouseout="window.status=\'\'; return true">' + strPrompt + '<\/a>');
}

function writeChurcheAddress() {Write_eMail('office','','','','');} // this script is just a central maintenance point

function getChurchAddress(elements,lines) {
 // this script is just a central maintenance point
  var sStreet = '1512 East Mulberry St.';
  var sCity = 'Sioux Falls';
  var sState = 'SD';
  var sZip = '57103';
  if (lines > 1) {var lineFeed = '<br />'} else {var lineFeed = ' '}
  if (elements == 'street') {var address = sStreet}
  if (elements == 'street city') {var address = sStreet + ', ' + sCity}
  if (elements == 'street city state') {var address = sStreet + lineFeed + sCity + ', ' + sState}
  if (elements == 'street city state zip') {var address = sStreet + lineFeed + sCity + ', ' + sState + ' ' + sZip}
  return address
}

function writeChurchAddress(elements,lines) {document.write(getChurchAddress(elements,lines));}

function WriteChurchPhone() {formatPhoneNumber('605.357.9125','');} // this script is just a central maintenance point

function writeChurchName(createLink) {
 // this script is just a central maintenance point
 if (createLink) {
   document.write('<p class="pageText siteTitle"><a href="http://sermononthemount-mennonite.org/">Sermon On The Mount Mennonite Church</a></p>'); }
  else {
   document.write('Sermon On The Mount Mennonite Church');
 }
}

function writeChurchMapLink(displayText) {
  document.write("<a target='new' " +
                 " onmouseover=\"window.status='Click on this link to display an interactive map of Sioux Falls'; return true\"" +
                 " onmouseout=\"window.status=''; return true\"" +
                 " href='http://maps.google.com/maps?q=1512+E+Mulberry+St+Sioux+Falls+South+Dakota+57103'>"+displayText +
                 "</a>");
//  <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=1512+E+Mulberry+St,+Sioux+Falls,+SD+57103-0421&amp;sll=37.0625,-95.677068&amp;sspn=42.581364,70.224609&amp;ie=UTF8&amp;hq=&amp;hnear=1512+E+Mulberry+St,+Sioux+Falls,+Minnehaha,+South+Dakota+57103&amp;t=h&amp;z=16&amp;ll=43.564829,-96.707482&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=1512+E+Mulberry+St,+Sioux+Falls,+SD+57103-0421&amp;sll=37.0625,-95.677068&amp;sspn=42.581364,70.224609&amp;ie=UTF8&amp;hq=&amp;hnear=1512+E+Mulberry+St,+Sioux+Falls,+Minnehaha,+South+Dakota+57103&amp;t=h&amp;z=16&amp;ll=43.564829,-96.707482" style="color:#0000FF;text-align:left">View Larger Map</a></small>
//  document.write("    href='http://maps.yahoo.com/map?q1= Sioux Falls, SD 57103-0421&mag=9&ard=1#mvt=m&lat=43.564838&lon=-96.707412&mag=3&q1=%201512%20E%20Mulberry%20St%2C%20Sioux%20Falls%2C%20SD%2057103-0421'>"+displayText);
}

function redirectHome(displayFlag) {
  if (displayFlag) {
    document.write('<b>THIS IS A FRAME ELEMENT</b><br />' +
                   'You will be redirected to the main frames page in a second...' +
                   '<meta http-equiv="refresh" content="2"; url="http://sermononthemount-mennonite.org">') 
  }
}

function framePrint(whichFrame){
 parent[whichFrame].focus();
 parent[whichFrame].print();
}

function displayPrintButton(whichFrame){
 var quoteMark = String.fromCharCode(39);
 document.write('<div style="text-align:right;float:right;">' +
                ' <a href="#" onclick="framePrint(' + quoteMark + whichFrame + quoteMark + ')"' +
                '   onmouseover="window.status=' + quoteMark + 'Click here to print this page' + quoteMark + '; return true"' +
                '   onmouseout="window.status=' + quoteMark + quoteMark + '; return true"' +
                '  >' +
                '  <img height="13px" border="0em" src="images/print_window_sm.gif" alt="Click here to print this page" />' +
                ' </a>' +
                '</div>');
}

function formatPhoneNumber(phoneNumber,extension) {
  var strSeparator = '-';
  phoneNumber = phoneNumber.replace(/\ /g,'');
  phoneNumber = phoneNumber.replace(/\./g,strSeparator);
  phoneNumber = phoneNumber.replace(/\(/g,'');
  phoneNumber = phoneNumber.replace(/\)/g,strSeparator);
  phoneNumber = phoneNumber.replace(/\//g,strSeparator);
//  phoneNumber = phoneNumber.replace(/\-/g,strSeparator);
 // determine if there is any punctuation
  var testValue = left(right(phoneNumber,5),1);
  if (!isNaN(parseFloat(testValue)) && isFinite(testValue)) {
    var nLoopCounter = 1;
    for (var i=phoneNumber.length-1;i>=0;i--) {
      if (nLoopCounter==4) {phoneNumber = String(phoneNumber).substr(0,i) + strSeparator + String(phoneNumber).substr(i);}
      if (nLoopCounter==7 && phoneNumber.length > i) {phoneNumber = String(phoneNumber).substr(0,i) + strSeparator + String(phoneNumber).substr(i);}
      nLoopCounter++;
    } 
  }
  document.write('<a class="phone" href="tel:+1' + phoneNumber.replace(new RegExp(strSeparator,"g"),'') + '">' + phoneNumber + '</a>')
//  document.write(phoneNumber)
  if (extension.length > 0) {document.write(' ext ' + extension)}
}

function right(str, n) {
 /*** IN: str - the string we are RIGHTing
      n - the number of characters we want to return

      RETVAL: n characters from the right side of the string
 ***/
  if (n <= 0)     // Invalid bound, return blank string
    return "";
   else if (n > String(str).length)   // Invalid bound, return
    return str;                       // entire string
   else { // Valid bound, return appropriate substring
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}

function left(str, n) {
 if (n <= 0)
   return "";
  else if (n > String(str).length)
   return str;
  else
   return String(str).substring(0,n);
}

function getMonthName(dtDate,lengthName) {
 if (lengthName=='long') {
   var months = new Array( "January","February","March", "April","May","June", "July","August","September","October", "November", "December");
  } else {
   var months = new Array( "Jan","Feb","Mar", "Apr","May","Jun", "Jul","Aug","Sep","Oct", "Nov", "Dec");
 }
 return months[dtDate.getMonth()]
}

function writeMonthName(dtDate,lengthName) {
 if (dtDate=='') { dtDate = new Date() } else { dtDate = new Date(dtDate) }
 if (lengthName=='') { lengthName = 'long'; }
 document.write(getMonthName(dtDate,lengthName));
}

function writeDateLastUpdated() {
 var dtDate = new Date(document.lastModified); 
 document.write('Site Last Updated:&nbsp; ' + getMonthName(dtDate,'long') + ' ' + dtDate.getDate() + ', ' + dtDate.getFullYear());
}

function toggleDivs(divID,action){
  if (action=='hide'){
    var command1 = 'hidden';
    var command2 = 'none'; }
   else {
    var command1 = 'visible';
    var command2 = 'block';
  }
  if (document.getElementById){ // DOM3 = IE5+, NS6+ 
    document.getElementById(divID).style.visibility = command1;
    document.getElementById(divID).style.display = command2;} 
   else { 
    if (document.layers){ // Netscape 4 
      document.layers[divID].visibility = command1; 
      document.layers[divID].display = command1;} 
     else { // IE 4 
      document.all[divID].style.visibility = command1;
      document.all[divID].style.display = command1;
    }
  } 
}
function hideAllDivs() { 
 var divs = document.getElementsByTagName('div'); 
 for(i=0;i<divs.length;i++){ 
  if (divs[i].id!='menu' && divs[i].id !=''){toggleDivs(divs[i].id,'hide');}
 }
}
function hideDiv(objDiv) {toggleDivs(objDiv,'hide');}
function showDiv(objDiv) { toggleDivs(objDiv, 'show'); }
function openBlanket(popUpDivVar) {
 if (navigator.appVersion.indexOf('MSIE 6.') == -1) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
  var blanket = document.getElementById('blanket');
  blanket.style.height = blanket_height + 'px';
  toggleDivs('blanket', 'show');
 }
}
