if(typeof Math == "undefined")
	throw("Core Library (Math) Required");

/*
Locale

Provides localised functionality for validation and currency formatting.

Assumptions:
* Prototype is included
* Core Library is included

Usage:

> var locale = new Locale();
> var regEx = locale.getRegularExpression('first_name');
> var currencyString = locale.currencyToString('89.00');
*/
var Locale = Class.create({
	initialize: function() {
		// Specify regular expressions for data validation
		this.regularExpressions = {
			first_name: /^[a-zA-Z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff '-]+$/,
			last_name: /^[a-zA-Z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff '-.]+$/,
			postcode: /^[a-zA-Z0-9 '-]+$/,
			telephone: /^[+]?[0-9 ()-]+$/,
			store_search: /^[a-zA-Z0-9 '-.]+$/,
			address: /^[a-zA-Z0-9\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff '-.]+$/
		};
		this.dateFormats = {
			fullMonths: ["January","February","March","April","May","June","July","August","September","October","November","December"]
		};
	},
	getCountryCode: function() {
		return "NZ";
	},
	getAdditionalSearchTerms: function() {
		return "New Zealand";
	},	
	/**
	 * Returns true if the given currency amount is zero or not a number
	 */
	isZeroAmount: function(amount) {
		return (parseInt(amount) == 0 || amount == "" || amount == NaN);
	},
	/**
	 * Returns a validated currency amount which converts any NaN/undefined values to zero
	 */
	getValidatedAmount: function(amount) {
		var validatedAmount = cost;
		if(this.isZeroAmount(validatedAmount)) 
			validatedAmount = 0;
		return validatedAmount;
	},
	/**
	 * Returns a localised current amount as a string
	 */
	currencyToString: function(amount) {
		var validatedAmount = this.getValidatedAmount(amount);
		return Math.formatNumber(validatedAmount, {
			decimals:2,
			currency:true,
			currencySymbol:'&pound;',
			formatWhole:true,
			wholeDelimiter:',',
			decimalDelimiter:'.'
		});
	},
	/**
	 * Returns the specified validation regular expression
	 */
	getRegularExpression: function (name) {
		if(this.regularExpressions[name] == undefined)
			throw("Regular Expression '" + name + "' not defined for this locale. ");
		return this.regularExpressions[name];
	},
	/**
	 * Returns the specified date format parameter
	 */
	getDateFormat: function (name) {
		if(this.dateFormats[name] == undefined)
			throw("Date format '" + name + "' not defined for this locale. ");
		return this.dateFormats[name];
	},
	getGoogleMapsUrl: function() {
		return "http://maps.google.co.nz/";
	},
	getGoogleTracker: function() {
		return "UA-4243241-1";
	},
	/*
	 * Returns an array of address lines in order
	 */
	getStoreAddress: function(store) {
		this.addressItems = new Array();
		var self = this;
//		[store.address1, store.address2, store.address3, store.address4, store.address5, store.postCode].each(function(addressItem) {
		[store.address1, store.address2, store.address3, store.postCode + ' ' + store.address4].each(function(addressItem) {
			if(addressItem != "")
				self.addressItems.push(addressItem);
		});
		return this.addressItems;
	}
});
