// JavaScript Document
/*******************************************************************************

'args.js', by Charlton Rose

Permission is granted to use and modify this script for any purpose,
provided that this credit header is retained, unmodified, in the script.

*******************************************************************************/


// This function is included to overcome a bug in Netscape's implementation
// of the escape () function:

function myunescape (str)
{
	str = '' + str;
	while (true)
	{
		var i = str . indexOf ('+');
		if (i < 0)
			break;
		str = str . substring (0, i) + ' ' + str . substring (i + 1, str . length);
	}
	return unescape (str);
}



// This function creates the args [] array and populates it with data
// found in the URL's search string:

function args_init ()
{
	args = new Array ();
	var argstring = window . location . search;
	if (argstring . charAt (0) != '?')
		return;
	argstring = argstring . substring (1, argstring . length);
	var argarray = argstring . split ('&');
	var i;
	var singlearg;
	for (i = 0; i < argarray . length; ++ i)
	{
		singlearg = argarray [i] . split ('=');
		if (singlearg . length != 2)
			continue;
		var key = myunescape (singlearg [0]);
		var value = myunescape (singlearg [1]);
		args [key] = value;
	}
}

function newWindow(newContent)
 {
  winContent = window.open(newContent, 'nextWin', 'right=0, top=0,width=1020,height=600, toolbar=no,scrollbars=no, resizable=no')         
 }

function num2money(n_value)
{
	// validate input
	if (isNaN(Number(n_value)))
		return 'ERROR';

	// save the sign
	var b_negative = Boolean(n_value < 0);
	n_value = Math.abs(n_value);

	// round to 1/100 precision, add ending zeroes if needed
	var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

	// separate all orders
	var b_first = true;
	var s_subresult;

	while (n_value > 1)
	{
		s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
		s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
		b_first = false;
		n_value = n_value/1e3;
	}

	// add at least one integer digit
	if (b_first)
		s_result = '0.' + s_result;

	// apply formatting and return
	return  b_negative ? '(£' + s_result + ')' : '£' + s_result;
}

// created 07/01/2007#MA
function currencyToStrInt( strCurrency )
{
	// remove currency symbol from price
	var strValue = strCurrency.substr(1);
	// remove any commas
	strValue = strValue.replace(",", "");
	strValue = "" + parseInt(strValue);
	return strValue;
}

// created 07/01/2007#MA
function toPound( strCurrency )
{
	// remove any commas
	strValue = strCurrency.replace("£", "&pound;");
	return strValue;
}
