﻿$(function() {
    // These first three lines of code compensate for Javascript being turned on and off. 
    // It simply changes the submit input field from a type of "submit" to a type of "button".

   
 var paraTag = $('input#submit').parent('p');
    $(paraTag).children('input').remove();
    $(paraTag).append('<input type="button" name="submit" id="submit" value="Send" />');


    $('#formcontainer input#submit').click(function() {
/*         $('#submitholder').append('<img src="images/loadingAnimation.gif" class="loaderIcon" alt="Loading..." />'); */
		clearinvalid();
        var name = $('input#name').val();
        var email = $('input#email').val();
        var phone = $('input#phone').val();
        
        var make_phone_calls = $('input#make-phone-calls').val();
        var host_fundraiser = $('input#host-fundraiser').val();
        var distribute_literature = $('input#distribute-literature').val();
        var attend_rally = $('input#attend-rally').val();
        var work_at_polling_place = $('input#work-at-polling-place').val();
        
        var comments = $('textarea#comments').val();

        $.ajax({
            type: 'post',
            url: 'script/sendEmail.php',
            //data: 'name=' + name + '&email=' + email + '&comments=' + comments,
			data: 'name=' + name + '&email=' + email + '&phone=' + phone + '&make_phone_calls=' + make_phone_calls + '&host_fundraiser=' + host_fundraiser + '&distribute_literature=' + distribute_literature + '&attend_rally=' + attend_rally + '&work_at_polling_place=' + work_at_polling_place + '&comments=' + comments,
			
            success: function(results) {
         		//$('#submitholder img.loaderIcon').fadeOut(1000);         		            
            	$('div#response').html(results);
            }
        }); // end ajax
    });
});

//get a success call from sendEMail.php
function successfulmessage(){
	$('div#response').append('<p id="success">Message sent!<br>Thank you.</p>'); 
	//$("#emailsuccess").fancybox({'overlayShow':true,frameWidth: 490,frameHeight: 240}).trigger('click'); 

}




function incorrectname(){
	$('#formcontainer #name').addClass('incorrect-fill');
}
function incorrectemail(){	
	$('#formcontainer #email').addClass('incorrect-fill');
}
function incorrectmessage(){	
	$('#formcontainer #comments').addClass('incorrect-fill');
}
function clearinvalid(){	
	$('#formcontainer #name, #formcontainer #email, #formcontainer #comments').removeClass('incorrect-fill');
}