


var hh, fh, pds, oh, ie, safari, mac;

//checks for all CAPS - returns validation = false if all caps is used
//author: Nick LaPolla
// use with Custom Field Validator as follows:
/* <asp:CustomValidator id="custValAllCaps[descriptFieldName]" 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 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);
}

// 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 changeMozHeight() {	

	var wh = window.innerHeight;
	
	if (pds.height == '')
		oh = pd.offsetHeight;
	
	//Safari doesn't move footer if height isn't different then initial height???
	var dh = oh - hh + ((safari)?-1:0)
	var nh = wh - hh - fh;
	
	if(nh > dh)
		pds.minHeight = nh + 'px';
	else
		pds.minHeight = dh + 'px';
}

function inspectStyle(elm){
  if (elm){
    var str = "";
    for (var i in elm){
	  str += i + ": " + elm[i] + "\n";
	}
	alert(str);
  }
}



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+"'");

  } 

}

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('encouraging-word/print.aspx?i=' + id + '&', 'pverse', winprops);
else
    window.open('encouraging-word/print.aspx', 'pverse', winprops);
}

function openLyricsWin(url) {
    if (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 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"
}


//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 addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

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();
}
}

function jmsajaxurl (options) {
    var url = options.url;
    url += "/" + options.method;
    if (options.data) {
        var data = ""; for (var i in options.data) {
            if (data != "")
                data += "&"; data += i + "=" + msJSON.stringify(options.data[i]);
        }
        url += "?" + data; data = null; options.data = "{}";
    }
    return url;
};

function ShortenString(string, length) 
{
    if (string.length > length) 
    {
        return string.substring(0, length - 3) + '...'
    }
    else
    {
        return string;
    }
}

var launchPlayerDomain = ""; //used by RemoteContentProcessor.js

function launchPlayer(playerLink) {

    if (!playerLink) {
        playerLink = '/listen/player.aspx'
    }


    var ScrollBarDisplay = 0;
    if (screen.availHeight < 799) ScrollBarDisplay = 1; //Show scrollbars in IE if screen is too short... (This is fixed in Firefox via player.css HTML tag)

    self.name = "opener";

    if (launchPlayerDomain == "") {
        listen = window.open(playerLink, 'klove_player', 'resizable=1,status=1,toolbar=0,location=0,scrollbars=' + ScrollBarDisplay + ',width=664,height=738');

    } else {
        listen = window.open(launchPlayerDomain + playerLink, 'klove_player', 'resizable=1,status=1,toolbar=0,location=0,scrollbars=' + ScrollBarDisplay + ',width=664,height=738');
    }
}


