
UTIL = (
	function () {
	
		var ajax = function (url, onSuccess, async, testData) {
			var xhr
			
			if (!window.ActiveXObject) {xhr = new XMLHttpRequest()} 
			else {
				try {xhr = new ActiveXObject("Msxml2.XMLHTTP.6.0")} 
				catch (x) {
					try {xhr = new ActiveXObject("Msxml2.XMLHTTP")} 
					catch (x) {xhr = new ActiveXObject("Microsoft.XMLHTTP")}
				}
			}
							
			var handler = function () {
				if (xhr.status == 200) {
					var data = eval('('+xhr.responseText+')')
					
					if (data._error) {alert('ERROR: '+data._error)} 
					else {onSuccess(data)}
				} 
				else {alert('ERROR: '+xhr.status+' - '+xhr.statusText)}
			}
					
			var setHandler = window.ActiveXObject || async
			if (setHandler) {
				xhr.onreadystatechange = function () {
					if (xhr.readyState == 4) {handler(xhr)}
				}
			}
			
			xhr.open('GET', url+(url.indexOf('?')>=0 ? '&' : '?')+(new Date().getTime()), async)
			xhr.send(null)
			
			if (!setHandler) {handler()}
		}
		
		var testPrices = {FSX_S9:251, FSP_S9:151, FSHS9:101, FRECPC:102}
		var currencies = {1:{id:1, code:'EUR', symbol:'&euro;'}, 2:{id:2, code:'USD', symbol:'$'}}
	
		var _ = {
			addToCart: function (prodId, prodName, outletId) {
				window.location.href = 'http://ecommerce.flexispy.com/cart.do'+
					'?act=add&prodID='+encodeURIComponent(prodId)+'&prodName='+encodeURIComponent(prodName)+
					'&currency='+_.getCurrency()+'&outletID='+outletId+
					'&'+new Date().getTime()   // prevent caching
			},
	
			getCountry: function () {return geoip_country_code()},
			
			getCurrency: function () {
				var c = _.getCountry()
				return c == "US" ? 2 : 1
			},
	
			getOutlet: function () {
				var outlet = getCookie(cookieName)
				if (!outlet) {readRef(); outlet = refNo}
				if (!outlet || outlet=="null" || outlet=="0") {outlet = verv_refNo}
				return outlet
			},
	
			getPrice: function (product) {
				var c = _.getCurrency()
				var r = {currency:currencies[c]}
				
				ajax('proxy.jsp?_url='+encodeURIComponent('http://ecommerce.flexispy.com/util.jsp?op=getPrice&product='+product+'&outlet='+_.getOutlet()+'&currency='+c),
					function(data) {r.amount = data.price},
					false,
					{price:testPrices[product]}
					)
					
				return r
			},
			
			renderPrice: function (product) {
				var price = _.getPrice(product)
				document.write(price.currency.symbol+price.amount)}
		}
	
		return _
	}
)()
	
document.write('<script src="http://j.maxmind.com/app/country.js"></script>')   // use GeoIP to detect user's country

