// 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()
{

	// Launch MODAL BOX if the Login Link is clicked
	

// When the 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 --
		movieid = this.txtMovieid.value;
		$.ajax(
		{  
   		 	type: "POST",
    		url: "login_check.php",  // Send the login 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') // LOGIN OK?
				 {  
				 var login_response = '<div id="logged_in">' +
					 '<div style="width: 350px; 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;">'+ 
					 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";  
				
				$('a.modalCloseImg').hide();  
				
				$('#simplemodal-container').css("width","500px");
				$('#simplemodal-container').css("height","120px");
				 
				 $(this).html(login_response); // Refers to 'status'
				
				// After 3 seconds redirect the 
				setTimeout('go_to_private_page()', 3000); 
				 } 
				 else if(msg == 'theatrelogin')
				 {
					  var login_response = '<div id="logged_in">' +
					 '<div style="width: 350px; 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;">'+ 
					 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";  
				
				$('a.modalCloseImg').hide();  
				
				$('#simplemodal-container').css("width","500px");
				$('#simplemodal-container').css("height","120px");
				 
				 $(this).html(login_response); // Refers to 'status'
				
				// After 3 seconds redirect the 
				setTimeout('go_to_theatrelogin_page()', 3000); 
				 }
				 else // ERROR?
				 {  
				 var login_response = msg;
				 $('#login_response').html(login_response);
				 }  
				  
			 });  
			   
		}  
			   
	});  
			  
			// -- End AJAX Call --

	return false;

	}); // end submit event
	
	
	
$("#signup > form").submit(function()
	{  

	// Hide 'Submit' Button
		$('#btnSave').hide();

		// Show Gif Spinning Rotator
		$('#ajax_loading1').show();

		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  
		//var name = $('#txtName').val();
//		var email = $('#txtEmail').val();
//		var mobileno = $('#txtMobileno').val();
//		var city = $('#txtCity').val();
//		var password = $('#txtPassword').val();
//		var cpassword = $('#txtConfirmpassword').val();
	// -- Start AJAX Call --
		$.ajax(
		{  
   		 	type: "POST",
    		url: "save_newuser.php",  // Send the login info to this page
    		data: str,  
    		success: function(msg)
			{  
   
			$("#signup").ajaxComplete(function(event, request, settings)
			{  
 
 				// Show 'Submit' Button
				$('#btnSave').show();
	
				// Hide Gif Spinning Rotator
				$('#ajax_loading1').hide();  
	
				 if(msg == 'OK') // LOGIN OK?
				 {  
				 var login_response = '<div id="register">' +
					 '<div style="width: 350px; 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 Registration Compleated! <br /> Please wait while you're redirected...</div></div>";  
				
				$('a.modalCloseImg').hide();  
				
				$('#signup-container').css("width","500px");
				$('#signup-container').css("height","120px");
				 
				 $(this).html(login_response); // Refers to 'status'
				
				// After 3 seconds redirect the 
				setTimeout('go_to_index_page()', 3000); 
				 }  
				 else // ERROR?
				 {  
					 var login_response = msg;
					 $('#signup_response').html(login_response);
					// if( name == "")
//					{
//					 	$('#signup_response').html(login_response);
//				 		$('#txtName').css("background-color","#F2F200");
//						$('#txtEmail').css("background-color","white");
//						$('#txtMobileno').css("background-color","white");
//						$('#txtCity').css("background-color","white");
//						$('#txtPassword').css("background-color","white");
//						$('#txtConfirmpassword').css("background-color","white");
//					 }
//					 else if(email == "")
//					 {
//						$('#signup_response').html(login_response);
//				 		$('#txtEmail').css("background-color","#F2F200");
//						$('#txtName').css("background-color","white");
//						$('#txtMobileno').css("background-color","white");
//						$('#txtCity').css("background-color","white");
//						$('#txtPassword').css("background-color","white");
//						$('#txtConfirmpassword').css("background-color","white");
//
//					 }
//					 else if(mobileno == "")
//					 {
//						$('#signup_response').html(login_response);
//				 		$('#txtMobileno').css("background-color","#F2F200");
//						$('#txtName').css("background-color","white");
//						$('#txtEmail').css("background-color","white");
//						$('#txtCity').css("background-color","white");
//						$('#txtPassword').css("background-color","white");
//						$('#txtConfirmpassword').css("background-color","white");
//
//					 }
//					 else if(city == "")
//					 {
//						$('#signup_response').html(login_response);
//				 		$('#txtCity').css("background-color","#F2F200");
//						$('#txtName').css("background-color","white");
//						$('#txtEmail').css("background-color","white");
//						$('#txtMobileno').css("background-color","white");
//						$('#txtPassword').css("background-color","white");
//						$('#txtConfirmpassword').css("background-color","white");
//
//					 }
//					 else if(password == "")
//					 {
//						$('#signup_response').html(login_response);
//				 		$('#txtPassword').css("background-color","#F2F200");
//						$('#txtName').css("background-color","white");
//						$('#txtEmail').css("background-color","white");
//						$('#txtMobileno').css("background-color","white");
//						$('#txtCity').css("background-color","white");
//						$('#txtConfirmpassword').css("background-color","white");
//
//					 }
//					 else if(cpassword == "")
//					 {
//						$('#signup_response').html(login_response);
//				 		$('#txtConfirmpassword').css("background-color","#F2F200");
//						$('#txtName').css("background-color","white");
//						$('#txtEmail').css("background-color","white");
//						$('#txtMobileno').css("background-color","white");
//						$('#txtCity').css("background-color","white");
//						$('#txtPassword').css("background-color","white");
//					} 
				 }
				  
			 });  
			   
		}  
			   
	});  
			  
			// -- End AJAX Call --

	return false;

	}); 
	});

function go_to_private_page()
{
	if(movieid == "")
	{
		window.location = 'index.php'; // Members Area
	}
	else
	{
		window.location = 'book_show.php?id='+movieid; // Members Area
	}
}

function go_to_index_page()
{
	$.signup.impl.close();
	$('#login_form').modal(); // Members Area
}

function go_to_theatrelogin_page()
{
	window.location = 'theatre/index.php'; // Members Area
}
