// 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
var $j = jQuery.noConflict();

$j(document).ready(function(){

var url;
$j("#join_link").click(function(){
$j('#join_form').modal();
$j('#simplemodal-container').css("width","420px");
$j('#simplemodal-container').css("height","250px");
url = "/do-join.php"
});

$j("#join_div_link").click(function(){
$j('#join_form').modal();
$j('#simplemodal-container').css("width","420px");
$j('#simplemodal-container').css("height","250px");
url = "/do-join.php";
});

$j("#join_sidebar").click(function(){
$j('#join_form').modal();
$j('#simplemodal-container').css("width","420px");
$j('#simplemodal-container').css("height","250px");
url = "/do-join.php";
});

$j("#login_link").click(function(){
$j('#login_form').modal();
document.getElementById("member_name_id").focus();
$j('#simplemodal-container').css("width","420px");
$j('#simplemodal-container').css("height","260px");
url = "/do-login-member.php";
});

$j("#login_div_link").click(function(){
$j('#login_form').modal();
document.getElementById("member_name_id").focus();
$j('#simplemodal-container').css("width","420px");
$j('#simplemodal-container').css("height","260px");
url = "/do-login-member.php";
});

// When the form is submitted
/* ###################################################### */
/* Code Forgot Password Start */
/* ###################################################### */
$j("#forgot_status > form").submit(function(){  

	if($j("#forgot_validation_output").val() == "false") {
		return false;
	}
	document.getElementById("forgot_loader").style.display = '';
	// 'this' refers to the current submitted form  
	var str = $j(this).serialize(); 

	$j.ajax({  
		type: "POST",
		url: url,  // Send the login info to this page
		data: str,  
		success: function(msg){  
			$j("#forgot_status").ajaxComplete(function(event, request, settings){  
				 if(msg == 'OK') { 
					 //var login_response; 
					 //login_response = get_login_response_template();
					 //document.getElementById("forgot_password_form").style.display = 'none';
					 //$j('#login_form').html(login_response); // Refers to 'status'
					 // After 3 seconds redirect the 
					 setTimeout("go_to_private_page('')", 3000); 
				 } else {  
					 var login_response = msg;
					 $j('#forgot_login_response').html(login_response);
					 document.getElementById("forgot_loader").style.display = 'none';
				 }  
				  
			 });     
		}     
	});    
	// -- End AJAX Call --
	return false;
}); // end submit event

/* ###################################################### */
/* Code Forgot Password End */
/* ###################################################### */

/* ###################################################### */
/* Code Reset Password Start */
/* ###################################################### */

// When the form is submitted
$j("#reset_pwd_status > form").submit(function(){  
	if($j("#reset_pwd_validation_output").val() == "false") {
		return false;
	}
	document.getElementById("reset_loader").style.display = '';
	// 'this' refers to the current submitted form  
	var str = $j(this).serialize();  

	// -- Start AJAX Call --
	$j.ajax({  
		type: "POST",
		url: "do-password_reset.php",  // Send the login info to this page
		data: str,  
		success: function(msg){  
			 $j("#reset_pwd_status").ajaxComplete(function(event, request, settings){  
				 if(msg == 'OK') {  
 					 //var login_response; 
					 //login_response = get_login_response_template();
					 //$j(this).html(login_response); // Refers to 'status'

					// After 3 seconds redirect the 
					setTimeout("go_to_private_page('')", 3000); 
				 }  else {  
					 var login_response = msg;
					 $j('#login_login_response').html(login_response);
					 document.getElementById("reset_loader").style.display = 'none';
				 }  
				  
			 });  
			   
		 }  
	   
	});   
	// -- End AJAX Call --
	return false;
}); // end submit event

/* ###################################################### */
/* Code Reset Password End */
/* ###################################################### */



/* ###################################################### */
/* Code Registration Start */
/* ###################################################### */

// When the form is submitted
$j("#status > form").submit(function(){  
	if($j("#reg_validation_output").val() == "false") {
		return false;
	}
	document.getElementById("join_loader").style.display = '';

	// 'this' refers to the current submitted form  
	var str = $j(this).serialize();  

	// -- Start AJAX Call --
	$j.ajax({  
		type: "POST",
		url: url,  // Send the login info to this page
		data: str,  
		success: function(msg){  
	   
			 $j("#status").ajaxComplete(function(event, request, settings){  
			 
				 if(msg == 'OK') {  
 					 var login_response; 
					 //login_response = get_login_response_template();
					 //$j(this).html(login_response); // Refers to 'status'

					// After 3 seconds redirect the 
					setTimeout("go_to_private_page('login')", 3000); 
				 }  else {  
					 var login_response = msg;
					 $j('#login_response').html(login_response);
					 document.getElementById("join_loader").style.display = 'none';
				 }  
				  
			 });  
			   
		 }  
	   
	});   
	// -- End AJAX Call --
	return false;
}); // end submit event

/* ###################################################### */
/* Code Registration End */
/* ###################################################### */

/* ###################################################### */
/* Code Settings Start */
/* ###################################################### */

// When the form is submitted
$j("#login_status > form").submit(function(){  

	if($j("#login_validation_output").val() == "false") {
		return false;
	}
	document.getElementById("login_loader").style.display = '';
	// 'this' refers to the current submitted form  
	var str = $j(this).serialize();  

	// -- Start AJAX Call --
	$j.ajax({  
		type: "POST",
		url: url,  // Send the login info to this page
		data: str,  
		success: function(msg){ 
			 $j("#login_status").ajaxComplete(function(event, request, settings){  
				 if(msg == 'OK') {  
 					 var login_response; 
					// login_response = get_login_response_template();
					 //$j(this).html(login_response); // Refers to 'status'
					 
					// After 3 seconds redirect the 
					setTimeout("go_to_private_page('login')", 3000); 
				 }  else {  
					 var login_response = msg;
					 $j('#login_login_response').html(login_response);
					 document.getElementById("login_loader").style.display = 'none';
				 }  
				  
			 });  
			   
		 }  
	   
	});   
	// -- End AJAX Call --
	return false;
}); // end submit event

/* ###################################################### */
/* Code Settings End */
/* ###################################################### */


});

function go_to_private_page(page) {
	if(page == 'login')
		window.location = '/index.php?page_key=loginAction'; // Members Area
	else	
	window.location = '/';
}
function get_login_response_template() {
	var login_response_template = '<div id="logged_in">' +
						 '<div style="width: 300px; float: left; margin-left: 10px;">' + 
						 '<div style="width: 15px; float: left;">' +
						 '<img align="absmiddle" src="images/LoaderIcon.gif" height="15px">' +
						 '</div>' +
						 '<div style="float: left; width: 265px;margin-left:20px" align="left">'+ 
						 ' diving in...</div></div>'; 

	$j('a.modalCloseImg').hide();  

	$j('#simplemodal-container').css("width","400px");
	$j('#simplemodal-container').css("height","80px");
	return login_response_template;
}
