// JavaScript Document

YAHOO.namespace('Intrepid');

function callbackCurrency(obj) {
	var response = obj.responseText;
	response = response.split("<!")[0];
	// alert(response);
	eval(response);
	updateCurrency(data['currency']);
}

function updateCurrency(sNew) {
	// alert('sCurrency = ' + sCurrency);
	if (sNew != '' && sNew != sCurrency) {
		sCurrency = sNew;
		setCookie('_INT_CURRENCY', sCurrency, getExpDate(), '/');
		var span = $('spanPrice');
		if (span) {
			// alert('setting span');
			if ((oPrices[sCurrency]['info'] && oPrices[sCurrency]['info'] != '') || [sCurrency]['price'] == 0) {
				if ([sCurrency]['price'] != 0) {
					span.innerHTML = 'Prices from ' + sCurrency + ' ' + oPrices[sCurrency]['symbol'] + '<strong>' + oPrices[sCurrency]['price'] + '</strong>' + '<br />' + unescape(oPrices[sCurrency]['info']);
				} else {
					span.innerHTML = 'Prices in ' + oPrices[sCurrency]['desc'] + 's (' + oPrices[sCurrency]['symbol'] + ') <br />' + unescape(oPrices[sCurrency]['info']);
				}
			} else {
				span.innerHTML = sCurrency + ' ' + oPrices[sCurrency]['symbol'] + '<strong>' + oPrices[sCurrency]['price'] + '</strong>';
			}
			//For trips with Kitties it is now law that we must show this for AUD advertised pricing
			$('spanTotalPriceAUD').style.display = (sCurrency == 'AUD' && $('spanTotalPriceAUD').hasClassName('valid'))?'inline':'none';
		} // 
	}
}

function initCurrencyDlg() {

	var handleCancel = function() {
		this.cancel();
	}
	var handleSubmit = function() {
		this.submit();
	}
	

	YAHOO.Intrepid.dlgCurrency = new YAHOO.widget.Dialog("dlgCurrency", { modal:true, visible:false, width:"350px", fixedcenter:true, constraintoviewport:true, draggable:true });
	
	var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn:handleCancel,scope:YAHOO.Intrepid.dlgCurrency,correctScope:true} );

	YAHOO.Intrepid.dlgCurrency.cfg.queueProperty("keylisteners", listeners);

	YAHOO.Intrepid.dlgCurrency.cfg.queueProperty("buttons", [ { text:"Submit", handler:handleSubmit, isDefault:true },
										 { text:"Cancel", handler:handleCancel } ]);

	YAHOO.Intrepid.dlgCurrency.cfg.queueProperty("onsuccess", callbackCurrency);
	
	var handleManual = function(type, args, obj) {
		alert("Manual submission of " + this.id + " detected");
	}

	YAHOO.Intrepid.dlgCurrency.manualSubmitEvent.subscribe(handleManual, YAHOO.Intrepid.dlgCurrency, true);
	YAHOO.Intrepid.dlgCurrency.render();

	YAHOO.Intrepid.dlgCurrency.cfg.setProperty('postmethod','async');

}

YAHOO.util.Event.addListener(window, "load", initCurrencyDlg);
