SeoAnalysis = {
	
	request: function(){
		SeoAnalysis.showPreloader(true);
		$.ajax({
			type: "POST",
			url: DOC_URL + "ajax_seo_analysis.php",
			data: {
				url: $("#seo_url").val(), 
				email: $("#seo_mail").val()
			},
			cache: false,
			dataType: "text",
			success: function(response){
				SeoAnalysis.showPreloader(false);
				SeoAnalysis.response(response);
			}
		});
	},
	
	response: function(response){
		var xml = new XMLParser(response);
		if(xml.getTag("result") == "ok"){
			this.showForm(false);
			$("#seo_box .message").fadeIn("slow");
			//setTimeout("SeoAnalysis.restore();", 5000);
		} else {
			Shadowbox.open({
				player:     'html',
				content:    '<div class="shadowbox_message" align="center"><br />' + Translation.error_seo_analysis + '<br /><br /><br /><div align="center"><input type="button" class="input_button" value="' + Translation.close + '" onclick="Shadowbox.close();" /></div></div>',
				options:	{
					//modal: true,
					displayNav: false
				},
				height:     170,
				width:      250
			});
		}
	},
	
	showPreloader: function(show){
		if(show){
			this.showForm(false);
			$("#seo_box .preloader").show();
		} else {
			this.showForm(true);
			$("#seo_box .preloader").hide();
		}
	},
	
	showForm: function(show){
		if(show){
			$("#seo_box .field_title").show();
			$("#seo_box .field").show();
			$("#seo_box .button").show();
		} else {
			$("#seo_box .field_title").hide();
			$("#seo_box .field").hide();
			$("#seo_box .button").hide();
		}
	},
	
	restore: function(){
		$("#seo_box .message").fadeOut("slow", function(){
			$("#seo_box .field").val(" ");
			SeoAnalysis.showForm(true);										  
		});
	}
}

$(window).load(function(){
	$("#seo_box .button").click(function(){
		SeoAnalysis.request();
	});
});
