function displayMoney(inv){
	
	inv = inv + ''
	decimal = inv.indexOf('.')
	if (decimal == -1) return inv + '.00'
	if ((decimal - inv.length) == -2) return inv + '0'
	if ((inv.length - decimal) > 2) return inv.substring(0,decimal+3)
	return inv
}


function makeMoney(o){
	o.onblur = function(){
		// Convert string to number
	var number = parseFloat( this.value ) 
	
	// Checks to see if number conatins a valid number
	if( isNaN( number ) || (this.value == '') )			
		number = 0

	// Round Number to 2 digits
	try {
		number = Math.round( number * 100 ) / 100
	}
	catch(e){
		 number = 0
	}

	var returnString = String(number)

	// Find position of decimal point from end of string
	var decimalPos = returnString.length - returnString.indexOf('.')
	// If no decimal point
	if ( returnString.indexOf('.')== -1)
		returnString += '.00'
	// If decimal point is second to last character
	else if( decimalPos == 2 )
		returnString += '0'
	// If decimal point is last character
	else if ( decimalPos == 1 )
		returnString += '00'

	/*/ Is value 1000 or greater then put in commas ,
	if(returnString.length > 7){
		var s = returnString.substring(decimalPos-1,returnString.length)		
		var i = 0
		for(var j = decimalPos-2; j > -1;j--){
			var c = ''
			if(i%3 == 0 && i > 0 && j>1 ) c = ','
			s = returnString.charAt(j) + c + s
			i++
		}
		returnString = s
	}
*/	
	this.value = returnString
	var t = document.getElementById("t")
	displayMoney("0")

	}
}


function makeNumerical(o){
	o.onblur = o.onkeyup = function(){
		var bag = '0123456789'
		var s = ''
		for(var i=0;i<this.value.length;i++)
			if(bag.indexOf(this.value.charAt(i)) != -1)
				s+=this.value.charAt(i)
		this.value = s
	}
}	

function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)) 
       rv = false;
  else {
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//reEmail = /.+\@.+\..+$/
		
		rv = reEmail.test(s)
    }
	if(rv){
	return rv
	}else{
		return false
	}
}

var FORMSENT = false
function checkform(inf){
msg = ""
if (inf.txndata1.value == "")
	msg += '\n - You need to enter your name'
if (!isEmailAddr(inf.email.value))
	msg += '\n - You need to enter your email address'
if (inf.Street.value == "")
	msg += '\n - You need to enter your street'
if (inf.Suburb.value == "")
	msg += '\n - You need to enter your suburb'
if (inf.City.value == "")
	msg += '\n - You need to enter your city'
if (inf.amount.value == "")
	msg += '\n - You need to enter a donation amount'	
if (inf.amount.value == "0.00")
	msg += '\n - You need to enter a donation amount larger then $0.00'	
if ((msg == "")&&(FORMSENT == false)){
	FORMSENT = true
	return true
	}
else if(FORMSENT == false) alert("You need to complete the following tasks:\n" + msg)
return false

}

function randomNumber(){
  var ran = Math.floor(Math.random()*10000);
  ccform.merchantreference.value = "Donation-"+ran
}
