/* function to include other .js files on page; thanks to phpied.com */
function include_js(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
};

var last_email = '';

$(document).ready(function() {
	highlightOnFocus('.login_input');
});

function doLogin(depth){
	var email_login = $('#email_login').val();
	var passwd_login = $('#passwd_login').val();
	
	var prefix = '';
	while(depth>=0){
		prefix += '../';
		depth--;
	}
	
	last_email = email_login;
	
	$.ajax({
		type: 'POST',
		url: prefix + 'users/ajax/doLogin.php',
		data: { email_login: email_login,
				passwd_login: passwd_login},
		dataType: "json",
		success: function(data){
			if(data.error != 'NONE'){
				$('#login_error_message').html(data.error);
			}else{
				if(data.redirect != 'NONE'){
					window.location = data.redirect;
				}else{
					window.location = prefix + "welcome.php";
				}
			}
		},
		failure: function(){
			alert('There was a error while logging in.  If the problem persists, please contact the administrator.');
		}	
	});
}

function sendVerifyEmail(){
	$.ajax({
		type: 'POST',
		url: 'users/ajax/resendVerification.php',
		data: {email: last_email},
		dataType: "json",
		success: function(data){
			if(data.error == ''){
					alert('An email has been sent, please follow the instructions in the email to verify your account.');
			}else if(data.error=='BLOCKED'){
					alert('This account is blocked.  If you would like to know why please contact the administrator.');
			}else{
					alert('There was an error sending the email.  If the problem persists please contact the administrator.');
			}
		}
	});
}

/* include additional javascript files below */
/* include_js('filename.js'); */
/* eof */