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", 13129734, 1.0000000000], ["CAD", 13129698, 1.0869200000], ["EUR", 13129706, 0.6941730000], ["GBP", 13129707, 0.6180080000], ["AUD", 13129696, 1.1130900000], ["HKD", 13129708, 8.0495400000], ["SGD", 13129729, 1.4372500000], ["PHP", 13129724, 48.5972000000], ["THB", 13129730, 34.4615000000], ["PLN", 13129725, 2.8465500000], ["DKK", 13129703, 5.1658000000], ["LTL", 13129716, 2.3970400000], ["SEK", 13129728, 7.0896400000], ["CZK", 13129702, 17.6826000000], ["EEK", 13129704, 10.8604000000], ["HUF", 13129709, 184.2830000000], ["LVL", 13129717, 0.4924110000]);
var intlLCP = new Array(["CA", 1.1000000000, 501], ["BE", 1.2000000000, 502], ["BG", 1.2000000000, 502], ["CY", 1.2000000000, 502], ["CZ", 1.2000000000, 502], ["DE", 1.2000000000, 502], ["DK", 1.2000000000, 502], ["EE", 1.2000000000, 502], ["ES", 1.2000000000, 502], ["FI", 1.2000000000, 502], ["FR", 1.2000000000, 502], ["GB", 1.2000000000, 502], ["GI", 1.2000000000, 502], ["GR", 1.2000000000, 502], ["HU", 1.2000000000, 502], ["IE", 1.2000000000, 502], ["IS", 1.2000000000, 502], ["IT", 1.2000000000, 502], ["LI", 1.2000000000, 502], ["LT", 1.2000000000, 502], ["LU", 1.2000000000, 502], ["LV", 1.2000000000, 502], ["MC", 1.2000000000, 502], ["MT", 1.2000000000, 502], ["NL", 1.2000000000, 502], ["PL", 1.2000000000, 502], ["PT", 1.2000000000, 502], ["RO", 1.2000000000, 502], ["SE", 1.2000000000, 502], ["SI", 1.2000000000, 502], ["SK", 1.2000000000, 502], ["SM", 1.2000000000, 502], ["AD", 1.2000000000, 502], ["AT", 1.2000000000, 502], ["HK", 1.1500000000, 503], ["AU", 1.2000000000, 504], ["SG", 1.2000000000, 504]);

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

