// Preload Images
img1 = new Image(16, 16);  
img1.src="images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="images/ajax-loader.gif";

// When DOM is ready
$(document).ready(function(){
	//png fix
	$(document).pngFix(); 
	// Launch MODAL BOX if the Login Link is clicked
	$("#rsvp_link").click(function(){
		$('#rsvp_form').modal();
	});

	$("#email_link").click(function(){
		$('#email_form').modal();
		$('#simplemodal-container').css("width","600px");
		$('#simplemodal-container').css("height","400px");
	});
	
	$("#email_link_home").click(function(){
		$('#email_form').modal();
		$('#simplemodal-container').css("width","600px");
		$('#simplemodal-container').css("height","400px");
		var email = $('#emailField').val();
		$('#emailFormField').val(email);

	});


	// When the rsvp form is submitted
	$("#status > form").submit(function(){  

		// Hide 'Submit' Button
		$('#submit').hide();
		
		// Show Gif Spinning Rotator
		$('#ajax_loading').show();
		
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  

		// -- Start AJAX Call --
		
		$.ajax({  
			type: "POST",
			url: "do_rsvp.php",  // Send the rsvp info to this page
			data: str,  
			success: function(msg){  
   
				$("#status").ajaxComplete(function(event, request, settings){  
				 
					 // Show 'Submit' Button
					$('#submit').show();
	
					// Hide Gif Spinning Rotator
					$('#ajax_loading').hide();  
				
					 if(msg == 'OK') // RSVP OK?
					 {  
						 var rsvp_response = '<div id="logged_in">' +
							 '<div style="width: 400px; float: left; margin-left: 70px;">' + 
							 '<div style="width: 40px; float: left;">' +
							 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="images/ajax-loader.gif">' +
							 '</div>' +
							 '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
							 "Your RSVP has been submitted! <br /> A confirmation email has been sent to you...</div></div>";   
						
						$('a.modalCloseImg').hide();  
						
						$('#simplemodal-container').css("width","600px");
						$('#simplemodal-container').css("height","120px");
						 
						 $(this).html(rsvp_response); // Refers to 'status'
						
						// After 3 seconds redirect the 
						setTimeout('go_to_private_page()', 3000); 
					 }  
					 else // ERROR?
					 {  
						 var rsvp_response = msg;
						 $('#rsvp_response').html(rsvp_response);
					 }  
      
 				});  
   
 			}  
   
  		});  
  
	// -- End AJAX Call --
	
	return false;
	
	}); // end submit event
	
	// When the email form is submitted
	$("#statusx > form").submit(function(){  

		// Hide 'Submit' Button
		$('#submit').hide();
		
		// Show Gif Spinning Rotator
		$('#ajax_loading').show();
		
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  

		// -- Start AJAX Call --
		
		$.ajax({  
			type: "POST",
			url: "do_email.php",  // Send the email info to this page
			data: str,  
			success: function(msg){  
   
				$("#statusx").ajaxComplete(function(event, request, settings){  
				 
					 // Show 'Submit' Button
					$('#submit').show();
	
					// Hide Gif Spinning Rotator
					$('#ajax_loading').hide();  
				
					 if(msg == 'OK') // RSVP OK?
					 {  
						 var email_response = '<div id="logged_in">' +
							 '<div style="width: 400px; float: left; margin-left: 70px;">' + 
							 '<div style="width: 40px; float: left;">' +
							 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="images/ajax-loader.gif">' +
							 '</div>' +
							 '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
							 "Thank You for joining the eLATED Community! </div></div>";   
						
						$('a.modalCloseImg').hide();  
						
						$('#simplemodal-container').css("width","600px");
						$('#simplemodal-container').css("height","120px");
						 
						 $(this).html(email_response); // Refers to 'status'
						
						// After 3 seconds redirect the 
						setTimeout('go_to_private_page()', 3000); 
					 }  
					 else // ERROR?
					 {  
						 var email_response = msg;
						 $('#email_response').html(email_response);
					 }  
      
 				});  
   
 			}  
   
  		});  
  
	// -- End AJAX Call --
	
	return false;
	
	}); // end submit event
});

function go_to_private_page()
{
window.location.reload()
}
