function getIntlElement(id) {
	return (document.getElementById ? document.getElementById(id) : (document.all ? document.all[id] : (document.layers ? document.layers[id] : null)));
}

function getIntlCookie(c) {
	if (document.cookie.length > 0) {
		var s = document.cookie.indexOf(c + "=");

		if (s > -1) {
			s = s + c.length + 1;

			var e = document.cookie.indexOf(";", s);

			return unescape(document.cookie.substring(s, (e != -1 ? e : document.cookie.length)));
		}
	}

	return null;
}

var sIntlCookie = getIntlCookie("intl_s");
var pIntlCookie = getIntlCookie("intl_p");
var fxRate;
var lcp;
var intlCountry;
var intlCurrency;
var intlExchangeRates = new Array(["USD", 16647154, 1.0000000000], ["CAD", 16647118, 1.0724800000], ["EUR", 16647126, 0.7980190000], ["GBP", 16647127, 0.6662110000], ["AUD", 16647116, 1.1544100000], ["HKD", 16647128, 8.0867800000], ["SGD", 16647149, 1.4177100000], ["PHP", 16647144, 47.4131000000], ["THB", 16647150, 33.6129000000], ["PLN", 16647145, 3.2054400000], ["DKK", 16647123, 5.9610000000], ["LTL", 16647136, 2.7629500000], ["SEK", 16647148, 7.5461200000], ["CZK", 16647122, 19.8283000000], ["EEK", 16647124, 12.5217000000], ["HUF", 16647129, 228.5600000000], ["LVL", 16647137, 0.5677290000]);
var intlLCP = new Array(["CA", 1.1000000000, 515], ["HU", 1.2000000000, 516], ["SM", 1.2000000000, 516], ["SK", 1.2000000000, 516], ["AD", 1.2000000000, 516], ["AT", 1.2000000000, 516], ["BE", 1.2000000000, 516], ["BG", 1.2000000000, 516], ["CY", 1.2000000000, 516], ["CZ", 1.2000000000, 516], ["DE", 1.2000000000, 516], ["DK", 1.2000000000, 516], ["EE", 1.2000000000, 516], ["ES", 1.2000000000, 516], ["FI", 1.2000000000, 516], ["FR", 1.2000000000, 516], ["GB", 1.2000000000, 516], ["GI", 1.2000000000, 516], ["GR", 1.2000000000, 516], ["IE", 1.2000000000, 516], ["IS", 1.2000000000, 516], ["IT", 1.2000000000, 516], ["LI", 1.2000000000, 516], ["LT", 1.2000000000, 516], ["LU", 1.2000000000, 516], ["LV", 1.2000000000, 516], ["MC", 1.2000000000, 516], ["MT", 1.2000000000, 516], ["NL", 1.2000000000, 516], ["PL", 1.2000000000, 516], ["PT", 1.2000000000, 516], ["RO", 1.2000000000, 516], ["SE", 1.2000000000, 516], ["SI", 1.2000000000, 516], ["HK", 1.1500000000, 517], ["AU", 1.2000000000, 518], ["SG", 1.2000000000, 518]);

function getIntlValue(n, c) {
	n += "=";

	var iN = c.indexOf(n);

	if (iN > -1) {
		var iV = c.indexOf(";", iN);

		if (iV == -1)
			iV = c.length;

		return c.substring(iN + n.length, iV);
	}

	return null;
}

if ((sIntlCookie && sIntlCookie.length > 0) || (pIntlCookie && pIntlCookie.length > 0)) {
	var intlCookie = (sIntlCookie && sIntlCookie.length > 0 ? sIntlCookie : pIntlCookie);

	intlCountry = getIntlValue("country", intlCookie);
	intlCurrency = getIntlValue("currency", intlCookie);
	fxRate = getIntlValue("exchangeRate", intlCookie);
	lcp = getIntlValue("lcp", intlCookie);
}

if (intlCountry && intlCurrency && !fxRate) {
	var pCookieValue;

	for (var i = 0; i < intlExchangeRates.length; i++)
		if (intlExchangeRates[i][0] == intlCurrency) {
			pCookieValue = ";quoteId=" + intlExchangeRates[i][1] + ";exchangeRate=" + intlExchangeRates[i][2];
			fxRate = intlExchangeRates[i][2];

			for (var j = 0; j < intlLCP.length; j++)
				if (intlLCP[j][0] == intlCountry) {
					pCookieValue += ";lcp=" + intlLCP[j][1] + ";lcpRuleId=" + intlLCP[j][2];
					lcp = intlLCP[j][1];
					break;
				}

			break;
		}

	if (pCookieValue)
		document.cookie = "intl_s=" + escape("country=" + intlCountry + ";currency=" + intlCurrency + pCookieValue) + "; path=/";
}

if (fxRate && intlCurrency)
	document.write("<style type=\"text/css\">.hide4Intl {display: none;}</style>");

function getIntlPrice(p) {
	if (fxRate && intlCurrency) {
		var nP = "";

		for (var i = 0; i < p.length; i++)
			if (p.charAt(i) == '.' || isNaN(p.charAt(i)) == false)
				nP += p.charAt(i);

		if (nP != "" && isNaN(nP) == false)
			return intlCurrency + "&nbsp;" + ((new Number(nP) * new Number(fxRate)) * (lcp ? new Number(lcp) : 1)).toFixed(2);

		return null;
	} else
		return p;
}

function displayIntlPricing() {
	if (fxRate && intlCurrency) {
		var pI = 0;
		var pE;

		while ((pE = getIntlElement("price" + pI))) {
			var p = pE.innerHTML;
			var r = p.indexOf(" - ");
			var p1 = getIntlPrice((r == -1 ? p : p.substring(0, r)));
			var p2 = (r == -1 ? null : getIntlPrice(p.substring(r + 3, p.length)));

			if (p1 != null)
				pE.innerHTML = p1 + (p2 ? " - " + p2 : "");

			pI++;
		}
	}
}

