addLoadListener(function()
{
	bObj = document.getElementsByTagName('body')[0];
	
	if (location.search.indexOf('jjid=') != -1) {
	 if (document.getElementById('entry_header')) {
	  links = document.getElementById('entry_header').getElementsByTagName('a');
	  links[1].onclick = function() {emailEntry(this,'entry');return false;};
	  links[2].onclick = function() {printEntry(this);return false;};
	  links[3].onclick = function() {emailEntry(this,'jill');return false;};
	 
	  addDiv = document.createElement('div');
	  addDiv.setAttribute('id','print');
	  bObj.insertBefore(addDiv, bObj.firstChild);

	  popDiv = document.createElement('div');
	  popDiv.setAttribute('id','popup');
	  popDiv.setAttribute('class','popgreen');
	  bObj.insertBefore(popDiv, bObj.nextSibling);
	 
	  html = '<div id="popup_top"></div>';
	  html += '<div id="popup_middle">';
	  html += '<div id="popup_middle_text">';
	  html += '</div>';
	  html += '</div>';
	  html += '<div id="popup_bottom"></div>';

	  document.getElementById('popup').innerHTML = html;
	 }
	} else {
	 responseDiv = document.createElement('div');
	 responseDiv.setAttribute('id','response_wrap');
	 document.getElementById('signup').insertBefore(responseDiv, document.getElementById('signup').firstChild);
	 
	 html = '<div id="response_inner">';
	 html += '<div id="response_top"></div>';
	 html += '<div id="response_middle">';
	 html += '<div id="response_middle_text"></div>';
	 html += '</div>';
	 html += '<div id="response_bottom"></div>';
	 html += '</div>';
	
	 document.getElementById('response_wrap').innerHTML = html;
	}
	
	preloading(
	"popup_green_top_slammed.png",
	"popup_brown_top_slammed.png",
	"popup_green_middle_solid_slammed.png",
	"popup_brown_middle_solid_slammed.png",
	"popup_green_middle_grad.gif",
	"popup_brown_middle_grad.gif",
	"yellow25per_bg_slammed.png",
	"blue60per_bg_slammed.png",
	"red35per_bg_slammed.png",
	"input_white_bg.gif",
	"input_blue_bg.gif",
	"input_red_bg.gif",
	"popup_green_bottom_slammed.png",
	"popup_brown_bottom_slammed.png",
	"send_blue.gif",
	"response_slot_slammed.png",
	"response_top_slammed.png",
	"response_middle_solid_slammed.png",
	"response_middle_grad.gif",
	"response_bottom_slammed.png"
	);
});

var myimages = [];
function preloading() {
for (x=0; x<preloading.arguments.length; x++){
myimages[x] = new Image();
myimages[x].src = "images/"+preloading.arguments[x];
}
}

var popOption = 'signup';

function buildForm() {
if (popOption == 'jill') {
 html = '<div class="popup_header ph_yellow">Share your thoughts with Jill.</div>';
 html += '<form name="emailForm" action="jills-journey-process.php" method="post">';
 html += '<input type="hidden" name="jjID" value="" />';
 html += '<div class="sender_email_jill">Your Email:<br />';
 html += '<input type="text" name="sender_email" class="text" tabindex="2" /></div>';
 html += 'Your Name:<br />';
 html += '<input type="text" name="sender_name" class="text" tabindex="1" /><br />';
 html += 'Message To Jill:<br />';
} else {
 html = '<div class="popup_header ph_yellow">All fields are required.</div>';
 html += '<form name="emailForm" action="jills-journey-process.php" method="post">';
 html += '<input type="hidden" name="jjID" value="" />';
 html += 'Your Name:<br />';
 html += '<input type="text" name="sender_name" class="text" tabindex="1" /><br />';
 html += 'Your Email:<br />';
 html += '<input type="text" name="sender_email" class="text" tabindex="2" /><br />';
 html += 'Friend\'s Name:<br />';
 html += '<input id="receiver_name" type="text" name="receiver_name" class="text" tabindex="3" /><br />';
 html += 'Friend\'s Email:<br />';
 html += '<input id="receiver_email" type="text" name="receiver_email" class="text" tabindex="4" /><br />';
 html += 'Message To Friend:<br />';
}
html += '<textarea name="message" class="text" rows="4" cols="4" tabindex="5"></textarea>';
html += '<div class="close_window_div">';
html += '<a href="javascript:;" onclick="popupDiv(\'popup\',\'hide\')" class="close_window" tabindex="7">Close Window</a><span class="chevron">&gt;&gt;</span>';
html += '</div>';
html += '<div class="send">';
html += '<a href="javascript:;" onclick="emailCheck(\''+popOption+'\'); return false;" tabindex="6">Send</a>';
html += '</div>';
html += '</form>';
return html;
}

function buildSuccess(oldList,newList) {
headerOption = (popOption == 'signup') ? 'response_header':'popup_header';
html = '<div class="'+headerOption+' ph_blue">Success!</div>';

if (popOption == 'jill') {
 html += '<strong>Thank you for sending me a note. Your email has been sent and I will be getting back with you as soon as I can. If you need prayer for anything you can go to our <a href="prayer-requests.php">Prayer Requests</a> page and share your need with us there. If you have any other questions, please don\'t hesitate to connect with us through our <a href="">Contact</a> page.</strong></p>';
 html += '<p><strong>Thanks again for stopping by. - Jill</strong>';
 onclicklink = 'popupDiv(\'popup\',\'hide\')';
} else if (popOption == 'signup') {
 if (oldList) {
  html += '<strong>It looks like you are already signed up for Jill\'s Journey. You will continue to receive it until you unsubscribe. So now you can sleep at night. No more worries.</strong>';
 }
 
 if (newList) {
  html += '<strong>Thank you for signing up for Jill\'s Journey. You are almost done. You will receive a confirmation email for signing up. I hope you are blessed and encouraged by what God has shared with me.</strong>';
 }

 onclicklink = 'responseClose()';
} else {
 html += '<strong>Thank you for sharing this entry with your friend. Your email has been sent to them along with the entry text.</strong>';
 onclicklink = 'popupDiv(\'popup\',\'hide\')';
}

html +='<div style="text-align: center"><a class="close_window" href="javascript:;" onclick="'+onclicklink+'">Close Window</a><span class="chevron">&gt;&gt;</span></div>';
return html;
}

function buildError(errorNum,field) {
headerOption = (popOption == 'signup') ? 'response_header':'popup_header';
html = '<div class="'+headerOption+' ph_red">Error</div>';
html += 'I\'m sorry, an error has occured.<div class="error_div">'+ajax_error[errorNum]+'</div>Please <a class="error_link" href="javascript:ajax_goback(\''+field+'\',true);\">click here</a> and try again.';
return html;
}

function printEntry(obj) {
entryDate = document.getElementById('entry_header').getElementsByTagName('h2')[0].innerHTML;
entryText = document.getElementById('entry_text').innerHTML;

printText = '<h1>Full Sail Ministries</h1><h2>Touching the World with God\'s Love</h2><h3>Jill\'s Journey</h3>';
printText += '<h4>'+entryDate+'</h4>';
printText += entryText;
printText += '<div id="print_footer">Full Sail Ministries &#8226; 130 N. Kelsey Street, Suite C &#8226; Visalia, CA &#8226; 93291 &#8226; (559) 651-1233<br />www.FullSail.org</div>';

document.getElementById('print').innerHTML = printText;
window.print();
}

var ajax_error = [];
ajax_error[0] = "Your email address is not in the correct format. Please check your entries and try again.";
ajax_error[1] = "Your friend's email address is not in the correct format. Please check your entries and try again.";
ajax_error[2] = "Your email address contains illegal characters. Please check your entries and try again.";
ajax_error[3] = "Your friend's email contains illegal characters. Please check your entries and try again.";
ajax_error[4] = "There are illegal characters in one of the fields you just entered. Please check your entries and try again.";
ajax_error[10] = "There was a problem signing you up. An email has been sent to our tech team and we will do everything we can to get you signed up for Jill's Journey.";

var formSenderName;
var formSenderEmail;
var formReceiverName;
var formReceiverEmail;
var formMessage;
var formJjID;
var startHeight;

function emailCheck() {
obj = document.emailForm;
if (popOption == 'signup') {
 document.emailForm.sender_name.className = 'text';
 document.emailForm.sender_email.className = 'text';
}
if (popOption == 'entry' || popOption == 'signup') {
 if (obj.sender_name.value.length < 1) {
  alert("Please enter your name.\n\nThank you.");
  obj.sender_name.focus();
  return false;
 } else if (obj.sender_email.value.length < 1) {
  alert("Please enter your email address.\n\nThank you.");
  obj.sender_email.focus();
  return false;
 }
}

if (popOption == 'entry') {
 if (obj.receiver_name.value.length < 1) {
  alert("Please enter your friend's name.\n\nThank you.");
  obj.receiver_name.focus();
  return false;
 } else if (obj.receiver_email.value.length < 1) {
  alert("Please enter your friend's email address.\n\nThank you.");
  obj.receiver_email.focus();
  return false;
 }
}

if (popOption != 'signup') {
 if (obj.message.value.length < 1) {
  alert("Please enter a message.\n\nThank you.");
  obj.message.focus();
  return false;
 }
}

req = createXMLHttpRequest();

if (!req) {
 obj.submit();
} else {
 formSenderName = obj.sender_name.value;
 formSenderEmail = obj.sender_email.value;
 if (popOption == 'entry') {
  formReceiverName = obj.receiver_name.value;
  formReceiverEmail = obj.receiver_email.value;
 }
 
 if (popOption != 'signup') {
  formMessage = obj.message.value;
  formJjID = obj.jjID.value;
 }
 
 if (popOption == 'signup') {
  document.getElementById('subscribe_loading').style.visibility = 'visible';
  document.getElementById('subscribe_loading').src = 'images/loader_red_blue_jj_trans.gif';
  url = 'email-signup-process.php?action=signup&ajax=true&list=jj&sender_name='+formSenderName+'&sender_email='+formSenderEmail;
 } else {
  url = 'jills-journey-process.php?action=send&popoption='+popOption+'&ajax=true&sender_name='+formSenderName+'&sender_email='+formSenderEmail+'&receiver_name='+formReceiverName+'&receiver_email='+formReceiverEmail+'&message='+escape(formMessage)+'&jjid='+formJjID;
 }
// alert(url);
 req.open('GET', url, true);
 if (popOption == 'signup') {
  req.onreadystatechange = handleResponseSignup;
 } else {
  req.onreadystatechange = handleResponse;
 }
 req.send(null);
 return false;
}
}

function handleResponseSignup() {
  if(req.readyState == 4){
    if (req.status == 200) {
      var response = req.responseText;
      update = response.split(':');
      
      document.getElementById('response_slot').style.display = 'block';
      
      if (update[0] == 'error') {
       document.getElementById('response_middle_text').innerHTML = buildError(update[1],update[2]);
       responseInnerHeight = document.getElementById('response_inner').offsetHeight;
	   document.getElementById('response_inner').style.top = (responseInnerHeight * -1) + 'px';
	   document.getElementById('response_wrap').style.height = responseInnerHeight + 'px';
       slideTop(responseInnerHeight * -1,0);
      } else if (update[0] == 'success') {
       document.getElementById('response_middle_text').innerHTML = buildSuccess(update[1],update[2]);
       responseInnerHeight = document.getElementById('response_inner').offsetHeight;
	   document.getElementById('response_inner').style.top = (responseInnerHeight * -1) + 'px';
	   document.getElementById('response_wrap').style.height = responseInnerHeight + 'px';
       slideTop(responseInnerHeight * -1,0);
      }
      document.getElementById('subscribe_loading').style.visibility = 'hidden';
    }
  }
}

function handleResponse() {
  if(req.readyState == 4){
    if (req.status == 200) {
      var response = req.responseText;
      update = response.split(':');
      
      popupMiddleBefore = document.getElementById('popup_middle').offsetHeight;
      popupTextBefore = document.getElementById('popup_middle_text').offsetHeight;
      document.getElementById('popup_middle').style.height = popupMiddleBefore+'px';
      startHeight = popupMiddleBefore;
      
      if (update[0] == 'error') {
       document.getElementById('popup_middle_text').innerHTML = buildError(update[1],update[2]);
       popupTextAfter = document.getElementById('popup_middle_text').offsetHeight;
       slide(popupTextBefore,popupTextAfter);
      } else if (update[0] == 'success') {
       document.getElementById('popup_middle_text').innerHTML = buildSuccess();
       popupTextAfter = document.getElementById('popup_middle_text').offsetHeight;
       slide(popupTextBefore,popupTextAfter);
      }
    }
  }
}

function ajax_goback(elm,error) {
if (error) {
 if (popOption == 'signup') {
  slideTop(0,document.getElementById('response_inner').offsetHeight * -1,elm);
 } else {
  slide(document.getElementById('popup_middle_text').offsetHeight,startHeight,elm);
 }
 return;
}

if (popOption != 'signup') {
 document.getElementById('popup_middle_text').innerHTML = buildForm();
 //popupDiv('popup','show'); // Recenter the div
 obj = document.emailForm;
 obj.sender_name.value = formSenderName;
 obj.sender_email.value = formSenderEmail;
 if (popOption == 'entry') {
  obj.receiver_name.value = formReceiverName;
  obj.receiver_email.value =formReceiverEmail;
 }
 obj.message.value = formMessage;
 obj.jjID.value = formJjID;
}

document.emailForm.elements[elm].className = 'text_error';
document.emailForm.elements[elm].focus();
}

function emailEntry(obj,optionSet) {
popOption = optionSet;

if (popOption == 'jill') {
 document.getElementById('popup').className = 'popbrown';
} else {
 document.getElementById('popup').className = 'popgreen';
}
document.getElementById('popup_middle').style.height = 'auto';
document.getElementById('popup_middle_text').innerHTML = buildForm();
jjid = obj.href.match(/.*\?jjid=(\d+)/);
popupDiv('popup','show');
document.emailForm.jjID.value = jjid[1];
}

function responseClose() {
document.emailForm.sender_name.value = '';
document.emailForm.sender_email.value = '';
slideTop(0,document.getElementById('response_inner').offsetHeight * -1,'responseClose');
}

var slideTimer = '';
var inc = 4;

function slideTop(initY, finalY, elm) {
window.clearTimeout(slideTimer);

obj = document.getElementById('response_inner');

if (initY != finalY) {
 if (initY > finalY) {
  rate = Math.floor((finalY - initY) / inc);
 } else {
  rate = Math.ceil((finalY - initY) / inc);
 }
 
 newTop = obj.offsetTop + parseInt(rate);
 obj.style.top = newTop + 'px';
 
 slideTimer = window.setTimeout("slideTop(" + newTop + ", " + finalY + ", '"+elm+"');", 2);
} else {
 if (elm != 'undefined') {
  document.getElementById('response_slot').style.display = 'none';
  document.getElementById('response_wrap').style.height = '0';
  
  if (elm != 'responseClose' && elm != '-1') {
   ajax_goback(elm);
  }
 }
}
}

function slide(initY, finalY, elm) {
window.clearTimeout(slideTimer);

obj = document.getElementById('popup_middle');

if (initY != finalY) {
 if (initY > finalY) {
  rate = Math.floor((finalY - initY) / inc);
 } else {
  rate = Math.ceil((finalY - initY) / inc);
 }
 
 newHeight = obj.offsetHeight + parseInt(rate);
 obj.style.height = newHeight + 'px';
 
 slideTimer = window.setTimeout("slide(" + newHeight + ", " + finalY + ", '"+elm+"');", 2);
} else {
 if (elm != 'undefined') {
  ajax_goback(elm);
 }
}
}

/* ================
Center Functions
================ */

function popupDiv(id,option) {
obj = document.getElementById(id);
if (option == 'show') {
 obj.style.display = 'block';
 winSize = windowSize();
 screenWidth = winSize[0];
 screenHeight = winSize[1];
// divWidth = screenWidth - 80;
// divHeight = screenHeight - 60;
 divWidth = obj.offsetWidth;
 divHeight = obj.offsetHeight;
 scrollPosTop = f_scrollTop();
 divLeft = parseInt((screenWidth-divWidth)/2);
 divTop = parseInt((screenHeight-divHeight)/2);
// obj.style.width = divWidth+'px';
// obj.style.height = divHeight+'px';
 obj.style.left = divLeft+'px';
 obj.style.top = scrollPosTop+divTop+'px';

// headerHeight = document.getElementById('header').offsetHeight;
// footerHeight = document.getElementById('footer').offsetHeight;
 //alert(headerHeight+' - '+footerHeight);
// document.getElementById('imgLib_iframe').style.height = (divHeight - headerHeight - footerHeight) + 'px';

 obj.style.visibility = 'visible';
 if (typeof document.uniqueID != 'undefined') {
//  createIframeLayer(document.getElementById(id));
 }
} else {
 obj.style.visibility = 'hidden';
 obj.style.display = 'none';
 if (typeof document.uniqueID != 'undefined') {
//  removeIframeLayer(document.getElementById(id))
 }
}
}

function createIframeLayer(menu)
{
//  if (!toggleSelects('hidden'))
//  {
    var layer = document.createElement('iframe');
// Altered Code: Name the new iframe so we can delete it later by name.
    layer.setAttribute("id","");
    layer.id = menu.getAttribute("id")+"iframe";
// End Altered Code
    layer.tabIndex = '-1';
    layer.src = 'javascript:false;';
    menu.parentNode.appendChild(layer);

    layer.style.left = menu.offsetLeft + 'px';
    layer.style.top = menu.offsetTop + 'px';
    layer.style.width = menu.offsetWidth + 'px';
    layer.style.height = menu.offsetHeight + 'px';
//  }
}

function removeIframeLayer(menu)
{
//  if (!toggleSelects('visible'))
//  {
//    var layers = menu.parentNode.getElementsByTagName('iframe');
//    alert(layers.length);
//    while (layers.length > 0)
//    {
//      layers[0].parentNode.removeChild(layers[0]);
//    }
//  }

// Altered Code: Targets the named iframe so it doesn't delete ALL the iframe on the page.
var layer = document.getElementById(menu.getAttribute("id")+'iframe');
var parent = layer.parentNode;
parent.removeChild(layer);
}

function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );
  return [myWidth,myHeight];

}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
	curleft = obj.offsetLeft
	curtop = obj.offsetTop
	while (obj = obj.offsetParent) {
		curleft += obj.offsetLeft
		curtop += obj.offsetTop
	}
}
return [curleft,curtop];
}
