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", 24454462, 1.0000000000], ["CAD", 24454426, 1.0437100000], ["EUR", 24454433, 0.7990310000], ["GBP", 24454434, 0.6693550000], ["AUD", 24454424, 0.9820280000], ["HKD", 24454435, 8.3421600000], ["SGD", 24454457, 1.3428800000], ["PHP", 24454451, 45.4079000000], ["THB", 24454458, 33.1148000000], ["PLN", 24454452, 3.4044100000], ["DKK", 24454431, 6.0224100000], ["LTL", 24454443, 2.7980400000], ["SEK", 24454456, 7.1424400000], ["CZK", 24454430, 20.2399000000], ["CLP", 24454428, 513.7700000000], ["HUF", 24454436, 236.8050000000], ["LVL", 24454444, 0.5668990000], ["TWD", 24454460, 31.7221000000], ["OMR", 24454449, 0.4141340000], ["PEN", 24454450, 2.8920400000], ["BRL", 24454425, 1.8552500000], ["JPY", 24454440, 81.7988000000], ["COP", 24454429, 1912.3400000000], ["EGP", 24454432, 6.4960600000], ["INR", 24454439, 53.2456000000], ["ILS", 24454438, 4.0103500000], ["ARS", 24454423, 4.6710300000], ["QAR", 24454453, 3.9164500000], ["SAR", 24454455, 4.0335800000], ["KRW", 24454441, 1200.2600000000], ["NOK", 24454447, 6.1787900000], ["MXN", 24454446, 13.7159000000], ["TRY", 24454459, 1.8955800000], ["CHF", 24454427, 0.9811840000], ["IDR", 24454437, 9625.7900000000], ["KWD", 24454442, 0.2983020000], ["AED", 24454422, 3.9504400000], ["UAH", 24454461, 8.6363200000], ["NZD", 24454448, 1.2874100000], ["RUB", 24454454, 32.0474000000], ["ZAR", 24454463, 8.2328900000]);
var intlLCP = new Array(["CA", 1.1000000000, 501], ["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);
}

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


