// Ergonet JavaScript Document
var dataSourcePath="/conf/eNbb/conf/app/dataSource.php";
var clientIP='';
var xmlhttp=false;
var pathForTheRecord='';
var xhr=true;
var currentBoxSetPid=0;
var pollForAccessTimeout=null;
var pollForAccessPeriod= (1000*60*5);
var deck = new Array('eNbbCoverTitle','eNbbCoverThumb','eNbbComments','eNbbInfo','keywordList','keywordTitle','kwMore','kwFewer','eNbbRelated','pages','eNbbPageNavigator','eNbbMessages');// ,'eNbbPageBrowser'
var historyStore=new Array();
historyStore.push('getCovers()');
var cookieValue=0;
var allowPageTransition = true;
//var instanceOne;
//var instanceOne = new ImageFlow();
// specific Display Functions
function getAuthorImageUpload(pid) {
	// get the flash uploader and replace the contents of div id = 'aiu'+pid	
	var str = "func=getAuthorImageUpload&pid="+pid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
}

function eNbbMessagesHide(){
	if(document.getElementById('eNbbMessages')){
		document.getElementById('eNbbMessages').style.display = "none";
		document.getElementById('eNbbMessages').innerHTML = "";
	}
}
function clickAboveToTurnShow(bool) {
	var obj = document.getElementById('clickAboveToTurn');
	if (obj != null) {
		if (bool) {
			obj.style.display="block";
		} else {
			obj.style.display="none";
		}
	}
}
function eNbbKeywordsShow(bool) {
	var obj = document.getElementById('eNbbKeywords');
	if (obj != null) {
		if (bool) {
			obj.style.display = "block";
		} else {
			obj.style.display="none";
		}
	}
}
function showPages() {
	var obj=document.getElementById('pages');
	if (obj != null) {
		obj.style.display="block";
	}
}

function nestedSearchResultsShowHide(id) {
	var obj=document.getElementById(id);
	if (obj != null) {
		var h=obj.offsetHeight;
		if (h > 15) {
			obj.style.height="15px";	
		} else {
			obj.style.height="auto";	
		}
	}
}

function displayFromOtherBooks(bool) {
	var obj = document.getElementById('fromOtherBooks');
	if (obj != null) {
		if (bool) {
			obj.style.display = 'block';
		} else {
			obj.style.display = 'none';
		}
	}
	var obj = document.getElementById('keywordTitle');
	if (obj != null) {
		if (bool) {
			obj.style.display = 'block';
		} else {
			obj.style.display = 'none';
		}
	}
}
// note: the deck array is set at the top of this library
function clearDeck() {
	var obj;
	for (var i=0; i<deck.length; i++) {
		obj = document.getElementById(deck[i]);
		if (obj != null) {
			obj.style.display='none';
		}
	}
}

function showDeck() {
	var obj;
	for (var i=0; i<deck.length; i++) {
		obj = document.getElementById(deck[i]);
		if (obj != null && deck[i] != 'eNbbComments') {
			obj.style.display='block';
		}
	}
}

// Specific Read Functions
var formCheckReturnValue=false;
function swapBookStatus(pid) {
	if (pid) {// only re-populate the anchor id: sbs+pid
		var str = "func=swapBookStatus&pid="+pid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function swapBookOtherStatus(pid) {
	if (pid) {// only re-populate the anchor id: sbs+pid
		var str = "func=swapBookOtherStatus&pid="+pid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function checkResendPassEmail() {
  var obj=document.getElementById('em');
  if (obj.value != '') {
    if (obj.value == "") {
      return;
    } else {
      formCheckReturnValue=true;
	  postFormData("resendPasswordForm");
    }
  } else {
	trace('missing: email');  
  }
}

function resendPassword() {
	
	var str = "func=resendPassword";
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function bookNewWiz(step) {
	var str = "func=bookNewWiz&step="+step;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function bookOtherNewWiz(step) {
	var str = "func=bookOtherNewWiz&step="+step;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

var currentMessage='';
function buyEbook() {
	addItemToBasket(0,2,0,domain,'buyEbook'); // see /lib/estall/shop.js
}

function buySubscription(pid){
	if(pid){
		addItemToBasket(pid,2,0,domain,'buySubscription'); // see /lib/estall/shop.js
		//var str = "func=buySubscription&pid="+pid;
		//str = dataSourcePath + "?" + str;
		//sendToServer(str);
	}
}

function goToCheckout() {
	var str = "func=checkout&ref="+cookieValue;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getOtherBookList(){
	var str = "func=getOtherBookList";
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}
function allowMessages(bool) {
	messagesOn = bool;
	if (messagesOn) {
		showMessage();
	} else {
		closeMessage();
	}
}
var messagesOn=false;
function eNbbMessages(str) {
	if (messagesOn) {
		var eNbbMessages = document.getElementById('eNbbMessages');
		if (eNbbMessages != null) {
			if (currentMessage != str) {
				currentMessage = str;
				eNbbMessages.innerHTML = str;
				showMessage();
			}
		} else {
			trace(str);
		}
	}
}

function showMessage() {
	var eNbbMessages = document.getElementById('eNbbMessages');
	if (eNbbMessages != null) {
		eNbbMessages.style.display = 'block';
	}
}

function closeMessage() {
	var eNbbMessages = document.getElementById('eNbbMessages');
	if (eNbbMessages != null) {
		eNbbMessages.style.display = 'none';
	}
}

function eNbbNext () {
	var str = "func=next,getKeywords,getPages"	;
	if (commentsOpen) {
		str +=",comment";
	}
	str = dataSourcePath + "?" + str;
	slideDirection="left";
	sendToServer(str);
}

function eNbbPrev() {
	var str = "func=previous,getKeywords,getPages"	;
	if (commentsOpen) {
		str +=",comment";
	}
	str = dataSourcePath + "?" + str;
	slideDirection="right";
	sendToServer(str);
}

function validate() {
	var str = "func=validate"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function enlarge() {
	var str = "func=enlarge"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function reduce() {
	var str = "func=reduce"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getCovers() {
	closeComments();
	var str = "func=getCovers"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getIndex() {
	closeComments();
	var str = "func=getIndex"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getStarred() {
		var str = "func=getStarred";
		str = dataSourcePath + "?" + str;
		sendToServer(str);
}

function getOtherFirstPage(pid){
	if(pid){
		var str = "func=getOtherFirstPage,getBookInfo,getOtherButtons&pid="+pid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function getSpecialOffers() {
	var str = "func=getSpecialOffers"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getFriends() {
	var str = "func=getFriends"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getContact() {
	var str = "func=getContact"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

//		Init functions
function getIPaddress() {
	var str = "func=getip"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getThumbnailOfCover() {
	var str = "func=getThumbnail"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getAuthor() {
	var str = "func=getAuthor"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getAuthorReccomList() {
	var str = "func=getAuthorReccomList"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getBuyAndDonateButtons() {
	var str = "func=getButtons"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getKeywords() {
	var str = "func=getKeywords"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getSearchResults() {
	closeComments();
	var str = "func=getSearch"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getRelated() {
	var str = "func=getRelated"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getFirstPage(pid) {
	var str = "func=getFirstPage,getThumbnail,getRelated,getBookInfo,getButtons";
	if (commentsOpen) {
		str +=",comment";
	}
	str +="&pid="+pid	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getFirstPageNoHistory(pid) {
	var str = "func=getFirstPage,getThumbnail,getRelated,getBookInfo";
	if (commentsOpen) {
		str +=",comment";
	}
	str +="&pid="+pid + "&NoHistory";
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getSpread(pid,scompid) {
	var str = "func=getThisPage,getThumbnail,getRelated,getKeywords,getPages,getBookInfo";
	if (commentsOpen) {
		str +=",comment";
	}
	str += "&pid="+pid+"&scompid="+scompid	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}
// this version of getSpread is used when we navigate using the back button.
// these page changes do not want to be added to history
function getSpreadNoHistory(pid,scompid) {
	var str = "func=getThisPage,getThumbnail,getRelated,getKeywords,getPages,getBookInfo";
	if (commentsOpen) {
		str +=",comment";
	}
	str += "&pid="+pid+"&scompid="+scompid	+ "&NoHistory";
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

var historyPointer=0;
function backHistory() {
	if (historyStore[historyStore.length-1]) {
		historyPointer--;
		eval(historyStore[historyPointer]);
	}
}

function foreHistory() {
	if (historyPointer<(historyStore.length-1)) {
		historyPointer++;
		eval(historyStore[historyPointer]);
	}
	
}

function setHistory(pid,scompid) {
	if (!pid) { scompid=0; }
	if (!scompid) { 
		if (pid >0) {
			historyStore.push('getFirstPageNoHistory('+pid+')');
			
		} else {
			historyStore.push('getCovers()');
		}
	} else {
		historyStore.push('getSpreadNoHistory('+pid+','+scompid+')');
	}
	historyPointer++;
}

function reportHistory() {
	var str='';
	for (var i=0; i<historyStore.length; i++) {
		if (i != historyPointer) {
			str += "<br /><span style='color:Green'>" + historyStore[i] + '</span>';
		} else {
			str += "<br /><span style='color:Red'>" + historyStore[i] + '</span>';
		}
		
	}
	str += "<br/><br/><br/>";
	trace(str);
}

function getPages() {
	var str = "func=getPages"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getJoinForm() {
	var str = "func=getJoinForm"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function getLoginForm() {
	var str = "func=getLoginForm"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

var getFile='';
function getLoginFormAfterLoad(getFileArg) {
	var id;
	if (getFileArg) {
		getFile = getFileArg;
		trace('gona get the file');
		id = window.setTimeout(getLoginFormWithGetFile,2000);
	} else {
		trace('gonna log in');
		id = window.setTimeout(getLoginForm,2000);
	}
}

function getLoginFormWithGetFile() {
	var str = "func=getLoginForm&f="+getFile	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}
function logout() {
	var str = "func=logout"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}
function viewAllBooks() {
	var str = "func=getBookList"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function setBookListScroll(pid) {
	if (pid) {
		var id = 'bookList'+pid;
		var obj = document.getElementById(id);
		if (obj != null) {
			var topPos = obj.offsetTop;
			var obj2 = document.getElementById('bookListSleeve');
			if (obj2 != null && topPos >128) {
				obj2.scrollTop = topPos - 128;
			}
		}
	}
}
// edit Functions:

function buyBoxSet() {
		
	/*
***************************   Result of Box Set Management by Local Javascript Farmed HERE
	
	No Longer just addItemToBasket
	
	Revision to enforce box set children client side only
	Contents of box set set to server at THIS point
	
	
	
	loop through children of the bookListContainer and extract the numeric part of each ID
	each div is called 'boxBookList'+pid
	.. or 'bookList'+pid .. no changed to 'boxBookList'
	( wether added by server or by client ).
	
	
	consider currentBoxSetSize
	
	*/
	var valArray = new Array();
	var boxMemberParams='';
	var obj = document.getElementById('contentsListInner');
	if (obj != null) {
		var n = obj.childNodes.length;
		if (n>0) {
			var str='';
			var pid=0;
			var n1 = "boxBookList".length;
			
			for (var i=0; i<n; i++) {
				str = obj.childNodes[i].id;
				pid=0;
				if (str.length > n1) {
					pid = parseInt(str.substr(n1));
					valArray.push(pid);
				} else { trace('dead:'+obj.childNodes[i].id); }
			}
			if (valArray.length) {
				boxMemberParams = "&boxBookList="+valArray.join(',');
			}
		}
	}
	var checksOut = false;
	if (valArray.length == currentBoxSetSize) {
		checksOut = true;
	}
	
	if (checksOut) {
		
		addBoxSetToBasket(boxMemberParams,'buyBoxSet'); // see /lib/estall/shop.js
		
	} else {
		var n = valArray.length;
		var x = currentBoxSetSize-n;
		var y = n-currentBoxSetSize;
		if (n < currentBoxSetSize) {
			if (x==1) {
				noteBoxSetNotes("<p>Your Box Set is not full. Please add one more book.</p>");
			} else {
				noteBoxSetNotes("<p>Your Box Set is not full. Please add "+x+" more books.</p>");
			}
		}
		if (n > currentBoxSetSize) {
			if (y==1) {
				noteBoxSetNotes("<p>Your Box Set is over-full. Please remove a book.</p>");
			} else {
				noteBoxSetNotes("<p>Your Box Set is over-full. Please remove "+y+" books.</p>");
			}
		}
	}
}


function addBoxSetToBasket(boxMemberParams,func) {
	var obj = document.getElementById('basket');
	if (obj != null) {
		obj.style.display="block";
	}
	var uri = addToBasketScript+'?add=1&func='+func+'&dn='+domain+'&ref='+cookieValue+'&pid='+currentBoxSetPid+'&pcid='+currentPcid+'&addToBasketQty=1'+boxMemberParams;
//	trace(uri);
	sendToServer(uri);
}





/*
***************************   Box Set Management by Local Javascript goes below !!!


The following half a dozen functions need to be modified as we are going to change the process.
Instead of storing the box set shildren in the table solkit - before order capture
we will keep the data in memory HERE in javascript.

This then allows for a second set of stuff to happen when we come back to the Special Offer interface from the basket.

It all happens here .....

*/

/*
***************************   Reset-up interface after basket view :: Box Set Management by Local Javascript 
.. goes here

*/


function boxSetAddRemBook(pid) {
	if (currentBoxSetPid) {
		
		var str = "func=boxSetAddRemBook&pid="+currentBoxSetPid+"&childpid="+pid+"&ref="+cookieValue;
//	trace(str);
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	} else {
		// no currentBoxSetPid	
		noteBoxSet("<p>12 or 24 book Box Set?  Click the images above to select.</p>");
	}
}

function boxSetEditing(id){
		document.getElementById(id).checked = true;
}

function isAlreadyInList(pid) {
	var out = false;
	var obj = document.getElementById('contentsListInner');
	if (obj != null) {
		var n = obj.childNodes.length;
		for (var i=0; i<n; i++) {
			if (obj.childNodes[i].id=='boxBookList'+pid) {
				return true;
				break;
			}
		}
	}
	return out;
}

function boxSetAddBook(pid) {
	if (currentBoxSetPid) {
	//	var str = "func=boxSetAddBook&pid="+currentBoxSetPid+"&childpid="+pid+"&ref="+cookieValue;
	//	str = dataSourcePath + "?" + str;
	//	sendToServer(str);
		
		var spacing = 102; // px
		var obj = document.getElementById('contentsListInner');
		if (obj != null) {
			
			if ( currentBoxSetEmpty ) {
				obj.innerHTML = '';
			}
			var n = obj.childNodes.length;
			
			var contentsListWidth = (n+1)*spacing;
			if (contentsListWidth < 720) {
				contentsListWidth = 720;
			}
			obj.style.width = contentsListWidth + 'px';
			if ( !isAlreadyInList(pid) ) {
				if ( (n < currentBoxSetSize) ) {
	//				trace('bookList'+pid);
					var id = 'bookList'+pid;
					// copy and add as child to contentsListInner
					// obj.innerHTML += id;
					
					var srcObj = document.getElementById(id);
					if (srcObj != null) {
						var title = srcObj.firstChild.title;
						var srcObjImgId = document.getElementById( 'bookListImg'+pid );
						if (srcObjImgId) {
							var imgSrc = srcObjImgId.src;
							var alt = srcObjImgId.alt;
	//						trace('imgSrc: '+imgSrc);
							var str = "<div class=\"boxSetRemBookThumb\" id=\"boxBookList"+pid+"\"><a href=\"javascript:boxSetRemBook("+pid+")\" ><img src=\""+imgSrc+"\" title=\""+title+". (click to remove).\" alt=\""+alt+"\" style=\"border:none; opacity:1;\" /></a></div>";
							obj.innerHTML = str + obj.innerHTML;
							currentBoxSetEmpty = false;
							noteBoxSetNotes('');
							if (n==0) {
								populate('emptySlotsReport','[1] Book in box');
							} else {
								populate('emptySlotsReport','['+(n+1)+'] Books in box');
								if ( (n+1)==currentBoxSetSize) {
									noteBoxSetNotes('<p>Your box set is now full.</p>');
								}
							}
						}
					} else {
	//					trace ('naa');	
					}
				} else {
					// message	
					noteBoxSetNotes('<p>Your box set is <i>full</i>. </p>');
				}
			} else {
				// is in the list already
				var srcObjImgId = document.getElementById( 'bookListImg'+pid );
				if (srcObjImgId) {
					var imgSrc = srcObjImgId.src;
					var alt = srcObjImgId.alt;
					if (alt) {
						noteBoxSetNotes("<p>The book \'"+alt+"\' is already in your box set</p>");
					} else {
						noteBoxSetNotes('<p>The book is already in your box set</p>');
					}
				}
				
				
			}
		}
	} else {
		// no currentBoxSetPid	
		noteBoxSet("<p>12 or 24 book Box Set?  Click the images above to select.</p>");	
		
	}
}
function noteBoxSet(txt) {
	var obj = document.getElementById('contentsListInner');
	if (obj != null) {
		obj.innerHTML=txt;
		currentBoxSetEmpty = true; // 
	}
}
function noteBoxSetNotes(txt) {
	//trace('boxSetNotes: '+txt);
	var obj = document.getElementById('boxSetNotes');
	if (obj != null) {
		obj.innerHTML=txt;
	}
}
function boxSetRemBook(pid) {
	if (currentBoxSetPid) {
//		var str = "func=boxSetRemBook&pid="+currentBoxSetPid+"&childpid="+pid+"&ref="+cookieValue;
//		str = dataSourcePath + "?" + str;
//		sendToServer(str);
		// remove the object from contentsListContainer
		var obj = document.getElementById('contentsListInner');
		if (obj != null) {
			var obj1 = document.getElementById('boxBookList'+pid);
			if (obj1 != null) {
				obj.removeChild(obj1);
				var n = obj.childNodes.length;
				if (n==1) {
					populate('emptySlotsReport','['+(n)+'] Book in box');
				} else {
					populate('emptySlotsReport','['+(n)+'] Books in box');
				}
				noteBoxSetNotes('');
			}
		}
		
	} else {
		// no currentBoxSetPid	
		noteBoxSet("<p>12 or 24 book Box Set?  Click the images above to select.</p>");
	}
}
function clearOutContentsListInner(txt) {
	if ( txt ) {
		var obj = document.getElementById('contentsListInner');
		if (obj != null) {
			obj.innerHTML=txt;	
			currentBoxSetEmpty = true;
			var contentsListWidth = 720;
			obj.style.width = contentsListWidth + 'px';
		}
	}
}
var currentBoxSetEmpty = true;
var currentBoxSetSize=0;
var currentPcid=0;
function setCurrPackToBoxSet(pid,pcid,id,size) {
//	trace('pid: '+pid+' size: '+pid+' pcid: '+pcid);
	if (pcid) {
		currentPcid=pcid;
	}
	clearOutContentsListInner('&nbsp;');
	if (pid) {
		currentBoxSetPid = pid;	
	}
	if (size) {
		currentBoxSetSize = size;
	}
	populate('emptySlotsReport','['+size+'] Books in box');
	if (!cookieValue) {
		trace('no cookie ! no go!');	
	} else {
		// product, catalogue and div identifiers
		// check the status of the checkbox using ID
		// send pid and picid off to server
		// server adds (or removes) the Pack described by picid
		// server returns the current Kit's contents, as text to 
		var add = 0;
		var obj = document.getElementById(id);
		if (obj!=null && obj.type=="checkbox") {
			if (obj.checked == false) {	add=0; }
		}
		var str = "func=setCurrPackToBoxSet&pid="+currentBoxSetPid+"&pcid="+pcid+"&add="+add+"&ref="+cookieValue;
	//trace(str);
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function setCurrentBoxSet(pid,rowID,vcq) {
	currentBoxSetSize=0;
	populate('emptySlotsReport','[0] Books in box');
	if (vcq) {
		currentBoxSetSize = vcq;
	}
	if (pid) {
		
		currentBoxSetPid = pid;
		setSelectedBoxSet(rowID);
		noteBoxSet("<p>There are "+currentBoxSetSize+" slots available in your boxset.<br />Please click the books on the right to add them to your box set.</p><p>To <i>remove</i> a book click the book covers that appear here.</p>");
		// shop.js :: addItemToBasket : 
		// addItemToBasket(pid,catid,numberOfSelectors,domain,func)
		// var uri = siteRoot+addToBasketScript+'?func='+func+'&dn='+domain+'&ref='+cookieValue+'&pid='+pid+'&catId='+catid+'&addToBasketQty='+addToBasketQty+versionParams;

		var str = "func=setCurrentBoxSet&pid="+pid+"&row="+rowID+"&ref="+cookieValue	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function viewCurrentBoxSet() {
	if (currentBoxSetPid) {
		
		var str = "func=viewCurrentBoxSet&pid="+currentBoxSetPid+"&ref="+cookieValue	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function specialOfferBoxSet(pid){
	//Turn off the small images
	boxsets = document.getElementsByClassName('boxSetImage');
	i=0;
	while(i<boxsets.length){
		boxsets[i].style.display = "none";
		i++;
	}
	boxsets = document.getElementsByClassName('boxSetImageBig');	//Go back to default state of no large img
	i=0;
	while(i<boxsets.length){
		boxsets[i].style.display = "none";
		i++;
	}
	if(pid && document.getElementById('boxSetImageBig'+pid)){	//turn on the large images
		document.getElementById('boxSetImageBig'+pid).style.display = "block";
	}
}
function setSelectedBoxSet(id) {
	var list = document.getElementById('boxSetsList');
	if (list !=null) {
		for (var i=0; i<list.childNodes.length; i++) {
			list.childNodes[i].style.backgroundImage="none";
		}
	}
	var obj = document.getElementById(id);
	if (obj !=null) {
		obj.style.backgroundImage="url(/graphics/browser/boxSetRowHover.png)";
	}
	clearOutContentsListInner('&nbsp;');
	
}












function addKeyword() {
	var str = "func=addKeyword";
	var obj = document.getElementById('opNewKw');
	if (obj != null) {
		var newKw = obj.value;
		if (newKw != '') {
			str += "&newKw="+newKw;
			str = dataSourcePath + "?" + str;
			sendToServer(str);
		}
	}
}

function removeKeyword() {
	var str = "func=removeKeyword"	;
	var obj = document.getElementById('opRemKwSelect');
	if (obj != null) {
		var opRemKw = obj.value;
		if (opRemKw != 0) {
			str += "&remKw="+opRemKw;
			str = dataSourcePath + "?" + str;
			sendToServer(str);
		}
	}
}

function addBook() {
	var str = "func=addBook"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function addOtherBook() {
	var str = "func=addOtherBook"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function addBoxset(bSid) {
	if(bSid){
		var str = "func=addBoxset&bsid="+bSid;
	}
	else{
		var str = "func=addBoxset";
	}
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function editBoxSetBook(book,boxset){
	if(boxset){
		var str = "func=editBoxSetBook&bSid="+boxset+"&bookid="+book;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function deleteBoxSetInfo(bsid){
	if(bsid){
		var str = "func=deleteBoxSetInfo&bSid="+bsid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function editBoxSetInfo(bsid){
		//get info from other elements
		bSName = escape(document.getElementById('bSName').value);//Grabs name as text
		var str = "func=editBoxSetInfo&bSid="+bsid+"&name="+bSName;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
}

function editSeq() {
	var str = "func=editSeq"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function selectBookToSeq(pid) {
	if (pid) {
		var str = "func=selectBookToSeq&pid="+pid	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function selectBookToEditor() {
	var pid=0;
	var obj = document.getElementById('bookEditSelector');
	if (obj !=null) {
		pid = obj.value;	
	}
	if (pid) {
		var str = "func=bookNewWiz&step=1&pid="+pid	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function selectOtherBookToEditor() {
	var pid=0;
	var obj = document.getElementById('bookEditSelector');
	if (obj !=null) {
		pid = obj.value;	
	}
	if (pid) {
		var str = "func=bookOtherNewWiz&step=1&pid="+pid	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function selectAuthorToEditor() {
	var aid=0;
	var obj = document.getElementById('authorEditSelector');
	if (obj !=null) {
		aid = obj.value;	
	}
	if (aid) {
		var str = "func=bookNewWiz&step=2&aid="+aid	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function selectOtherAuthorToEditor() {
	var aid=0;
	var obj = document.getElementById('authorEditSelector');
	if (obj !=null) {
		aid = obj.value;	
	}
	if (aid) {
		var str = "func=bookOtherNewWiz&step=2&aid="+aid	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}
function scrollToSeqLnk(pid) {
	var id = 'seqLnk'+pid;
	var obj = document.getElementById(id);
	if (obj != null) {
		var top = obj.offsetTop - 180;
		if (top < 0) { top=0; }
		var obj2 = document.getElementById('bookSeqScrollSleeve');
		if (obj2 != null) {
			obj2.scrollTop = top;
		}
	}
}

function editSeqUp() {
	var str = "func=editSeqUp"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function editSeqDown() {
	var str = "func=editSeqDown"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function editSeqStarred(pid) {
	if(pid){
		var str = "func=editSeqStarred&pid="+pid;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	}
}

function releaseBook() {
	var str = "func=releaseBook"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function suspendBook() {
	var str = "func=suspendBook"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function addPages() {
	var str = "func=addPages"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function createRelationship() {
	var str = "func=createRelationship"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function addFriend() {
	var str = "func=addFriend"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

// articulation , read and edit -
var commentsOpen = false;
var commentsActive = false;
function allowComments(bool) {
	if (bool) {
		commentsActive = true;
	} else {
		commentsActive = false;
	}
	var but = document.getElementById('comments');
	if (but != null) {
		if (commentsActive) {
			but.style.opacity="1";
		} else {
			but.style.opacity="0";
		}
	}
	var comCount = document.getElementById('eNbbCommentsCount');
	if (comCount != null) {
		if (commentsActive) {
			comCount.style.opacity="1";
		} else {
			comCount.style.opacity="0";
		}
	}
	
}

var recomActive=false;
function allowRecom(bool) {
	if (bool) {
		recomActive=true;
	} else {
		recomActive=false;
	}
	var arl = document.getElementById('authorsRecomList');
	if (arl != null) {
		if (recomActive) {
			arl.style.opacity="1";
		} else {
			arl.style.opacity="0";
		}
	}
}
function comments() {
	 //  call up associated comments to the current scomp - along with the comments submission form.
	 if (commentsActive) {
		 openComments();
		var str = "func=comment"	;
		str = dataSourcePath + "?" + str;
		sendToServer(str);
	 }
}

function commentsOpenClose() {
	var obj = document.getElementById("eNbbComments");
	if (obj != null) {
		if (obj.style.display == "block") {
			closeComments();
		} else {
			comments();
		}
	}
}

function openComments() {
	 if (commentsActive) {
		var obj = document.getElementById("eNbbComments");
		if (obj != null) {
	//		obj.style.top = '805px'; // 30*8 = 240 pixels of slide -> 565
			// 30*8 = 240 pixels of slide -> 550  .. so start at 790
			obj.style.top = '790px'; 
			obj.style.display = "block";
			commentSlideUp();
			commentsOpen = true;
		}
	 }
}

function closeComments() {
	var obj = document.getElementById("eNbbComments");
	if (obj != null) {
		commentSlideDown();
		commentsOpen = false;
	} 
}

var commentSlideTimeout=null;
var commentSlideCounter=0;
function commentSlideUp() {
	commentSlideCounter++;
	if (commentSlideCounter > 30) {
		clearTimeout(commentSlideUp);
		commentSlideCounter=0;
	} else {
		commentSlideTimeout = window.setTimeout(commentSlideUp,10);
	}
	var commentObj = document.getElementById('eNbbComments');
	if (commentObj != null) {
		commentObj.style.top = ( commentObj.offsetTop - 8 ) + 'px';
	}
}

function commentSlideDown() {
	commentSlideCounter++;
	var commentObj = document.getElementById('eNbbComments');
	if (commentObj != null) {
		
		if (commentSlideCounter > 30) {
			clearTimeout(commentSlideUp);
			commentSlideCounter=0;
			commentObj.style.display = "none";
			commentObj.innerHTML = "";
		} else {
			commentSlideTimeout = window.setTimeout(commentSlideDown,10);
		}
	
		commentObj.style.top = ( commentObj.offsetTop + 8 ) + 'px';
	}
}

function highlightPageRight() {
	//  eNbbPageDisplay
	var obj = document.getElementById("eNbbPageDisplay");
	if (obj != null) {
		obj = obj.style;
		obj.backgroundImage="url("+siteRoot+"graphics/browser/stageHighlightRight.png)";
	}
}

function highlightPageLeft() {
	var obj = document.getElementById("eNbbPageDisplay");
	if (obj != null) {
		obj = obj.style;
		obj.backgroundImage="url("+siteRoot+"graphics/browser/stageHighlightLeft.png)";
	}
}

function unHighlightPage() {
	var obj = document.getElementById("eNbbPageDisplay");
	if (obj != null) {
		obj = obj.style;
		obj.backgroundImage="url("+siteRoot+"graphics/browser/stage.png)";
	}
}

// General Function below

/*

	in order to allow the server to kick visitors out if the page is left up but not changed
	we have a regular poll.
	The poll only runs if no request has been sent for the interval in question
	
	The poll does not need to ask for anything as the manageAccess function issues it's own stuff
	If the user is logged in - then leaves the computer up - we should have no problem with access.
	Their session should be maintained by the access poll.

*/

function pollForAccess() {
	clearTimeout(pollForAccessTimeout);
	pollForAccessTimeout = window.setTimeout(pollForAccess,pollForAccessPeriod);
	var str = dataSourcePath + "?func=poll";
	sendToServer(str);
}

function nonRootInit(delayedCall) {
	if( !window.XMLHttpRequest && window.ActiveXObject ) {
		window.XMLHttpRequest = function() {
		var a = [ 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.5.0' ],
		i = a.length; 
		while(i--) 
		{
			try {
			return new ActiveXObject( a[i] );
			alert(a[i]);
			} catch (e) { alert(e); }
			}
			return null;
		};
	}
	if( window.XMLHttpRequest ) {
	 xmlhttp = new XMLHttpRequest();  
	}
	if (createXMLHttpObject() && autoXhrMode) {
		lastLocation="";
		xhr=true;
	}
	initCookie(cookieName); // see shop.js in the estall library
	pollForAccessTimeout = window.setTimeout(pollForAccess,pollForAccessPeriod);
	var str = "func=getSearchForm"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
	preloadGraphics();
	window.setTimeout(delayedCall,500);
}

function init() {
	if( !window.XMLHttpRequest && window.ActiveXObject ) {
		window.XMLHttpRequest = function() {
		var a = [ 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.5.0' ],
		i = a.length; 
		while(i--) 
		{
			try {
			return new ActiveXObject( a[i] );
			alert(a[i]);
			} catch (e) { alert(e); }
			}
			return null;
		};
	}
	if( window.XMLHttpRequest ) {
	 xmlhttp = new XMLHttpRequest();  
	}
	if (createXMLHttpObject() && autoXhrMode) {
		lastLocation="";
		xhr=true;
	}
	initCookie(cookieName); // see shop.js in the estall library
	pollForAccessTimeout = window.setTimeout(pollForAccess,pollForAccessPeriod);
	var str = "func=getip,getCovers,getSearchForm"	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
	preloadGraphics();
	displayKwSuggestions(false);	
}

function preloadGraphics() {
	var img1 = new Image();
	img1.src = siteRoot+"graphics/browser/stageHighlightLeft.png";
	var img2 = new Image();
	img2.src = siteRoot+"graphics/browser/stageHighlightRight.png";
	var img3 = new Image();
	img3.src = siteRoot+"graphics/browser/WBwebsiteSpecialOffersBackground.jpg";
	
	/*
	SpecialOffersHeading.png
	
	etc etc..
	please provide ..
	 - see page template for all css url calls (not css file)
	*/
}
function initOther() {
	if( !window.XMLHttpRequest && window.ActiveXObject ) {
		window.XMLHttpRequest = function() {
		var a = [ 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.5.0' ],
		i = a.length; 
		while(i--) 
		{
			try {
			return new ActiveXObject( a[i] );
			alert(a[i]);
			} catch (e) { alert(e); }
			}
			return null;
		};
	}
	if( window.XMLHttpRequest ) {
	 xmlhttp = new XMLHttpRequest();  
	}
	if (createXMLHttpObject() && autoXhrMode) {
		lastLocation="";
		xhr=true;
	}
	initCookie(cookieName); // see shop.js in the estall library
	var str = "func=getip,getOtherBookList";
	str = dataSourcePath + "?" + str;
	sendToServer(str);
	var img1 = new Image();
	img1.src = siteRoot+"graphics/browser/stageHighlightLeft.png";
	var img2 = new Image();
	img2.src = siteRoot+"graphics/browser/stageHighlightRight.png";
	var img3 = new Image();
	img3.src = siteRoot+"graphics/browser/WBwebsiteSpecialOffersBackground.jpg";
	
	
}

function createXMLHttpObject() {
	if( window.XMLHttpRequest ) {
		xmlhttp = new XMLHttpRequest();
		return true;
	} else {
		return false;
	}
}

function sendToServer(uri) {
	// Create an XMLHttpRequest and open it.
	// send the request with it's parameter string 
	// the response will be in the form of a string of javascript function calls
	// the response is then evaluated using eval(string)
	if (uri) {
		//trace('send: '+uri);
		if (uri.substr(0,1) != "/") { uri="/"+uri; };
		xmlhttp = null;
		createXMLHttpObject();
		pathForTheRecord=uri;
		xmlhttp.open("GET", uri, true);
		xmlhttp.onreadystatechange = evaluateServerResponse; // NOTE: No Brackets on the end or it will NOT work.
		//xmlhttp.initialise;
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		loading('1','Loading');
		xmlhttp.send(null);
	}
}

function postToServer(params) {
	var uri = dataSourcePath;
	if (uri.substr(0,1) != "/") { uri="/"+uri; };
	xmlhttp = null;
	createXMLHttpObject();
//	populate('eNbbPageBrowser',(uri+params));
	xmlhttp.open("POST", uri, true);
	xmlhttp.onreadystatechange = evaluateServerResponse; // note the absence of brackets!
	//xmlhttp.initialise;
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	loading('1','Loading');
	xmlhttp.send(params);
}

function loading(s,n) {
	var obj=document.getElementById('xhrReportImage');
	if (obj!=null) {
		switch(s) {
			case '1':
				obj.src=xhrActiveGraphic;
			break;
			case '0':
				obj.src=xhrStoppedGraphic;
			break;
		}
	} else {
		alert("L'xhrReport n'existe pas!");
	}
}

function evaluateServerResponse() {
	if (xmlhttp.readyState == 4) {
			
			if (xmlhttp.status == 200) {
				
				var xhrString = xmlhttp.responseText;
	
				xhrString = xhrString.replace("\n",'');
				xhrString = xhrString.replace("~amp~",'&amp;');
				
				if (xhrString.indexOf('<b>Warning</b>:')!=-1 || xhrString.indexOf('<!DOCTYPE HTML PUBLIC')!=-1) {
					note('Server-side error! - header received');
					
					trace(xhrString);
					xhrString="";
				}
				if (xhrString.indexOf('<b>Parse error</b>:')!=-1) {
					note('Server-side error! - parse error');
					
					trace(xhrString);
					xhrString="";
				}
				if (xhrString.indexOf('<b>Fatal error</b>:')!=-1) {
					note('Server-side error! - Fatal error');
					
					trace(xhrString);
					xhrString="";
				}
				if (xhrString.indexOf('<b>Notice</b>:')!=-1) {
					note('Server-side Notice');
					
					trace(xhrString);
					xhrString="";
				}
				if (xhrString) {
					try {
						eval(xhrString);
						loading('0','Complete');
					}
					catch(err) {
						note(err);
						trace(xhrString);
						loading('0','Complete');
					}
				}
			
		} else {
			if (xmlhttp.status==0) {
			} else {
			alert("Error!\n The server returned the following error code: "+xmlhttp.status+"\nRequested path: "+pathForTheRecord);
			loading('0','Complete');
			}
		} // end state 200
	} else {
		if (xmlhttp.readyState == 3) {
		}	
		
	} // end ready state 4
}
var traceCalls=0;
function trace(t) {
	var traceOutputDiv = document.getElementById('debugDiv');
	if (traceOutputDiv != null) {
		var traceString = traceOutputDiv.innerHTML;
		
		if (traceOutputDiv != null) {
			traceOutputDiv.innerHTML = t+'<br/>| '+traceString;
			traceCalls++;
			traceOutputDiv.style.width="300px";
			traceOutputDiv.style.height="auto";
			traceOutputDiv.style.overflow="auto";
			traceOutputDiv.style.backgroundColor="#000000";
			traceOutputDiv.style.color="#FFFFFF";
		}
	}
}
function clearTrace() {
	var traceOutputDiv = document.getElementById('debugDiv');
	if (traceOutputDiv != null) {
		traceOutputDiv.innerHTML = "";
	}
}
var noteTimeout=null;
function note(t) {
	var obj=document.getElementById('errorNote');
	if (obj != null) {
		obj.innerHTML = t;
		noteTimeout = window.setTimeout('clearNote()',4000);
	}
}
function clearNote() {
	var obj=document.getElementById('errorNote');
	window.clearTimeout(noteTimeout);
	if (obj != null) {
		obj.innerHTML = '';
	}
}

function populate(d,t) {
	if (d == "eNbbPageDisplay") {

		pageTransition(t);
		
	} else {
		var element = document.getElementById(d);
		if (element != null) {
			element.innerHTML = t;
		}	
	}
}

function setValue(inpt,val) {
	if (val) {
		var obj=document.getElementById(inpt);
		if (obj != null) {
			obj.value=val;	
			var obj1 = document.getElementById('kwSuggestions');
			if (obj1 != null) {
				obj1.innerHTML = '';
				postFormData('searchKwForm');
				kwSrow=0;
			}
		}
	}
}
function getKwSearch(txt) {
	var obj=document.getElementById('ssKw');
	if (obj != null) {
		obj.value=txt;
		postFormData('searchKwForm');
	}
}
function getKwSuggestions(e) {
	var keyNum; 
	keyNum= e.keyCode;
	if ((keyNum != 13)&&(keyNum != 37)&&(keyNum != 38)&& (keyNum != 39)&& (keyNum != 40)){
		var obj=document.getElementById('ssKw');
		if (obj != null) {
			var kw=obj.value;
			var str = "func=getKwSuggestions";
			str += "&kw="+kw+'&kwSrow='+kwSrow;
			str = dataSourcePath + "?" + str;
			sendToServer(str);
		}
	}
}
var kwSrow=0;
var kwsRows=0;
function rowMove(e) {
	var keynum;
	/*
	if(window.event) {
	  keynum = e.keyCode;
	} else if(e.which) {
	  keynum = e.which;
	}*/
	keynum = e.keyCode;
	kwSrow=1;
	var kwSuggestions = document.getElementById('kwSuggestions');
	if (kwSuggestions != null) {
		//trace('js kwSrow: '+kwSrow);
		switch(keynum) {
			case 38:
				kwSrow = kwSrow - 1 * ( kwSrow > 0 );
			//	kwSrow--;
			break;
			case 40:
				kwSrow = kwSrow + 1 * ( kwSrow < (kwsRows-1) );
			//	kwSrow++;
			break;
			case 13:			
				//setValue('ssKw',kwSuggestions.childNodes[kwSrow].innerHTML);
			var obj=document.getElementById('ssKw');
			if (obj != null) {
				
				if (kwSuggestions.childNodes[kwSrow]) {
					
					obj.value=kwSuggestions.childNodes[kwSrow].innerHTML;	
					var obj1 = document.getElementById('kwSuggestions');
					if (obj1 != null) {
						obj1.innerHTML = '';
				//		trace('postFormData');
						postFormData('searchKwForm');
						kwSrow=0;
					}
				} else {
					if (obj.value != '') {
						postFormData('searchKwForm');	
					}
				}
			}
			break;
		}
	} else {
		kwSrow = 1;
	}
	if (kwSrow < 1) {
		displayKwSuggestions(false);	
	} else {
		displayKwSuggestions(true);		
	}
	if (kwSrow>=0) {
		if (kwSrow < kwSuggestions.childNodes.length) {
			hightlightKwSuggestRow();
		}
	} else {
		kwSrow=0;
	}
}
function displayKwSuggestions(bool) {
	var kwSuggestions = document.getElementById('kwSuggestions');
	if (kwSuggestions != null) {
		if (bool) {
			kwSuggestions.style.display='block';
		} else {
			kwSuggestions.innerHTML = '';
			kwSuggestions.style.display='none';
		}
	}
}
function hightlightKwSuggestRow() {
	var kwSuggestions = document.getElementById('kwSuggestions');
	var kwSrowInput = document.getElementById('kwSrowInput');
	if (kwSrowInput != null) {
		kwSrowInput.value = kwSrow;	
	}
	for (var i=0; i<kwSuggestions.childNodes.length; i++) {
		if (i == kwSrow) {
			kwSuggestions.childNodes[i].style.backgroundColor='#CCCCCC';
			// set scroll
			var kwrSt = kwSuggestions.childNodes[i].offsetTop;
			kwSuggestions.scrollTop=kwrSt;
		} else {
			kwSuggestions.childNodes[i].style.backgroundColor='#FFFFFF';
		}
	}
}
function swapImage(id,src) {
	var img = document.getElementById(id);
	if (img != null) {
		img.src=src;
	}
}

var currentPage = 2;

var goingImageArray = new Array();
var comingImageArray = new Array();


function pageTransition(t) {
	if (t) {
		var page1 = document.getElementById("page1");
		var page2 = document.getElementById("page2");
		
		if (page1 != null && page2 != null) {
			/*
			.. but
			if it's a form then DO not otherwise we get two sets of form onjects and that stops us using focus .. every other time ..
		*/	
			if (allowPageTransition ) {
	
				if (currentPage == 1) {
					
					page2.style.display="none";
					page2.innerHTML = t;
				//	page2.style.display = "block";
				//	page1.style.display = "none";
					if (faderMode == "fade") {
						goingImageArray = page1.getElementsByTagName("img");
						comingImageArray = page2.getElementsByTagName("img");
						
						for (var i=0; i<comingImageArray.length; i++) {
							setImageOpacity(comingImageArray[i],1);
						}
						
					}
					page2.style.display="block";
					
				//	reportImages(comingImageArray);
					
					page2.style.zIndex = 100;
					page1.style.zIndex = 99;
					fader(page1,page2);
					
					currentPage = 2;
				} else {
					
					page1.style.display="none";
					page1.innerHTML = t;
					
					if (faderMode == "fade") {
						goingImageArray = page2.getElementsByTagName("img");
						comingImageArray = page1.getElementsByTagName("img");
						
						
						for (var i=0; i<comingImageArray.length; i++) {
							setImageOpacity(comingImageArray[i],1);
						}
					}
					page1.style.display="block";
				//	page1.style.display = "block";
				//	page2.style.display = "none";
					
					page1.style.zIndex = 100;
					page2.style.zIndex = 99;
					fader(page2,page1);
					
					currentPage = 1;
				}
			} else {
				if (currentPage == 1) {
					page1.innerHTML = t;
				}else {
					page2.innerHTML = t;
				}
				allowPageTransition = true;
			}
		}
	}
}

function reportImages(arr) {
	for (i=0; i<arr.length; i++) {
	}
}

var fadeOutObject;
var fadeInObject;
var fadeCounter;
var fadeTimeout;
var slideDirection="left"; // se next() and previous()

//var faderMode = "slide"; // or fade .. or whatever
var faderMode = "fade";

function fader(going,coming) {

	fadeOutObject = going;
	fadeInObject=coming;
	fadeCounter=0;
	switch (faderMode) {
		case "fade":
			fadeTimeout = window.setTimeout(processFade,1);
		break;
		case "slide":
			if (slideDirection=="left") {
				fadeInObject.style.left = "1000px";
			} else {
				fadeInObject.style.left = "-1000px";
			}
			fadeTimeout = window.setTimeout(processSlide,1);
		break;
	}
}

function processFade() {
	fadeCounter+=10;
	var n = fadeCounter;
	for (var i=0; i<goingImageArray.length; i++) {
		setImageOpacity(goingImageArray[i],(100-n));
	}
	for (var i=0; i<comingImageArray.length; i++) {
		setImageOpacity(comingImageArray[i],n);
	}
	if (fadeCounter < 100) {
		fadeTimeout = window.setTimeout(processFade,1);
	} else {
		window.clearTimeout(fadeTimeout);
		fadeOutObject.innerHTML='';
		closeComments();
	}
}

function processSlide() {
	fadeCounter++;
	
	if (slideDirection=="left") {
		fadeOutObject.style.left = ( fadeOutObject.offsetLeft - 20 ) + "px";
		fadeInObject.style.left = ( fadeInObject.offsetLeft - 20 ) + "px";
	} else {
		fadeOutObject.style.left = ( fadeOutObject.offsetLeft + 20 ) + "px";
		fadeInObject.style.left = ( fadeInObject.offsetLeft + 20 ) + "px";
	}
	if (fadeCounter < 50) {
		fadeTimeout = window.setTimeout(processSlide,1);
	} else {
		window.clearTimeout(fadeTimeout);
		closeComments();
	}
}

var IE = false;
function setImageOpacity(obj,num) {
	//var obj = ie4?eval("document.all."+which):document.getElementById(which);
	
	if (obj != null) {
		if (IE) {
			if (obj.filters.alpha != null) {
				try {obj.filters.alpha.opacity=num;} catch (err) {}; //alert('obj filters'); 
			}
		} else {
			if (obj.style.MozOpacity) {
				obj.style.MozOpacity=num/100; 
			}
			if (obj.style.opacity) {
				obj.style.opacity=num/100; 
			}
			if (obj.style.setProperty) {
				var n = num/100;
				try {obj.style.setProperty('-khtml-opacity',n,null); } catch (err) {};
			}
		}
	}
}

function loadImage(path) {
	
	var img = new Image();
	img.src = path;
	
}

function postFormData(formName) {
	var paramArray = new Array();
	var params = "";
	var fldValuesArray = new Array();
	var checksArray = new Array();
	var fieldArray = new Array();
	var n=0;
	if (formName && document.forms[formName] !=null) { n= document.forms[formName].elements.length; }
	var paramsArray = new Array();
	var str='';
	
	for (var i=0; i<n; i++) {
		var str = document.forms[formName].elements[i].id;
		
		if (document.forms[formName].elements[i].name != 'undefined') {
			if (document.forms[formName].elements[i].type!="hidden") {
				if (document.forms[formName].elements[i].type!="checkbox") {
					if(document.forms[formName].elements[i].type=="radio"){
						if(document.forms[formName].elements[i].checked==true){
							fldValuesArray[i]= document.forms[formName].elements[i].value;
							fieldArray[i]=document.forms[formName].elements[i].id;
						}
					}
					else{
						fldValuesArray[i]=document.forms[formName].elements[i].value;
						fieldArray[i]=document.forms[formName].elements[i].id;
					}
				} else {
					fieldArray[i]=document.forms[formName].elements[i].id;
					if (document.forms[formName].elements[i].checked) {
						fldValuesArray[i]=document.forms[formName].elements[i].value;
					} else {
						fldValuesArray[i]=0;
					}
				} // end checkbox
			} else {
				fldValuesArray[i]=document.forms[formName].elements[i].value;
				fieldArray[i]=document.forms[formName].elements[i].id;
			} // end if hidden
		} // end if document.forms[formName].elements[i].name
	
	} // end for i
	
	
	var formSaveReport='';
	if (fieldArray.length>0 && fldValuesArray.length>0) {
		for (var i=0; i<fieldArray.length; i++) {
			if (fldValuesArray[i]) {
				var temp = fldValuesArray[i].split('&');
				fldValuesArray[i] = temp.join("~amp~");
			}
			paramArray.push(fieldArray[i] + "=" + fldValuesArray[i]);
		}
	}
	if (checksArray.length>0 && chkValuesArray.length>0) {
		for (var i=0; i<checksArray.length; i++) {
			paramArray.push(checksArray[i] + "=" + chkValuesArray[i]);
		}
	}
	params = '&'+paramArray.join("&");
	if (params) {
		postToServer(params);
	}
}

function scrollPageBodyToTop() {
	var obj=document.getElementById('page1');
	if (obj != null) {
		obj.scrollTop=0;
	}
	var obj=document.getElementById('page2');
	if (obj != null) {
		obj.scrollTop=0;
	}
}

function generateBook(pid) {
	var str = "func=generateBook&pid="+pid	;
	str = dataSourcePath + "?" + str;
	sendToServer(str);
}

function showShopPanel() {
	// included as dummy - called by eStall - only needed for Conducta implementation - not for eNbb
	//document.getElementById('shopPanel').style.display = "block";
}
var delayedArgs='';
var getProductGalleryDelayedTimeout=null;
function flashUploadReturn() {
	var sw = flashUploadReturn.arguments[0];
	var pid = flashUploadReturn.arguments[1];
	delayedArgs='com=productBuild&pid='+pid;
	getProductGalleryDelayedTimeout = window.setTimeout('getDelayedCommand()',1000);
}
function getDelayedCommand() {
	// populate the gallery dic - it's called picid
	// retrieve the thumbnail file associated with the galleryline records that, in turn, are associated by quoting the pid.
	//var params =delayedArgs;
	//sendToServer('/lib/eNbb/conf/app/dataSource.php?'+params);
	// javascript:getAuthorReccomList()
	getAuthorReccomList();
}

