<!-- // General Use Javascripts for fcchurch.org
document.write('<META HTTP-EQUIV="expires" CONTENT="Wed, 19 Feb 2003 08:00:00 GMT">');
document.write('<meta http-equiv="Pragma" content="no-cache">');
document.write('<meta http-equiv="no-cache">');
document.write('<meta http-equiv="Expires" content="-1">');
document.write('<meta http-equiv="Cache-Control" content="no-cache">');

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openWindow(url, name, features) {
  popupWin = window.open(url, name, features);
  popupWin.focus();
}

function openSmallWindow(url, name) {
  popupWin = window.open(url, name, 'resizable,scrollbars height=400, width=600');
  popupWin.focus();
}
/*********************************************************************
   * Get an object, this function is cross browser
   * Usage: 
   * var object = get_object(element_id);
   * @Author Hamid Alipour http://blog.code-head.com/
  **/
  function getObjectByID(id) {
   var object = null;
   if (document.layers) {   
    object = document.layers[id];
   } else if (document.all) {
    object = document.all[id];
   } else if (document.getElementById) {
    object = document.getElementById(id);
   }
   return object;
  }
  /*********************************************************************/

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 trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

// Opens a Window for My Utmost... from RBC with a file name in the form MMDD.htm where MMDD is the month and day for today
function reflectionToday()
{
	toDay=new Date();
	Month=right("00"+toDay.getMonth()+1,2);
	Day=right("00"+toDay.getDate(),2);
	TodaysReflectionURL="Reflections/"+Month+Day+".html";
	popupWin = window.open('http://www.rbc.org/utmost/','DailyReflection','scrollbars=yes, resizable=yes, width=800');
	popupWin.focus(); 
}// Ends reflectionToday Function

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

function checkEmail (strng,msg) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address for "+msg+".\n";
}
if (strng.toLowerCase() == "none" || strng.toLowerCase() == "unknown") {
   return error;
}
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address for "+msg+".\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address for "+msg+" contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng,msg) {
var error = "";
if (strng == "") {error = "You didn't enter a phone number for "+msg+".\n";}
if (strng.toLowerCase() == "none" || strng.toLowerCase() == "unknown") {return error;}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {error = "The phone number for "+msg+" contains illegal characters.";}
    if (!(stripped.length == 10)) {error = "The phone number for "+msg+" is the wrong length. Make sure you included an area code.\n";} 
	else {error = "("+stripped.substr(0,3)+") "+stripped.substr(3,3)+"-"+stripped.substr(-4,4);}
return error;
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr, msg){
	error = "";
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		error ="The "+msg+" format should be : mm/dd/yyyy.\n";
	}
	if (strMonth.length<1 || month<1 || month>12){
		error = "Please enter a valid month for the "+msg+".\n";
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		error = "Please enter a valid day for the "+msg+".\n";
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		error = "Please enter a valid 4 digit year for the "+msg+".\n";
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		error = "Please enter a valid "+msg+".\n";
	}
return error
}

// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng,msg) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username for "+msg+" .\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username for "+msg+" is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username for "+msg+" contains illegal characters.\n";
    } 
return error;
}       

// Author : Jehiah Czebotar
// Usage  : alert(isdefined('myvar'));
function isDefined( variable){return (typeof(window[variable]) == "undefined")?  false: true;}

// non-empty textbox
function isEmpty (strng,msg) {
var error = "";
  if (strng.length == 0) {
     error = "The "+msg+" has not been filled in.\n"
  }
return error;	  
}

// Original JavaScript code by Chirp Internet: www.chirp.com.au 
// Please acknowledge use of this code by including this header. 
// plus 30 days 
function setCookie(name, value) { 
	var today = new Date(); 
	var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); 
	document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString(); 
}

function getCookie(name) { // use: getCookie("name");
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : "";
}

function deleteCookie(name) {
var expired = new Date(today.getTime() - 24 * 3600 * 1000); // less 24 hours 
document.cookie=name + "=null; path=/; expires=" + expired.toGMTString(); 
} 

//-->
