//currency conversion data

var pwCurData = {
1: ["United States Dollar", "USD", "$", 1.0, true, []],
2: ["Australian Dollar", "AUD", "$", 1.0896815674, true, []],
12: ["United Kingdom Pound", "GBP", "\u00a3", 0.6462358743, true, []],
22: ["Japan Yen", "JPY", "\u00a5", 83.9607094233, true, []],
32: ["Canada Dollar ", "CAD", "$", 1.0371018685, true, []],
42: ["United Arab Emirates Dirhams", "AED", "$", 3.6727000883, false, []],
52: ["Afghanistan Afghanis", "AFN", "$", 44.2999992371, false, []],
62: ["Albania Leke", "ALL", "$", 107.82, false, []],
72: ["Armenia Drams", "AMD", "$", 363.799987793, false, []],
82: ["Netherlands Antilles Guilders", "ANG", "$", 1.7893999815, false, []],
92: ["Angola Kwanza", "AOA", "$", 90.0999984741, false, []],
102: ["Argentina Pesos", "ARS", "$", 3.9430010382, false, []],
112: ["Aruba Guilders", "AWG", "$", 1.79, false, []],
122: ["Azerbaijan New Manats", "AZN", "$", 0.8033000231, false, []],
132: ["Bosnia and Herzegovina Convertible Marka", "BAM", "$", 1.536831494, false, []],
142: ["Barbados Dollars", "BBD", "$", 2.0, false, []],
152: ["Bangladesh Taka", "BDT", "$", 69.3000190527, false, []],
162: ["Bulgaria Leva", "BGN", "$", 1.5368481538, false, []],
172: ["Bahrain Dinars", "BHD", "$", 0.3770400084, false, []],
182: ["Burundi Francs", "BIF", "$", 1228.0, false, []],
192: ["Bermuda Dollars", "BMD", "$", 1.0, false, []],
202: ["Brunei Dollars", "BND", "$", 1.3436887597, false, []],
212: ["Bolivia Bolivianos", "BOB", "$", 6.9699997902, false, []],
222: ["Brazil Reais", "BRL", "$", 1.7255001476, false, []],
232: ["Bahamas Dollars", "BSD", "$", 1.0, false, []],
242: ["Bhutan Ngultrum", "BTN", "$", 46.4850030103, false, []],
252: ["Botswana Pulas", "BWP", "$", 6.8493151692, false, []],
262: ["Belarus Rubles", "BYR", "$", 3030.0, false, []],
272: ["Belize Dollars", "BZD", "$", 1.959800005, false, []],
282: ["Congo\/Kinshasa Francs", "CDF", "$", 905.0, false, []],
292: ["Switzerland Francs", "CHF", "$", 1.011343058, false, []],
302: ["Chile Pesos", "CLP", "$", 496.50008, false, []],
312: ["China Yuan Renminbi", "CNY", "$", 6.7940003088, false, []],
322: ["Colombia Pesos", "COP", "$", 1806.6999511719, false, []],
332: ["Costa Rica Colones", "CRC", "$", 511.3115527734, false, []],
342: ["Cuba Convertible Pesos", "CUC", "$", 0.9259, false, []],
352: ["Cuba Pesos", "CUP", "$", 26.5, false, []],
362: ["Cape Verde Escudos", "CVE", "$", 86.8000030518, false, []],
372: ["Czech Republic Koruny", "CZK", "$", 19.3946994081, false, []],
382: ["Djibouti Francs", "DJF", "$", 175.75, false, []],
392: ["Denmark Kroner", "DKK", "", 5.850059363, false, []],
402: ["Dominican Republic Pesos", "DOP", "$", 36.4000015259, false, []],
412: ["Algeria Dinars", "DZD", "$", 73.8304818259, false, []],
422: ["Estonia Krooni", "EEK", "$", 12.2946519521, false, []],
432: ["Egypt Pounds", "EGP", "$", 5.7060000113, false, []],
442: ["Eritrea Nakfa", "ERN", "$", 15.0, false, []],
452: ["Ethiopia Birr", "ETB", "$", 16.3488998413, false, []],
462: ["Euro", "EUR", "\u20ac", 0.7857694657, true, []],
472: ["Fiji Dollars", "FJD", "$", 1.9286404185, false, []],
482: ["Falkland Islands Pounds", "FKP", "$", 0.6462358743, false, []],
492: ["Georgia Lari", "GEL", "$", 1.8504999876, false, []],
502: ["Guernsey Pounds", "GGP", "$", 0.6462358743, false, []],
512: ["Ghana Cedis", "GHS", "$", 1.4299999475, false, []],
522: ["Gibraltar Pounds", "GIP", "$", 0.6462358743, false, []],
532: ["Gambia Dalasi", "GMD", "$", 26.9500007629, false, []],
542: ["Guinea Francs", "GNF", "$", 5710.0, false, []],
552: ["Guatemala Quetzales", "GTQ", "$", 8.0469999313, false, []],
562: ["Guyana Dollars", "GYD", "$", 203.1999969482, false, []],
572: ["Hong Kong Dollars", "HKD", "$", 7.7703543521, false, []],
582: ["Honduras Lempiras", "HNL", "$", 18.8950004578, false, []],
592: ["Croatia Kuna", "HRK", "$", 5.728517765, false, []],
602: ["Haiti Gourdes", "HTG", "$", 39.75, false, []],
612: ["Hungary Forint", "HUF", "$", 225.4285897404, false, []],
622: ["Indonesia Rupiahs", "IDR", "$", 8998.0, false, []],
632: ["Israel New Shekels", "ILS", "\u20aa", 3.77924602, false, []],
642: ["Isle of Man Pounds", "IMP", "$", 0.6462358743, false, []],
652: ["India Rupees", "INR", "$", 46.4850030103, false, []],
662: ["Iraq Dinars", "IQD", "$", 1170.025, false, []],
672: ["Iran Rials", "IRR", "$", 9953.016, false, []],
682: ["Iceland Kronur", "ISK", "$", 117.9599990845, false, []],
692: ["Jersey Pounds", "JEP", "$", 0.6462358743, false, []],
702: ["Jamaica Dollars", "JMD", "$", 84.6500015259, false, []],
712: ["Jordan Dinars", "JOD", "$", 0.7090003114, false, []],
722: ["Kenya Shillings", "KES", "$", 81.1988449951, false, []],
732: ["Kyrgyzstan Soms", "KGS", "$", 46.8349990845, false, []],
742: ["Cambodia Riels", "KHR", "$", 4227.0, false, []],
752: ["Comoros Francs", "KMF", "$", 386.5732360374, false, []],
762: ["North Korea Won", "KPW", "$", 143.0792725253, false, []],
772: ["South Korea Won", "KRW", "$", 1172.3707895809, false, []],
782: ["Kuwait Dinars", "KWD", "$", 0.287500154, false, []],
792: ["Cayman Islands Dollars", "KYD", "$", 0.8098000288, false, []],
802: ["Kazakhstan Tenge", "KZT", "$", 147.3999938965, false, []],
812: ["Laos Kips", "LAK", "$", 8155.0, false, []],
822: ["Lebanon Pounds", "LBP", "$", 1501.00064, false, []],
832: ["Sri Lanka Rupees", "LKR", "$", 112.5200078418, false, []],
842: ["Liberia Dollars", "LRD", "$", 71.0, false, []],
852: ["Lesotho Maloti", "LSL", "$", 7.2401263928, false, []],
862: ["Lithuania Litai", "LTL", "$", 2.713104811, false, []],
872: ["Latvia Lati", "LVL", "$", 0.5571767704, false, []],
882: ["Libya Dinars", "LYD", "$", 1.2800012834, false, []],
892: ["Morocco Dirhams", "MAD", "", 8.7111293508, false, []],
902: ["Moldova Lei", "MDL", "$", 12.3360191626, false, []],
912: ["Madagascar Ariary", "MGA", "$", 2000.0, false, []],
922: ["Macedonia Denars", "MKD", "$", 48.0499992371, false, []],
932: ["Myanmar Kyats", "MMK", "$", 6.4099998474, false, []],
942: ["Mongolia Tugriks", "MNT", "$", 1315.0008, false, []],
952: ["Macau Patacas", "MOP", "$", 8.0034649827, false, []],
962: ["Mauritania Ouguiyas", "MRO", "$", 285.00064, false, []],
972: ["Mauritius Rupees", "MUR", "$", 30.2000007629, false, []],
982: ["Maldives Rufiyaa", "MVR", "$", 12.8, false, []],
992: ["Malawi Kwachas", "MWK", "$", 150.0, false, []],
1002: ["Mexico Pesos", "MXN", "$", 13.0425370837, false, []],
1012: ["Malaysia Ringgits", "MYR", "$", 3.1125007523, false, []],
1022: ["Mozambique Meticais", "MZN", "$", 36.25, false, []],
1032: ["Namibia Dollars", "NAD", "$", 7.2401263928, false, []],
1042: ["Nigeria Nairas", "NGN", "$", 151.6000541016, false, []],
1052: ["Nicaragua Cordobas", "NIO", "$", 21.5450000763, false, []],
1062: ["Norway Kroner", "NOK", "kr", 6.1929604004, false, []],
1072: ["Nepal Rupees", "NPR", "$", 73.8001630518, false, []],
1082: ["New Zealand Dollars", "NZD", "$", 1.3861834582, false, []],
1092: ["Oman Rials", "OMR", "$", 0.3850500052, false, []],
1102: ["Panama Balboas", "PAB", "$", 1.0, false, []],
1112: ["Peru Nuevos Soles", "PEN", "$", 2.7950000763, false, []],
1122: ["Papua New Guinea Kina", "PGK", "$", 2.7188689703, false, []],
1132: ["Philippines Pesos", "PHP", "$", 44.1899986267, false, []],
1142: ["Pakistan Rupees", "PKR", "$", 85.6100326099, false, []],
1152: ["Poland Zlotych", "PLN", "$", 3.095997959, false, []],
1162: ["Paraguay Guarani", "PYG", "$", 4750.0, false, []],
1172: ["Qatar Riyals", "QAR", "$", 3.6408000792, false, []],
1182: ["Romania New Lei", "RON", "$", 3.3661000729, false, []],
1192: ["Serbia Dinars", "RSD", "$", 80.9773025513, false, []],
1202: ["Russia Rubles", "RUB", "$", 30.8434902422, false, []],
1212: ["Rwanda Francs", "RWF", "$", 582.0, false, []],
1222: ["Saudi Arabia Riyals", "SAR", "$", 3.7502000332, false, []],
1232: ["Solomon Islands Dollars", "SBD", "$", 7.8963534693, false, []],
1242: ["Seychelles Rupees", "SCR", "$", 12.0500001907, false, []],
1252: ["Sudan Pounds", "SDG", "$", 2.3650000095, false, []],
1262: ["Sweden Kronor", "SEK", "$", 7.2673176927, false, []],
1272: ["Singapore Dollars", "SGD", "$", 1.3436887597, false, []],
1282: ["Saint Helena Pounds", "SHP", "$", 0.6462358743, false, []],
1292: ["Slovakia Koruny", "SKK", "$", 22.9058089417, false, []],
1302: ["Sierra Leone Leones", "SLL", "$", 3900.024, false, []],
1312: ["Somalia Shillings", "SOS", "$", 1617.0, false, []],
1322: ["Seborga Luigini", "SPL", "$", 0.1666666667, false, []],
1332: ["Suriname Dollars", "SRD", "$", 2.7100000381, false, []],
1342: ["S\u00e3o Tome and Principe Dobras", "STD", "$", 19200.0112, false, []],
1352: ["El Salvador Colones", "SVC", "$", 8.75, false, []],
1362: ["Syria Pounds", "SYP", "$", 46.5999984741, false, []],
1372: ["Swaziland Emalangeni", "SZL", "$", 7.2401263928, false, []],
1382: ["Thailand Baht", "THB", "\u00e0\u00b8\u00bf", 30.9949989452, false, []],
1392: ["Tajikistan Somoni", "TJS", "$", 4.3769001961, false, []],
1402: ["Turkmenistan Manats", "TMM", "$", 14250.0, false, []],
1412: ["Tunisia Dinars", "TND", "$", 1.4841004652, false, []],
1422: ["Tonga Pa'anga", "TOP", "$", 1.9588638059, false, []],
1432: ["Turkey New Lira", "TRY", "$", 1.5162500167, false, []],
1442: ["Trinidad and Tobago Dollars", "TTD", "$", 6.3000001907, false, []],
1452: ["Tuvalu Dollars", "TVD", "$", 1.0896815674, false, []],
1462: ["Taiwan New Dollars", "TWD", "$", 31.9360024237, false, []],
1472: ["Tanzania Shillings", "TZS", "$", 1519.0016, false, []],
1482: ["Ukraine Hryvnia", "UAH", "$", 7.9264998436, false, []],
1492: ["Uganda Shillings", "UGX", "$", 2260.0016, false, []],
1502: ["Uruguay Pesos", "UYU", "$", 20.7759990692, false, []],
1512: ["Uzbekistan Sums", "UZS", "$", 1630.0, false, []],
1522: ["Venezuela Bolivares", "VEB", "BSF", 4300.0, false, []],
1532: ["Venezuela Bolivares Fuertes", "VEF", "BSF", 4.3, false, []],
1542: ["Vietnam Dong", "VND", "$", 19450.0, false, []],
1552: ["Vanuatu Vatu", "VUV", "$", 96.7710446436, false, []],
1562: ["Samoa Tala", "WST", "$", 2.3691068044, false, []],
1572: ["Communaut\u00e9 Financi\u00e8re Africaine Francs BEAC", "XAF", "$", 515.4309813832, false, []],
1582: ["Silver Ounces", "XAG", "$", 0.0501656194, false, []],
1592: ["Gold Ounces", "XAU", "$", 0.0007963953, false, []],
1602: ["East Caribbean Dollars", "XCD", "$", 2.6700048763, false, []],
1612: ["International Monetary Fund Special Drawing Rights", "XDR", "$", 0.661338985, false, []],
1622: ["Communaut\u00e9 Financi\u00e8re Africaine Francs BCEAO", "XOF", "$", 515.4309813832, false, []],
1632: ["Palladium Ounces", "XPD", "$", 0.0019035928, false, []],
1642: ["Comptoirs Fran\u00e7ais du Pacifique Francs", "XPF", "$", 93.7672393384, false, []],
1652: ["Platinum Ounces", "XPT", "$", 0.0006416728, false, []],
1662: ["Yemen Rials", "YER", "$", 237.5, false, []],
1672: ["South Africa Rand", "ZAR", "$", 7.2401263928, false, []],
1682: ["Zambia Kwacha", "ZMK", "$", 4910.0032, false, []],
1692: ["Zimbabwe Dollars", "ZWD", "$", 361.9, false, []],
1693: ["Turkmenistan New Manats", "TMT", "$", 2.85, false, []]
};

var pwCurOrder = [1,2,12,22,32,42,52,62,72,82,92,102,112,122,132,142,152,162,172,182,192,202,212,222,232,242,252,262,272,282,292,302,312,322,332,342,352,362,372,382,392,402,412,422,432,442,452,462,472,482,492,502,512,522,532,542,552,562,572,582,592,602,612,622,632,642,652,662,672,682,692,702,712,722,732,742,752,762,772,782,792,802,812,822,832,842,852,862,872,882,892,902,912,922,932,942,952,962,972,982,992,1002,1012,1022,1032,1042,1052,1062,1072,1082,1092,1102,1112,1122,1132,1142,1152,1162,1172,1182,1192,1202,1212,1222,1232,1242,1252,1262,1272,1282,1292,1302,1312,1322,1332,1342,1352,1362,1372,1382,1392,1402,1412,1422,1432,1442,1452,1462,1472,1482,1492,1502,1512,1522,1532,1542,1552,1562,1572,1582,1592,1602,1612,1622,1632,1642,1652,1662,1672,1682,1692,1693];

var pwCurId = 1;
var pwCurCur = pwCurData[pwCurId];

var pwCurBId = 1;
var pwCurBCur = pwCurData[pwCurBId];

var pwCurModifier = 1;

var pwCurFormat = 0;

function pwSetBaseCurrency(curCurrencyId) {
	pwCurBId = curCurrencyId;
	pwCurBCur = pwCurData[pwCurBId];
}

function pwSetCurrentCurrency(curCurrencyId) {
	pwCurId = curCurrencyId;
	pwCurCur = pwCurData[pwCurId];
	
	if(pwCurId==pwCurBId) {
		pwCurModifier = 1;
	} else {
		fromUS = parseFloat(pwCurCur[3]);
		toUS = parseFloat(pwCurBCur[3]);
		pwCurModifier = fromUS / toUS;
	}
}

function pwSetCurrencyFormat(priceFormat) {
  pwCurFormat = priceFormat;
}

function pwCurSelectCurrency() {
	var div = document.getElementById("pw_c_popup");
	if(div.style.display=="") {
		pwCurClose();
		return;
	}
	var container = document.getElementById("pw_c_container");
	if(container.firstChild==null) {
		container.innerHTML = pwLoadCurrencySelector();
	}
	var link = document.getElementById("pw_c_popup_link");
	
	/* added by jonathan *///div.style.display="";
	//link.style.display="none";
}

function pwCurCurCode() {
	return pwCurCur[1];
}

function pwLoadCurrencySelector(el) {
	var html = '<select id="pw_c_selector" onchange="pwCurSelectorChanged(this);" style="width: 54px;">'; //</select>";
	for(var i=0; i < pwCurOrder.length; i++) { //>
		var cId = pwCurOrder[i];
		var cData = pwCurData[cId];
		/*
		var opt = document.createElement("OPTION");
		opt.value = cId;
		opt.text = cData[1] + " " + cData[0];
		if(cId==pwCurId) {
			opt.selected = true;
		}
		el.appendChild(opt);
	*/
		
		if(cId==pwCurId) {
			html += '<option value="' + cId + '" selected="true">' + cData[1] + " " + cData[0] + '</option>';
		} else {
			html += '<option value="' + cId + '">' + cData[1] + " " + cData[0] + '</option>';
		}
	}
	html += '</select>';
	return html;
	//document.write(html);
	//el.innerHTML = html;
}

function pwCurClose() {
	var div = document.getElementById("pw_c_popup");
	var link = document.getElementById("pw_c_popup_link");
	/* added by jonathan *///div.style.display="none";
	//link.style.display="";
}

function pwCurSelectorChanged(el) {
	var cId = el.value;
	pwSetCurrentCurrency(cId);
	
	var i2=new Image(1,1);
	i2.src="/ppr/home/set_user_currency/" + cId;
	i2.onload=function() { pwCurVoid(); };
		
	for(var i=0; i < pwCurAreas.length; i++) { //>
		var a = pwCurAreas[i];
		if(a["callback"] != null) {
			a["callback"](pwCurCur, pwCurBCur, pwCurModifier);
		} else {
			if(a["span"] == null) {
				a["span"] = document.getElementById(a["spanId"]);
			}
			if((a["codeId"] != null) && (a["code"] == null)) {
				a["code"] = document.getElementById(a["codeId"]);
			}
			if(a["code"]==null) {
				a["span"].innerHTML = pwCurFormatAmount(a["amount"], a["forceCents"]) + " " + pwCurCur[1];
				new Effect.Opacity(a["span"], { from: 0, to: 1.0, duration: 0.5 });
			} else {
				a["span"].innerHTML = pwCurFormatAmount(a["amount"], a["forceCents"]);
				a["code"].innerHTML = pwCurCur[1];
				new Effect.Pulsate(a["span"], { pulses: 5, duration: 1.5 });
			}
		}
	}
	var link = document.getElementById("pw_c_popup_link");
	link.innerHTML = "currency: "+pwCurCur[1];
	/*added by jonathan*///pwCurClose();
	close_extras($('currency'));
}

function pwCurVoid() { 
		return; 
	}

var pwCurIdCounter = 0;

function pwCurNextId() {
	pwCurIdCounter += 1;
	return pwCurIdCounter;
}

function pwCurConvert(amount) {
	if(pwCurId==pwCurBId) {
		return parseFloat(amount);
	}
	return amount * pwCurModifier;
}

function pwCurFormatAmount(amount, forceCents) {
	if(forceCents==null) {
		forceCents = true;
	}
	amount = pwCurConvert(amount);
	var dc = null;
	var dollars = parseInt(amount);
	var cents = parseInt((amount - dollars) * 100);
	if(cents == 0 && !forceCents) {
		return dollars;
	} else {
		return amount.toFixed(2);
	}
}

function pwCurArea(amount, spanClazz, codeClazz, forceCents, spanId, codeId, callback, registerArea, useExistingId, format, taxWarning) {
  if (taxWarning == null) taxWarning = "";
	if(spanId == null) {
		spanId = "pwc_s_" + pwCurNextId();
	}
	if(registerArea==false && codeId == null) {
	
	} else {
		if((codeId == null) && (codeClazz!=null)) {
			codeId = "pwc_c_" + pwCurNextId();
		}
	}
	
	if (forceCents == null) forceCents = true;
	
	var spanIdHtml = ' id="' + spanId + '"';
	var spanClazzHtml = "";
	if(spanClazz != null) spanClazzHtml = ' class="' + spanClazz + '"';
	
	var codeIdHtml = "";
	if(codeId != null) codeIdHtml = ' id="' + codeId + '"';
	var codeClazzHtml = "";
	if(codeClazz!=null) codeClazzHtml = ' class="' + codeClazz + '"';
	var codeHtml = pwCurCur[1];
	if(codeId != null || codeClazz!=null) codeHtml = '<span' + codeIdHtml + spanClazzHtml + '>' + pwCurCur[1] + '</span>';
	
	var html = "";
	if (format == null) format = pwCurFormat;
	switch(format) {
	case 1: html = '<span' + spanIdHtml + spanClazzHtml + '>' + pwCurCur[2] + pwCurFormatAmount(amount, forceCents) + ' ' + taxWarning + '</span>'; break;
	case 2: html = '<span' + spanIdHtml + spanClazzHtml + '>' + pwCurFormatAmount(amount, forceCents) + ' ' + codeHtml + taxWarning + '</span>'; break;
	case 3: html = '<span' + spanIdHtml + spanClazzHtml + '>' + pwCurFormatAmount(amount, forceCents) + ' ' + taxWarning + '</span> '; break;
	case 4: html = '<span' + spanIdHtml + spanClazzHtml + '>' + pwCurFormatAmount(amount, forceCents) + pwCurCur[2] + ' ' + taxWarning + '</span> '; break;
	default: html = '<span' + spanIdHtml + spanClazzHtml + '>' + pwCurCur[2] + pwCurFormatAmount(amount, forceCents) + ' ' + codeHtml + taxWarning + '</span>';
	}
	if((registerArea)||(registerArea==null)) {
		pwCurRegisterArea(amount, spanId,codeId, null, null, forceCents, callback);
	}
	if(useExistingId!=null) {
		var el = null;
		if (typeof useExistingId == 'string') {
		  el = document.getElementById(useExistingId);
		} else {
		  el = useExistingId;
		}
		el.innerHTML = html;
	} else {
	
		document.write(html);
	}
}

function pwCurWritePrice(amount, forceCents) {
	document.write(pwCurFormatAmount(amount, forceCents) + " " + pwCurCur[1]);
}

var pwCurAreas = [];

function pwCurRegisterArea(amount, spanId, codeId, span, code, forceCents, callback) {
	pwCurAreas.push( {
		amount:amount,
		spanId:spanId,
		codeId:codeId,
		span:span,
		code:code,
		forceCents:forceCents,
		callback:callback
	});

}
