//	Company	:	Douglas Instruments Limited, UK
//	File	:	PiceList.js
//	Created	:	2009-10-09
//	Function:	Multiple Currency Display Script
//	Author	:	Peter Baldock
//	Comment	:	All European contries except UK in EURLocations.
//				Only US in USDLocations.
//				UK+dependencies, Canada, Brazil, Australia+NZ, SA in GBPLocations
//				Rest of World : see no price (eg China, Japan, India etc.)
//				February 2009 rates preserved; USD=1.55; EUR=1.25;
//
//	Make pdf:	pdfFactory, Landscape mode, scaling = 85%
//
//
//	Revisions:
//	2009-11-04 GR removed from EURLocations at agent's request
//	2009-11-20 CY removed from EURLocations, ditto
//	2010-01-08 10% UK Price increase; USD rate revised 1.55->1.65
//	2010-05-26 USD rate revised down 1.65->1.55

// fundamental variables start here	=================================================

var PageHeading = "Price List - June 2010";

var GBPUSD 		= 1.55;
var GBPEUR 		= 1.25;

var prGBOryx8			= 46300;
var prGBOryx4			= 38200;
var prGBOryxNano		= 27200;
var prGBCCDuo_10		= 79;
var prGBCCDuo_100	= 713;
var prGBCCD_10		= 88;
var prGBCCD_100		= 792;
var prGBCCP_10		= 88;
var prGBCCP_100		= 792;
var prGBSW2PS_10	= 55;
var prGBSW2PS_100	= 534;
var prGBSW2UV_10	= 66;
var prGBSW2UV_100	= 655;
var prGBSW3PS_10	= 72;
var prGBSW3PS_100	= 666;
var prGBSW3UV_10	= 77;
var prGBSW3UV_100	= 748;
var prGBXTQ_10		= 72;
var prGBVBphilic_10	= 28;
var prGBVBphilic_80	= 198;
var prGBVBphobic_10	= 28;
var prGBVBphobic_80	= 198;
var prGBMtip2			= 28;
var prGBMtip3			= 39;
var prGBMtip4			= 50;
var prGBMtip5			= 61;
var prGBMtip7			= 83;
var prGBLHS			= 770;
var prGBService		= 3300;
var prGBUPG_VD_6	= 2200;
var prGBUPG_XYZV	= 1650;
var prGBUPG_8_6		= 7700;
var prGBUPG_8_4		= 9900;
var prGBUV_280		= 1100;






// fundamental variables end here	=================================================

// set default values	=========================================================

var DocName = document.location.href;
var AMCprix = DocName.indexOf("?PDSS#");
var sGeopluginLocationCode = "";
if(typeof(geoplugin_countryCode)!=("undefined")) sGeopluginLocationCode = geoplugin_countryCode();

if(AMCprix>0)
{
	var arg = DocName.substring(AMCprix+6, DocName.length);
	sGeobytesLocationCode = arg;
	sGeopluginLocationCode = arg;
	document.write("Country code override. Using Country Code = "+sGeopluginLocationCode+"<br>");
}

var Zone = "None";
var ZoneVerified = false;
var GeoBLocated = ((typeof(sGeobytesLocationCode)!="undefined")&&(typeof(sGeobytesIpAddress)!="undefined"));
var GeoPLocated = (typeof(sGeopluginLocationCode)!="undefined");
var Located = GeoBLocated && GeoPLocated;
var IsDI = ((Located)&&(sGeobytesIpAddress=="80.175.253.211"));


//	Debugging for DI	=========================================================
if(IsDI)
{
	//sGeobytesLocationCode = prompt("Country Code (Two Capital Letters)?", "UK");//Test by manually entering codes

	document.write("Browsing from Douglas Instruments (IP="+sGeobytesIpAddress+")  : ");
	document.write("Geobytes code = "+sGeobytesLocationCode+"; ");
	document.write("Geoplugin code = "+sGeopluginLocationCode+";<br><br>");
}
// enumerate countries	=========================================================
// 2009-11-04 GR removed from EURLocations
// 2009-11-20 CY removed from EURLocations
var GBPLocations = "UK,AR,AU,BR,CA,FK,GB,GG,GI,GS,IL,IM,IO,IS,JE,KN,MX,NZ,VG,ZA";
var EURLocations = "AD,AL,AT,BA,BE,BG,CH,CY,CZ,DE,DK,ES,FI,FO,FR,HR,HU,IE,IT,LV,LI,LT,LU,"
				+"MC,MD,ME,MK,MR,MT,NL,NO,PL,PT,RO,RS,SE,SI,SJ,SK,TR,VA";
var USDLocations = "US";

//	Sort out currency zones	=========================================================
if(Located)
{
   	var sGBCountryCode=sGeobytesLocationCode.substring(0,2);
   	var sGPCountryCode=sGeopluginLocationCode;

	sCountryCode = sGPCountryCode;
	ZoneVerified = true;
	if((USDLocations.indexOf(sGPCountryCode)>=0)&&(USDLocations.indexOf(sGBCountryCode)>=0))
	{
	  Zone = "USD";
	}else if((EURLocations.indexOf(sGPCountryCode)>=0)&&(EURLocations.indexOf(sGBCountryCode)>=0))
	{
	  Zone = "EUR";
	}else if((GBPLocations.indexOf(sGPCountryCode)>=0)&&(GBPLocations.indexOf(sGBCountryCode)>=0))
	{
	  Zone = "GBP";
	}else if(sCountryCode=="DI")
	{
	  Zone = "ALL";
	}
	else
	{
		Zone = "None"; // default anyway
		ZoneVerified = false;
	}
	if(sGeobytesIpAddress.substr(0, 9)=="216.9.247")
	{
		Zone = "None"; // default anyway
		ZoneVerified = false;
	}
}

// rounding functions	=========================================================
var sep = "&nbsp;/&nbsp;";
function RoundNearest( Value, Increment){ return Increment*Math.round(Value/Increment); }
function Round(Value)
{
	if (Value>10000)
	{
		return RoundNearest(Value, 100);
	}
	else
	{
		return RoundNearest(Value, 5);
	}
}
function EURPrice(Value) { return Round(Value*GBPEUR); }
function USDPrice(Value) { return Round(Value*GBPUSD); }

// formatting functions	=========================================================
function BigGBPText(value)
{
	thou = Math.floor(value/1000);
	return "GBP   £"+thou+",&nbsp;"+Math.round(value-1000*thou);
}

function BigEURText(Value)
{
	EUR = EURPrice(Value);
	thou = Math.floor(EUR/1000);
	return "Euros   &#8364;"+thou+"&nbsp;"+Math.round(EUR-1000*thou);
}

function BigUSDText(Value)
{
	USD = USDPrice(Value);
	thou = Math.floor(USD/1000);
	return "USD   $"+thou+",&nbsp;"+Math.round(USD-1000*thou);
}
function GBPText(Value){ return "£"+Value; }
function EURText(Value){ return "&#8364;"+EURPrice(Value); }
function USDText(Value){ return "$"+USDPrice(Value); }

function LocalPrice(Value, Currency)
{
		if (Currency=="GBP") return GBPText(Value);
		if (Currency=="EUR") return EURText(Value);
		if (Currency=="USD") return USDText(Value);
		if (Currency=="ALL") return TriplePrice(Value);
		return "";
}

function BigLocalPrice(Value, Currency)
{
		if (Currency=="GBP") return BigGBPText(Value);
		if (Currency=="EUR") return BigEURText(Value);
		if (Currency=="USD") return BigUSDText(Value);
		if (Currency=="ALL") return BigTriplePrice(Value);
		return "";
}

function TriplePrice(Value) { return GBPText(Value)+sep+EURText(Value)+sep+USDText(Value); }
function BigTriplePrice(Value) { return BigGBPText(Value)+"<br><br>"+BigEURText(Value)+"<br><br>"+BigUSDText(Value); }

// do the job	=========================================================

if(ZoneVerified) document.write("Prices are quoted in "+Zone+"<br><br>");

var 	prOryx8		= BigLocalPrice(prGBOryx8, Zone);
var 	prOryx4		= BigLocalPrice(prGBOryx4, Zone);
var 	prOryxNano	= BigLocalPrice(prGBOryxNano, Zone);
var 	prCCDuo_10	= LocalPrice(prGBCCDuo_10, Zone);
var 	prCCDuo_100	= LocalPrice(prGBCCDuo_100, Zone);
var 	prCCD_10	= LocalPrice(prGBCCD_10, Zone);
var 	prCCD_100	= LocalPrice(prGBCCD_100, Zone);
var 	prCCP_10	= LocalPrice(prGBCCP_10, Zone);
var 	prCCP_100	= LocalPrice(prGBCCP_100, Zone);
var 	prSW2PS_10	= LocalPrice(prGBSW2PS_10, Zone);
var 	prSW2PS_100= LocalPrice(prGBSW2PS_100, Zone);
var 	prSW2UV_10	= LocalPrice(prGBSW2UV_10, Zone);
var 	prSW2UV_100= LocalPrice(prGBSW2UV_100, Zone);
var 	prSW3PS_10	= LocalPrice(prGBSW3PS_10, Zone);
var 	prSW3PS_100= LocalPrice(prGBSW3PS_100, Zone);
var 	prSW3UV_10	= LocalPrice(prGBSW3UV_10, Zone);
var 	prSW3UV_100= LocalPrice(prGBSW3UV_100, Zone);
var 	prXTQ_10	= LocalPrice(prGBXTQ_10, Zone);
var 	prVBphilic_10	= LocalPrice(prGBVBphilic_10, Zone);
var 	prVBphilic_80	= LocalPrice(prGBVBphilic_80, Zone);
var 	prVBphobic_10= LocalPrice(prGBVBphobic_10, Zone);
var 	prVBphobic_80= LocalPrice(prGBVBphobic_80, Zone);
var 	prMtip2		= LocalPrice(prGBMtip2, Zone);
var 	prMtip3		= LocalPrice(prGBMtip3, Zone);
var 	prMtip4		= LocalPrice(prGBMtip4, Zone);
var 	prMtip5		= LocalPrice(prGBMtip5, Zone);
var 	prMtip7		= LocalPrice(prGBMtip7, Zone);
var 	prLHS		= LocalPrice(prGBLHS, Zone);

