<!-- //

// Function to check if a field string is empty
	
	function isEmptyField(srcField) {
		srcText = srcField.value;
		srcText = srcText.replace(/^\s+/g, '').replace(/\s+$/g, '');
		if(srcText == "") {
			srcField.value = "";
			return true;
		} else return false;
	}

	function openKeystage(getLink) {
		window.open(getLink, '', 'toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=450,height=450');
		return false;
	}
	
	function openVideo(getLink) {
		window.open(getLink, '', 'toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=450,height=450');
		return false;
	}
	
	function embedSoundPlayer(soundURL,soundTitle,soundSIze,language) {
		var flashString;
		if (flash.ver[8]) {
			flashString = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='141' height='23'>";
			flashString += "<param name='movie' value='/universal_code_library/catalogue_v3/catalogue_includes/audio_player/audio_player.swf?soundURL=" + escape(soundURL) + "&soundTitle=" + escape(soundTitle) + "&language=" + escape(language) + "'><param name='quality' value='high'>";
			flashString += "<param name='wmode' value='transparent'>";
			flashString += "<embed src='/universal_code_library/catalogue_v3/catalogue_includes/audio_player/audio_player.swf?soundURL=" + escape(soundURL) + "&soundTitle=" + escape(soundTitle) + "&language=" + escape(language) + "' ";
			flashString += "wmode='transparent' ";
			flashString += "quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='141' height='23'><\/embed>";
			flashString += "<\/object>";
		} else {
			if (language == "french") {
				flashString = "<dl><dd><a href='" + soundURL + "'>Lire le fichier MP3</a> [" + soundSIze + "Kb]</dd></dl>";
			} else {
				flashString = "<dl><dd><a href='" + soundURL + "'>Play MP3 file</a> [" + soundSIze + "Kb]</dd></dl>";
			}
		}
		return flashString;
	}
	
	function validateEmailForm(getForm) {
		if(!isValidEmail(getForm.emailAddress.value)) {
			alert("This is not a valid email address.\nPlease try again");
			return false;
		} else return true;
	}
	
	var badChars = new Array("<",">","\/","=","%","@");
	
	function detectBadChars(srcText) {
		badFound = false;
		for(i=0;i<badChars.length;i++) {
			if(srcText.indexOf(badChars[i]) > -1) badFound = true;
		}
	}
	
	function validateReviewForm() {
		alertMessage = "";
		if(siteLang == "english") {
			if(isEmptyField(document.getElementById("review_author"))) alertMessage += "\nYou must enter YOUR NAME.";
			if(isEmptyField(document.getElementById("review_password"))) alertMessage += "\nYou must enter a PASSWORD.";
			if(isEmptyField(document.getElementById("review_title"))) alertMessage += "\nYou must enter a REVIEW TITLE.";
			if(isEmptyField(document.getElementById("review_content"))) alertMessage += "\nYou must enter some REVIEW CONTENT.";
			if(isEmptyField(document.getElementById("captcha_image"))) alertMessage += "\nYou must enter the SECURITY CODE.";
			//invalid characters
			if(detectBadChars(document.getElementById("review_author").value)) alertMessage += "\nThe YOUR NAME entry contains characters that are not permitted.";
			if(detectBadChars(document.getElementById("review_title").value)) alertMessage += "\nThe REVIEW TITLE entry contains characters that are not permitted.";
			if(detectBadChars(document.getElementById("review_content").value)) alertMessage += "\nThe REVIEW CONTENT entry contains characters that are not permitted.";
		}
		if(alertMessage!="") {
			alert("There are problems with this form:" + alertMessage);
			return false;
		} else return true;
	}

// expand/collapse function for thumbnail listings

	var seriesArray;
	var seriesCount;

	function addExpanders(getSeriesCount) {
		if(getSeriesCount > 1) {
			// store values
			seriesCount = getSeriesCount;
			seriesArray = new Array(seriesCount+1);
			// loop through and add HTML
			for(i=1;i<=seriesCount;i++) {
				// store visible state
				seriesArray[i] = true;
				// add HTML
				thisDT = document.getElementById("series_" + (i)).getElementsByTagName("DT")[0];
				getHTML = thisDT.innerHTML;
				thisDT.innerHTML = "<a id='expander_" + (i) + "' class='collapse' href='javascript:toggleSeries(" + (i) + ")' title='Click to expand\/collapse this section of the list'><\/a>" + getHTML;
			}
		}
	}
	
	function toggleSeries(getIndex) {
		if(seriesArray[getIndex] == true) {
			// hide series
			document.getElementById("series_" + getIndex).className = "catalogueList thumbnails seriesCollapsed";
			// update button
			document.getElementById("expander_" + getIndex).className = "expand";
			// store state
			seriesArray[getIndex] = false;
		} else {
			// show series
			document.getElementById("series_" + getIndex).className = "catalogueList thumbnails seriesExpanded";
			// update button
			document.getElementById("expander_" + getIndex).className = "collapse";
			// store state
			seriesArray[getIndex] = true;
		}
	}

// Search form functions
	
	var searchFormAreas = new Array();
	
	function storeSearchFormAreaState(getIndex,getState) {
		searchFormAreas[getIndex] = getState;
	}
	
	function createSearchFormAreaLabel(getIndex,getLabel,getField) {
		document.write("<label for='" + getField + "'><strong><a href='javascript:toggleSearchFormArea(" + getIndex + ");'>" + getLabel + "<\/a><\/strong><\/label>");
	}
	
	function toggleSearchFormArea(getIndex) {
		if(searchFormAreas[getIndex] == true) {
			// hide content
			document.getElementById("searchFormAreaContent_" + getIndex).className = "searchFormAreaContent inactive";
			// update label etc
			document.getElementById("searchFormArea_" + getIndex).className = "searchFormArea inactive";
			// store new state
			searchFormAreas[getIndex] = false;
			// clear all form elements
			clearFormValues("searchFormAreaContent_" + getIndex);
		} else {
			// show content
			document.getElementById("searchFormAreaContent_" + getIndex).className = "searchFormAreaContent active";
			// update label etc
			document.getElementById("searchFormArea_" + getIndex).className = "searchFormArea active";
			// store new state
			searchFormAreas[getIndex] = true;
			// set focus on first input field if one exists
			formElements = document.getElementById("searchFormAreaContent_" + getIndex).getElementsByTagName("INPUT");
			if(formElements.length > 0) {
				formElements[0].select();
				formElements[0].focus();
			}
		}
	}
	
	function clearFormValues(getFormArea) {
		// inputs
		formElements = document.getElementById(getFormArea).getElementsByTagName("INPUT");
		for(i=0;i<formElements.length;i++) {
			formElements[i].value = "";
		}
		// selects
		formElements = document.getElementById(getFormArea).getElementsByTagName("SELECT");
		for(i=0;i<formElements.length;i++) {
			formElements[i].selectedIndex = 0;
		}
	}
	
	function searchFormValidation(getForm, siteLang) {
		criteriaFound = false;
		// keystage (uk only)
		if(getForm.Keystage) {
			if(getForm.Keystage.selectedIndex > 0) criteriaFound = true;
			if(!isEmptyField(getForm.KeystageCode)) criteriaFound = true;
		}
		// check for field input
		if(!isEmptyField(getForm.BookTitle)) criteriaFound = true;
		if(getForm.Keyword) {
			if(!isEmptyField(getForm.Keyword)) criteriaFound = true;
		}
		if(!isEmptyField(getForm.Series)) criteriaFound = true;
		if(!isEmptyField(getForm.Author)) criteriaFound = true;
		if(!isEmptyField(getForm.Illustrator)) criteriaFound = true;
		if(getForm.ProductCode) {
			if(!isEmptyField(getForm.ProductCode)) criteriaFound = true;
		}
		if(getForm.ISBN) {
			if(!isEmptyField(getForm.ISBN)) criteriaFound = true;
		}
		
		if(getForm.MinAge) {
			if(getForm.MinAge.selectedIndex > 0) criteriaFound = true;
		}
		
		if(getForm.LexileMeasure) {
			if(!isEmptyField(getForm.LexileMeasure)) criteriaFound = true;
		}
		
		if(getForm.MinPrice && getForm.MaxPrice) {
			if(!isEmptyField(getForm.MinPrice) && !isEmptyField(getForm.MaxPrice)) criteriaFound = true;
		}
		
		if(getForm.NewTitleDateRange) {
			if(getForm.NewTitleDateRange.selectedIndex > 0) criteriaFound = true;
		}
		
		// return
		if(criteriaFound) {
			return true;
		} else {
			if(siteLang == "english") {
				alert("You have not entered any search criteria.\nPlease try again");
			} else if(siteLang == "french") {
				alert("Vous n'avez saisi aucun critère de recherche.\nVeuillez recommencer");
			} else if(siteLang == "spanish") {
				alert("No ha escrito nada en el cuadro de búsqueda");
			} else if(siteLang == "italian") {
				alert("You have not entered any search criteria.\nPlease try again");
			}
			return false;
		}
	}
	
// -->

