﻿var forgot_password;
var new_user_registration;

var forgot_password_html =
	"<br />"+
	"If you used your email address as your login ID enter it here and we will send your password to you:" +
	"<br /><br />" +
	"<b>Email Address:</b> <input type='text' id='forgot_password_email' />" +
	"<br /><br />" +
	"<span class='forgot_password_note'>" +
	"** If you did not provide your email address, ask your teacher to retrieve your <b>Login ID</b> and <b>Password</b>" +
	"</span>" +
	"<br /><br />";
var forgot_password_not_found =
	"<br/>" +
	"<span class='forgot_password_error'>" +
	"We could not found any account associated with your email address." +
	"<br/>" +
	"Please try again." +
	"</span>" +
	"<br/><br/>";
var forgot_password_done =
	"<br/>" +
	"<span class='forgot_password_success'>" +
	"Your password has been sent to your email. You will receive an email shortly." +
	"<br/><br/>" +
	"Thank you." +
	"</span>" +
	"<br/><br/>";

jq(function() {
	jq('.tool_tip_holder').tooltip({
		fade: 0,
		showURL: false,
		showBody: ' -- ',
		extraClass: "tooltip_class"
	});
	forgot_password = jq('#forgot_password_dialog').dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		resizable: false
	});
	new_user_registration = jq('#new_user_registration').dialog({
		bgiframe: true,
		modal: true,
		autoOpen: false,
		resizable: false
	});
});

function show_student_registration() {
	new_user_registration.dialog('option', 'buttons', { "GO": function() { document.getElementById('form_registration').submit(); } });
	new_user_registration.dialog('option', 'width', 550);
	new_user_registration.dialog("open");
}

function show_forgot_password() {
	jq('#forgot_password_dialog').html(forgot_password_html);
	forgot_password.dialog('option', 'buttons', { "Send": check_password });
	forgot_password.dialog("open");
}
//forgot_password.dialog('option', 'buttons', { "Ok": function() { $(this).dialog("close"); } });
function check_password() {
	if (jq('#forgot_password_email').val() == "" || jq('#forgot_password_email').val() == undefined)
		return;
	forgot_password.dialog('option', 'buttons', {});
	jq.ajax({
		type: "POST",
		url: "http://" + domain + "/_forgot_password.aspx/forgotPassword",
		data: JSON.stringify({ log_type: "student", email: jq('#forgot_password_email').val() }),
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(msg) {
			if (msg.d == "done") {
				jq('#forgot_password_dialog').html(forgot_password_done);
				return;
			}
			jq('#forgot_password_dialog').html(forgot_password_not_found + forgot_password_html);
			forgot_password.dialog('option', 'buttons', { "Send": check_password });
		}
	});
}