function check_search( form_name )
{
	var search_form = document.forms[ form_name];
	
	if( search_form.searchtext.value == 'Enter keyword, page no. or item no.')
	{
			alert('Please enter a search term');
			
			search_form.searchtext.focus();
			
			return( false );
	}
	
	return( true );	
}

function check_subscribe( form_name )
{
	var subscribe_form = document.forms[ form_name];
	
	if( subscribe_form.email.value == 'Please enter your e-mail address')
	{
			alert('Please enter your e-mail address');
			
			subscribe_form.email.focus();
			
			return( false );
	}
	
	var subscribe_window = window.open('/subscribe.asp?email='+escape(subscribe_form.email.value), 'subscribe', 'width=300,height=200,scrollbars=no');
	
	subscribe_window.focus();
	
	return( false );	
}

function gotoZoom(brand, site, book, page, image, height, width) {
	var thispage = escape(window.location.href.substr(window.location.href.toLowerCase().indexOf('.co.uk/') + 7));

	var win = window.open('./izoom/zoom.htm?brand=' + brand + '&site=' + site + '&book=' + book + '&p=' + page + '&i=' + image + '&w=' + width + '&h=' + height + '&l=' + thispage, 'shotzoom', 'height=540,width=720,scrollbars=yes');
	win.focus();
}

function gotoPage(book, page, occurance, page_type, shot_lnk)
{
	if(!page_type) page_type='spread';
	if(!shot_lnk) shot_lnk='0';
	top.location.href = '/page.asp?b=' + book + '&p=' + page + '&o=' + occurance + '&t=' + page_type + '&s=' + shot_lnk;
}

function getCDMainWindow() {
	return(window.top.mainWindow);
}

function setCDMainWindow() {
	window.name = 'cdmainwindow';
}

function setLastLocation() {
	//top.addCookie('lastlocation', location.href);
	top.lastLocation = location.href;
}

function getLastLocation() {
	//return(top.getCookie('lastlocation'));
	return(top.lastLocation);
}

function openShot(book, page, occurance, shot, status_code, upsell) {
	if(!status_code) status_code='';

	var popupWindow = window.open('/iteminfo.htm?b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&u=' + upsell, 'shotview', 'height=500,width=580,scrollbars=no');
}

function gotoShot(book, page, occurance, shot, status_code, upsell) {
	var referrerURL = '';

	if(!status_code) status_code='';

	if(document.forms['mainform'])
		if(document.forms['mainform'].elements['refererURL'])
			referrerURL = escape(document.forms['mainform'].elements['refererURL'].value);

	window.location.href = '/shot.asp?b=' + book + '&p=' + page + '&s=' + shot + '&status_code=' + status_code + '&r=' + referrerURL + '&u=' + upsell;
}

function gotoSavedOrders() {
	gotoLocation('shopbag.htm?retrieve');
}

function gotoSection(section, brand) {
	var sectionLink;

	section = section.toUpperCase();

	switch(section) {
		case 'BROWSE OUR CATALOGUES' :
			sectionLink = 'http://www.browse.' + brand + '.co.uk';
			break;
		case 'OFFERS OF THE MONTH' :
			sectionLink = 'http://www.offers.' + brand + '.co.uk';
			break;
		case 'CLEARANCE COUNTDOWN' :
			sectionLink = 'http://www.clearance.' + brand + '.co.uk';
			break;
		case 'QUICKSHOP' :
			sectionLink = 'http://www.' + brand + '.co.uk/ss/order/order_form1.jsp';
			break;
		case 'TRACK ORDER' :
			sectionLink = 'https://www.' + brand + '.co.uk/ss/account/find_invoice.jsp';
			break;
		case 'REQUEST A CATALOGUE' :
			sectionLink = 'https://www.' + brand + '.co.uk/ss/CustomerServlet?mode=requestCatalogue&brand=1';
			break;
		default :
			sectionLink = '';
	}

	if(sectionLink != '')
		gotoLocation(sectionLink);
	else
		alert('not yet available');
}

function gotoLocation(locationLink) {
	top.location.href = '/redirect.asp?url=' + escape(locationLink);
}

function gotoShoppingBasket() {
	gotoLocation('shopbag.asp');
}

function shopMore() {
	if(getLastLocation())
		location.href = getLastLocation();
	else
		gotoHome();
}

function printOrder() {
	window.open('printsb.asp', 'print', 'width=700,height=400,scrollbars=yes');
}

function openCustom() {
	window.open('custom_popup/custom_popup.htm', 'custom_popup', 'width=500,height=420,scrollbars=no');
}

function findPage()
{
	var page = document.forms['pagesearch'].elements['pagesrch'].value.toUpperCase();
	var book = document.forms['pagesearch'].elements['book'].value;

	page = page.replace(/[^0-9]/g, '');

	if(page.length > 0) {
		top.location.href = '/search.asp?t=page&p=' + escape(page) + '&b=' + escape(book) + '&l=' + escape(top.location.href);
	} else {
		document.forms['pagesearch'].elements['pagesrch'].value = '';
		document.forms['pagesearch'].elements['pagesrch'].focus();
		alert('Please enter a page to search for.');
	}
}

function findItem() {
	var code = document.forms['itemsearch'].elements['code01'].value.toUpperCase() +
		document.forms['itemsearch'].elements['code02'].value.toUpperCase() +
		document.forms['itemsearch'].elements['code03'].value.substr(0,2).toUpperCase();

	code = code.replace(/[^0-9]/g, '');

	if(code.length > 0) {

		while(code.length < 8)
			code = '0' + code;

		top.location.href = '/search.asp?t=item&c=' + escape(code) + '&l=' + escape(top.location.href);
	} else {
		document.forms['itemsearch'].elements['code01'].value = '';
		document.forms['itemsearch'].elements['code02'].value = '';
		document.forms['itemsearch'].elements['code03'].value = '';
		document.forms['itemsearch'].elements['code01'].focus();
		alert('Please enter a code to search for.');
	}
}

function gotoProduct(book, page, occurance, shot) {
	//openShot(book, page, shot);
	gotoPage(book, page, occurance, 'spread', shot);
}

function gotoHome() {
	gotoLocation('home.asp');
}

function moveNext(inputBox) {
	if(document.forms['itemsearch'].elements['code0' + inputBox].value.length > 2)
		document.forms['itemsearch'].elements['code0' + (inputBox + 1)].focus();
}

function gotoHelp() {
	window.open('/help.htm', 'help', 'height=400,width=580,scrollbars=yes');
}
