﻿ConfirmButtons = {
	init : function()
	{
		var confirmButtons = $('input[data-confirmText]');
		var replacementClick = function () 
		{ 
			if (confirm($(this).attr('data-confirmText')))
			{
			    if($(this).attr('name') != $(this).attr('id').replace(/_/, ':'))
			    {
			        var hiddenField = $('<input type="hidden" value="' + $(this).attr('value') +'" name="' + $(this).attr('name') + '" />')
			        $(this).after(hiddenField);
			    }
				__doPostBack($(this).attr('name'), '');
			}
		}
		var replaceButtons = function() 
		{ 
			var replacementButton = $('<input type="button" />');
			var originalButton = $(this);
			var replaceAttr = function(key, value) 
			{
				replacementButton.attr(value, originalButton.attr(value));
			}

			jQuery.each(['id', 'class', 'name', 'style', 'value', 'data-confirmText', 'disabled'], replaceAttr);
			replacementButton.click(replacementClick);
			$(this).replaceWith(replacementButton); 
		}
		confirmButtons.each(replaceButtons);
	}
}

$(document).ready(ConfirmButtons.init);