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 intlCountry;
var intlCurrency;
var intlExchangeRates = new Array(["GBP", 7952742, 0.7149840000], ["EUR", 7952741, 0.7604280000], ["CAD", 7952740, 1.2629800000], ["USD", 7952743, 1.0000000000]);

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

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)).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];
				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("productWarranties", "productBMLNoPayments", "productBMLLowPayments", "spShipping", "spSalesTax", "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);
	}
}

