window.onload = function() 
{
	if (document.getElementById)
	{
		aLinks = document.getElementsByTagName('a');
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].href.indexOf('/myesb/') > -1) aLinks[aIndex].onclick = openMyESBWindow;
			if ((aLinks[aIndex].id == 'insplink') || (aLinks[aIndex].id == 'insplink2')) aLinks[aIndex].onclick = JSFnInspCopyAlert;
		}
		
		var aQSearchInput = document.getElementById('qsearchinputbox');
		if (aQSearchInput != null) 
		{
			aQSearchInput.onfocus = JSFnClearQSearch;
			aQSearchInput.onblur = JSFnResetQSearch;
			aQSearchInput.style.color = '#888';
			aQSearchInput.value = aQSearchInput.title;
		}
		
		var aSearchFormClearButton = document.getElementById('searchclear');
		if (aSearchFormClearButton != null) aSearchFormClearButton.onclick = clearSearchForm;
			
		var aSearchBarHeader = document.getElementById('searchbarheader');
		if (aSearchBarHeader != null) JSFnConfigureSearchBarHeader();
			
		if (window.GBrowserIsCompatible)
		{
			aMap = document.getElementById('map');
			if ((GBrowserIsCompatible())  && (aMap != null))
			{
				var map = new GMap2(aMap);
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				map.setCenter(point, 16);
				
				marker = new GMarker(point);
				map.addOverlay(marker);
				GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<p><strong>' + googledesc + '</strong</p><img src="gfx/' + googleimg + '" alt="" style="width:80px; height: 106px;"></img>');});
			}
		}
	}
}

function JSFnConfigureSearchBarHeader()
{
	var aSearchBarHeader = document.getElementById('searchbarheader');
	if (aSearchBarHeader != null)
	{
		aULs = aSearchBarHeader.getElementsByTagName('ul');
		if (aULs != null)
		{
			var aLI = document.createElement('li');
			var aText = document.createTextNode('  \u25CB ');
			aLI.appendChild(aText);
			var aLink = document.createElement('a');
			aLink.onclick = function(){window.print(); return false;};
			aLink.href = "#";
			var aText = document.createTextNode('Print This Search');
			aLink.appendChild(aText);
			aLI.appendChild(aLink);			
			var aText = document.createTextNode(' ');
			aLI.appendChild(aText);
			aULs[0].appendChild(aLI);
			
		}
	}
}

function JSFnInspCopyAlert()
{
	return confirm('Inspection copies are supplied for a maximum period of 60 days from the date of the accompanying invoice. They may be retained free of charge if 12 copies or more of the same title are ordered directly from the European Bookshop. Otherwise they must be returned to the bookshop, or paid for in full at the prices shown on the invoice. Customers are responsible for postage costs when returning unwanted inspection copies.');
}

function JSFnClearQSearch()
{
	if (this.value == this.title) 
	{
		this.value = '';
		this.style.color = '#000';
	}
}

function JSFnResetQSearch()
{
	if (this.value == '') 
	{
		this.style.color = '#888';
		this.value = this.title;
	}
}


// Function used to retrieve variable values from the url
function findVar(varName)
{
	temp = null;
	searchString = varName.toLowerCase() + "=";
	testString = window.location.search.toLowerCase();
	testStart = testString.indexOf(searchString)
	if (testStart != -1)
	{
		testEnd = testString.indexOf("&", testStart)
		if(testEnd != -1)
		{
			temp = testString.substring(testStart + varName.length + 1, testEnd);
		}
		else if (testEnd == -1)
		{
			temp = testString.substring(testStart + varName.length + 1, testString.length);
		}
	}
	return unescape(temp);
}

function goBack()
{
	history.go(-1);
}

function openHelpWindow()
{
	aHelpWindow=window.open(this.href, 'help', 'width=600px, height=700px, scrollbars'); 
	aHelpWindow.focus(); 
	return false;
}

function openMyESBWindow()
{
	aMyESBWindow=window.open(this.href, 'myesb', 'width=600px, height=700px, scrollbars'); 
	aMyESBWindow.focus(); 
	return false;
}

/* Right column Adverts code */

var nowCount = 0;

function disppic()
{
	document.dpic.src=pic[nowCount].src;
	nowCount++;
	if(nowCount==maxCount)
	{
		nowCount=0;
	}
	setTimeout("disppic()",6000);
}

function ClickAd()
{
	var cv = nowCount-1;
	if(cv == -1)
	{
		cv=maxCount-1;
	}
	
	if (loc[cv] != '') document.location=loc[cv];
}

function CheckErase()
{
	if(confirm("Do you want to erase your entire shopping basket?"))
	{
		return true;
	}
	return false;
}

function clearSearchForm()
{
	document.getElementById('esbcode').value = "";
	if (document.getElementById('subject[]' ) != null) document.getElementById('subject[]').selectedIndex = -1;
	document.getElementById('section[]').selectedIndex = -1;
	document.getElementById('ability[]').selectedIndex = -1;
	document.getElementById('age[]').selectedIndex = -1;
	document.getElementById('monthfrom').selectedIndex = 0;
	document.getElementById('yearfrom').selectedIndex = 0;
	document.getElementById('monthto').selectedIndex = 11;
	document.getElementById('yearto').selectedIndex = 0;
	document.getElementById('popularity').selectedIndex = 0;
	document.getElementById('init').value = "";
	document.getElementById('author').value = "";
	document.getElementById('title').value = "";
	document.getElementById('isbn').value = "";
	document.getElementById('rpp').options[0].selected = true;
	return false;
}

function JSFnSelectAll()
{
	aChoiceRequired = false;
	aLastBoxOn = false;

	var aCheckBoxes = document.getElementsByTagName('input');
	for (aIndex = 0; aIndex < aCheckBoxes.length; aIndex++)
	{
		if (aCheckBoxes[aIndex].name.indexOf('cb') == 0) 
		{
			if (aCheckBoxes[aIndex].className != 'optional') 
			{
				aCheckBoxes[aIndex].checked = !(aCheckBoxes[aIndex].checked);
				aLastBoxOn = aCheckBoxes[aIndex].checked;
			}
			else
			{
				if (aCheckBoxes[aIndex].parentNode.parentNode.className != 'highlighted') aCheckBoxes[aIndex].parentNode.parentNode.className = 'highlighted';
				else aCheckBoxes[aIndex].parentNode.parentNode.className = '';

				aChoiceRequired = true;				
			}
		}
	}
	if (aChoiceRequired == true) alert('Warning - we could not select all books as there is a choice to be made where the books are now highlighted. \nThese titles must be selected manually.');
}