// JavaScript Document
// Requires prototype framework v.1.6+

/* -------------------------------------------------------------------
|
|	You may want to add the following rule to your CSS. This will be
|	the style that applies only to your error messages.
|
|	.ajaxForm_error { color: red; }
|
---------------------------------------------------------------------- */

// Modify variables to suit your needs.
// Redirection to a success page.
var redirect = false;
// Page to redirect to on Success, relative of site root
var redirectTo = 'thankyou.html';
// Id of the div or any html element that either the success or error message should appear in.
var messageDiv = 'notify'; 
// ID of the form being submitted
var formId = 'sweepstakes'; 
// Path to the form to email script
var scriptPath = 'templates/superwindows/scripts/formtoemailpro3.php'; 

// No need to edit below this line
// ------------------------------------------------------------------------------------------------

function processForm(e) {
		var formValues = $(formId).serialize(true);
		new Ajax.Request(scriptPath, {
						 method: 'post',
						 parameters: formValues,
						 onSuccess: function(transport) {
							var result = transport.responseText;
							if(result.include('Thank you')) {
								if(redirect) {
									var url = window.location.hostname;
									window.location = "http://"+url+"/"+redirectTo;
								}
								if($(messageDiv).hasClassName('ajaxForm_error')) {
									$(messageDiv).removeClassName('ajaxForm_error');
								}
								$(messageDiv).innerHTML = result;
								formId.reset();
							} else {
								$(messageDiv).className += ' ajaxForm_error';
								$(messageDiv).innerHTML = result;	
							}
						 }
						 });
		Event.stop(e);
}

document.observe("dom:loaded", function() {
	Event.observe(formId, 'submit', processForm);
									   });
