/* Copyright by Robert Baumgartner. All rights reserved.
 * visit http://the-godking.com for more detailed information
 *
 * jQuery Plugin that shows a "valid HTML" Text (or image, or whatever), 
 * but just if the current site actually really validates!
 * Validation done by the W3C HTML Validation service (http://validator.w3.org)
 * 
 * HOW TO USE:
 * jQuery("#validationButtons").w3cValidator({
 *    parserLocation: "path/to/w3cValidator.php"
 * });
 * 
 * Optional:
 * jQuery("#validationButtons").w3cValidator({
 *    parserLocation: "path/to/w3cValidator.php",
 *    URL_isValid: "HTML to show if site validates",
 *    URL_isInvalid: "HTML to show if site doesn't validates"
 * });
 */
 
(function($) {
	$.fn.w3cValidator = function(options) {
		var opts = $.extend({}, $.fn.w3cValidator.defaults, options);
		function str_replace(search, replace, subject) {
		return subject.split(search).join(replace);
		}
		return this.each(function() {
			currentURL = ""+encodeURIComponent(window.location);
			var $this = $(this);
			$.ajax({
				type: "POST",
				url: opts["parserLocation"],
				data: "url="+currentURL,
				success: function(isValid){
					if(isValid == "true") {
						$this.append(opts["URL_isValid"]);
					} else {
						$this.append(opts["URL_isInvalid"]);
					}
				}
			});
		});
	};
	
	// plugin defaults
	$.fn.w3cValidator.defaults = {
		URL_isValid: '<a href="http://validator.w3.org/check?uri=referer">valid HTML</a>',
		URL_isInvalid: '<a href="http://validator.w3.org/check?uri=referer">invalid HTML</a>'
	};
})(jQuery);