/*
	This is a javascript to achieve the styling for the preside form submit button (according to its template).
	By default, preside form builder does not have any button wrapper.
*/

var button_wrapper = {
	init : function() {
		// Check that the browser supports the methods used
		if (!document.getElementById || !document.createElement || !document.appendChild) return false;
		
		var oElement, oPullquote, oPullquoteP, oQuoteContent, i, j;
		
		// Find all input element with class submit
		var arrElements = document.getElementsByTagName('input');
		var oRegExp = new RegExp("(^|\\s)submit");
		
		for (i=0; i<arrElements.length; i++) {
			
			// Save the current element
			oElement = arrElements[i];
			
			if (oRegExp.test(oElement.className)) {
				// Create the button wrapper
				oButtonWrapper = document.createElement('span');
				oButtonWrapper.className = 'button-wrapper';
				
				// Create a new submit button
				oSubmitButton = document.createElement('input');
				oSubmitButton.type = oElement.type;
				oSubmitButton.value = oElement.value;
				
				// Put the new submit button into the wrapper
				oButtonWrapper.appendChild(oSubmitButton);
				
				// Append the button wrapper into the same parent as the one that needs to be replaced
				oElement.parentNode.appendChild(oButtonWrapper);
				
				// Remove the old submit button
				oElement.parentNode.removeChild(oElement);
				
				i = i+2;
			}
		}
	}
};

// addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
addEvent(window, 'load', button_wrapper.init);
