function buy (name, code, price, cat, weight)
{
	window.location = 'https://vault2.secured-url.com/bmsoftware/0pages/buy.php?t=' + name + '&r=' + code + '&p=' + price + '&c=' + cat + '&w=' + weight;
}

function trolley ()
{
	window.location = 'https://vault2.secured-url.com/bmsoftware/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
	else
		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;
}
