var toolsUrl = '';

function doIPLookup() {
	var ip = document.getElementById('ip_lookup').value;
	if (ip!='') {
		blockUI('Please wait while we perform checks on the ip '+ip);
		$.get(toolsUrl+'ajaxReverseIP.php?ip=' + ip, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}
}

function doMXLookup() {
	var host = document.getElementById('mx_info').value;
	if (host!='') {
		blockUI('Please wait while we perform an MX check on '+host);
		$.get(toolsUrl+'ajaxMXLookup_1.php?type=1&host=' + host, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}
}

function getIPLocation(ip) {
	var url = url+'ipGeo.php?ip='+ip;
	$.getJSON(toolsUrl, function(data){
		if(data['status'] == 'ok'){
			alert(data['CountryName']);
			return data['CountryName'];
		} else {
			return null;
		}
	});	
}

function doProperMxLookup(host,element) {
	if (host!='') {
		if (document.getElementById(element).style.display=='none') {
			blockUI('Please wait while we perform a diagnostic test on '+host);
			$.get(toolsUrl+'ajaxMXLookup.php?type=2&host=' + host, function(data) {
				document.getElementById(element).innerHTML = data;
				$('#'+element).show('slow');
				unblockUI();
			});
		} else {
			$('#'+element).hide('slow');
		}
	}	
}
function doDomainLookup() {
	var domain = document.getElementById('domain_info_input').value;
	if (domain!= '') {
		blockUI('Please wait while we perform checks on the domain '+domain);
		$.get(toolsUrl+'ajaxDomainInfo_1.php?domain=' + domain, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}
}


function doReverseLookup() {
	var domain = document.getElementById('reverse_lookup').value;
	if (domain!= '') {
		blockUI('Please wait while we perform a reverse lookup on '+domain);
		$.get(toolsUrl+'ajaxReverseIP.php?domain=' + domain, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}
}

function doIpLocation(ip) {
	var url = toolsUrl+'ipGeo.php?ip='+ip;
	$.getJSON(url, function(data){
		if(data['status'] == 'ok'){
			document.getElementById('ip_location').innerHTML = '<img src="images/tools/flags/'+data['CountryCode'].toLowerCase()+'.gif" alt="'+data['CountryName']+'" />';
		}
	});	
}
function doPingIP() {
	var domain = document.getElementById('ping_ip_input').value;
	if (domain!= '') {
		blockUI('Please wait while we ping '+domain);
		$.get(toolsUrl+'pingDomain.php?showheader=true&ip=' + domain, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}
}


function doWhois() {
	var domain = document.getElementById('domain_lookup_input').value;
	if (domain!= '') {
		blockUI('Please wait we perform a whois on'+domain);
		$.get(toolsUrl+'ajaxDomainWhois.php?domain=' + domain, function(data) {
			$.facebox(data);
			unblockUI();
		});
	}	
}

function pingDomain(domain,element) {
	if (document.getElementById(element).style.display == 'none') {
		blockUI('Please wait while we ping the address ' + domain);
		$.get(toolsUrl+'pingDomain.php?showheader=false&ip=' + domain, function(data) {
			document.getElementById(element).innerHTML = data;
			$('#'+element).show('slow');
			unblockUI();
		});	
	} else {
		$('#'+element).hide('slow');
	}
}

function blockUI(message) {
	$.blockUI({ message: '<h1>'+message+'</h1>' });
}

function unblockUI() {
	$.unblockUI();
}