// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15605926-2']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

window.addEvent("domready", function (event) {
	document.getElements('a').each(function(item, index) {
		if (item.getProperty('rel') == 'external') item.setProperty('target', '_blank');
	});
});

// Everything Else
function fillSelect(date, target, wordy, price) {
	if ($(date).value) {
		u = '/shows/selector/'+$(date).get('value');
		if (wordy) u += '/1';
		$(target).empty();
		var option = new Element('option').set('text', 'Loading...').inject(target);
		var req_1 = new Request.HTML({
			url: u,
			method: 'get',
			onComplete: function() {
				if (price) {
					// Show the price of the selected show
					fillPrices($('ShowId').value);
					$('ShowId').addEvent('change', function() {
						fillPrices(this.value);
					});
				}
			},
			update: $(target+'Wrapper')
		}).send();
	}
}

function fillPrices(id) {
	ticket_types = ['Adults', 'Children', 'Seniors', 'Ashevillans'];
	if (id) {
		var req_2 = new Request({
			method: 'get',
			url: '/shows/prices/'+id,
			data: { 'do' : '1' },
			onComplete: function(response) {
				responses = response.split(',');
				responses.each(function(item, index) {
					$('ticket'+ticket_types[index]+'Cost').set('value', formatMoney(item));
				});
			}
		}).send();
	}
}

function formatMoney(amount) {
	var i = parseFloat(amount);
	if (isNaN(i)) { i = 0.00; }
	var minus = '';
	if (i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if (s.indexOf('.') < 0) { s += '.00'; }
	if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function toggle_count(n) {
	if ($('ticket'+n).checked == true) {
		$('ticket'+n+'Count').value = 1;
		$('ticket'+n+'CountWrapper').setStyle('visibility', 'visible');
	} else {
		$('ticket'+n+'Count').value = 0;
		$('ticket'+n+'CountWrapper').setStyle('visibility', 'hidden');
	}
}

function spm_trap(n) {
	locationstring="mailto:"+n+"@lazoomtours.com?subject=LaZoom Tours";
	window.location=locationstring;
}
