function validate_Load()
{
	ValidationMap.Date = ValidateDate;
	//ValidationMap.Suburb = ValidateSuburbField;
	ValidationMap.Time = ValidateTime;
	ValidationMap.TimeSplit = ValidateTimeSplit;
	ValidationMap.Money = function(field) { return ValidateCurrency(field,1); };
	ValidationMap.Float = function(field) { return ValidateFloat(field.value); };;
	ValidationMap.Integer = function(field) { return ValidateInt(field.value); };
	ValidationMap.ABN = function(field) { return ValidateABN(field.value); };
	ValidationMap.DateTime = ValidateDateTime;
	ValidationMap.Phone = function (field) { return ValidatePhone(field.value); };
}

// returns true if value is a positive integer
// returns false otherwise.
function ValidateNatural(value) {
	if (value == '')
		return true;
	var re = /^\d*$/
	if (!re.test(value))
	{
		alert('Non numeric character encountered where a number was expected.'); 
		return false;
	}
	return true;
}

// returns true if value is an integer
// returns false otherwise.
function ValidateInt(value) {
	if (value == '')
		return true;
	var re = /^[+-]?\d*$/
	if (!re.test(value))
	{
		alert('Non numeric character encountered where a number was expected.'); 
		return false;
	}
	return true;
}

// returns true if value is a floating point number
// returns false otherwise.
function ValidateFloat(value) {
	if (value == '')
		return true;
	var re = /^[+-]?\d*\.?\d*$/
	if (!re.test(value))
	{
		alert('Non numeric character encountered where a number was expected.'); 
		return false;
	}
	return true;
}

// returns true if value is a valid representation of a currency amount (with 2 decimal places)
// returns false otherwise.
function ValidateCurrency(field, format) {
	if (field.value == '')
		return true;
	//
	//	This regular expression matches for a valid currency expression. 
	//	Valid examples are: -$3,456.34; 34453457; (3456); $(1,345.04); -2.34
	//	It has four parts, separated by the 'or' operator, |
	//  They are:
	//		^[+-]?[$]?\d+(\.\d\d)?$							Matches small amounts that don't have commas, such as 12345.67, optional currency symbol $ at the front, negative represented using -
	//		^[+-]?[$]?\d{1,3},(\d\d\d,)*\d\d\d(\.\d\d)?$	As above except allows for comments every third digit before the decimal point
	//		^[$]?\(\d+(\.\d\d)?\)$							As per the first expression, except it represents negatives using brackets e.g. $(123,456.78)
	//		^[$]?\(\d{1,3},(\d\d\d,)*\d\d\d(\.\d\d)?\)$		As per the second expression, except it represents negatives using brackets
	var re =	/^[+-]?[$]?\d+(\.\d\d)?$|^[+-]?[$]?\d{1,3},(\d\d\d,)*\d\d\d(\.\d\d)?$|^[$]?\(\d+(\.\d\d)?\)$|^[$]?\(\d{1,3},(\d\d\d,)*\d\d\d(\.\d\d)?\)$/
	if (!re.test(field.value))
	{
		alert('Invalid format for currency/money field.  Please use only a single currency symbol, numbers, commas and 2 decimal places'); 
		return false;
	}
	if (!format)
	{
		var length = field.maxLength;
		var value = field.value;
		value = value.replace(/^\$|,/g,"");
		length -= 3;  // decimal places
		length -= Math.floor(length / 4); // commas
		length -= 1; // Leading '-' symbol
		if (Math.floor(value) > Math.pow(10,length)-1)
		{
			alert('The maximum value for this field (' + (Math.pow(10,length)-1).toString() + ') has been exceeded.');
			return false;
		}
	}

	return FormatCurrencyField(field,format);
}

function FormatCurrencyField(field,format) 
{
	field.value = FormatCurrency2(field.value,format);
	return true;
}

function FormatCurrency(value)
{
	return FormatCurrency2(value,1);
}

function FormatCurrencyAlt(value)
{
	return FormatCurrency2(value,3);
}

function FormatMoney(value)
{
	return FormatCurrency2(value,0);
}

function FormatMoneyAlt(value)
{
	return FormatCurrency2(value,2);
}

function FormatCurrency2(value,format)
{
	//Implemented formats are as follows:
	//	0: -34,569.00
	//	1: -$34,569.00
	//	2: (34,569.00)
	//	3: $(34,569.00)
	var CurrencyFormat = "";
	var pos = 0;
	var decPos = 0;
	
	if (value != value) // NaN
		value = 0;
	
	value = "" + value;

	if (value.length != 0) 
	{		
		value = StripCurrency(value)
		value = value * 100;
		value = Math.round(value);
		value = "" + value/100;		
		decPos = value.indexOf(".");	
				
		for (var len = value.length - 1; len >= 0; len--)
		{
			if (len <= decPos - 1 || decPos == -1)
				pos++;		
				
			if (((pos - 1) % 3 == 0 && len >= 0 && pos - 1 > 0) && (value.substr(len,1) != '-') && (value.substr(len,1) != '(')) 
			{ 
				CurrencyFormat = "," + CurrencyFormat; 
			} 
			
			if(len == decPos)
				CurrencyFormat = "." + CurrencyFormat; 
			else
				CurrencyFormat = value.substr(len,1) + CurrencyFormat;
		} 			
		
		if(decPos == -1)
			CurrencyFormat = CurrencyFormat + ".00";
		decPos = CurrencyFormat.indexOf(".");
		if (decPos == CurrencyFormat.length - 2)
			CurrencyFormat = CurrencyFormat + '0';		
			
		if (format)
		{		 
			CurrencyFormat = CurrencyFormat.replace(/[-]/, "");
			if(value < 0)
			{
				switch (format)
				{
					case 1:
						CurrencyFormat = "-$" + CurrencyFormat;	break;				
					case 2:
						CurrencyFormat = "(" + CurrencyFormat + ")"; break;
					case 3:
						CurrencyFormat = "$(" + CurrencyFormat + ")"; break;
				}
			}
			else if (format == 1 || format == 3)
				CurrencyFormat = "$" + CurrencyFormat;
		}					
		return CurrencyFormat;
	}
	
	if (format == 1 || format == 3)
		return '$0.00';
	else
		return '0.00';
}

function CurrencyFormatter(format,decimalPlaces)
{
    function InternalFormatCurrency(value)
    {
	    //Implemented formats are as follows:
	    //	0: -34,569.00
	    //	1: -$34,569.00
	    //	2: (34,569.00)
	    //	3: $(34,569.00)
	    var CurrencyFormat = "";
	    var pos = 0;
	    var decPos = 0;
    	
	    if (value != value) // NaN
		    value = 0;
    	
	    value = "" + value;

	    if (value.length != 0) 
	    {		
	        var multiplier = Math.pow(10,decimalPlaces);
		    value = StripCurrency(value)
		    value = value * multiplier;
		    value = Math.round(value);
		    value = "" + value/multiplier;		
		    decPos = value.indexOf(".");	
    				
		    for (var len = value.length - 1; len >= 0; len--)
		    {
			    if (len <= decPos - 1 || decPos == -1)
				    pos++;		
    				
			    if (((pos - 1) % 3 == 0 && len >= 0 && pos - 1 > 0) && (value.substr(len,1) != '-') && (value.substr(len,1) != '(')) 
			    { 
				    CurrencyFormat = "," + CurrencyFormat; 
			    } 
    			
			    if(len == decPos)
				    CurrencyFormat = "." + CurrencyFormat; 
			    else
				    CurrencyFormat = value.substr(len,1) + CurrencyFormat;
		    } 			
    		if (decPos == -1)
    		    CurrencyFormat += ".";
            decPos = CurrencyFormat.indexOf("."); 
            while (CurrencyFormat.length - decPos < decimalPlaces)
                CurrencyFormat += "0";
    			
		    if (format)
		    {		 
			    CurrencyFormat = CurrencyFormat.replace(/[-]/, "");
			    if(value < 0)
			    {
				    switch (format)
				    {
					    case 1:
						    CurrencyFormat = "-$" + CurrencyFormat;	break;				
					    case 2:
						    CurrencyFormat = "(" + CurrencyFormat + ")"; break;
					    case 3:
						    CurrencyFormat = "$(" + CurrencyFormat + ")"; break;
				    }
			    }
			    else if (format == 1 || format == 3)
				    CurrencyFormat = "$" + CurrencyFormat;
		    }					
		    return CurrencyFormat;
	    }
    	for (CurrencyFormat = "0."; decimalPlaces > 0; decimalPlaces--)
    	    CurrencyFormat += "0";
    	
	    if (format == 1 || format == 3)
		    return '$' + CurrencyFormat;
	    else
		    return CurrencyFormat;
    }
    return InternalFormatCurrency;
}

function StripCurrency(value)
{
	var nBracketPos = value.indexOf("(");
	var sCurrency = value.replace(/[\$,\(\)]/g,'');
	var fCurrency = parseFloat(sCurrency);
	if (nBracketPos >= 0)
		fCurrency *= -1;
	if (fCurrency != fCurrency) // NaN
		return 0;
	return fCurrency;
}

function FormatDate(field, d, m, y)
{
	if (y.length == 1)
		y = '0' + y;
	if (y.length == 2)
	{
		// Do year 70/30 window calculations
		var tempy = new Number(y);
		var date = new Date();
		var hi, lo;
		lo = Math.floor((date.getFullYear() - 70) / 100);
		hi = Math.floor((date.getFullYear() + 30) / 100);
		if (tempy <= date.getFullYear() + 30 - Math.floor(date.getFullYear()/100)*100)
			y = hi + y;
		else 
			y = lo + y;
	}
	// Check if it is a valid date.
	var ny, nd, nm;
	ny = new Number(y);
	nd = new Number(d);
	nm = new Number(m);
	if (ny < 1890 || ny > 9999 || (ny == 1890 && nd == 1 && nm == 1))
	{
		alert('That date falls outside the acceptable range of dates.');
		return false;
	}
	if (nm < 1 || nm > 12)    //validation of the month
	{
		alert('The date entered is an invalid date.');
		return false;
	}
	var nMaxDays = 31;

	// validation of the acceptable number of days in any month
	if (nm == 4 || nm == 6 || nm == 9 || nm == 11)
		nMaxDays = 30;
	if (nm == 2)
	{
		nMaxDays = 28;
		if ((!(ny%4) && ny%100) || !(ny%400))//(!ny%4 && (ny%100)) || !ny%400)
			nMaxDays =29;
	}
	if (nd > nMaxDays || nd < 1)
	{
		alert('The date entered is an invalid date.');
		return false;
	}
	
	if (d.length == 1)
		d = '0' + d;
	if (m.length == 1)
		m = '0' + m;

	field.value = d + '/' + m + '/' + y;
	return true;
}

function ValidateDateTime(field) {
	var value = field.value;
	if (value == '')
		return true; // Allow the user to delete a date

	if (!contains("apmAPM:/ 0123456789", value))
	{
		alert('The date-time you entered contains invalid characters.');
		return false;
	}

	var re1 = /^(\d{1,2})\/(\d{1,2})\/(\d|\d{2}|\d{4}) (\S{4,6})$/
	var re2 = /^(\d\d)(\d\d)(\d\d\d\d) (\S{4,6})$/
	var re3 = /^(\d{1,2}) (\d{1,2}) (\d|\d{2}|\d{4}) (\S{4,6})$/
	
	var valid = true;
	if (re1.test(value))
	{
		valid = FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
		if (!valid)
			return false;
		value = field.value;
		field.value = RegExp.$4;
		valid = ValidateTime(field);
		if (!valid)
			return false;
		field.value = value + ' ' + field.value;
		return true;
	}
	else if (re2.test(value))
	{
		valid = FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
		if (!valid)
			return false;
		value = field.value;
		field.value = RegExp.$4;
		valid = ValidateTime(field);
		if (!valid)
			return false;
		field.value = value + ' ' + field.value;
		return true;
	}
	else if (re3.test(value))
	{
		valid = FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
		if (!valid)
			return false;
		value = field.value;
		field.value = RegExp.$4;
		valid = ValidateTime(field);
		if (!valid)
			return false;
		field.value = value + ' ' + field.value;
		return true;
	}

	alert('Invalid format for a date-time.  The valid date formats are DD/MM/YY, DDMMYYYY and DD MM YY. Valid time formats are HHMM H:MMa H:MMAM H:MMam. The date and time must be separated by a single space.'); 
	return false;
}

function ValidateDate(field) {
	var value = field.value;
	if (value == '')
		return true; // Allow the user to delete a date
	if (!contains("/ 0123456789", value))
	{
		alert('The date you entered contains invalid characters.  The valid formats are DD/MM/YY, DDMMYYYY and DD MM YY');
		return false;
	}
	var re1 = /^(\d{1,2})\/(\d{1,2})\/(\d|\d{2}|\d{4})$/
	var re2 = /^(\d\d)(\d\d)(\d{2}|\d{4})$/
	var re3 = /^(\d{1,2}) (\d{1,2}) (\d|\d{2}|\d{4})$/
	var valid = true;
	if (re1.test(value))
	{
		return FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
	}
	else if (re2.test(value))
	{
		return FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
	}
	else if (re3.test(value))
	{
		return FormatDate(field, RegExp.$1, RegExp.$2, RegExp.$3);
	}
	
	alert('Invalid format for a date.  The valid formats are DD/MM/YY, DDMMYYYY and DD MM YY'); 
	return false;
}

function ValidateTime(field) {
	var msg = 'Invalid characters in time field. Please use only numbers, :, A, a, P or p.';
    var msg2 = 'Invalid format for a time field.  Valid formats are HHMM H:MMa H:MMAM H:MMam.';
	var value = field.value;
	if (value == '')
		return true; // Allow the user to delete a time
	if (!contains("apmAPM: 0123456789", value))
	{
		alert(msg);
		return false;	// this should be the only time we return msg
	}
	value = value.replace(/\s/g,'');  // strip spaces
	if ((value.length == 4) && (value.indexOf(':') == -1))
		value = value.substr(0,2) + ':' + value.substr(2,2);    
	var separator = value.indexOf(':');
	if (separator == -1) { // missing hour/minute separator.
		alert(msg2);
		return false;
	}
	var hour = value.substr(0, separator);
	var minute;
	var meridian;

	var am = value.indexOf('a');
	if (am == -1) am = value.indexOf('A');
	var pm = value.indexOf('p');
	if (pm == -1) pm = value.indexOf('P');
	var endtime=0;
	
	if (am != -1)
	{
		endtime = am;
		meridian = 'AM';
	}
	if (pm != -1)
	{
		endtime = pm;
		meridian = 'PM';
	}

	if (!endtime) { // 24 hour time.
		minute = value.substr(separator+1);
	}
	else minute = value.substr(separator+1, endtime-separator-1);
	
	if (am != -1 && pm != -1) { // Can only be one of am or pm.
		alert(msg2);
		return false;
	}

	if (endtime && value.substr(endtime).length > 2) { // meridian specifier can't be more than 2 chars
		alert(msg2);
		return false;
	}
	else if (endtime) {
		if (value.substr(endtime).length == 2 && (value.charAt(value.length - 1) != 'm' && value.charAt(value.length - 1) != 'M' )) {
		  alert(msg2);
		  return false;
		}
	}

	if (hour.length > 2 || minute.length > 2) { // Only 2 digits allowed for hour/minute
		alert(msg2);
		return false;
	}

	if (ValidateNatural(hour) && hour >= 0) { // hour must be a number and > 1
		if ((endtime && hour > 12) || (!endtime && hour >= 24)) {
			alert(msg2);
			return false;
		}
	}
	else {
		alert(msg2);
		return false;
	}

	if (ValidateNatural(minute)) {
		if (minute >= 60) {
			alert(msg2);
			return false;
		}
	}
	else {
		alert(msg2);
		return false;
	}
	
	if (meridian == undefined)
	{
		if (hour >= 12)
		{
			hour -= 12;
			meridian = 'PM';
			if (!hour) hour = 12;
		}
		else
			meridian = 'AM';
	}
	if (minute.length == 1)
		minute = '0' + minute;
		
	if (minute.length == 0)
		minute = "00" + minute;
	
	field.value = hour + ':' + minute + meridian;
	
	return true;
}

function ValidateTimeSplit(field) 
{
	if (!ValidateTime(field))
		return false;
	
	//strip out AM/PM from field.value
	var value = field.value;
	if (value == '')
		return true; // Allow the user to delete a time	
	var meridian = value.substr(value.length-2);
		
	field.value = value.substr(0,value.length-2);
	
	var ampmfield = field.name + 'AMPM'; 	
	document.getElementById(ampmfield).value = meridian; //set am/pm on the associated combo box
	
	return true;
}

function ValidateTime24(field) {
	var msg = 'Invalid characters in time field, please use only numbers,:,A,a,P or p.';
    var msg2 = 'Invalid format for a time field.  Valid formats are HHMM H:MMa H:MMAM H:MMam.';
	var value = field.value;
	if (value == '')
		return true; // Allow the user to delete a time
	if (!contains("apmAPM: 0123456789", value))
	{
		alert(msg);
		return false;	// this should be the only time we return msg
	}
	value = value.replace(/\s/g,'');  // strip spaces
	if (value.length == 4 && value.indexOf(':') == -1)
		value = value.substr(0,2) + ':' + value.substr(2,2);    
	var separator = value.indexOf(':');
	if (separator == -1) { // missing hour/minute separator.
		alert(msg2);
		return false;
	}
	var hour = value.substr(0, separator);
	var minute;
	var meridian;

	var am = value.indexOf('a');
	if (am == -1) am = value.indexOf('A');
	var pm = value.indexOf('p');
	if (pm == -1) pm = value.indexOf('P');
	var endtime=0;
	
	if (am != -1)
	{
		endtime = am;
		meridian = 'AM';
		if (hour == '12')
			hour = '0';
	}
	if (pm != -1)
	{
		endtime = pm;
		meridian = 'PM';
	}

	if (!endtime) { // 24 hour time.
		minute = value.substr(separator+1);
	}
	else minute = value.substr(separator+1, endtime-separator-1);
	
	if (am != -1 && pm != -1) { // Can only be one of am or pm.
		alert(msg2);
		return false;
	}

	if (endtime && value.substr(endtime).length > 2) { // meridian specifier can't be more than 2 chars
		alert(msg2);
		return false;
	}
	else if (endtime) {
		if (value.substr(endtime).length == 2 && (value.charAt(value.length - 1) != 'm' && value.charAt(value.length - 1) != 'M' )) {
		  alert(msg2);
		  return false;
		}
	}

	if (hour.length > 2 || minute.length > 2) { // Only 2 digits allowed for hour/minute
		alert(msg2);
		return false;
	}

	if (ValidateNatural(hour) && hour >= 0) { // hour must be a number and > 1
		if ((endtime && hour > 12) || (!endtime && hour >= 24)) {
			alert(msg2);
			return false;
		}
	}
	else {
		alert(msg2);
		return false;
	}

	if (ValidateNatural(minute)) {
		if (minute >= 60) {
			alert(msg2);
			return false;
		}
	}
	else {
		alert(msg2);
		return false;
	}
	
	if (meridian == undefined)
	{
		if (hour >= 12)
		{
			hour -= 12;
			meridian = 'PM';
			if (!hour) hour = 12;
		}
		else
			meridian = 'AM';
	}
	if (minute.length == 1)
		minute = '0' + minute;
		
	if (minute.length == 0)
		minute = "00" + minute;
		
	if (meridian == 'PM' && hour < 12)
		hour -= -12;

	var sHour = '' + hour;
	if (sHour.length == 2 && sHour.charAt(0) == '0')
		sHour = sHour.substr(1);
		
	field.value = sHour + ':' + minute;
	
	return true;
}

function StringToDate(value)
{
    var parts = value.split("/");
    return new Date(parts[2],parts[1]-1,parts[0]);
}

function DateToString(date)
{
    var day = date.getDate();
    var month = date.getMonth() + 1;
    if (day.length < 2)
        day = '0' + day;
    if (month.length < 2)
        month = '0' + month;
    return day + '/' + month + '/' + date.getFullYear();
}

// returns true if value is true or false
// returns false otherwise.
function ValidateBoolean(value) {
	var lcvalue = value.toLowerCase();
	if (lcvalue == 'true' || lcvalue == 'false') {
		return true;
	}
	else {
		alert('This field can only be "true" or "false"');
		return false;
	}
}

function ValidatePhone(value) {
	if (value == '')
		return true;
	var msg='Invalid format for phone field.  Please limit to characters consisting of numbers, +, -, round brackets, x, X or spaces.';
	var re = /^[-xX+() \d]*$/
	if (!re.test(value))
	{
		alert(msg); 
		return false;
	}
	return true;
}

function ValidateSuburb(type, field)
{
	var state;
	var postcode;
	var typedata
	if (type.indexOf('|') >= 0)
		typedata = type.split('|');
	else
		typedata = type.split(':');
	
	if (typedata.length > 1)
		state = window.document.all(typedata[1] + '');
	if (typedata.length > 2)
		postcode = window.document.all(typedata[2] + '');
	
	//we don't want to validate if they are trying to clear the suburb
	if (field.value == '')
	{
		//wipe state and suburb
		if (state != undefined)
		{
			if(state.length != undefined)
			{
				for (var i = 0; i < state.length; i++)
					SetFieldValue(state[i], '');
			}
			else
				SetFieldValue(state, '');
		}	
		if (postcode != undefined)
		{
			if(postcode.length != undefined)
			{
				for (var i = 0; i < postcode.length; i++)
					SetFieldValue(postcode[i], '');
			}
			else
				SetFieldValue(postcode, '');
		}
		
		if (state && Events != undefined)
			Events.FireEvent(typedata[1],state[1]);
		else if (state)
			state.fireEvent('onchange');
		if (postcode && Events != undefined)
			Events.FireEvent(typedata[2],postcode[1]);	
		else if (postcode)
			postcode.fireEvent('onchange');
		return true;		
	}

	var suburb = field.value;
	suburb = suburb.replace(/%/g,'%25');
	var country = typedata[0].substr(6);
	if (country.length > 0)
		suburb = suburb + '&country=' + country;
	var retval = window.showModalDialog('list.asp?listid=1&suburb=' + suburb + '&random='+Math.random(), '', 'dialogWidth: 490px; dialogHeight: 190px; help: no; status: no;');
	if (retval == undefined || retval == '')
		return false;

	var suburbdata = retval.split(':');
	if(suburbdata[0] != undefined && field.maxLength < suburbdata[0].length)
	{
	   	alert('The Suburb you have selected is greater than the maximum number of characters allowed in this field.  Please contact your system administrator to have this Suburb abbreviated.');
	   	suburbdata[0]=suburbdata[1]=suburbdata[2]="";
	}
    field.value = suburbdata[0];
    if (typedata[1] != undefined && state != undefined)
    {
	    if (state.length >= 0)
	    {
		    for (var i = 0; i < state.length; i++)
			    SetFieldValue(state[i], suburbdata[1]);
	    }
	    else
		    SetFieldValue(state, suburbdata[1]);
    }
    if (typedata[2] != undefined && postcode != undefined)
    {
	    if (postcode.length >= 0)
	    {
		    for (var i = 0; i < postcode.length; i++)
			    SetFieldValue(postcode[i], suburbdata[2]);
	    }
	    else
		    SetFieldValue(postcode, suburbdata[2])
    }
	if (state && Events != undefined)
		Events.FireEvent(typedata[1],state[1]);
	else if (state)
		state.fireEvent('onchange');
	if (postcode && Events != undefined)
		Events.FireEvent(typedata[2],postcode[1]);	
	else if (postcode)
		postcode.fireEvent('onchange');
		
	return true;
}

function ValidateABN(value)
{
	if (value == '')
		return true;
	var re = /^\d\d( \d{3}){3}$/;
	if (!re.test(value))
	{
		alert('The ABN must be in the form 99 999 999 999.');
		return false;
	}
	var nAbnNumber, x, zero;
	nAbnNumber = new Array(14);
	zero = '0';
	for(x=0;x<14;x++)
		nAbnNumber[x] = value.charCodeAt(x) - zero.charCodeAt(0);
	nAbnNumber[0] -=1;

	nAbnNumber[0] *= 10;
	nAbnNumber[1] *= 1;
	nAbnNumber[3] *= 3;
	nAbnNumber[4] *= 5;
	nAbnNumber[5] *= 7;
	nAbnNumber[7] *= 9;
	nAbnNumber[8] *= 11;
	nAbnNumber[9] *= 13;
	nAbnNumber[11] *= 15;
	nAbnNumber[12] *= 17;
	nAbnNumber[13] *= 19;
	
	var nCheckDigit = 0;
	for(x=0;x<14;x++)
	{
		if(x != 2 && x != 6 && x != 10)
			nCheckDigit +=nAbnNumber[x];	
	}
	if(nCheckDigit % 89 != 0)
	{
		alert('The ABN is not accurate.  The check digit calculation results in an error.  Please confirm the ABN and enter a valid number before proceeding.');
		return false;
	}
	return true;
}

function ValidateACN(value)
{
	if (value == '')
		return true;
	var re = /^\d{3}( \d{3}){2}$/;
	if (!re.test(value))
	{
		alert('The ACN must be in the form 999 999 999.');
		return false;
	}
	return true;
}

function contains(smstring,lrgstring) {
	//returns true iff lrgstring contains only the characters in smstring.
	strlen1 = smstring.length
	strlen2 = lrgstring.length
	for (i=0;i<strlen2;i++)
	{
		charisok = false;	
		for (j=0;j<strlen1;j++)
		{
			if (smstring.charAt(j) == lrgstring.charAt(i))
				charisok = true;			
		}
		if (!charisok)
			return false;
	}
	return true;
}

// All fields will call this function to perform simple type based
// validation.  Additional types can be added as necessary
// Returns true if type is valid
// Returns false otherwise
function Validate(type, field) {
	if (type == 'text') return true;
	if (type == 'natural') return ValidateNatural(field.value);
	if (type == 'integer') return ValidateInt(field.value);
	if (type == 'float') return ValidateFloat(field.value);
	if (type == 'currency') return ValidateCurrency(field,1);	// -$3.45
	if (type == 'currency2') return ValidateCurrency(field,3);	// $(3.45)
	if (type == 'money') return ValidateCurrency(field,0);		// -3.45
	if (type == 'money2') return ValidateCurrency(field,2);		// (3.45)
	if (type == 'date') return ValidateDate(field);
	if (type == 'time') return ValidateTime(field);
	if (type == 'time24') return ValidateTime24(field);
	if (type == 'boolean') return ValidateBoolean(field.value);
	if (type == 'phone') return ValidatePhone(field.value);
	if (type == 'abn') return ValidateABN(field.value);
	if (type == 'acn') return ValidateACN(field.value);
	if (type.substring(0, 6) == 'suburb') return ValidateSuburb(type, field)
	if (type == 'datetime') return ValidateDateTime(field);
	alert('This field has an invalid or unknown data type associated with it!');
	return false;
}

