$(document).ready( function(){
  var currencyCode = $("#currencyCode").val();
  if(currencyCode != null && currencyCode != "")
    displaycurrency(currencyCode);
});

// disclaimerclosed variable used to determine if mouse is on tooltip or not (1=not, 0=on)
var disclaimerclosed = 1;

function dropcurrencylist() {
	//drop down currency list]
	var curlist = document.getElementById('currencyselect');
	if(curlist.style.display=='block'){
		curlist.style.display='none';
	}
	else{
		document.getElementById('curdisclaimer').style.display = "none";
		curlist.style.display='block';
	}
}

function displaycurrency(thecurrency)
{
  //set value into currency combo box and show disclaimer
	var curbox = document.getElementById('currencybox');
	switch (thecurrency.toLowerCase()) {
		case 'eur':
			curbox.innerHTML = "<img src='/images/common/flg-eur.png' id='flagtype' width='16' height='11' /> Euro - EUR";
			break;
		case 'gbp':
			curbox.innerHTML = "<img src='/images/common/flg-gbp.png' id='flagtype' width='16' height='11' /> British Pound - GBP";
			break;
		case 'cad':
			curbox.innerHTML = "<img src='/images/common/flg-cad.png' id='flagtype' width='16' height='11' /> Canadian Dollar - CAD";
			break;
		case 'jpy':
			curbox.innerHTML = "<img src='/images/common/flg-jpn.png' id='flagtype' width='16' height='11' /> Japanese Yen - JPY";
			break;
		case 'cny':
			curbox.innerHTML = "<img src='/images/common/flg-cny.png' id='flagtype' width='16' height='11' /> Chinese Yuan - CNY";
			break;
		case 'inr':
			curbox.innerHTML = "<img src='/images/common/flg-inr.png' id='flagtype' width='16' height='11' /> Indian Rupee - INR";
			break;
		case 'aud':
			curbox.innerHTML = "<img src='/images/common/flg-aud.png' id='flagtype' width='16' height='11' /> Australian Dollar - AUD";
			break;
		case 'usd':
			curbox.innerHTML = "<img src='/images/common/flg-usd.png' id='flagtype' width='16' height='11' /> US Dollar - USD";
			break;
		default:
			curbox.innerHTML = "<img src='/images/common/flg-usd.png' id='flagtype' width='16' height='11' /> US Dollar - USD";
	}
	document.getElementById('currencyselect').style.display = "none";
}

function setcurrency(thecurrency) {
	displaycurrency(thecurrency);
	
	$.ajax({
    url: "/selectCurrency.do?default-method=selectCurrency",
    cache: false,
    dataType: "json",
    data: {currencyCode:thecurrency.toUpperCase()},
    success: function(data) {
      // If currency code is set to the session bean correctly, a response object will be returned. The current page should be refreshed.
      disclaimerclosed = 0;
    	$("#curdisclaimer").fadeIn("fast");
    	setTimeout ('closedisclaimer()', 4000);
    }
  });
}

function closedisclaimer() {
	//loop timer until mouse is off disclaimer, if mouse is off (disclaimerclosed = 1) then okay to close it, otherwise continue loop
	if (document.getElementById('curdisclaimer').style.display == "none") {
		//if its already closed
		return;
	}
	else {
		if (disclaimerclosed == 1) {
			$("#curdisclaimer").fadeOut("slow");
			location.reload(true);
			return;
		}
		setTimeout ('closedisclaimer()', 1000);
	}
}

function closenow()
{
  $("#curdisclaimer").fadeOut("slow");
	location.reload(true);
}
