function openLyricsWin(url) {
/* begin configuration */
var w = "350"; 
var h = "400"; 
var menu = "no"; 
var scroll = "yes"; 
var tool = "no"; 
var location = "no"; 
var resize = "no";
/* end configuration */

var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'width='+w+', height='+h+', top='+wint+', left='+winl+', menubar='+menu+', scrollbars='+scroll+', toolbar='+tool+', location='+location+', resizable='+resize+''
window.open(url, 'popup', winprops);
}

function openPVPrintWin(id) {
/* begin configuration */
var w = "450"; 
var h = "295"; 
var menu = "no"; 
var scroll = "no"; 
var tool = "no"; 
var location = "no"; 
var resize = "no";
/* end configuration */

var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'width='+w+', height='+h+', top='+wint+', left='+winl+', menubar='+menu+', scrollbars='+scroll+', toolbar='+tool+', location='+location+', resizable='+resize+''
if(typeof id != 'undefined')
	window.open('/Ministry/VerseOfTheDay/PrinterFriendly.aspx?i='+ id +'&', 'pverse', winprops);
else
	window.open('/Ministry/VerseOfTheDay/PrinterFriendly.aspx', 'pverse', winprops);
}

function launchPledgeRequest()
{
	request = window.open('/pledge/pledgeRequest.aspx','pledgeRequest','width=415,innerWidth=415,height=315,innerHeight=315,toolbar=no,directories=no,status=no,scrollbars=no,resizable=no,menubar=no');
}

function pauseScript(millis) 
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); } 
while(curDate-date < millis);
} 

function getQueryString(variable) 
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) 
  {
    var pair = vars[i].split("=");
    if (pair[0] == variable) 
    {
      return pair[1];
    }
  }
  return "None"
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_changeProp(objName,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if ((theValue == true || theValue == false) && theValue != '')
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  } 
}


//checks for all CAPS - returns validation = false if all caps is used
//author: Nick LaPolla
// use with Custom Validator as follows:
/* <asp:CustomValidator id="custValAllCaps[field name]" runat="server" 
    ErrorMessage="Please do not use all CAPS in the [field name]."
	ControlToValidate="txt[field name]" Display="None" ClientValidationFunction="AllCapsCheck">
*/
function AllCapsCheck(val, arguments)
{
	if (arguments.Value.toUpperCase() == arguments.Value)
	{
		arguments.IsValid = false;
	}
	else
	{
		arguments.IsValid = true;
	}
} 


//used with numberOnly and textOnly to extract the key pressed from the event
//author: Nick B LaPolla
function keyPressed(e)
{
	var keynum;

	// gets the character code pressed for either IE or other browsers
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	//converts the character code to the actual character and returns it
	return String.fromCharCode(keynum);
}

//used on all pages where there is a need to change the text color of a group of elements - one to highlight and the rest to a normal color
//Author: Nick LaPolla
function setColor(id, colorNorm, colorHighlight, idNum, num)
{
  var tf = false
  if (idNum > 0) { tf = true; }
  var divId, divElement;
  for ( i=1; i<=num; i++ )
  {
	divId = id + i;
	divElement = document.getElementById(divId);
	divElement.style.color = colorNorm;
  }
  if (idNum > 0)
  {
      if (tf == true)
      {
        if (idNum < 2 )
        {
            if (tf == true) 
            {
                idNum = 1;
            }
        }
	    divId = id + idNum;
	    divElement = document.getElementById(divId);
	    divElement.style.color = colorHighlight;
      }
  }
  return false;
}


// allows the user to enter ONLY numbers into a text box - example of use:
// <input type="text" onkeypress="return numberOnly(event)">
// "e" is the event
//author: Nick LaPolla
function numberOnly(e)
{
	var numcheck
	numcheck = /\d/;

	//checks to see if it is a number and if it is, returns true
	//if returns true, then the number displays in the textbox
	return numcheck.test(keyPressed(e));
}

// allows the user to enter ONLY text (non-numeric characters) into a text box - example of use:
// <input type="text" onkeypress="return textOnly(event)">
// "e" is the event
//author: Nick LaPolla
function textOnly(e)
{
	var numcheck
	numcheck = /\d/;

	//checks to see if it is a number - if it is, then it returns false
	//if returns true, then the text displays in the textbox
	return !numcheck.test(keyPressed(e));
}


//checks to see if a string is numeric - including . and - (negative sign)
function IsNumeric(strString)
   //  check for valid numeric strings 
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function toggleMoreInfo(id) {

  var linkEl, divEl;

  imgEl = document.getElementById("moreImg" + id);
  divEl = document.getElementById("moreDiv" + id);
  
  if (divEl.style.display == "") {
    divEl.style.display = "none";
    imgEl.src = imgEl.src.toLowerCase().replace("hide", "show");
    imgEl.alt = "Show"
  }
  else {
    divEl.style.display = "";
    imgEl.src = imgEl.src.toLowerCase().replace("show", "hide");
    imgEl.alt = "Hide"
  }
  return false;
}

//used on all pages where user has options for regional searches (by state, by zip, local listings)
//including the BTM directory and the Station List
//Author: Nick LaPolla
function toggleDiv(id, idNum, num)
{
  var tf = false
  if (idNum > 0) { tf = true; }
  var divId, divElement;
  for ( i=1; i<=num; i++ )
  {
	divId = id + i;
	divElement = document.getElementById(divId);
	divElement.style.display = "none";
  }
  if (idNum > 0)
  {
      if (tf == true)
      {
        if (idNum < 2 )
        {
            if (tf == true) 
            {
                idNum = 1;
            }
        }
	    divId = id + idNum;
	    divElement = document.getElementById(divId);
	    divElement.style.display = "";
      }
  }
  return false;
}

//used on the Community Calendar Page
//Author: Nick LaPolla
function inactivateEndTimeDdls ( ddl1, ddl2, ddl3 )
{
	var ddlObj1, ddlObj2, ddlObj3;
	ddlObj1 = document.getElementById(ddl1);
	ddlObj1.disabled = !ddlObj1.disabled;
	ddlObj2 = document.getElementById(ddl2);
	ddlObj2.disabled = !ddlObj2.disabled;
	ddlObj3 = document.getElementById(ddl3);
	ddlObj3.disabled = !ddlObj3.disabled;
}

//used on the Community Calendar Page
//Author: Nick LaPolla
function toggleMultiDivs(id, e, txtbx, total)
{
  var divId, divElement;
  var isNumber = true;
  //if (e != null) { isNumber = numberOnly(e); }

  for ( i=1; i<=total; i++ )
  {
	divId = id + i;
	divElement = document.getElementById(divId);
	divElement.className = "hide";
  }

  if (isNumber)
  {
    //If a dependent checkbox control is passed and someone enters a number here, the checkbox will be unchecked
    //this "if" is a special exception for Community Calendar - otherwise, pass null for "otherControl"
    //if (otherControl != null)
    //{
    //   otherControl.checked = false;
    //   toggleDiv('NoDate', 0, 1);
    //}

	var num = txtbx.options[txtbx.selectedIndex].value;
	//var num = keyPressed(e);
	//if (num > total) 
	//{
	//	num = total;
	//	txtbx.value = num;
	//}
	//else { txtbx.value = num; }
	for ( i=1; i<=num; i++ )
	{
		divId = id + i;
		divElement = document.getElementById(divId);
		divElement.className = "show";
	}
  }
  else { txtbx.value = ""; }

  return isNumber;
}

//used in Community Calendar
function toggleDivController (thisId, thisNum, thisTotal, otherId, otherControl, otherTotal)
{
	toggleDiv(thisId, thisNum, thisTotal);
	toggleMultiDivs(otherId, null, otherControl, null,  otherTotal)
}

// checks each keypressed in a focused control (eg text box) 
// and submits the named button when return is pressed
function KeyDownHandler(btnName)
{
	if (btnName == "")
	{
		// return if there is no button to submit
		return;
	}

    // process only the Enter key
    if (event.keyCode == 13)
    {
		// cancel the default submit
        event.returnValue=false;
        event.cancel = true;
        // submit the form by programmatically clicking the specified button
		__doPostBack(btnName,"");
	}
}

function toggleMoreInfo(id) {

  var linkEl, divEl;

  imgEl = document.getElementById("moreImg" + id);
  divEl = document.getElementById("moreDiv" + id);
  
  if (divEl.style.display == "") {
    divEl.style.display = "none";
    imgEl.src = imgEl.src.toLowerCase().replace("hide", "show");
    imgEl.alt = "Show"
  }
  else {
    divEl.style.display = "";
    imgEl.src = imgEl.src.toLowerCase().replace("show", "hide");
    imgEl.alt = "Hide"
  }
  return false;
}

function KeyDownHandler(btn) 
{
	// process only the Enter key
	if (event.keyCode == 13)
	{
	// cancel the default submit
	event.returnValue=false;
	event.cancel = true;
	// submit the form by programmatically clicking the specified button
    btn.click();
	}
}

function inspectStyle(elm){
  if (elm){
    var str = "";
    for (var i in elm){
	  str += i + ": " + elm[i] + "\n";
	}
	alert(str);
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function getCookie(NameOfCookie)
{
if (document.cookie.length > 0) 
{ 
begin = document.cookie.indexOf(NameOfCookie+"="); 
if (begin != -1) // Note: != means "is not equal to"
{ 
begin += NameOfCookie.length+1; 
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end)); } 
}
return null; 
}

function setCookie(NameOfCookie, value, expiredays) 
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) 
{
if (getCookie(NameOfCookie)) {
document.cookie = NameOfCookie + "=" +
"; expires="+ new Date();
}
}
