addLoadListener(function()
{
	if (location.search.indexOf('lnid=') != -1) {
	 if (typeof nostory != 'undefined') {
      return;
     }
	 
	 lnid = location.search.substr(6);

	 links = document.getElementById('entry_header').getElementsByTagName('a');
	 links[1].onclick = function() {emailNews(lnid);return false;};
	 links[2].onclick = function() {printNews(this);return false;};

	 bObj = document.getElementsByTagName('body')[0];
	 addDiv = document.createElement('div');
	 addDiv.setAttribute('id','print');
	 bObj.insertBefore(addDiv, bObj.firstChild);

	 popDiv = document.createElement('div');
	 popDiv.setAttribute('id','popup');
	 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;
	
	 preloading(
	 "popup_green_top_slammed.png",
	 "popup_green_middle_solid_slammed.png",
	 "popup_green_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",
	 "send_blue.gif"
	 );
	}
});

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

function buildForm() {
html = '<div class="popup_header ph_yellow">All fields are required.</div>';
html += '<form name="emailForm" action="upcoming-events-process.php" method="post">';
html += '<input type="hidden" name="lnID" value="" />';
html += 'Your Name:<br />';
html += '<input type="text" name="sender_name" class="text" /><br />';
html += 'Your Email:<br />';
html += '<input type="text" name="sender_email" class="text" /><br />';
html += 'Friend\'s Name:<br />';
html += '<input id="receiver_name" type="text" name="receiver_name" class="text" /><br />';
html += 'Friend\'s Email:<br />';
html += '<input id="receiver_email" type="text" name="receiver_email" class="text" /><br />';
html += 'Message To Friend:<br />';
html += '<textarea name="message" class="text" rows="4" cols="4"></textarea>';
html += '<div style="float: right;">';
html += '<a href="javascript:;" onclick="popupDiv(\'popup\',\'hide\')" class="close_window">Close Window</a><span class="chevron">&gt;&gt;</span>';
html += '</div>';
html += '<div class="send">';
html += '<a href="javascript:;" onclick="emailCheck(); return false;">Send</a>';
html += '</div>';
html += '</form>';
return html;
}

function buildSuccess() {
html = '<div class="popup_header ph_blue">Success!</div>';
html += '<p><strong>Thank you for shaing this news item with your friend. Your email has been sent to them with all the news information.</strong></p><div style="text-align: center"><a class="close_window" href="javascript:;" onclick="popupDiv(\'popup\',\'hide\')">Close Window</a><span class="chevron">&gt;&gt;</span></div>';
return html;
}

function buildError(errorNum,field) {
html = '<div class="popup_header 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 printNews(obj) {
pObj = document.getElementById('entry_header').getElementsByTagName('p')[0];
entryHeader = document.getElementById('entry_header').getElementsByTagName('h2')[0].innerHTML;
entryDate = pObj.innerHTML;
textInfo = document.getElementById('entry_text').innerHTML;

printText = '<h1>Full Sail Ministries</h1><h2>Touching the World with God\'s Love</h2>';
if (pObj.className == 'gj') {
 newsHeader = 'Geoff and Jill News Information';
} else if (pObj.className = 'wom') {
 newsHeader = 'Just for Women News Information';
}
printText += '<h3>'+newsHeader+'</h3>';
printText += '<strong>'+entryHeader+'</strong><br />';
printText += entryDate+'<br /><br />';
printText += textInfo+'<br />';
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.";

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

function emailCheck() {
obj = document.emailForm;
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;
} else 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;
} else 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;
 formReceiverName = obj.receiver_name.value;
 formReceiverEmail = obj.receiver_email.value;
 formMessage = obj.message.value;
 formLnID = obj.lnID.value;
 
 url = 'news-process.php?action=send&ajax=true&sender_name='+formSenderName+'&sender_email='+formSenderEmail+'&receiver_name='+formReceiverName+'&receiver_email='+formReceiverEmail+'&message='+escape(formMessage)+'&lnid='+formLnID;
 req.open('GET', url, true);
 req.onreadystatechange = handleResponse;
 req.send(null);
 return false;
}
}

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) {
 slide(document.getElementById('popup_middle_text').offsetHeight,startHeight,elm);
 return;
}
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;
obj.receiver_name.value = formReceiverName;
obj.receiver_email.value =formReceiverEmail;
obj.message.value = formMessage;
obj.lnID.value = formLnID;
document.emailForm.elements[elm].className = 'text_error';
document.emailForm.elements[elm].focus();
}

function emailNews(id) {
document.getElementById('popup_middle').style.height = 'auto';
document.getElementById('popup_middle_text').innerHTML = buildForm();
popupDiv('popup','show');
document.emailForm.lnID.value = id;
}

var slideTimer = '';
var inc = 4;

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];
}

