window.onload = GetCountry;

var request = false;
try {
 request = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
   request = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
   try {
     request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (failed) {
     request = false;
   }
 }
}
if (!request)
alert("Error initializing XMLHttpRequest!");
/********************************************/
var request2 = false;
try {
 request2 = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
   request2 = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
   try {
     request2 = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (failed) {
     request2 = false;
   }
 }
}
if (!request2)
alert("Error initializing XMLHttpRequest!");

/******************/
/* Trim functions */
/******************/
function LTrim( value ) {
var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");
}
function RTrim( value ) {
var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");
}
function trim( value ) {
return LTrim(RTrim(value));
}
/*************************/
/* End of trim functions */
/*************************/

function GetCountry(){
country = window.location.search.substring(1);
if (!country) country = "Europe";
Show(country);
}

function Show(country){
HideAll();
if (country == 'Benelux')
	{
	document.getElementById(country).style.backgroundImage = "url(Images/BigTabOn.jpg)";
	}
else
	{
	tab = country + "Tab";
	document.getElementById(tab).style.backgroundImage = "url(Images/TabOn.png)";
	}

url = "Prices/" + country + ".html";
request.open("GET", url, true);
request.onreadystatechange = LoadCountry;
request.send(null);
}

function LoadCountry(){
if (request.readyState == 4)
 	{
 	if (request.status == 200)
   		{
     	response = request.responseText;
     	response = trim(response);
     	document.getElementById('story').innerHTML = response;
     	if (country == "Multi") Price();
     	}
   }
}

function ShowUpper(id){
HideAll();
document.getElementById(id).style.backgroundImage = "url(Images/BigTabOn.jpg)";
}

function HideAll(){
document.getElementById('story').innerHTML = "";

country = ['Europe','America', 'Alpine', 'Czech', 'France','Germany','Italy','Spain','UK','Multi'];
tab = ['EuropeTab','AmericaTab', 'AlpineTab', 'CzechTab', 'FranceTab','GermanyTab','ItalyTab','SpainTab','UKTab','MultiTab'];
for (k=0;k<country.length;k++)
	{
	document.getElementById(tab[k]).style.backgroundImage = "url(Images/TabOff.png)";
	}
	
UTab = ['Benelux'];
for (k=0;k<UTab.length;k++)
	{
	document.getElementById(UTab[k]).style.backgroundImage = "url(Images/BigTabOff.jpg)";
	}
}

function Buy(type){
window.location = "Order.html?" + type;
}

function Price(){
/* ******************************** */
/* Flipping country checkboxes      */
/* Based on the state of E checkbox */
/* ******************************** */

var C = new Array("E","A","CZ","BE","F","G","I","S","U",'AL');

if (document.getElementById("E").checked)
	{
	for (k=3;k<10;k++)
		{
		document.getElementById(C[k]).disabled = true;
		document.getElementById(C[k]).checked = false;
		}
	}
else
	{
	for (k=3;k<9;k++)
		{
		document.getElementById(C[k]).disabled = false;
		}
	}
/* ***************************** */
/* Checked boxes >> total prices */
/* ***************************** */

for (k=0;k<5;k++)
	{
	if (document.subscription.sub[k].checked)
		{
		subtype = document.subscription.sub[k].value;
		}
	}

basevalue = 0;

if (document.getElementById("E").checked) basevalue = basevalue + 1500;
if (document.getElementById("A").checked) basevalue = basevalue + 1000;
if (document.getElementById("CZ").checked) basevalue = basevalue + 500;
if (document.getElementById("BE").checked) basevalue = basevalue + 400;
if (document.getElementById("F").checked) basevalue = basevalue + 400;
if (document.getElementById("G").checked) basevalue = basevalue + 400;
if (document.getElementById("I").checked) basevalue = basevalue + 400;
if (document.getElementById("S").checked) basevalue = basevalue + 400;
if (document.getElementById("U").checked) basevalue = basevalue + 400;
if (document.getElementById("AL").checked) basevalue = basevalue + 400;

if (subtype == "1") multiplier = 1;
if (subtype == "4") multiplier = 2.5;
if (subtype == "10") multiplier = 5;
if (subtype == "20") multiplier = 7.5;
if (subtype == "50") multiplier = 15;

basevalue = basevalue * multiplier;
saving = basevalue * 0.15;

n = 0;
for (k=0;k<countries.length;k++)
	{
	if (document.countries.elements[k].checked) n++;
	}

if (n < 2) saving = 0;
	
newprice = basevalue - saving;

basevalue = basevalue.toFixed(2);
saving = saving.toFixed(2);
newprice = newprice.toFixed(2);

document.getElementById("original").innerHTML = "£ " + addCommas(basevalue);		document.getElementById("reduction").innerHTML = "£ " + addCommas(saving);
document.getElementById("final").innerHTML = "£ " + addCommas(newprice);		
}

function BuyMulti(){
type = "";

check = 0;

for (k=0;k<countries.length;k++)
	{
	if (document.countries.elements[k].checked) 
		{
		type += document.countries.elements[k].id + "~";
		check++;
		}
	}
if (check == 0) return false;
	
type = type.substring(0,type.length-1);

for (k=0;k<5;k++)
	{
	if (document.subscription.sub[k].checked)
		{
		subtype = document.subscription.sub[k].value;
		}
	}
type += "|" + subtype;

price = document.getElementById("final").innerHTML;
if (check == 1) price = document.getElementById("original").innerHTML;
	
price = price.substring(2,price.length);
price = price.replace(/,/g,''); 
price = parseFloat(price);

type += "|" + price;

window.location = "Order.html?" + type;
}

function ShowMulti(button){
buttonparts = button.split("|");
country = buttonparts[0];
s = buttonparts[1];
multiplier = new Array();
multiplier[1] = 1;
multiplier[4] = 2.5;
multiplier[10] = 5;
multiplier[20] = 7.5;
multiplier[50] = 15;

if (country == 'E' || country == 'A')
	{
	saving = 375 * parseFloat(multiplier[s]);
	saving = saving.toFixed(2);
	saving = addCommas(saving);
	saving = "<em>\u00A3" + saving + "</em>";
	
	message = "Save " + saving + "<br />Buy Europe plus America<br />22,000+ Hospitals<br />Click the Multi-Save tab";
	document.getElementById("M").innerHTML = message;
	document.getElementById("M").style.visibility = 'visible';
	}

if (country == 'BE' || country == 'F' || country == 'G' || country == 'I' || country == 'S' || country == 'U' || country == 'AL' || country == 'CZ')
	{
	var c = [];
	c['BE'] = 'Benelux';
	c['F'] = 'France';
	c['G'] = 'Germany';
	c['I'] = 'Italy';
	c['S'] = 'Spain';
	c['U'] = 'United Kingdom';
	c['AL'] = 'Switzerland &amp; Austria';
	c['CZ'] = 'Czech Republic';
	
	basesaving = 120;
	if (country == 'CZ') basesaving = 135;;
	
	saving = basesaving * parseFloat(multiplier[s]);
	if (country == 'CZ') saving = 135 * parseFloat(multiplier[s]);
	saving = saving.toFixed(2);
	saving = addCommas(saving);
	saving = "<em>\u00A3" + saving + "</em>";
	
	message = "Save at least " + saving + "<br />Buy " + c[country] + " plus one more country<br />Click the Multi-Save tab";
	document.getElementById("M").innerHTML = message;
	document.getElementById("M").style.visibility = 'visible';
	}
}

function HideMulti(){
document.getElementById('M').style.visibility = 'hidden';
}

function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

