with (window.navigator) {
	var isIE = (userAgent.match(/MSIE/)), 	
	isIE6 = (userAgent.match(/MSIE 6.[0-9]/)),	
	isIE7 = (userAgent.match(/MSIE 7.[0-9]/)),	
	isIE8 = (userAgent.match(/MSIE 8.[0-9]/));	
}

// grab curreny country / region from URL
var currentCountry = document.location.pathname.substring(1, 3);

// by id
function $(id)
{
	return document.getElementById(id);
}

function go(u)
{
	document.location.href=u;
}

// get by tag
function byTag(tag, obj)
{
	return (obj || document).getElementsByTagName(tag);
}

function byAttribute(att, value, obj)
{
	var re = new RegExp(value);
	var r = [];
	var els = (obj || document).getElementsByTagName("*");
	for (var c = 0, l = els.length; c < l; c ++) {
		var a = els[c].getAttribute(att);
		//alert("result: " + a + " > " + att + " > " + els[c].getAttribute("rel"));
		if (a && a.match(re)) {
			r.push(els[c]);
		}
	}
	return r;
}

function create(el)
{
	return document.createElement(el);
}

// extend objects
function extend(obj, props, force)
{
	for (var x in props) {
		if (typeof(obj[x]) == "undefined" || force) {
			obj[x] = props[x];
		}
	}
}

// returns objs document co-ordinates
function position(obj, type)
{
	type = type.toLowerCase().ucFirst();
	var orig = obj;
	var retval = 0;
	if (type == "Left" && obj.x) {
		return obj.x;
	}
	else if (type == "Top" && obj.y) {
		return obj.y;
	}
	else {
		var useType = (type == "Left" || type == "Right" || type == "Center") ? "Left" : "Top";
		while (obj.offsetParent) {
			//if (obj && obj.style && obj.style.position) obj.style.position = "relative";
			retval += eval("obj.offset" + useType);
			obj = obj.offsetParent;
		}
		switch (type) {
			case "Center" : return retval + (orig.offsetWidth / 2); break;
			case "Right" : return retval + (orig.offsetWidth); break;
			default: return retval;
		}			
	}
	return false;

}

function screenHeight()
{
	return screenDimension("Height");
}

function screenWidth()
{
	return screenDimension("Width");
}

// gets dimnensions for screen size (height + width)
function screenDimension(type)
{
	return eval("(self.inner" + type + ") ? self.inner" + type + " : (document.documentElement && document.documentElement.client" + type + ") ? document.documentElement.client" + type + " : document.body.client" + type);
}

// 
function findParent(tag, obj)
{
	tag = tag.toUpperCase();
	while (obj && obj.tagName != tag) {
		obj = obj.parentNode;
	}
	return obj;
}

// 
function findParentByClassName(tag, obj)
{
	tag = new RegExp(tag, 'i');
	while (obj && obj.className && ! obj.className.match(tag)) {
		obj = obj.parentNode;
	}
	return obj;
}

// Add easier event handling
if (! window.Event) {
	var Event = {};
}

// Event object extending
var ev = {
	
	get: function(e)
	{
		return (! e) ? window.event : e;
	},

	target: function(e)
	{
		e = this.get(e);
		return (e.target) ? e.target : (e.srcElement) ? e.srcElement : false;
	},

	add: function(elm, evType, fn, useCapture)
	{
		// cross-browser event handling for IE5+, NS6 and Mozilla By Scott Andrew
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return elm;
		} 
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return elm;
		} 
		else {
			elm['on' + evType] = fn;
			return elm;
		}	
	},
		
	key: function(e)
	{
		e = this.get(e);
		return (e.keyCode) ? e.keyCode : (e.which) ? e.which : e.charCode;
	},
		
	stop: function(e)
	{
		e = this.get(e);
		if (document.all) {
			e.returnValue = false;
			e.cancelBubble = true;
		}
		else {
			e.preventDefault();
			e.stopPropagation();
		}		
	}
	
};
extend(Event, ev);

// uppercase first letter
String.prototype.ucFirst = function() {
	return this.substring(0,1).toUpperCase() + this.substring(1);
};

// Array extensions
Array.prototype.search = function(value, offset) {
	if (typeof(offset) == "undefined") {
		offset = 0;
	}
	for (var q = offset, l = this.length; q < l; q ++) {
		if (this[q] == value || this[q].match(value)) {
			return q;
		}
	}
	return -1;
};

Array.prototype.has = function(value) {
	return (this.search(value) != -1);
};

Array.prototype.walk = function(func) {
	for (var x = 0, l = this.length; x < l; x ++) {
		func(this[x]);
	}
};

// add classname
function addClass(obj, c)
{
	var s = obj.className.split(/ /);
	for (var q = 0, l = s.length; q < l; q ++) {
		if (s[q] == c) {
			return obj;
		}
	}
	s.push(c);
	obj.className = s.join(' ');
	return obj;
}

// add classname
function removeClass(obj, c)
{
	var r = [];
	var s = obj.className.split(/ /);
	for (var q = 0, l = s.length; q < l; q ++) {
		if (s[q] != c) {
			r.push(s[q]);
		}
	}
	obj.className = r.join(' ');
	return obj;
}

function setCollapseImage(obj, state)
{
	if (state == "open") {
		this.collapseState = "closed";
		with (obj) {
			alt = title = "Click to open";
			src = "images/arr_right.gif";
			style.width = 15;
			style.height = 17;								
		}
	}
	else {
		with (obj) {
			alt = title = "Click to close";
			src = "images/arr_down.gif";
			style.width = 17;
			style.height = 15;								
		}
	}
}

function makeCollapsable()  
{ 
	var x = byTag("*");
	for (var i = 0, k = x.length; i < k; i ++) {
		
		// tab panel?
		if (x[i].className.match(/tab_panel/)) {
			setupTabPanel(x[i]);
		}	
	}	
}

function setupTabPanel(p)
{	
	p.lastTab = null;
	var li = byTag('li', byTag('UL', p)[0]), f = 0;
	
	for (var d = byTag('div', p), x = 0, l = d.length; x < l; x ++) {
		if (d[x].className.match(/tabx_[a-z]/)) {
			li[f].tabElement = d[x];											
			li[f].onclick = function() {				
				var p = this.parentNode.parentNode;				
				if (p.lastTab != null) {
					p.lastTab.tabElement.style.display = 'none';
					removeClass(p.lastTab, 'on');
				}				
				this.tabElement.style.display = 'block';
				addClass(this, 'on');
				p.lastTab = this;				
			}
						
			if (! f) {
				p.lastTab = li[f];
			}
			f ++;
		}
	}
}

function toggleState(obj)
{
	var x = $(obj.id.replace(/country/, 'state'));
	if (x) {
		if (obj.value == 'Australia') {
			x.disabled = false;
			findParent('LI', x).style.display = 'block';
		}
		else {
			x.disabled = true;
			findParent('LI', x).style.display = 'none';
		}
	}
}

// add collapsable items
Event.add(window, "load", makeCollapsable, false);