// Preload Images
var base = 'http://www.mrtv4.net.mm';
img1 = new Image(16, 16);  
img1.src="../img/front_images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="../img/front_images/ajax-loader.gif";

// When DOM is ready
$(document).ready(function(){

	
	$("#status > form").submit(function(){ 
										
	$('#signin_submit').hide();
	$('#ajax_loading').show();
	
	var $form = $( this ),
        url = $form.find( 'input[name="redirect"]' ).val();
	 req = $form.find( 'input[name="srequest"]' ).val();	
		if(req){
			url = url+'?req=true';
		}
	var str = $(this).serialize(); 
	$.ajax({  
    	type: "POST",
    	url: base+"/login",  // Send the login info to this page
    	data: str,  
    	success: function(msg){  
   		$("#status").ajaxComplete(function(event, request, settings){   
 			$('#signin_submit').show();
			$('#ajax_loading').hide(); 			
			if(msg == 'OK') // LOGIN OK?
 			{  
				var login_response = '<div id="logged_in">' +									
									 '<div style="width: 100px; margin:auto">' +
									 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="'+base+'/img/front_images/ajax-loader.gif">' +
									 '</div>' +
									 '<div style="margin: 10px 0px 0px 10px; width: 180px; color: #669900">'+ 
									 "You are successfully signed in! <br /> Please wait ...</div></div>";  				
				$(this).html(login_response); // Refers to 'status'				
				setTimeout(		function(){
									window.location = base+'/'+url;
								} 
							, 3000); 
			}  
 			else // ERROR?
			{  
				var login_response = msg;
				$('#login_response').html(login_response);
			}        
 		});     
 		}     
  	});  
  
	// -- End AJAX Call --
	return false;

	}); // end submit event
	

	$('#logout').submit(function(){
								   
		$('#signout_submit').hide();
		$('#ajax_loading').show();
		
		var $form = $( this ),
        	url = $form.find( 'input[name="redirect"]' ).val();
		var str = $(this).serialize(); 
		
		$.ajax({  
    	type: "POST",
    	url: base+"/logout",  // Send the login info to this page
    	data: str,  
    	success: function(msg){  
   		$("#status").ajaxComplete(function(event, request, settings){    								
			if(msg == 'OK') // LOGIN OK?
 			{  							
				setTimeout(		function(){
									window.location = base+'/'+url;
								} 
							, 3000); 
			}  
 			else // ERROR?
			{  
				var login_response = msg;
				$('#login_response').html(login_response);
			}        
 		});     
 		}     
  	});  
  
	// -- End AJAX Call --
	return false;
		
	});
	
});

