$(function(){
	whois.start();
	$('#whois-input').focus();
});

whois = {

	start: function(){
		$('#whois-button').click(function(ev){
			ev.preventDefault();
			whois.submit();
		});
		$('#whois-form').submit(function(ev){
			ev.preventDefault();
			whois.submit();
		});
	},

	submit: function(){
			$('#whois-result-padding').html('<img src="/ajax-loader-big.gif" />');
			whois.httpAjax({
				post: {
					ajax: 'whois',
					query: $('#whois-input').val()
				},
				func: function(res){
					if(res.status == 'ok'){
						$('#whois-result-padding').fadeOut('fast', function(){
							$(this).html(res.whois).fadeIn('fast');
						});
					}else{
						alert(res.status);
					}
				}
			});
	},

	httpAjax: function(obj){
		$.ajax({
			url: '/whois.php',
			cache: false,
			type: 'POST',
			dataType: 'json',
			data: obj.post,
			error: function(XMLHttpRequest, textStatus, errorThrown){
//				alert("ERROR!\n\nXMLHttpRequest: " + XMLHttpRequest + "\ntextStatus: " + textStatus + "\nerrorThrown: " + errorThrown);
			},
			success: function(res){
				obj.func(res);
			}
		});
	}



}


