/*<!---------------------------------------------------------------------------
'	(C) Copyright 1996 - 2002
'	Australia and New Zealand Banking Group Limited
'   	ABN 11 005 357 522
'----------------------------------------------------------------------------
' $Revision: 7 $
' $Author: Doylee $ 
' $Workfile: printTransactionAccounts.cfm $ 
' $Modtime: 23/09/02 11:09a $
' Author: Elissa Doyle
' Created: 25/09/2002
' Description: 
'	Common JSfunctions for the transaction product selector
' Modifications:
'--------------------------------------------------------------------------->*/
// cancels the submit if data in error
function goNext() {

	if (document.forms.productselector.formok.value == 0) {
		document.forms.productselector.formok.value = 1;
		return false;
	}
	else
		return true;
}

function readFormat(num,maxNumber,minNumber) {
	// thanks to Jim Ley (jim@jibbering.com) for the parser currency parsing code (through deja.com)

	 sepString=",.";
	 if (!maxNumber) maxNumber=999999999;

	if (num.length > 2 & num.charAt(0) == "(" & num.charAt(num.length-1) == ")"){
		num = "-" + num.substr(1, num.length-2);
	}

	 while (num.indexOf(sepString.charAt(0))>-1) {

	num=num.substr(0,num.indexOf(sepString.charAt(0)))+num.substr(num.indexOf(sepString.charAt(0))+1);
	 }
	 if (num.indexOf(sepString.charAt(1))>-1)
	num=num.substr(0,num.indexOf(sepString.charAt(1)))+'.'+num.substr(num.indexOf(sepString.charAt(1))+1);

	if (num > maxNumber ) {
		alert('Number is too large; a maximum number of '+writeFormat(maxNumber)+' is allowed');
		document.forms.productselector.formok.value = 0;
		return maxNumber ;
	}
	else if (num < minNumber ) {
		alert('Number is too small; a minimum number of '+writeFormat(minNumber)+' is allowed');
		document.forms.productselector.formok.value = 0;
		return minNumber;
	}
	else {
		document.forms.productselector.formok.value = 1;
		if (num == " " || num == "" || isNaN(num)){
			if (num == " ")
				return "[space]";
			else
				return num;
		}
		else {
			return parseFloat(num);
		}

	}
}
function writeFormat(num,dp,sepString) {
	// thanks to Jim Ley (jim@jibbering.com) for the parser currency parsing code (through deja.com)

	if (num != "" || num == 0)
	{
		if (isNaN(num))
		{
			alert(num + ' is not a number. The value you enter must be numeric');
			document.forms.productselector.formok.value = 0;
			return '';
		}
		else
		{

			if (!dp)
				dp=0;

			if (!sepString)
				sepString=",.";

			num=Math.round(num*Math.pow(10,dp));
			num=num.toString();


			//str=sepString.charAt(1)+num.substr(num.length-dp);
			str='';

			num=num.substr(0,num.length-dp);

			while (num.length>3)
			{
				str=sepString.charAt(0)+num.substr(num.length-3)+str;
				num=num.substr(0,num.length-3);
			}

		 str=num+str
		 str = str.replace("-,", "-");
		 return str;
		 }
	 }
	 else {
		 return '';
	 }
}


