setTimeout('window.location.reload()', 3600000);

var objectID = 0;
var ready = true;
var objectCount = 0;
var load = 2000;
function searchFocus() {
	document.getElementById('search').style['background'] = 'url(\'searchActive.png\') no-repeat';
}
function searchBlur() {
	document.getElementById('search').style['background'] = 'url(\'search.png\') no-repeat';
}
function removeDomain(id) {
	document.getElementById('item' + id).parentNode.removeChild(document.getElementById('item' + id));
	objectCount--;
	if (objectCount == 0) {
		document.getElementById('container').style.width = '240px';
		document.getElementById('content').style.width = '200px';
		document.getElementById('container').style.marginLeft = '-110px';
		document.getElementById('content').innerHTML = '<div style="width: 200px;">Fill in the address of a domain in the field above and click view to get its stats.</div>';
	}
	else {
		document.getElementById('container').style.marginLeft = '-' + (10 + (120 * objectCount)) + 'px';
		document.getElementById('container').style.width = 20 + (241 * objectCount) + 'px';
		document.getElementById('content').style.width = (240 * objectCount) + 'px';				
	}
}
function viewDomain() {
	if (objectCount < 3) {
		if (document.getElementById('searchField').value.length > 3 || arguments[1] != null) {
			if (ready == true) {
				var domain = document.getElementById('searchField').value;
				if (arguments[0] != null) {
					domain = arguments[0];
				}
				ready = false;
				if (objectCount == 0) {
					document.getElementById('content').innerHTML = "";
				}
				objectCount++;
				objectID++;
				while(document.getElementById('item' + objectID)) {
					objectID++;
				}
				document.getElementById('container').style.marginLeft = '-' + (10 + (120 * objectCount)) + 'px';
				document.getElementById('container').style.width = 20 + (241 * objectCount) + 'px';
				document.getElementById('content').style.width = (240 * objectCount) + 'px';
				document.getElementById('content').innerHTML += '<div class="item" id="item' + objectID + '"></div>';

				var ajax = new sack();
				var start = new Date();
				var finish = new Date();
				ajax.requestFile = 'rank.php?url=' + domain + '&id=' + objectID + '&key=' + hex_md5("05073d7b44cd29e556af4abe128d702e" + "f20064d11bc38f201f9eb4cebdadc108" + domain);						
				if (arguments[1]) {
					ajax.requestFile += '&www';						
				}
				ajax.onCompletion = function() {
					if (document.getElementById('item' + objectID).innerHTML == 'ERROR') {		
						removeDomain(objectID);
					}
					else {
						finish.setTime(new Date());
						if (objectID != 1) {
							load += finish.getTime() - start.getTime();
							load /= 2;
						}
						else {
							load = finish.getTime() - start.getTime();								
						}
					}
					ready = true;
				}
				ajax.element = 'item' + objectID;
				document.getElementById('item' + objectID).innerHTML = 'Loading...<div class="loadingMeter" id="loadingMeter' + objectID + '"></div>';
				for (var time = 25, width = 0; time < load + 25; time += 25) {
					width = (time / (load + 25)) * 220;
					setTimeout('if (document.getElementById(\'loadingMeter' + objectID + '\')) { document.getElementById(\'loadingMeter' + objectID + '\').style[\'width\'] = \'' + width + 'px\'; }', time);
				}
				setTimeout('if (document.getElementById(\'loadingMeter' + objectID + '\')) { document.getElementById(\'item' + objectID + '\').innerHTML += \'<br />Please, be patient.\'; }', load + 100);
				ajax.runAJAX();
			}
		}
		else {
			alert('The address is too short.');
		}
	}
	else {
		alert('You can only view 3 items at once.');
	}
}
function viewHelp(title) {
	if (title == 'Google PageRank') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> is a tool for calculating a pages popularity. Google uses it to determine the upcome of results when you make a search using Google.com. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else if (title == 'Alexa Rank') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> is a list created by Alexa to list pages after popularity. It is based of some users who have installed Alexa Toolbar which monitors the users visits. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else if (title == 'Google backlinks') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> shows the amount of hits you get when you search for a domainname on Google. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else if (title == 'Registration date') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> is the day when the domain first was purchased and registered. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else if (title == 'Modification date') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> is the day when the domain most recently was modified. It could be the day the registration was extended or the day the domain was sold. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else if (title == 'Expiration date') {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>' + title + '</b> is the day when the domain will be free again if not the registration is extended. <a href="#" onclick="hideHelp()">Close</a>';
	}
	else {
		document.getElementById('help').style['display'] = 'block';
		document.getElementById('help').innerHTML = '<b>Error</b><br />An error has occured. Please close this pop-up. <a href="#" onclick="hideHelp()">Close</a>';
	}
}
function hideHelp() {
	document.getElementById('help').style['display'] = 'none';
}
function viewWhois(id) {
	if (document.getElementById('whoisContainer' + id)) {
		document.getElementById('whois').style['display'] = 'block';
		document.getElementById('whois').innerHTML = document.getElementById('whoisContainer' + id).innerHTML;
	}
	else {
		alert('No such domain is currently viewed.');
	}
}
function hideWhois() {
	document.getElementById('whois').style['display'] = 'none';
}