function doCalc(lang) {
	
	var errormsg = "";
	switch(lang) {
		case "eng":
 	 		errormsg = "The minimum floor space is 12m².";
  			break;  
		case "de":
  			errormsg = "Die Mindestgröße einer Standfläche beträgt 12m².";
 		 	break;
		case "spa":
  			errormsg = "El tamaño mínimo de stand es 12m².";
 		 	break;
		case "it":
  			errormsg = "La superficie minima ammissibile di uno stand è di 12m².";
 		 	break;
		case "fr":
			errormsg = "La surface minimale d’un emplacement est de 12m².";
	}
	
	
	var warningmsg = ""; // REMEMBER to change these for the All-in-one function BELOW
	switch(lang) {
		case "eng":
 	 		warningmsg = "Your total stand size will change.";
  			break;  
		case "de":
  			warningmsg = "Die Standgröße wird aktualisiert.";
 		 	break;
		case "spa":
  			warningmsg = "Se va a cambiar el area de su stand.";
 		 	break;
		case "it":
  			warningmsg = "Le dimensioni e la superficie totale dello stand non corrispondono. La superficie totale verrà modificata.";
 		 	break;
		case "fr":
			warningmsg = "La surface totale de stand va changer.";
	}
	
	var myform = document.calcform;
	var dim1 = myform.dim1.value;
	var dim2 = myform.dim2.value;
	var standsize = myform.standsize.value;
	var standselect = myform.standtype.value.split("#");
	var cost = parseFloat(standselect[0]);
	var aumafee = 0.6;

	// WE HAVE OUR VARIABLES
	
	
	
	
	// option 1 - Both Dim boxes are filled in.
	// Ignore the top m2 and claculate new squarem
	if ((dim1 != "") && (dim2  !=  "") ) {
		var squarem = dim1*dim2;
		
		// *NEW* If there's a value in the standsize box, and it's not equal to this sum, show a warning
		if ((myform.standsize.value != "") && (myform.standsize.value != squarem)) {
			alert (warningmsg);
		}
		
		myform.standsize.value = squarem;
		document.getElementById('square_m').innerHTML = squarem;
		
		
	}
	
	// option 2 - Only the standsize box is filled in
	if ((dim1 == "") || (dim2 == "")) {
		var squarem = standsize;
		document.getElementById('square_m').innerHTML = squarem;
	}
	
	
	
	if (squarem < 12) {
		alert (errormsg);
	} else {
		document.getElementById('square_m').innerHTML = squarem;
			
		var netcost = squarem * cost;
		formattednetcost = eval(Math.round(netcost*100)) / 100;
		formattednetcost = format(formattednetcost, lang);
		document.getElementById('netcost').innerHTML = formattednetcost;
			
		var totalauma = aumafee*squarem;
		formattedtotalauma = eval(Math.round(totalauma*100)) / 100;
		formattedtotalauma = formattedtotalauma;
		document.getElementById('totalauma').innerHTML = format(formattedtotalauma, lang);
			
		var totalcost = netcost+parseFloat(formattedtotalauma);
			
		formattedtotal = eval(Math.round(totalcost*100)) / 100;
		formattedtotal = format(formattedtotal, lang);
		document.getElementById('formatted_total').innerHTML = formattedtotal;
		document.getElementById('submitbutton').style.visibility="visible";
	}
}
		
function resetDropDown() {
	myform = document.calcform;
	myform.standtype.selectedIndex = 0;
	document.getElementById('square_m').innerHTML = 0;
	document.getElementById('netcost').innerHTML = 0;
	document.getElementById('totalauma').innerHTML = 0;
	document.getElementById('formatted_total').innerHTML = 0;
	document.getElementById('submitbutton').style.visibility="hidden";
}

function resetDims() {
	myform = document.calcform;
	myform.standsize.value = "";
	myform.dim1.value = "";
	myform.dim2.value = "";
}

// - - - - For the All-In-One Package Calculator - - - - - //

function doCalc2(lang) {
	var errormsg = "";
	switch(lang) {
		case "eng":
 	 		errormsg = "The All-In-One Package is not available for your chosen stand size. Please choose a stand size from 12m² to 30m².";
  			break;  
		case "de":
  			errormsg = "Das Komplettpaket ist nicht für die von Ihnen gewählte Standgröße erhältlich. Bitte wählen Sie eine Standgröße zwischen 12m² und 30m².";
 		 	break;
		case "spa":
  			errormsg = "El Paquete ‘Todo en Uno’ no está disponible para la superficie de stand seleccionada. Se ruega seleccionar una superficie de stand de 12m² a 30m².";
 		 	break;
		case "it":
  			errormsg = "Il Pacchetto completo non è disponibile per le dimensioni di stand indicate. Scegliere una dimensione dello stand compresa tra 12m² e 30m².";
 		 	break;
		case "fr":
			errormsg = "La Formule tout compris n’est pas proposée pour la taille de stand demandée. Veuillez choisir une taille de stand comprise entre 12 et 30m².";
	}
	
	var warningmsg = "";
	switch(lang) {
		case "eng":
 	 		warningmsg = "Your total stand size will change.";
  			break;  
		case "de":
  			warningmsg = "Die Standgröße wird aktualisiert.";
 		 	break;
		case "spa":
  			warningmsg = "Se va a cambiar el area de su stand.";
 		 	break;
		case "it":
  			warningmsg = "Le dimensioni e la superficie totale dello stand non corrispondono. La superficie totale verrà modificata.";
 		 	break;
		case "fr":
			warningmsg = "La surface totale de stand va changer.";
	}
	var myform = document.calcform;
	var dim1 = myform.dim1.value;
	var dim2 = myform.dim2.value;
	var standsize = myform.standsize.value;
	var standselect = myform.standtype.value.split("#");
	var cost = parseFloat(standselect[0]);
	
	
	// option 1 - Both Dim boxes are filled in.
	// Ignore the top m2 and claculate new squarem
	if ((dim1 != "") && (dim2  !=  "") ) {
		var squarem = dim1*dim2;
		
		// *NEW* If there's a value in the standsize box, and it's not equal to this sum, show a warning
		if ((myform.standsize.value != "") && (myform.standsize.value != squarem)) {
			alert (warningmsg);
		}
		
		myform.standsize.value = squarem;
		document.getElementById('square_m').innerHTML = squarem;
	}
	
	// option 2 - Only the standsize box is filled in
	if ((dim1 == "") || (dim2 == "")) {
		var squarem = standsize;
		document.getElementById('square_m').innerHTML = squarem;
	}
	
	//var squarem = dim1*dim2;
	if ((squarem < 12) || (squarem > 30)) {
		alert (errormsg);
	} else {
		document.getElementById('square_m').innerHTML = squarem;
			
		var totalcost = squarem * cost;
		formattedtotal = eval(Math.round(totalcost*100)) / 100;
		formattedtotal = format(formattedtotal, lang);
		document.getElementById('formatted_total').innerHTML = formattedtotal;
		document.getElementById('submitbutton').style.visibility="visible";
	}
}


function resetDropDown2() {
	myform = document.calcform;
	myform.standtype.selectedIndex = 0;
	document.getElementById('square_m').innerHTML = 0;
	document.getElementById('formatted_total').innerHTML = 0;
	document.getElementById('submitbutton').style.visibility="hidden";
}
		

function format(str, lang) {
	str = str.toString();
	index = str.indexOf('.');
	if (index < 0) {
		str = str + ".00";	
	} else {
		str = str.substring(0, index + 3);
	}
	if (str.length < (index + 3)) {
		str += "0";
	}
	// now add space between thousands and hundreds.
	strArray = str.split(".");
	mainNumber = strArray[0];
	decimals = strArray[1];
	mainNumberlength = mainNumber.length;
	if (mainNumberlength > 3) {
		lpos = mainNumberlength - 3;
		// do something;
		hundreds = str.slice(lpos,mainNumberlength);
		thousands = str.slice(0,lpos);
		
		if (lang == "it") {
			str = thousands + "." + hundreds + "," + decimals;
		} else {
			str = thousands + " " + hundreds + "." + decimals;
		}
		
		
	}
	if ((lang == "de")  || (lang == "fr") || (lang == "spa")) {
		 str = str.replace('.', ',');
	} 
	if (lang == "it") {
		if (str.length <= 6) {
			str = str.replace('.', ',');
		}
	}
	return str;
}