$(document).ready(function() {
	$("#cloakCheckForm").submit(function() {
		$("#cloakInfo").show('slow');
		$("#cloakInfoBody tr:first td").each(function() {
			$(this).html('');
		});
	    $("#cloakInfoDiv").block({
	        css: {
	            border: '0px solid #e6e6e6',
	            padding: '5px',
	            backgroundColor: '#ffffff',
	            opacity: '.9',
	            filter: 'alpha(opacity = 90)',
	            zoom: '1',
	            color: '#000000',
	            width: '400px',
	            textAlign: 'left'
	        },
	        overlayCSS: {
	            border: '0px solid #e6e6e6',
	            backgroundColor: '#000000',
	            opacity: '.5',
	            filter: 'alpha(opacity = 50)',
	            zoom: '1'
	        },
	        message: '<div style="line-height:50px;" class="domainTitle"><img src="/images/ajax-loader.gif" style="float:left; padding-right:10px;" />Checking Page for Cloaking...</div>'
	    });
	    //now, get the data
		$.ajax({
			type: "GET",
			url: "http://bclaydev.bruceclay.com/services/sitechecker.py/GetCloakingCheck",
			data: "url="+$("#cloakBox").val(),
			dataType: 'jsonp',
			jsonp: 'jsonp',
			timeout: 12000,
			success: function(json) {
				if(json.error) {
					$("#cloakInfoDiv").unblock().block({
						css: {
				            border: '0px solid #e6e6e6',
				            padding: '5px',
				            backgroundColor: '#ffffff',
				            opacity: '.9',
				            filter: 'alpha(opacity = 90)',
				            zoom: '1',
				            color: '#000000',
				            width: '600px',
				            textAlign: 'left'
				        },
				        overlayCSS: {
				            border: '0px solid #e6e6e6',
				            backgroundColor: '#000000',
				            opacity: '.5',
				            filter: 'alpha(opacity = 50)',
				            zoom: '1'
				        },
				        message: '<div style="line-height:50px;" class="domainTitle">This page could not be checked. Please check the page URL that you entered. <input type="button" id="cloakInvalid" value="OK" /></div>'
					});
					$("#cloakInvalid").click(function() {
		    			$("#cloakInfoDiv").unblock();
		    			return false;
		    		});
				} else {
					$("#cloakDomain").html($("#cloakBox").val());
					$.each(json.Criteria, function(i,item) {
						cl = '/images/x.gif';
						if (item.Description.indexOf('ResultSuccess') > 0) {
							cl = '/images/check.gif';
						}
						d = "#cloak" + item.CheckedCriterion;
						$(d).html('<img src="'+cl+'" />');
					});	
					$("#cloakInfoDiv").unblock();
				}
			}
		});
		return false;
	});
});