jQuery(document).ready(function() {
								
	// Autofill fields
	jQuery("#fname").autofill({
		value: 'First Name',
	});
	jQuery("#lname").autofill({
		value: 'Last Name',
	});
	jQuery("#email").autofill({
		value: 'Email Address',
	});

	jQuery("#add1").autofill({
		value: 'Address',
	});
	jQuery("#add2").autofill({
		value: 'Address cont.',
	});
	jQuery("#city").autofill({
		value: 'City',
	});
	jQuery("#zip").autofill({
		value: 'Zip Code',
	});
	jQuery("#phone").autofill({
		value: 'Phone Number',
	});
	jQuery("#mobile").autofill({
		value: 'Mobile Phone Number',
	});
	jQuery("#other").autofill({
		value: 'Other',
	});
jQuery("#fnamea").autofill({
		value: 'First Name',
	});
jQuery("#lnamea").autofill({
		value: 'Last Name',
	});
jQuery("#emaila").autofill({
		value: 'Email',
	});
jQuery("#zipa").autofill({
		value: 'Zip Code',
	});
	

	
	
	// VALIDATION
	initValidation();
	
	function initValidation(){
jQuery("#default-form").validationEngine({
			promptPosition: "topRight",
			success :  function() { ajaxMCSubmit() },
			failure : function() { }
    	});
		

		jQuery("#volunteer-form").validationEngine({
			promptPosition: "topRight",
			success :  function() { ajaxMCVolSubmit() },
			failure : function() { }
    	});

		
	}





	
	function ajaxMCSubmit(){
	
	// Once validation is passed once it needs to be reinitialized.
	initValidation();
	
	
	var groups = "";
	jQuery("input:checked").each( function(){
		groups += jQuery(this).val() + ",";	 
	});
	
	var passvars = {
					action: "mc_submit",
					list: jQuery('#default-list').val(),
					email: jQuery('#email').val(),
					zip: jQuery('#zip').val(),
					mobile: jQuery('#mobile').val(),
					fname: jQuery('#fname').val(),
					lname: jQuery('#lname').val(),
					add1: jQuery('#add1').val(),
					add2: jQuery('#add2').val(),
					city: jQuery('#city').val(),
					state: jQuery('#state').val(),
					phone: jQuery('#phone').val(),
					other: jQuery('#other').val(),

					group: groups
					}
	jQuery.post( "/wp-admin/admin-ajax.php",
		passvars, 
		function(data){
			if(data.status){
				//jQuery.fn.colorbox({href:'/email-signup-2/?e='+email+'&z='+zip, open:true, width:'500px', height:'300px', scrolling:false});
				jQuery("#cb_success").html(data.msg);
				jQuery.fn.colorbox({width:"400px", height:"250px",inline:true, href:"#cb_success"});
				//alert(data.msg);

			} else{
				// alert("Error. " + data.msg);	
				jQuery("#cb_error").html(data.msg);
				jQuery.fn.colorbox({width:"400px", height:"250px", inline:true, href:"#cb_error"});
				//				alert(data.msg);
			}
		},
		"json");
}


function ajaxMCVolSubmit(){
	
	// Once validation is passed once it needs to be reinitialized.
	initValidation();
	
	var passvars = {
					action: "mc_vol_submit",
					list: jQuery('#default-list').val(),
					fnamea: jQuery('#fnamea').val(),
					lnamea: jQuery('#lnamea').val(),
					emaila: jQuery('#emaila').val(),
					zipa: jQuery('#zipa').val(),
					}
	jQuery.post( "/wp-admin/admin-ajax.php",
		passvars, 
		function(data){
			if(data.status){
				//jQuery.fn.colorbox({href:'/email-signup-2/?e='+email+'&z='+zip, open:true, width:'500px', height:'300px', scrolling:false});
				//jQuery("#cb_success").html(data.msg);
				window.location = "/thanks/";
				//jQuery.fn.colorbox({width:"400px", height:"250px",inline:true, href:"#cb_success"});
				//alert(data.msg);

			} else{
				// alert("Error. " + data.msg);	
				jQuery("#cb_error").html(data.msg);
				jQuery.fn.colorbox({width:"400px", height:"250px", inline:true, href:"#cb_error"});
				//				alert(data.msg);
			}
		},
		"json");
}


});
