var strLatestStockUpdate = "2010-03-12";

arrayCurrency = new Array(20);
arrayCurrency[0] = "AUD|$|Australia Dollars|1.110252|WORLD";
arrayCurrency[1] = "BRL|R$|Brazil Reais|1.788009|WORLD";
arrayCurrency[2] = "CAD|$|Canada Dollars|1.028607|WORLD";
arrayCurrency[3] = "CZK|Kc|Czech Republic Koruny|18.975091|EU";
arrayCurrency[4] = "DKK|kr|Denmark Kroner|5.479406|EU";
arrayCurrency[5] = "EUR|€|Euro|0.736270|EU";
arrayCurrency[6] = "HUF|Ft|Hungary Forint|196.330605|EU";
arrayCurrency[7] = "ISK|kr|Iceland Kronur|127.980689|WORLD";
arrayCurrency[8] = "INR|Rs|India Rupees|45.780228|WORLD";
arrayCurrency[9] = "ILS|She|Israel New Shekels|3.771004|WORLD";
arrayCurrency[10] = "JPY|¥|Japan Yen|89.250508|WORLD";
arrayCurrency[11] = "MXN|$|Mexico Pesos|12.655722|WORLD";
arrayCurrency[12] = "NZD|$|New Zealand Dollars|1.457306|WORLD";
arrayCurrency[13] = "NOK|kr|Norway Kroner|5.926227|WORLD";
arrayCurrency[14] = "PLN|zl|Poland Zlotych|2.856804|EU";
arrayCurrency[15] = "SEK|kr|Sweden Kronor|7.149996|EU";
arrayCurrency[16] = "CHF|Fr|Switzerland Francs|1.077503|WORLD";
arrayCurrency[17] = "THB|Bht|Thailand Baht|32.659054|WORLD";
arrayCurrency[18] = "GBP|£|United Kingdom Pounds|0.664986|EU";
arrayCurrency[19] = "USD|$|United States Dollars|1.000000|WORLD";


var strCurrentCurrency = "USD";

function WriteCurrencyValue(strCurrencyName,fltCurrencyValue,strPriceType,intPriceVAT) {

	var fltValue = 0;
	var strPriceInfo = "";

	fltValue = parseFloat(fltCurrencyValue);

	if (strCurrentCurrency!=strCurrencyName) {

		for (var i=0; i<=arrayCurrency.length-1; i++) {
			var strCurrencyInfo = new String(arrayCurrency[i]); 
			arrayInfo = strCurrencyInfo.split("|");
			if (strCurrencyName == arrayInfo[0]) var fltCurrencyRate = arrayInfo[3];
			if (strCurrentCurrency == arrayInfo[0]) var fltCurrencyGoal = arrayInfo[3];
		}	
		
		fltValue = fltCurrencyValue / fltCurrencyRate * fltCurrencyGoal;
	
	}

	for (var i=0; i<=arrayCurrency.length-1; i++) {
		var strCurrencyInfo = new String(arrayCurrency[i]); 
		arrayInfo = strCurrencyInfo.split("|");
		if (strCurrentCurrency == arrayInfo[0]) {
			strCurrencySign = arrayInfo[1];
			strCurrencyType = arrayInfo[4];
		}
	}	
	
	switch (strPriceType) {
	
		case "WORLD" :
			fltValue = fltValue;
			strPriceInfo = "(excl. VAT)";
			strPriceSign = "*";
		break;
		
		case "EU" :
			if (strCurrencyType=="WORLD") {
				fltValue = fltValue;
				strPriceInfo = "(excl. VAT)";
				strPriceSign=" *";
			} else  {
				fltValue = fltValue + (fltValue*intPriceVAT/100);
				strPriceInfo = "(inc. "+intPriceVAT+"% VAT)";
				strPriceSign = "";
			}
		break;		

		case "EUVAT" :
			if (strCurrencyType=="WORLD") {
				fltValue = fltValue - (fltValue*intPriceVAT/100);
				strPriceInfo = "(excl. VAT)";
				strPriceSign=" *";
			} else  {
				fltValue = fltValue;
				strPriceInfo = "(inc. "+intPriceVAT+"% VAT)";
				strPriceSign = "";
			}
		break;			

		default :
			fltValue = fltValue;
			strPriceInfo = "";
			strPriceSign = "";
		break;
	}
	
	fltValue = Math.round(fltValue * 100) / 100;
	
	var strValueResult = "";
	
	if (fltValue == parseInt(fltValue))  {
		strValueResult = fltValue + ".00";
	} else {
		if ((fltValue*10) == parseInt(fltValue*10))  {
			strValueResult = fltValue + "0";
		} else {
			strValueResult = fltValue;
		}
	}
	
	document.writeln("<b>" + strValueResult + "</b> " + strCurrencySign + strPriceSign +"<br><span class=txts>" + strPriceInfo + "</span>");
	
} 

function getCurrentCurrency() {

	var strCookie = getCookie("CURRENCY");
	var strQueryString = getQueryString("currency");
	
	if (strQueryString!="") {
		strCurrentCurrency = strQueryString;
	} else {
		if (strCookie!="") {
			strCurrentCurrency = strCookie;
		} else {
			strCurrentCurrency = "USD";
		}
	}
	
}

function WriteCurrencySelect() {

	document.writeln("<tr><form name=\"formCurrency\" method=\"GET\"><td valign=top colspan=5 class=txts align=right>");
	document.writeln("Change currency: <select name=\"currency\" onChange=\"ChangeCurrency();\" class=txtds>");

	for (var i=0; i<=arrayCurrency.length-1; i++) {
		var strCurrencyInfo = new String(arrayCurrency[i]); 
		arrayInfo = strCurrencyInfo.split("|");
		if (strCurrentCurrency == arrayInfo[0]) strSELECTED = " SELECTED"; else strSELECTED = "";
		document.writeln("<option value=\""+arrayInfo[0]+"\""+strSELECTED+">"+arrayInfo[2]+"</option>");
	}

	document.writeln("</select>");
	document.writeln("</td><input type=\"hidden\" name=\"rel_id\" value=\"\"></form></tr>");
}

function ChangeCurrency() {

	var strNewCurrency = document.formCurrency.currency[document.formCurrency.currency.options.selectedIndex].value;
	setCookie("CURRENCY",strNewCurrency);
	
	document.formCurrency.rel_id.value = getQueryString("rel_id");
	document.formCurrency.submit();

}

function GetVatInfo() {
	document.writeln("<tr><td class=T1S  width=600 class=txt><table border=0 cellpadding=0 cellspacing=5><tr><td class=txt>");
	document.writeln("* - prices without VAT may be subject to customs fees and import duties of the country to which you have your order shipped.");
	document.writeln("</td></tr></table></td></tr>");
}

function setCookie(strCookieName,strCookieValue) {
	var dateExpires = new Date();
	dateExpires.setTime(dateExpires.getTime() + (1000*60*60*24*365));
	document.cookie = strCookieName + "=" + escape(strCookieValue) + ";expires=" + dateExpires.toGMTString() + ";path=/";
}

function getCookie(strCookieName) {

	var strCookieValue = "";
	var intStart = document.cookie.indexOf(strCookieName + "=");
	var intLength = intStart + strCookieName.length + 1;

	if (intStart == -1) {
		return strCookieValue;
	} else {
	
		var intEnd = document.cookie.indexOf( ";", intLength);
		if (intEnd == -1) intEnd = document.cookie.length;
	
		strCookieValue = unescape(document.cookie.substring(intLength, intEnd));
	
		return strCookieValue;
		
	}
}

function delCookie(strCookieName) {
	document.cookie = strCookieName + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT;path=/";
}

function getQueryString(strVariableName) {

	var strValue = "";
	var strQuery = document.location.search.substring(1);
	var arrayQuery = strQuery.split("&");
  
	for (var i=0; i<arrayQuery.length; i++) {
		var strVariableNameValue = new String(arrayQuery[i]);
		var arrayVariableNameValue = strVariableNameValue.split("=");
		if (arrayVariableNameValue[0] == strVariableName) {
			return arrayVariableNameValue[1];
		}
	} 
  
	return strValue;
  
}



