var xmlHttp;
var verbose = true;
var navArray = new Array();
navArray[0] = new Array("about", 3, 10, "about.php");
navArray[1] = new Array("books", 10, 0, "books.php");
navArray[2] = new Array("speaking", 33, 0, "speaking.php");
navArray[3] = new Array("blog", 14, 3, "blog.php");
navArray[4] = new Array("store", 35, 5, "store.php");
navArray[5] = new Array("contact", 15, 0, "contact.php");

var tableArray	= new Array();

tableArray[0]	= '<table cellspacing="0" cellpadding="0" width="100%"><tr><td width="90" valign="top" style="padding-right:8px;text-align:left;">';
tableArray[1]	= '</td><td style="text-align:left;" valign="top"><span style="color:#000000;text-align:left;">';
tableArray[2]	= '</span> ';
tableArray[3]	= '</td></tr></table>';


bookIndex = 0;
bookArray = new Array();
//bookArray structure: Array(book_title, book_price, book_shipping, book_description, book_cover_big_url, book_cover_small_url, featured_selection, is_book);

buttonArray	= new Array();

var currentIndex	= 0;


bookArray[currentIndex] = new Array("Thin Places", 14.99, 4.8, "For those of us who have survived sexual abuse, life twists and turns in alleys of confusion. Thank God He picks us up thousands of times, dusts us off, heals us, and enables us to continue walking. That's been my story. I was sexually abused by neighborhood boys throughout my kindergarten year. That was nearly forty years ago, but the mark they left on me, though faded, is still there.<br/><br />Someday, when the New Earth dawns, I'll be free of this mark forever. And Jesus will use every trauma to beautify me--not with the earthly type of beauty I sometimes long to praised for here on earth, but an ethereal, eternal beauty. I pray the Lord would truly, deeply use my own markedness to change the landscape of the Kingdom of God. In this way, I can revel in the mark, be openly cautious about the vulnerabilty the mark creates, and thank God for His protection and provision along the journey.", "images/book_covers/thinplaces_large.jpg", "images/book_covers/thinplaces_small.jpg", "files/Thin Places_ch1.pdf", true, false);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=598186&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



bookArray[currentIndex] = new Array("A Slow Burn", 14.99, 4.8, "Emory Chance needs to find who killed her daughter Daisy and unravel the mystery behind a sickening premonition &mdash; a man with a snake tattoo. The second book in the Defiance, Texas Trilogy, A Slow Burn is a suspenseful story about courageous love, the power of forgiveness, and the bonds that never break.<br /><br />&nbsp;\"Beautifully and sensitively written, her characters realistic and well-developed. Mary DeMuth has a true gift for showing how God's light can penetrate even the darkest of situations.\" – Chuck Colson<br /><br />&nbsp;She touched Daisy’s shoulder. So cold. So hard. So unlike Daisy.<br /><br />&nbsp;Yet so much like herself it made Emory shudder.<br /><br />Burying her grief, Emory Chance is determined to find her daughter Daisy's murderer &mdash; a man she saw in a flicker of a vision. But when the investigation hits every dead end, her despair escalates. As questions surrounding Daisy's death continue to mount, Emory's safety is shattered by the pursuit of a stranger, and she can't shake the sickening fear that her own choices contributed to Daisy's disappearance. Will she ever experience the peace her heart longs for?<br /> <br />The second book in the Defiance, Texas Trilogy, this suspenseful novel is about courageous love, the burden of regret, and bonds that never break. It is about the beauty and the pain of telling the truth. Most of all, it is about the power of forgiveness and what remains when shame no longer holds us captive.", "images/book_covers/daisychain_large.jpg", "images/book_covers/daisychain_small.jpg", "files/A Slow Burn chapter one.pdf", true, false);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=317357&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;


bookArray[currentIndex] = new Array("Daisy Chain", 14.99, 4.8, "\"The abrupt disappearance of young Daisy Chance from a small Texas town in 1973 spins three lives out of control—Jed, whose guilt over not protecting his friend Daisy strangles him; Emory Chance, who blames her own choices for her daughter’s demise; and Ouisie Pepper, who is plagued by headaches while pierced by the shattered pieces of a family in crisis.<BR><BR> In this first book in the Defiance, Texas Trilogy, fourteen-year-old Jed Pepper has a sickening secret: He’s convinced it’s his fault his best friend Daisy went missing. Jed’s pain sends him on a quest for answers to mysteries woven through the fabric of his own life and the lives of the families of Defiance, Texas. When he finally confronts the terrible truths he’s been denying all his life, Jed must choose between rebellion and love, anger and freedom. <BR><BR>Daisy Chain is an achingly beautiful southern coming-of-age story crafted by a bright new literary talent. It offers a haunting yet hopeful backdrop for human depravity and beauty, for terrible secrets and God’s surprising redemption.", "images/book_covers/daisychain_large.jpg", "images/book_covers/daisychain_small.jpg", "files/daisychain.pdf", true, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240414&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



bookArray[currentIndex] = new Array("Authentic Parenting in a Postmodern Culture", 12.99, 4.8, "\"I heartily recommend this book for parents, those aspiring to parenthood, and even grandparents who yearn to better understand the complexities of raising children today.\" <BR><BR><b>William R. Cutrer M.D., Gheens Professor of Christian Ministry, The Southern Baptist Theological Seminary, Louisville, Kentucky</b><BR><BR>> Move from a prescribed method of parenting to parenting from the heart, from the inside out.<BR><BR>> Experience your child's heart by participating in life-changing art projects.<BR><BR>> Understand the postmodern world we live in so you can walk in your child's shoes and parent with wisdom and confidence.<BR><BR>> Create a haven in your house so your kids are wildly enthusiastic about coming home every day.<BR><BR>> Learn to have the kind of conversations with your kids that prevents rebellion when they leave the nest.", "images/book_covers/authentic_parenting_in_a_postmodern_culture_large.jpg", "images/book_covers/authentic_parenting_in_a_postmodern_culture_small.jpg", "files/AuthenticParenting.pdf", false, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240418&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



bookArray[currentIndex] = new Array("Wishing on Dandelions", 12.99, 4.8, "\"Step into words so beautiful they hurt, pages of rich symbol, and emotions so genuine you can't look away. Experience a powerful, lyrical voice in contemporary fiction.\" <b>Sharon Hinck, author of </i>The Secret Life of Becky Miller</i></b><BR><BR>> Find unexpected romance for a girl who feels unlovable and incapable of love.", "images/book_covers/wishing_on_dandelions_large.jpg", "images/book_covers/wishing_on_dandelions_small.jpg", "files/WishingOnDandelions.pdf", false, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240421&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;




bookArray[currentIndex] = new Array("Watching the Tree Limbs", 12.99, 4.8, "\"Mary E. DeMuth has set the bar high for her next offering in <i>Watching the Tree Limbs</i>, her first novel, and has proved she is more than capable of creating good fiction. A combination of mystery and revelation, pathos and hope, <i>Watching the Tree Limbs</i> will keep you mesmerized long after you've finished the last page. A welcomed addition to Christian fiction.\" <b>Lisa Samson, author of <i>The Church Ladies</i> and <i>Club Sandwich</i></b>.<BR><BR>> Experience firsthand God's surprising redemption in the most terrible circumstances. ", "images/book_covers/watching_the_tree_limbs_large.jpg", "images/book_covers/watching_the_tree_limbs_small.jpg", "files/WatchingTheTreeLimbs.pdf", false, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240420&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



bookArray[currentIndex] = new Array("Building the Christian Family You Never Had", 13.99, 4.8, "\"<i>Building the Christian Family You Never Had</i> offers a fresh start and bright hope as you seek to raise godly children.\" <b>Karol Ladd, author of <i>The Power of a Positive Mom</i></b><BR><BR>> Learn how to so completely heal from tragedy that others would never know the tragedy occurred.<BR><BR>> Shield your children from the negative influences of family members while still preserving those relationships.<BR><BR>> Don't duplicate the home you were raised, learning how to parent your children in an entirely different, life-giving way.", "images/book_covers/building_the_christian_family_you_never_had_large.jpg", "images/book_covers/building_the_christian_family_you_never_had_small.jpg", "files/BuildingChristianFamily.pdf", false, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240417&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



bookArray[currentIndex] = new Array("Ordinary Mom Extraordinary God", 10.99, 4.8, "\"In her honest, mom-next-door way, Mary DeMuth shares with you God's perspective and the encouragement you are longing to hear.\" <b>Jill Savage, Founder and Executive Director of Hearts at Home</b><BR><BR>> Find joy in the your daily tasks of motherhood. <BR><BR>> View your days as adventures of finding God's strength in the mundane.", "images/book_covers/ordinary_mom_extraordinary_god_large.jpg", "images/book_covers/ordinary_mom_extraordinary_god_small.jpg", "files/OrdinaryMomExtraordingGod.pdf", false, true);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=240416&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;



// Downloadables

pdfBooksStart	= currentIndex; // should be the first array index below

bookArray[currentIndex] = new Array("Nonfiction Book Proposals that Grab an Editor or Agent by the Throat (in a good way!)", 25, 0, "", "", "", "exert.pdf", false, false);

buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=71997&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;


//bookArray[currentIndex] = new Array("150 Conversation Starters", 5, 0, "", "", "", "exert.pdf", false, false);

//buttonArray[currentIndex]	= '<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=71996&cl=13566&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ej_add_to_cart.gif" border="0" alt="Add to Cart"/></a>';

currentIndex	++;


function getStar(navObj, relativeTop, relativeLeft)
{
	if(document.all)
	{
		offsetTop = navObj.offsetTop + relativeTop;
		offsetLeft = navObj.offsetParent.offsetLeft + navObj.offsetLeft + relativeLeft;
	}
	else
	{
		offsetTop = navObj.offsetTop + relativeTop;
		offsetLeft = navObj.offsetLeft + relativeLeft;
	}
	document.getElementById('stardiv').style.left = offsetLeft + 'px';
	document.getElementById('stardiv').style.top = offsetTop + 'px';
	document.getElementById('stardiv').style.display = "block";
}

function getNav(navType)
{
	navHTML = "<img src='images/nav_" + navType + "_left_spacer.jpg'>";
	for(i = 0; i < navArray.length; i++)
	{
		navHTML += "<A HREF='" + navArray[i][3] + "'><img ID=nav" + navArray[i][0] + " onMouseOver='getStar(this, " + navArray[i][1] + ", " + navArray[i][2] + ");' onMouseOut=\"document.getElementById('stardiv').style.display = 'none';\" src='images/nav_" + navType + "_" + navArray[i][0] + ".jpg' BORDER=0></A>";
	}
	navHTML += "<A HREF='speaking.php?view=freestuff'><img src='images/nav_" + navType + "_free_stuff.jpg' border=0></A><img src='images/nav_" + navType + "_right_spacer.jpg'>";
	document.write(navHTML);
}

function setStar(currentPageIndex)
{
	currentNavObj = document.getElementById('nav' + navArray[currentPageIndex][0]);
	relativeTop = navArray[currentPageIndex][1]
	relativeLeft = navArray[currentPageIndex][2]
	if(document.all)
	{
		offsetTop = currentNavObj.offsetTop + relativeTop;
		offsetLeft = currentNavObj.offsetParent.offsetLeft + currentNavObj.offsetLeft + relativeLeft;
	}
	else
	{
		offsetTop = currentNavObj.offsetTop + relativeTop;
		offsetLeft = currentNavObj.offsetLeft + relativeLeft;
	}
	document.getElementById('currentstardiv').style.left = offsetLeft + 'px';
	document.getElementById('currentstardiv').style.top = offsetTop + 'px';
	document.getElementById('currentstardiv').style.display = "block";
}

function createXmlHttpRequestObject()
{
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		}
		catch (e) {}
	}
	
	if(!xmlHttp)
	{
		if(verbose)
			alert("Error creating the XMLHttpRequest object");
	}
	else
		return xmlHttp;
}

function getAJAXDocument(url, objectName)
{
	try
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function() {
			if(xmlHttp.readyState == 4)
			{
				try
				{
					response = xmlHttp.responseText;
					document.getElementById(objectName).innerHTML = response;
				}
				catch (e)
				{
					if(verbose)
						alert("Error reading the response: " + e.toString());
				}
			}				
		};
  		xmlHttp.send("");
	}
	catch(e)
	{
		if(verbose)
			alert("The following error occurred: " + e.toString());
	}
}

function addToCart(book)
{
	bookTotal = 0;
	bookCount = 0;
	formHTML = "<input type='submit' src='http://www.paypal.com/en_US/i/btn/x-click-but01.gif' name='submit' value='Add to Cart' alt='Make payments with PayPal - it's fast, free and secure!'>";
	
	for(i = 0; i < document.storeform.books.length; i++)
	{
		if( document.storeform.books[i].checked )
		{
			bookTotal += bookArray[i][1] + bookArray[i][2];
			formHTML += "<input type='hidden' name='item_name_" + (bookCount + 1) + "' value='" + bookArray[i][0] + "'><input type='hidden' name='amount_" + (bookCount + 1) + "' value='" + bookArray[i][1] + "'><input type='hidden' name='handling_" + (bookCount + 1) + "' value='" + bookArray[i][2] + "'>";
			bookCount++;
		}
	}

	if(bookCount > 0)
	{
		document.getElementById('cartdiv').innerHTML = "Cart Total: " + bookTotal.toFixed(2) + "<BR>" + bookCount + " book(s)<BR>" + formHTML;
		document.getElementById('cartdiv').style.display = "block";
	}
	else
	{
		document.getElementById('cartdiv').innerHTML = "";
		document.getElementById('cartdiv').style.display = "none";
	}
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}

function loadBookImages()
{
	var resultsText	= '';
	
	for( i = 0; i < bookArray.length; i ++ )
	{
		resultsText	= resultsText + '<img src="' + bookArray[ i ][ 4 ] + '" width="1" height="1" />';
	}
	
	return( resultsText );
}

function getBook(book, findFeatured)
{
	if(book >= bookArray.length)
		book = 0;
	if(book < 0)
		book = bookArray.length - 1;
	if(!bookArray[book][8])
	{
		if(book < bookIndex)
			getBook(--book, findFeatured);
		else
			getBook(++book, findFeatured);
	}
	else
	{
		newHTML = "";
	
		if(findFeatured)
		{
			for(i = 0; i < bookArray.length; i++)
			{
				if(bookArray[i][7])
				{
					book = i;
					break;
				}
			}
		}
		
		if(bookArray[book][7])
			newHTML += "<center><img src='images/books_featured_selection.png' /></center>";
		newHTML += bookArray[book][3]  + "<BR><A HREF='" + bookArray[book][6] + "' TARGET=_blank>Click here for excerpt</A>";
		document.getElementById('bookdiv').innerHTML = newHTML;
		document.getElementById('bookCoverImg').src = bookArray[book][4];
		bookIndex = book;
	}
	
	document.getElementById( 'buy_book_link' ).href	= bookIndex == 0 ? 'http://www.amazon.com/Thin-Places-Mary-E-DeMuth/dp/031028418X/ref=sr_1_1?ie=UTF8&s=books&qid=1262712444&sr=1-1' : 'store.php';
}

function loadBookThumbs()
{
	newHTML = "";
	seed = Math.floor(Math.random()*bookArray.length);
	book = seed;
	book = 1;
	for(i = 0; i < 4; i++, book++)
	{
		if(book >= bookArray.length)
			book = 0;
		if(book < 0)
			book = bookArray.length - 1;
		
		if(bookArray[book][8])
			newHTML += "<img style='padding: 7px;' src='" + bookArray[book][5] + "' />";
		else
			i--;
	}
	document.getElementById('bookCoverDiv').innerHTML = newHTML;
}

function editNews(id)
{
	window.location = "newsedit.php?news=" + newsArray[id][0];
//	document.newsform.submittype.value = 'UPDATE';
//	document.newsform.newsid.value = id; 
//	document.newsform.newstext.value = newsArray[id][1];
//	alert(document.newsform.newstext.value);
}

function deleteNews(id)
{
	if(confirm('Are you sure you wish to delete this news item?')) 
	{ 
	 	document.newsform.submittype.value = 'DELETE';
		document.newsform.newsid.value = newsArray[id][0];
		document.newsform.submit();
	}
} 

function checkContactForm()
{
	complete = true;
	if(document.contactform.contactname.value.length == 0)
		complete = false;
	if(document.contactform.contactcomment.value.length == 0)
		complete = false;
	if(document.contactform.contactemail.value.length == 0)
		complete = false;

	if(complete)
		document.contactform.submit();
	else
		alert("All fields are required.  Please fill in your name, your email address and a message for Mary.");
}

function checkNewsletterForm()
{
	complete = true;
	if(document.signupform.contactname.value.length == 0)
		complete = false;
	if(document.signupform.contactemail.value.length == 0)
		complete = false;

	if(complete)
		return true;
	else
	{
		alert("All fields are required.  Please fill in your name and your email address to sign up for the newsletter.");
		return false;
	}
}

function getStore()
{
	navHTML = "";
	for(i = 0; i < pdfBooksStart; i++)
	{
		if(i > 0)
			navHTML += "<br />";
			
		//navHTML += "<INPUT TYPE=checkbox id=books VALUE=" + i + " onClick='addToCart(" + i + ");'/><A STYLE='color: #000000;' TITLE='" + bookArray[i][0] + "'>" + bookArray[i][0] + "</A>: $" + bookArray[i][1] + " + $" + bookArray[i][2].toFixed(2) + " S/H";

		navHTML +=	tableArray[0] +
						buttonArray[i] +
					tableArray[1] +
						bookArray[i][0] +
						":" +
					tableArray[2] +
						"$" + bookArray[i][1] + " + $" + bookArray[i][2].toFixed(2) + " S/H" +
					tableArray[3]
				;
	}
	document.write(navHTML);
}

function getPDFStore()
{
	navHTML = "";
	for(i = pdfBooksStart; i < bookArray.length; i++)
	{
		if(i > 0)
			navHTML += "<br />";
			
		//navHTML += "<INPUT TYPE=checkbox id=books VALUE=" + i + " onClick='addToCart(" + i + ");'/><A STYLE='color: #000000;' TITLE='" + bookArray[i][0] + "'>" + bookArray[i][0] + "</A>: $" + bookArray[i][1] + " + $" + bookArray[i][2].toFixed(2) + " S/H";

		navHTML +=	tableArray[0] +
						buttonArray[i] +
					tableArray[1] +
						bookArray[i][0] +
						":" +
					tableArray[2] +
						"$" + bookArray[i][1] + " + $" + bookArray[i][2].toFixed(2) + " S/H" +
					tableArray[3]
				;
	}
	document.write(navHTML);
}
