function gotoZoom(book, page, image, height, width) {
	var thispage = window.location.href.substr(window.location.href.toLowerCase().indexOf('.co.uk/') + 7);
	var win = window.open('izoom/zoom.htm?b=' + book + '&p=' + page + '&i=' + image + '&h=' + height + '&w=' + width + '&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 gotoMoviePage(book, page, occurance, page_type, shot_lnk, movie)
{
	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 + '&movie=' + movie;
}

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) {
	gotoPage(book, page, occurance, 'spread', shot);
}

//function openShotPopup(s0, book, page, occurance, shot, status_code, upsell, referrer) {
//	if(!status_code) status_code='';
//	status_code='';
//	if(!referrer) referrer =  location.href;

//	referrer = referrer.replace(/&(ic|iq|status_code)=[^&]*/gi, '');
//	referrer = escape(referrer);

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

function openShotPopup(s0, title, id) {
//	if(!status_code) status_code='';
//	status_code='';
//	if(!referrer) referrer =  location.href;

//	referrer = referrer.replace(/&(ic|iq|status_code)=[^&]*/gi, '');
//	referrer = escape(referrer);

    var popW = 580, popH = 500;
	var leftPos = (screen.width/2)-(popW/2);
	var topPos = (screen.height/2)-(popH/2);
	
	title = cleanText(title);
	//window.open ("prod_details.aspx?id="+id+"&s0="+s0, "shotview", "location=0,status=1,scrollbars=1,width=" + popW + ",height=" + popH + ",resizable=0,top=" + topPos + ",left="+ leftPos);
	window.open ("/product/entertainment/for-the-home/dvds/"+title+"/"+id, "shotview", "location=0,status=1,scrollbars=1,width=" + popW + ",height=" + popH + ",resizable=0,top=" + topPos + ",left="+ leftPos);

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

function cleanText(text) {
    var cleaned = text.toLowerCase();
    cleaned = cleaned.replace(/[^a-z0-9 ]/gi, '');
    cleaned = cleaned.replace(/ +/gi, '-');
    return(cleaned);
}

function openMovie(site, book, page, occurance, shot, status_code, movie) {
	if(!status_code) status_code='';
	//var popupWindow = window.open('/iteminfo.htm?b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&movie=' + movie, 'shotview', 'height=500,width=580,scrollbars=no');
	var popupWindow = window.open('/iteminfo.htm?s0=' + site + '&b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&movie=' + movie, 'shotview', 'height=500,width=580,scrollbars=no');

}

function moreInfo(book, page, occurance, article) {
	var url = '/moreinfo.asp?b=' + book + '&p=' + page + '&o=' + occurance + '&a=' + article;
	top.location = url;
}

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

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

function gotoShot(book, page, occurance, shot, status_code) {
	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;
}

function gotoMovie(book, page, occurance, shot, status_code, movie) {
	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 + '&movie=' + movie;
}

function gotoAccessoryShot(s0, book, page, occurance, shot, status_code, movie, movie_book, movie_page, movie_occurance, movie_shot) {
	var referrerURL = '';

	if(!status_code) status_code='';

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

	window.location.href = '/shot.asp?s0=' + s0 + '&b=' + book + '&p=' + page + '&s=' + shot + '&status_code=' + status_code + '&r=' + referrerURL + '&frommovie=' + movie+ '&movie_book=' + movie_book + '&movie_page=' + movie_page + '&movie_occurance=' + movie_occurance + '&movie_shot=' + movie_shot;
}

function gotoLocation(locationLink) {
	top.location.href = locationLink;
}

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

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 an item reference 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');
}

