function toggleMoreBooks() {
	animatedcollapse.show('apachesolr-hide');
	$('#apachesolr-hide-link').html('<a class="book-link" href="/zip-ajax.php?isbn=0">Find More Books at the Website of a Bookstore Near You &gt;&gt;</a>');
}

function toggleMoreStores() {
	animatedcollapse.show('apachesolr-hide');
	$('#apachesolr-hide-link').html('<a href="/indie-store-finder?storetype=1">Find more great Indie Bookstores on the Indie Store Finder Map &gt;&gt;</a>');
}

function wishlistOp(op, rel_count, qid, isbn, lid, uid, addbutton, removebutton) {
	$('#wishlink-'+rel_count).html('<img src="/sites/all/themes/indiebound/images/loading.gif" />');
	$.post("/wishlist.php", { op: op, rel_count: rel_count, id: qid, isbn: isbn, lid: lid, uid: uid, addbutton: addbutton, removebutton: removebutton }, function(ajaxmsg) {	
	 if (ajaxmsg.substring(0,1) == 'e') {
		 alert("Warning! You can have a maximum of 100 books on each list.  This book was not added.  Please create a new list to continue adding books.");
		 $('#wishlink-'+rel_count).html(ajaxmsg.substring(1));
	 }
	 else {
		 $('#wishlink-'+rel_count).html(ajaxmsg);
	 }
	if (uid > 0) reArrange(lid,uid,0,0);
	}, "text");
}

function wishlistAdd(uid, lid, isbn, msg) {
	$('#wishlink-1').html('<img src="/sites/all/themes/indiebound/images/loading.gif" />');
	 msg = (typeof msg == 'undefined') ? '0' : msg;
	$.post("/wishlist.php", { op: 'addajaxpost', msg: msg, isbn: isbn, uid: uid, lid: lid }, function(ajaxmsg) {
	 if (ajaxmsg.substring(0,1) == 'e') {
		 alert("Warning! You can have a maximum of 100 books on each list.  This book was not added.  Please create a new list to continue adding books.");
			$('#wishlink-1').html('<a href="/wishlist.php?op=addajax&uid='+uid+'&isbn='+isbn+'" class="book-link"><img src="/sites/all/themes/indiebound/images/book-btn-bladd.gif" alt="Add this book to my book lists" /></a>');
			$(document).trigger('close.facebox');
	 }
	 else {
		$('#wishlink-1').html('<a href="/user/'+uid+'/lists"><img src="/sites/all/themes/indiebound/images/book-btn-blremove.gif" alt="Add this book to my book lists" /></a>');
		$(document).trigger('close.facebox');
	 }
}, "text");
}

function wishlistMail(mailfrom, mailto, mailmsg, uid, lid, buddies) {
	 mailmsg = (typeof mailmsg == 'undefined') ? '0' : mailmsg;
	$('#wishlist-mail').html('<p>&nbsp;</p><p>&nbsp;</p><center><img src="/sites/all/themes/indiebound/images/loading.gif" /><br clear="all" />Sending email...</center>');
	$.post("/wishlist.php", { op: 'sendmail', from: mailfrom, to: mailto, msg: mailmsg, uid: uid, lid: lid, id: buddies }, function(ajaxmsg) {
		$('#wishlist-mail').html(ajaxmsg);
	});
}

function makeAffiliateLink(aid,isbn) {
	var img = 'http://images.booksense.com/images/books/' + isbn.substring(10) + '/' + isbn.substring(7, 10) + '/FC' + isbn + '.JPG';
	$('#yourID').html('<em>Just copy & paste this code into your website:</em><br /><textarea rows="6" cols="30" readonly>&lt;a href=&quot;http://www.indiebound.org/book/'+isbn+'?aff='+aid+'&quot;&gt;&lt;img src=&quot;'+img+'&quot; /&gt;&lt;br /&gt;Shop Indie Bookstores&lt;/a&gt;</textarea><br /><br /><strong>Here\'s what your link will look like:</strong><br /><div style="text-align: center; border: 1px solid #000; padding: 8px;"><a href="http://www.indiebound.org/book/'+isbn+'?aff='+aid+'"><img src="'+img+'"><br />Shop Indie Bookstores</a></div>');
}

function textCounter( field, countfield, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    return false;
  }
  else
  {
    countfield.value = maxlimit - field.value.length;
  }
}

function wopen(url, name, w, h)
{
w += 32;
h += 96;
 var win = window.open(url,
  name,
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=no, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}

$(document).ready(function() {
	animatedcollapse.addDiv('apachesolr-hide','fade=1');
	animatedcollapse.init();
});
