// wnd_forgotpswd.js

var wnd_forgotpswd_email;

//------------------------------------------	WND_ITMS: _wnd_forgotpswd_itms
var _wnd_forgotpswd_itms =
	[
	{id:"signin_welcome", type:"div", text:"Reset Password"},
	{id:"signin_welcline", type:"div"},
	{id:"forgotpswd_txt", text:"Enter the email address you used to register with Plooper.", type:"div"},
	{id:"forgotpswd_email_lbl", text:"EMail", type:"div"},
	{id:"forgotpswd_email_inp", type:"inputtext",valid:"email",keyup:wnd_forgotpswd_keyup},	
	{id:"forgotpswd_but_cancel", type:"button", value:"Cancel",click:wnd_forgotpswd_cancel},
	{id:"forgotpswd_but_submit", type:"button", value:"Submit",click:wnd_forgotpswd_submit}
	];
//------------------------------------------	WND: _wnd_forgotpswd
var _wnd_forgotpswd =
	{
	transparent:true,
	id:"wnd_forgotpswd",
	klass:"wnd_forgotpswd",
	init:wnd_forgotpswd_init,
	allowClones:false,
	dfltfocus:"forgotpswd_email_inp",
	itms:_wnd_forgotpswd_itms,
	rect:{top:40, left:50, height:360, width:620}
	};
//------------------------------------------
function wnd_forgotpswd_init(wnd)
	{
	enable_elem($("#forgotpswd_but_submit"), false);
	}
//------------------------------------------
function wnd_forgotpswd_cancel(wnd)
	{
	wnd_close($("#wnd_forgotpswd"), _wnd_signin);
	}

//------------------------------------------
function wnd_forgotpswd_keyup(event)
	{
	var email = $(this);
	email.css("background","#ffffff");
	var filled = !isBlank(email.attr("value"));
	enable_elem($("#forgotpswd_but_submit"), filled);
	if (filled) if (event.keyCode == 13) wnd_forgotpswd_submit();
	}

	
//------------------------------------------
function wnd_forgotpswd_submit()
	{
	if (wnd_validate($(this).parent()))
		{
		wnd_forgotpswd_sendemail();
		}
	else $("#forgotpswd_email_inp").focus().select();
	}

	
//------------------------------------------
function wnd_forgotpswd_sendemail(obj)
	{
	var data = new Object();
	data.command = "sendpswd";
	data.email = $("#forgotpswd_email_inp").attr("value");
	var dataString = $.toJSON(data);
	delete data;
	$.post('email.php', {data: dataString}, done_wnd_forgotpswd_sendemail);
	}
//------------------------------------------
function done_wnd_forgotpswd_sendemail(res)
	{
	var obj = $.evalJSON(res);
	if (obj.success)
		{
		wnd_forgotpswd_email = $("#forgotpswd_email_inp").attr("value");
		wnd_close($("#wnd_forgotpswd"), _wnd_forgotemail);
		}
	else
		{
		$("#forgotpswd_email_inp").css("background","#ff0000").focus().select();
		} 
	delete obj;
	}
