/*# Metadata ################################### Header v.2
# $URL$
# $Rev$
# $Date$
# $Author$
### TOC ###################################################
#
### Description ###########################################
#
#########################################################*/

window.addEvent("domready", function(){
	if ($('main')) {

		var main = $('main');
		var browserOffset = {};

		if (Browser.chrome) {
			browserOffset = { x: -8, y: 22 };
		}
		else {
			browserOffset = { x: 35, y: 22 };
		}

		var paymentTip = new GT.PaymentTip(main.getElements('.paymentTable tbody tr, .lastpayment'), {
			offset: browserOffset,
			delayHide: 700,
			durationShow: 200,
			durationHide: 200
		});
	}
	if($('showCountryCurrencyForm')) {
		var countryCurrencyForm = new GT.CountryCurrencyForm({
			opener: $('showCountryCurrencyForm')
		});		
	}
	if($('paymentToolTip')){
		BODY.addEvent('click:relay(#paymentToolTip a)', function (event, el) {
			event.preventDefault();
			window.open(el.href,'_blank');
		});
	}
	
	if($('countryCurrencyForm') && $('selectCountry') && $('selectCurrency')){
		var selectedCurrency, 
			selectedCountry;
		
		var countries = $$('#selectCountry option'),
			currencies = $$('#selectCurrency option');
		
		$('selectCountry').addEvent('change', function() {
			selectedCountry = $('selectCountry').get('value');
			selectedCurrency = $('selectCountry').getElements('option[value='+selectedCountry+']')[0].getProperty('relatedCurr');
			$('selectCurrency').getElements('option[value='+selectedCurrency+']')[0].setProperty('selected','selected');
		});
	}

	if ($('confirmBuyForm')) {
		function confirmBuy(target) {
			var check = confirm(confirmMsg);
			if (check == true) {
				var button = target.getElement('button');
				var bgStyle = 'url("'+ xslFolder +'/imgs/formButton-deactive.gif") repeat-x scroll left bottom #E0E0E0';
				button.setStyles({
					background: bgStyle,
					border: '1px solid #666',
					color: '#333'
				});
				button.getElement('span').set('text', paymentConf);
				button.disabled = 1
				return check;
			}
			return check
		}

		$('confirmBuyForm').setProperty('onsubmit', '');
		$('confirmBuyForm').getElement('button').removeProperty('disabled');
		$('confirmBuyForm').addEvent('submit', function(event) {
			return confirmBuy(event.target);
		});
	}
});

