updateOrderField();
function updateOrderField() {

	// Variables
	var euro = document.getElementById("currency_euro").innerHTML;

	// Store the form in an easy name
	objFrm = document.getElementById("frmOrder");

	// Header: order information
	document.getElementById("orderInfo").innerHTML = "<b>Order information:</b><br />";

	// Loop the list to figure out what server they selected
	objServers = objFrm.frmServer;
	for (i=0; i<objServers.length; i++) {

		if (objServers[i].checked) {

			// Get the info we need
			var type = document.getElementById(objServers[i].value + "_name").innerHTML;
			var slots = document.getElementById(objServers[i].value + "_slots").innerHTML; 

			var prices = new Array();
			prices["sek"] = document.getElementById(objServers[i].value + "_price_sek").innerHTML;
			prices["euro"] = document.getElementById(objServers[i].value + "_price_eur").innerHTML;

			document.getElementById("orderInfo").innerHTML += type + " " + slots + " slots<br />";

			// Update the slots
			objFrm.frmSlots.value = slots;

			// Update the name
			objFrm.frmServerFullName.value = type;

		}
		
	}

	// Add the server months to the output
	if (objFrm.frmServerMonth.value >= 1) {
		document.getElementById("orderInfo").innerHTML += "Rent for " + objFrm.frmServerMonth.value + " month<br />";
	}


	// Header: Payment information
	document.getElementById("orderInfo").innerHTML += "<br /><b>Payment information:</b><br />";

	// Loop the list to figure out what server they selected
	objCurrency = objFrm.frmCurrency;
	for (i=0; i<objCurrency.length; i++) {

		if (objCurrency[i].selected && objCurrency[i].value != -1) {
			document.getElementById("orderInfo").innerHTML += "Currency: " + objCurrency[i].innerHTML + "<br />";
			var currency = objCurrency[i].value;

			// Update the form
			objFrm.frmCurrencyFullName.value = objCurrency[i].innerHTML
		}



	}


	// Loop the list to figure out what payment method to use
	objPayment = objFrm.frmPaywith;
	for (i=0; i<objPayment.length; i++) {

		if (objPayment[i].selected && objPayment[i].value != -1) {
			document.getElementById("orderInfo").innerHTML += "Method: " + objPayment[i].innerHTML + "<br />";
			var paymethod = objPayment[i].value

			// Update the form
			objFrm.frmPaywithFullName.value = objPayment[i].innerHTML;

		}

	}


	// Check so they didn't make an error
	if (paymethod == "paypal" && currency == "sek") {
		alert("You can not pay with swedish kronor when using paypal");
		objPayment[0].selected = true;
	}

	if (paymethod == "plusgiro" && currency == "euro") {
		alert("You can not pay with euros when using PlusGiro");
		objPayment[0].selected = true;
	}


	// Header: Price information
	document.getElementById("orderInfo").innerHTML += "<br /><b>Price information:</b><br />";

	// Add the exchange fee
	var exchange = 0;
	if ((paymethod == "paypal" || paymethod == "bank") && currency == "euro") {
		exchange = Math.ceil(10 / euro);
		document.getElementById("orderInfo").innerHTML += "Exchange fee: " + exchange + " " + currency + "<br />";
	}

	// Check if they should get any of our offers
	var discount = 0;
	if ((objFrm.frmServerMonth.value >= 3 && objFrm.frmServerMonth.value <= 5) && currency != null) {
		discount = (currency == "euro" ? Math.floor(50 / euro) : 50);
	} else if ((objFrm.frmServerMonth.value == 6) && currency != "") {
		discount = (currency == "euro" ? Math.floor(200 / euro) : 200);
	}

	// Add the offer to the listing
	if (discount > 0)
		document.getElementById("orderInfo").innerHTML += "Discount: -" + discount + " " + currency + "<br />";

	// Calculate the total price
	if (objFrm.frmServerMonth.value >= 1 && currency != null) {
		var price = (prices[currency] * objFrm.frmServerMonth.value) + exchange - discount;
		document.getElementById("orderInfo").innerHTML += "Total price: " + price + " " + currency + "<br />";

		// Uppdate the price
		objFrm.frmPrice.value = price;

	}

	// Copy the stuff into inte form so we can POST it
	objFrm.frmOrderInfo.value = document.getElementById("orderInfo").innerHTML;

}


function checkSubmit() {

	// Save us some typing
	objFrm = document.getElementById("frmOrder");

	var ok = true;

	for (i=0; i<objFrm.frmServer.length; i++) {

		if (objFrm.frmServer[i].checked == true)
			ok = true;

	}

	// Check all stuff
	if (objFrm.frmFirstname.value == "")
		ok = false;

	if (objFrm.frmLastname.value == "")
		ok = false;

	if (objFrm.frmEmail.value == "")
		ok = false;

	if (objFrm.frmBirthYear.value == -1)
		ok = false;

	if (objFrm.frmBirthMonth.value == -1)
		ok = false;

	if (objFrm.frmBirthDay.value == -1)
		ok = false;

	if (objFrm.frmDns.value == "")
		ok = false;

	if (objFrm.frmServerMonth.value == -1)
		ok = false;

	if (objFrm.frmCurrency.value == -1)
		ok = false;

	if (objFrm.frmPaywith.value == -1)
		ok = false;


	if (!ok) {
		alert("You have missed to fill out something");
		return false;
	} else {
		return true;
	}

}
