function upgradePrice(FREE_USERS) {
	var users = $('#users').val();
	if (users < FREE_USERS) {
		users = FREE_USERS;
	}
	var sunits = $('#storage_units').val();
	var users = $('#users').val();
	costs = {
		1: 0,
		2: 100,
		5: 150,
		10: 200,
		15: 250,
		20: 300,
		30: 350,
		40: 400,
		60: 450,
		100: 500
	}
	cost = costs[users] + (sunits * 10);
	if (cost == 0) {
		$('#cost_text').html('FREE');
	}
	else {
		$('#cost_text').html('$'+cost+' per month');
	}
	$('#cost').val(cost);
}

function checkSubdomain() {
	var subdomain = $("#subdomain").val().toLowerCase();
	if (subdomain.length > 0) {
		// Make sure there are only letters numbers and dashes
		if (!subdomain.match(/^[a-z0-9\-]+$/i)) {
			$("#subdomain-check").css('color','red');
			$("#subdomain-check").html('<img src="images/warning.gif" alt="" height="16" width="16" /> Please use only letters, numbers and/or dashes.');
		}
		else {
			$("#subdomain-check").css('color','gray');
			$("#subdomain-check").html('<img src="images/busy.gif" alt="" height="16" width="16" /> Checking availability...');
			$.get('subdomain-check.php', { subdomain: subdomain },
				function(data) {
					if (data) {
						$("#subdomain-check").css('color','green');
						$("#subdomain-check").html('<img src="images/available.gif" alt="" height="16" width="16" /> Available!');
					}
					else {
						$("#subdomain-check").css('color','red');
						$("#subdomain-check").html('<img src="images/unavailable.gif" alt="" height="16" width="16" /> This subdomain unavailable.');
					}
				}
			);
		}
	}
	else {
		$("#subdomain-check").empty();
	}
}

function checkAffUsername() {
	var username = $("#username").val();
	if (username.length > 0) {
		// make sure there are only letters numbers and dashes
		if (!username.match(/^[a-z0-9\-]+$/i)) {
			$("#username-check").css('color','red');
			$("#username-check").html('<img src="images/warning.gif" alt="" height="16" width="16" /> Please use only letters, numbers and/or dashes.');
		}
		else {
			$("#username-check").css('color','gray');
			$("#username-check").html('<img src="images/busy.gif" alt="" height="16" width="16" /> Checking availability...');
			$.get('username-check.php', { username: username },
				function(data) {
					if (data) {
						$("#username-check").css('color','green');
						$("#username-check").html('<img src="images/available.gif" alt="" height="16" width="16" /> Available!');
					}
					else {
						$("#username-check").css('color','red');
						$("#username-check").html('<img src="images/unavailable.gif" alt="" height="16" width="16" /> This username unavailable.');
					}
				}
			);
		}
	}
	else {
		$("#username-check").empty();
	}
}

function updateStorage(company_id) {
	$('#usage').html('Updating...');
	$.get('/account/update-usage.php', {id:company_id}, function(data) {
			$('#usage').html(data);
		}
	)
}