function setHost ()
{
	if (window.location.hostname == "bmco") return "http://comgenssl";
	if (window.location.hostname == "bmcouk") return "http://bmssl";

	return "https://vault2.secured-url.com/bmsoftware";
}

function buy (name, code, price, cat, weight)
{
	var f = window.location;
	window.location = setHost () + '/0pages/buy.php?t=' +
		name + '&r=' + code + '&p=' + price + '&c=' + cat + "&w=" + weight + "&f=" + f;
}

function trolley ()
{
	window.location = setHost () + '/0pages/trolley.php';
}

function textUntilR (year, month, day, text, alttext)
{
	now = new Date ();
	expire = new Date (year, month - 1, day, now.getHours (), now.getMinutes (), now.getSeconds() + 1);

	if (expire.getTime () >=  now.getTime ()) return text;

	return alttext;
}

function textUntil (year, month, day, text, alttext)
{
	temp = textUntilR (year, month, day, text, alttext);
	document.write (temp);
}


function buyUntil(year, month, day, name, code, offerprice, regularprice, cat, weight)
{
	price = textUntilR (year, month, day, offerprice, regularprice);
	buy (name, code, price, cat, weight);
}

// Function to write the price to 2 decimal places in an orderfrom

function writeprice (price)
{
   document.write ("£" + dec (price / 100, 2));
}

// Function to format a number to a specified number of decimal places

function dec (num, dp)
{
	var n = "" + num;
	var dp1 = n.indexOf (".");
	var l = n.length;

	if (dp > 0 && dp1 == -1)
	{
		n += ".";
		dp1 = n.indexOf (".");
		l = n.length;
	}

	while (l - dp1 < dp + 1)
	{
		n += "0";
		l = n.length;
	}

	return n;
}

function na (name, code, price, cat, weight)
{
	alert (name + ' is no longer available, please select an alternative');
}
