$(document).ready(function() {
	$("#domain_list li").each(function() {
		whois($(this).html());
	});
});

function whois(domain) {	
	$.get("/ajax.php?a=whois&domain=" + domain, function(result) {
		$("#domain_list #" + domain.replace(".", "_")).html('');
		
		avail = result.substring(result.indexOf("|")+1);
		if(avail == "VRIJ") { 
			status	= "Beschikbaar";
			action 	= "Registreren"; 
			$("#domain_list #" + domain.replace(".", "_")).addClass('available');
		} else { 
			status 	= "Niet beschikbaar";
			action 	= "Verhuizen"; 
		}
		
		$("#domain_list #" + domain.replace(".", "_")).append("<div id='domain'>" + domain + "</div>");
		$("#domain_list #" + domain.replace(".", "_")).append("<div id='status'>" + status + "</div>");
		$("#domain_list #" + domain.replace(".", "_")).append("<div id='action'><a href=\"javascript:void(0)\" class=\"pijl_klein_rechts\" onclick=\"get_domain('" + domain + "')\">" + action + "</a></div>");
	});
}

function get_domain(domain) {
	$.get("/ajax.php?a=reg_add_domain&domain=" + domain, function(result) {
		if(result == "OK") {
			$("#domain_list #" + domain.replace(".", "_")).remove();
			
			reg_cart_renew();
			reg_domains_renew();
		}
	});
}

function reg_del_dom(domain) {	
	$.get("/ajax.php?a=reg_del_domain&domain=" + escape(domain), function(result) {
		if(result == "OK") {
			reg_cart_renew();
			reg_domains_renew();	
		}
	});
}

// Refresh functions
function reg_cart_renew() {
	$.get("/ajax.php?a=reg_update_cart", function(result) {
		$("#cart").html(result);
	});
}

function reg_domains_renew() {
	$.get("/ajax.php?a=reg_update_domains", function(result) {
		$("#reg_chosen_domains").html(result);
	});
}

function reg_add_mod(mid) {
	quantity = $("#mod_" + mid +  "_quantity").val();
	if(!quantity) { quantity = 1; }
	
	$.get("/ajax.php?a=reg_add_module&mid=" + escape(mid) + "&quantity=" + quantity, function(result) {
		if(result == "OK") {	
			reg_cart_renew();
		}	
	});
}


