 if(typeof window.onload != 'function')
	window.onload = expandContent

window.onresize = expandContent


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 expandContent(event) {

	if (typeof(pd = document.getElementsByTagName("div")[0]) != 'undefined' && pd.className == 'PageParent'){
	
		pds = pd.style;
		fh = 57;
		hh = 200;
		
		var ua = navigator.userAgent.toLowerCase()
		safari = ua.indexOf('safari') + 1
		ie = ua.indexOf('msie') + 1
		mac = ua.indexOf('mac') + 1
	
	
		if (ie && !mac) {
		  	        		
			var b = (document.documentElement && document.documentElement.clientHeight)?document.documentElement:document.getElementsByTagName("body")[0];
			var ch = b.clientHeight
		
			if (pds.height == '')
				oh = pd.offsetHeight;
							
			var dh = oh - hh
			var nh = ch - fh - hh
			
			if(nh > dh)
			{
				pds.minHeight = nh + 'px';
				
				if(oh == pd.offsetHeight)
					pds.height = pds.minHeight;
				else
					pds.height = 'auto';
			}
			else
			{
				pds.minHeight = dh + 'px';
			}			
			
		}
		else if(!ie) {
			//Safari needs a delay to have access to relative style values
			window.setTimeout("changeMozHeight()", 0);
		}
	}
}

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('/EncouragingWord/PrinterFriendly.aspx?i='+ id +'&', 'pverse', winprops);
else
	window.open('/EncouragingWord/PrinterFriendly.aspx', 'pverse', winprops);
}

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 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"
}

// 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();
}
}



