function redirwin(orgid,url,wintype) {
	//Default sizes for window

	//give prod info windows a handle unique(ish) to the sku/qlink
	var WinID = 0
	if (url.charCodeAt) {
		for(iLoop=0;iLoop<url.length;iLoop++) {
			WinID += url.charCodeAt(iLoop);
		}
		window.name="mainwin";
		if (wintype=="redirwin") WinID = window.open("/ld?page=redirect&id=" + orgid + "&url=" + escape(url),'redirwin', 'toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=600');
	}
}

function redurl(url,id) {
	document.getElementById("ut1").src = ("http://www.lake-district.com/redirect.pl?id=" + id + "&url=" + escape(url));
	return 1;
}

function addbm(url, title){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}


function openwin(url,wintype,namealert) {
	//Default sizes for window
	winheight='280';
	winwidth='350';

	if (namealert && !username) {
		// need the user's name for external link 
		// check that this is a redirect and needs the name entered ?
		username = prompt('Please enter your name, including surname, to proceed to this website:','');
		if (username) {
			//alert('Name entered');
			url = url + '&name=' + username;
		}
		else {
			//alert('Name missing');
		}
	}
		
	//give prod info windows a handle unique(ish) to the sku/qlink
	var WinID = 0
	if (url.charCodeAt) {
		for(iLoop=0;iLoop<url.length;iLoop++) {
			WinID += url.charCodeAt(iLoop);
		}
		
		window.name="mainwin";
		if (wintype=="extwin") WinID = window.open(url,'extwin', 'toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=800,height=600');
		if (wintype=="infowin") WinID = window.open(url,WinID, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=400');
		if (wintype=="orgpicswin") WinID = window.open(url,WinID, 'toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=450');

		if (wintype=="prodwin") WinID = window.open(url,WinID, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=480,height=450');
		if (wintype=="mfrwin") WinID = window.open(url, wintype, 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
		if (wintype=="pricewin") WinID = window.open(url, wintype, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=300,height=100');
		if (wintype=="linkwin") WinID = window.open(url, wintype, 'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
		if (wintype=="helpwin") WinID = window.open(url, wintype, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+winwidth+',height='+winheight);
		if (wintype=="mailwin") WinID = window.open(url, wintype, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+winwidth+',height='+winheight);
		if (wintype=="ODwin") WinID = window.open(url, wintype, 'toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width='+winwidth+',height='+winheight);
	}
}



function mapwin(url) {
	var WinID = window.open(url,WinID, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=200,height=200');
	WinID.location.href = "http://www.google.com";
}

function getCookie ( cookie_name ) {
	var results = document.cookie.match ( cookie_name + '=(.*?)(;|\$)' );
	if ( results ) {
		return ( unescape ( results[1] ) );
	}
	else {
		return null;
	}
}

var basketitems = getCookie("basket");

function delete_cookie ( cookie_name )
{
	var cookie_date = new Date ( );  // current date & time
	cookie_date.setTime ( cookie_date.getTime() - 1 );
	document.cookie = cookie_name += "=;path=/;expires=" + cookie_date.toGMTString();
}

function recalcbasket() {
	var basketitems = getCookie("basket");
	var total = 0;
	if (basketitems != null) {
		var basketarray = new Array();
		if (basketitems.length > 0) {
			basketarray = basketitems.split(",");
			total = basketarray.length;
		}
	}
	document.getElementById("baskettotal").innerHTML = total + "&nbsp;items";
}

function addtobasket(id) {
	var myitem;
	var basketitems = getCookie("basket");
	var basketarray = new Array();
	var newbasket;
	newbasket = id;
	if (basketitems != null) {
		basketarray = basketitems.split(",");
		var i=0;
		for (i=0;i < basketarray.length;i++) {
			if (basketarray[i] == id) {
				// same value
			}
			else {
				newbasket = newbasket + "," + basketarray[i];
			}
		}
		if (newbasket.substr(newbasket.length-1,newbasket.length-1) == ",") {
			newbasket = newbasket.substr(0,newbasket.length-1);
		}
	}
	document.cookie = ("basket=" + newbasket + ";path=/;");
	document.getElementById("bkt_" + id).innerHTML = "In basket,<a href='javascript:removefrombasket(" + id + ");'>remove</a>";
	recalcbasket();
}

function removefrombasket(id) {
	var myitem;
	var basketitems = getCookie("basket");
	var basketarray = new Array();
	var newbasket;
	if (basketitems != null) {
		basketarray = basketitems.split(",");
		var newbasket = '';
		var i=0;
		for (i=0;i < basketarray.length;i++) {
			if (basketarray[i] == id) {
				// same value
			}
			else {
				newbasket = newbasket + basketarray[i] + ",";
			}
		}
		if (newbasket.substr(newbasket.length-1,newbasket.length-1) == ",") {
			newbasket = newbasket.substr(0,newbasket.length-1);
		}
		document.cookie = ("basket=" + newbasket + ";path=/;");
	}
	document.getElementById("bkt_" + id).innerHTML = "<a href='javascript:addtobasket(" + id + ");'>Add to enquiry basket</a>";
	recalcbasket();
}

