function gotoZoom(book, page, image, height, width, site) {
	var thispage = window.location.href.substr(window.location.href.toLowerCase().indexOf('.co.uk/') + 7);
	
	var fullurl = '/shared/izoom/zoom.htm?b=' + book + '&p=' + page + '&i=' + image + '&h=' + height + '&w=' + width + '&l=' + thispage + "&site=" + site;
//	if ((cm!=null) && (cm != '')){
//		fullurl = fullurl + '&cm=' + cm;
//	}
	var win = window.open(fullurl, '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, cm_re) {
	if(!status_code) status_code='';
	status_code='';
	if(!referrer) referrer =  location.href;

	referrer = referrer.replace(/&(ic|iq|status_code)=[^&]*/gi, '');
	referrer = escape(referrer);
	
	var fullurl = '';
	
	if (s0 == 'adultgifts')
	{
	    fullurl = '/iteminfo_adult.htm?s0=' + s0 + '&b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&u=' + upsell + '&r=' + referrer;
	}
	else
	{
	    fullurl = '/iteminfo.asp?s0=' + s0 + '&b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&u=' + upsell + '&r=' + referrer;
	}

	if ((cm_re!=null) && (cm_re != '')){
		fullurl = fullurl + '&cm_sp=' + cm_re;
	}
	
    var popW = 620, popH = 580;
    var leftPos = (screen.width/2)-(popW/2);
    var topPos = (screen.height/2)-(popH/2);
      	
	//var popupWindow = window.open(fullurl, 'shotview', 'height=500,width=580,scrollbars=no');
	var popupWindow = window.open (fullurl, "shotview", "location=0,status=1,scrollbars=1,width=" + popW + ",height=" + popH + ",resizable=0,top=" + topPos + ",left="+ leftPos);
}

function openShotPopup_Clearance(s0, s1, s2, s3, pt, pc, status_code, upsell, referrer, cm_re) {
	if(!status_code) status_code='';
	status_code='';
	if(!referrer) referrer =  location.href;

	referrer = referrer.replace(/&(ic|iq|status_code)=[^&]*/gi, '');
	referrer = escape(referrer);
	
	var fullurl = '';
	
    fullurl = '/shot_clearance.asp?s0=' + s0 + '&s1=' + s1 + '&s2=' + s2 + '&s3=' + s3 + '&pt=' + pt + '&pc=' + pc + '&status_code=' + status_code + '&u=' + upsell + '&r=' + referrer;

	if ((cm_re!=null) && (cm_re != '')){
		fullurl = fullurl + '&cm_sp=' + cm_re;
	}
	
    var popW = 580, popH = 565;
    var leftPos = (screen.width/2)-(popW/2);
    var topPos = (screen.height/2)-(popH/2);
      	
	//var popupWindow = window.open(fullurl, 'shotview', 'height=500,width=580,scrollbars=no');
	var popupWindow = window.open (fullurl, "shotview", "location=0,status=1,scrollbars=0,width=" + popW + ",height=" + popH + ",resizable=0,top=" + topPos + ",left="+ leftPos);
}

function openShotPopupCUK(s0, s1, s2, s3, title, id, book, page, occurance, shot, status_code, upsell, referrer, cm_re) {
      if(!status_code) status_code='';

      status_code='_';
      var popW = 580, popH = 500;
      var leftPos = (screen.width/2)-(popW/2);
      var topPos = (screen.height/2)-(popH/2);

      //var fullurl = "/product/"+s0+"/"+s1+"/"+s2+"/"+s3+"/" + title + "/" +id + "/" + book + "/" + page + "/" + occurance + "/" + shot + "/" + status_code + "/" + upsell + "/" + referrer;
      
      var fullurl = "/iteminfo_cuk.asp?s0=" + s0 + "&s1=" + s1 + "&s2=" + s2 + "&s3=" + s3 + "&title=" + title + "&id=" + id + "&b=" + book + "&p=" + page + "&o=" + occurance + "&s=" + shot + "&status_code=" + status_code + "&u=" + upsell + "&r=" + referrer;

      if ((cm_re!=null) && (cm_re != '')){
        fullurl = fullurl + "&cm_sp=" + cm_re;
      }
      
      var popupWindow = window.open (fullurl, "shotview", "location=0,status=1,scrollbars=1,width=" + popW + ",height=" + popH + ",resizable=0,top=" + topPos + ",left="+ leftPos);

      //var popupWindow = window.open(fullurl, 'shotview', 'height=500,width=580,scrollbars=no');
      }

function openMovie(site, book, page, occurance, shot, status_code, movie, referrer) {
	if(!status_code) status_code='';
	if(!referrer) referrer = location.href;
	var popupWindow = window.open('/iteminfo.htm?s0=' + site + '&b=' + book + '&p=' + page + '&o=' + occurance + '&s=' + shot + '&status_code=' + status_code + '&movie=' + movie + '&r=' + referrer, 'shotview', 'height=500,width=600,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=600,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');
}
