animation = null;
responseBox = null;
domainCheckUrl=null;

i = 0;

function animate() {
	responseBox.innerHTML = "Lekérdezés";
	for (j = 0; j < i; j++)
		responseBox.innerHTML += '.';
	i++;
	if (i == 4)
		i = 0;
}

function checkDomainAvailability(domain, tld, _responseBox) {
	responseBox = _responseBox;
	responseBox.style.color = '#888';
	animation = setInterval("animate()", 300);
	$.getJSON(domainCheckUrl, {
		'domain' : domain, 'tld' : tld
	}, getAnswer);
}

function getAnswer(data) {
	ansBox = responseBox;
	clearTimeout(animation);
	if (data.available == 1) {
		ansBox.style.color = '#080';
		ansBox.innerHTML = 'A domain szabad';
	} else if (data.available == 0) {
		ansBox.style.color = '#f00';
		ansBox.innerHTML = 'A domain foglalt';
	} else if (data.available == 3) {
		ansBox.style.color = '#f00';
		ansBox.innerHTML = 'A domain foglalt';
	} else if (data.available == -1) {
		ansBox.style.color = '#f00';
		ansBox.innerHTML = 'Kapcsolódási hiba';
	} else if (data.available == -2) {
		ansBox.style.color = '#f00';
		ansBox.innerHTML = 'Érvénytelen domain';
	}
}

function cropHttp(str) {
	if (str.substring(0, 7) == "http://")
		return str.substring(7);
	else 
		return str;
}
