var HTTP_PATH = "http://www.5dollarsforfree.com";
var left_popup = ((screen.width)/2 - 176) ;

// Preload Images
img1 = new Image(16, 16);
img1.src= HTTP_PATH+"/app/webroot/img/spinner.gif";

img2 = new Image(220, 19);
img2.src=HTTP_PATH+"/app/webroot/img/ajax-loader.gif";

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

//rohit 20100424
var overlayObject = $("a[rel]").overlay({
	    top: 50,
            left:left_popup,

		expose: {
				color: '#232323',
				closeOnClick: true
				},

				onClose:function() {
			    					$('#reg-login').hide();
			    					$('#reg-register').hide();
				            		},
		effect:'apple'
	});

$('#show-register').click(function() {
	    $('#reg-login').hide();
	    $('#reg-register').show();
	    return false;
	});


	$('#show-login').click(function() {
	    $('#reg-register').hide();
	    $('#reg-login').show();
	    return false;
	});


	$('.join').click(function() {
	    $('#reg-register').show();
	    $('#reg-login').hide();
	    return true;
	});

	$('#login').click(function() {
	    $('#reg-login').show();
	    $('#reg-register').hide();
	    return true;
	});

	$('.login-link').click(function() {
	    $('#reg-login').show('fast');
	    $('#reg-register').hide('slow');
	    return true;
	});

        $('.forgotpassword').click(function() {
	    $('.forgotpasswordform').show();
	    $('#status').hide();
	    return true;
	});

$('#join_link').click(function() {
	    $('#reg-register').show();
	    $('#reg-login').hide();
	    return true;
	});

$('.backtologin').click(function() {
	    $('#status').show();
	    $('.forgotpasswordform').hide();
	    return true;
	});



// Launch MODAL BOX if the Login Link is clicked
//$("#login_link").click(function(){
//$('#login_form').modal();
//});
//// Launch MODAL BOX if the Login Link is clicked
//$("#join_link").click(function(){
//$('#join_form').modal();
//});

//When the forgot password dorm is submitted

$(".forgotpasswordform > 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:HTTP_PATH+"/customers/forgotPass",
    //url: "do_login.php",  // Send the login info to this page
    data: str,
    success: function(msg){

$(".forgotpasswordform").ajaxComplete(function(event, request, settings){

 // Show 'Submit' Button
$('#submit').show();

// Hide Gif Spinning Rotator
$('#ajax_loading').hide();

 if(msg == 'OK') // LOGIN OK?
 {
 var login_response2 = '<div id="logged_in">' +
	 '<div style="width: 350px; float: left;">' +
	 '<div style="width: 40px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="'+HTTP_PATH+'/app/webroot/img/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; float: left; width: 200px;">'+
	 "You are sent a mail on your email id. <br /> Please wait while you're redirected...</div></div>";

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

$('#simplemodal-container').css("width","350px");
$('#simplemodal-container').css("height","120px");

 //$(this).html(login_response2); // Refers to 'status'

// After 3 seconds redirect the
setTimeout('go_to_password_success_page()', 3000);
 }
 else // ERROR?
 {
 //var login_response2 = msg;
 //$('#login_response2').html(login_response2);
 $('a.modalCloseImg').hide();

$('#simplemodal-container').css("width","500px");
$('#simplemodal-container').css("height","120px");
setTimeout('go_to_password_failure_page()', 1000);

 }

 });

 }

  });

// -- End AJAX Call --

return false;

}); // end submit event



// 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 --


$.ajax({

    type: "POST",
    url:HTTP_PATH+"/customers/doLogin",
    //url: "do_login.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: 340px; float: left;">' +
	 '<div style="width: 30px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="'+HTTP_PATH+'/app/webroot/img/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 5px; float: right; width: 300px;">'+
	 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";

$('a.modalCloseImg').hide();
$('.is-member').hide();
$('#simplemodal-container').css("width","350px");
$('#simplemodal-container').css("height","120px");

 $(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the
setTimeout('go_to_private_page()', 3000);
 }
 else // ERROR?
 {
 var login_response = msg;
 $('#login_response').html(login_response);
 return false;
 }

 });

 }

  });

// -- End AJAX Call --

return false;

}); // end submit event

//joinj starts
// When the form is submitted
$("#join_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:HTTP_PATH+"/customers/doJoin",
    //url: "do_login.php",  // Send the login info to this page
    data: str,
    success: function(msg){

$("#join_status").ajaxComplete(function(event, request, settings){

 // Show 'Submit' Button
$('#submit').show();

// Hide Gif Spinning Rotator
$('#ajax_loading').hide();

 if(msg == 'OK') // LOGIN OK?
 {
//  var join_response = '<div style="bgcolor:#ffffff; " id="logged_in">' +
//	 '<div style="width: 340px; float: left; bgcolor:#ffffff; ">' +
//	 '<div style="width: 30px; float: left; bgcolor:#ffffff;">' +
//	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="'+HTTP_PATH+'/app/webroot/img/ajax-loader.gif">' +
//	 '</div>' +
//	 '<div style="margin: 10px 0px 0px 5px; float: right; bgcolor:#ffffff; width: 300px;">'+
//	 "Your account is successfully created! <br /> Please wait while you're redirected...</div></div>";
var join_response = '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="'+HTTP_PATH+'/app/webroot/img/ajax-loader.gif">'+"Please wait while you're redirected...";
$('a.modalCloseImg').hide();
$('#simplemodal-container').css("width","350px");
$('#simplemodal-container').css("height","120px");




$(this).html(join_response); // Refers to 'status'

// After 3 seconds redirect the
setTimeout('go_to_index_page()', 3000);
 }
 else // ERROR?
 {
 var join_response = msg;
 $('#join_response').html(join_response);
 }

 });

 }

  });

// -- End AJAX Call --

return false;

}); // end submit event


//join ends
});

function go_to_private_page()
{
window.location = HTTP_PATH; // Members Area
}
function go_to_index_page()
{
window.location = HTTP_PATH+"/page/join"; // Members Area
}

function go_to_password_success_page()
{
window.location = HTTP_PATH+"/page/passwordSuccess";
}

function go_to_password_failure_page()
{
window.location = HTTP_PATH+"/page/passwordFailure";
}

