// This file contains various site functions that are used on various 
// pages so have been moved to the sitelayout.jsp
/*-------------------------------------------------------------------* 
 * Programmer: Robert Giddings                Date: 12/01/2011       *
 *                                            Version: 2             *
 * Standards : v1.15                          Project: SDR00552      *
 * Reason: 	Added document.addToBasketForm.qty.value=1; to reset 	 *
 *			value that might be in the session due to manual buy now *
 *			qty box. The buy now buttons that use this method don't  *
 *			have a qty box next to them, but they use the same 		 *
 *			action.											         *
 *-------------------------------------------------------------------* 
 * Programmer: Robert Giddings                Date: 01/03/2011       *
 *                                            Version: 3             *
 * Standards : v1.15                          Project: SDR00552      *
 * Reason: 	Made addToBasket() ajax based.						   	 *
 *-------------------------------------------------------------------*/
function validateSearch1(form) {
	if (form.frmSearchString.value == "") {
    	alert("Please enter a keyword.");
        form.frmSearchString.focus();
        return false;
	}
	return true;
}

function authorSearch(author) {
	if (!((author == "") || (author == " ") || (author.indexOf("*") > -1))) {   
		jQuery(".searchBox").val("");
		document.QuickSearchForm.author.value = author;
       	document.QuickSearchForm.submit();
	}
}

function keywordSearch(keywords) {
	if(jQuery.trim(keywords) != "" && keywords.indexOf("*") == -1) {
		jQuery(".searchBox").val(keywords);
		document.QuickSearchForm.submit();
	}
}

function addToBasket(isbn) {
	addMultipleToBasket(isbn, 1);
}

function addMultipleToBasket(isbn, qty) {
	$.ajax({
  		url: '/BerteShopWeb/ajaxAddToBasket.do?isbn=' + isbn + '&qty=' + qty,
  		cache: false,
  		success: function(html){
  			document.getElementById('shopping').innerHTML = html;
  		}
	});
}

function viewCategory(category) {
	document.viewCategoryForm.category.value=category;
	document.viewCategoryForm.submit();
}

function showSubCategories(category) {
	document.showSubCategoriesForm.category.value=category;
	document.showSubCategoriesForm.submit();
}

function showCategory(category) {
	document.viewCategoryForm.category.value=category;
	document.viewCategoryForm.submit();
}
