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

function hideIntlElement(n) {
	var e = getIntlElement(n);

	if (e)
		e.style.display = "none";
}

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", 14698699, 1.0000000000], ["CAD", 14698663, 1.0625100000], ["EUR", 14698671, 0.7538270000], ["GBP", 14698672, 0.6847000000], ["AUD", 14698661, 1.1317700000], ["HKD", 14698673, 8.0583700000], ["SGD", 14698694, 1.4488800000], ["PHP", 14698689, 47.4287000000], ["THB", 14698695, 33.8383000000], ["PLN", 14698690, 2.9358700000], ["DKK", 14698668, 5.6093900000], ["LTL", 14698681, 2.6031000000], ["SEK", 14698693, 7.3242600000], ["CZK", 14698667, 19.2363000000], ["EEK", 14698669, 11.7944000000], ["HUF", 14698674, 200.5890000000], ["LVL", 14698682, 0.5341640000]);
var intlLCP = new Array(["CA", 1.1000000000, 513], ["AD", 1.2000000000, 514], ["SM", 1.2000000000, 514], ["SK", 1.2000000000, 514], ["AT", 1.2000000000, 514], ["BE", 1.2000000000, 514], ["BG", 1.2000000000, 514], ["CY", 1.2000000000, 514], ["CZ", 1.2000000000, 514], ["DE", 1.2000000000, 514], ["DK", 1.2000000000, 514], ["EE", 1.2000000000, 514], ["ES", 1.2000000000, 514], ["FI", 1.2000000000, 514], ["FR", 1.2000000000, 514], ["GB", 1.2000000000, 514], ["GI", 1.2000000000, 514], ["GR", 1.2000000000, 514], ["HU", 1.2000000000, 514], ["IE", 1.2000000000, 514], ["IS", 1.2000000000, 514], ["IT", 1.2000000000, 514], ["LI", 1.2000000000, 514], ["LT", 1.2000000000, 514], ["LU", 1.2000000000, 514], ["LV", 1.2000000000, 514], ["MC", 1.2000000000, 514], ["MT", 1.2000000000, 514], ["NL", 1.2000000000, 514], ["PL", 1.2000000000, 514], ["PT", 1.2000000000, 514], ["RO", 1.2000000000, 514], ["SE", 1.2000000000, 514], ["SI", 1.2000000000, 514], ["SG", 1.2000000000, 531], ["AU", 1.2000000000, 531], ["HK", 1.1500000000, 532]);

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);
}

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 (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) {
		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++;
		}

		var eTH = new Array("productBMLNoPayments", "productBMLLowPayments", "shippingSellingPoint", "shippingCost", "salesTaxSellingPoint", "salesTax", "productFinalPriceText", "productFinalPrice", "productShippingLink", "extraShippingCharges", "featuredHeaderLinks", "headerTI1", "headerTI2", "headerAd", "headerPromo", "winBuyer");

		for (var i = 0; i < eTH.length; i++)
			hideIntlElement(eTH[i]);

		for (var i = 1; i < 6; i++)
			hideIntlElement("hideIntl" + i);
	}
}

