var game = '';

function calculate(game) {
	var monthly = 0;
	var total = 0;
	var type = '';
	var branded = '';
	var slots = 0;
	var price_per_slot = 0;
	var vtype = '';
	var period = 3;
	
	switch(game) {
		default:
			// Calculate total price gameslots
			type = document.getElementById('type').value;
			if (type == 'private') { 
				price_per_slot = document.getElementById('price_private').value;	
			}
			if (type == "public") {
				price_per_slot = document.getElementById('price_public').value;
			}
			total += document.getElementById('slots').value * price_per_slot;
			
			// Calculate branded/debranded
			branded = document.getElementById('branded').value;
			if (branded == 'debranded') {
				total += 5;
			}
			
			// Calculate price voiceserver slots
			/*
			vtype = document.getElementById('voiceserver').value;
			if (vtype != "0") {
				total += document.getElementById('tsslots').value * 0.5;
			}
			*/
			
			monthly = total;
			break;
		case 'bf2-ranked':
			// Base price
			slots = document.getElementById('slots').value;
			switch(slots) {
				case '16': total += 59.95; break;
				case '18': total += 63.75; break;
				case '20': total += 67.50; break;
				case '22': total += 69.95; break;
				case '24': total += 74.95; break;
				case '32': total += 89.95; break;
				case '64': total += 159.95; break;
			}
			
			// Branded/unbranded
			branded = document.getElementById('branded').value;
			if (branded == 'debranded') {
				total += 5;
			}
			
			// Additional teamspeak slots
			//total += document.getElementById('tsslots').value * 0.5;
			
			monthly = total;
			
			break;
	}
		
	// Payment period
	period = document.getElementById('period').value;
	total = total*period;
	
	// Add an extra 2.50 fee for paypal
	payment = document.getElementById('payment').value;
	if (payment == "paypal") {
		total += 2.5;
		monthly += 2.5;
	}
	
	document.getElementById('monthly').value = round_decimals(monthly, 2);
	document.getElementById('total').value = round_decimals(total, 2);
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

function checkContactForm() {
	var type;
	
	type = document.getElementById('type').value;
	if (type == "sponsoring") {
	}
}