/*
 (C) Copyright 2009 - Softel vdm, Inc. - www.softelvdm.com
*/

// C:\Development\DotNetNuke\LoginControl\Site050100\Website\DesktopModules\softelvdm.logincontrol\\js\sftloginpopup.js

Type.registerNamespace('Softelvdm.DNN');Softelvdm.DNN.LoginPopup=function(){Softelvdm.DNN.LoginPopup.initializeBase(this);this.containerID="";this.currPageID="";this.cmdLoginID="";this.CE={};this.CFB={};this.RES={};this._onLoadDelegate=Function.createDelegate(this,this._onLoad);Sys.Application.add_load(this._onLoadDelegate);}
Softelvdm.DNN.LoginPopup.prototype={dispose:function(){var own=this;own._onLoadDelegate=null;},_onLoad:function(src,args){var own=this;},initialize:function(){var own=this;$("#SftLoginPopup")[0].ModuleControlID=this.containerID;$("#"+own.cmdLoginID).click(function(event){event.preventDefault();window.SftLoginPopupOpenOverlay();});},loadLocalizedResources:function(SftLoginPopupAPI)
{var own=this;if(own.CE.Localize){dnn.xmlhttp.callControlMethod('Softelvdm.DNN.LoginPopup.'+own.get_id(),'GetLocalizedResources',{},function(payload,ctx,req){own.RES=Sys.Serialization.JavaScriptSerializer.deserialize(payload);SftLoginPopupAPI.load();},function(payload,ctx,req){own.RES={};alert('An error occurred communicating with the server - Please reload/refresh the current page.');SftLoginPopupAPI.load();});}else{SftLoginPopupAPI.load();}},overlayOnBeforeLoad:function(SftLoginPopupAPI)
{var own=this;var wrap=$("#SftLoginPopup div.SftLoginPopupContainer");if(wrap.is(":empty"))
wrap.load(own.CE.ContentsHtml);else
own.clearall();},overlayOnLoad:function()
{var own=this;var wrap=$("#SftLoginPopup div.SftLoginPopupContainer");wrap.find("#buttonLogin").unbind("click").bind("click",function(){own.loginClick();}).keydown(function(event){own.keydownhandler(event);});wrap.find("#alinkRegister").attr("href",own.CE.RegisterURL).click(function(){own.wait(true);}).keydown(function(event){own.keydownhandler(event);});wrap.find("#alinkForgot").attr("href",own.CE.PasswordURL).click(function(){own.wait(true);}).keydown(function(event){own.keydownhandler(event);});wrap.find("#txtUserName").keydown(function(event){own.keydownhandler(event);}).focus();wrap.find("#txtPswd").keydown(function(event){own.keydownhandler(event);});wrap.find("#checkRemember").keydown(function(event){own.keydownhandler(event);});},keydownhandler:function(event)
{var own=this;if(event.keyCode==0x0d||event.keyCode==0x0a){event.preventDefault();own.loginClick();}},loginClick:function(){var own=this;own.wait(true);own.CE.strUserName=$("#SftLoginPopup #txtUserName").val();own.CE.strPswd=$("#SftLoginPopup #txtPswd").val();own.CE.fRemember=$("#SftLoginPopup #checkRemember").attr("checked");dnn.xmlhttp.callControlMethod('Softelvdm.DNN.LoginPopup.'+own.get_id(),'LogMeIn',{'CE':Sys.Serialization.JavaScriptSerializer.serialize(own.CE)},function(payload,ctx,req){own.CFB=Sys.Serialization.JavaScriptSerializer.deserialize(payload);if(own.CFB.URL!=""){window.location.href=own.CFB.URL;}else{own.wait(false);own.msg(true);}},function(payload,ctx,req){own.CFB={};own.wait(false);alert('error: '+payload);});},wait:function(waiting)
{var own=this;if(waiting){own.msg(false);$("#SftLoginPopup .sectionWait").show();}else
$("#SftLoginPopup .sectionWait").hide();},clearall:function(show)
{var own=this;own.msg(false);$("#SftLoginPopup #txtUserName").val(own.CE.strUserName);$("#SftLoginPopup #txtPswd").val(own.CE.strPswd);$("#SftLoginPopup #checkRemember").attr("checked",own.CE.fRemember);},msg:function(show)
{var own=this;var errCtrl=$("#SftLoginPopup #errormessages");var imgCtrl=$("#SftLoginPopup #erroricon");var msg="";if(show){for(var i=0;i<own.CFB.Messages.length;++i){msg+=own.CFB.Messages[i].Message+"<br/>";}
if(own.CFB.MsgIcon!=""&&imgCtrl.length>0)
imgCtrl.attr("src",own.CFB.MsgIcon);errCtrl.html(msg);$("#SftLoginPopup .sectionError").show();$("#SftLoginPopup div.SftLoginPopupContainer").removeClass("success").addClass("error");}else{$("#SftLoginPopup .sectionError").hide();errCtrl.html("");$("#SftLoginPopup div.SftLoginPopupContainer").addClass("success").removeClass("error");}}}
Softelvdm.DNN.LoginPopup.registerClass('Softelvdm.DNN.LoginPopup',Sys.Component);$(function(){$("body").append('<div class="SftLoginPopup" id="SftLoginPopup"><div class="SftLoginPopupContainer"></div></div>');var SftLoginPopupAPI=$("#SftLoginPopup").overlay({expose:{color:null,closeOnClick:false,maskId:'SftLoginPopupExposeMask',onBeforeLoad:function(){$('#SftLoginPopupExposeMask').bgiframe();}},api:true,closeOnClick:false,onBeforeLoad:function(){var own=Sys.Application.findComponent($("#SftLoginPopup")[0].ModuleControlID,null);own.overlayOnBeforeLoad(SftLoginPopupAPI);},onLoad:function(){var own=Sys.Application.findComponent($("#SftLoginPopup")[0].ModuleControlID,null);own.overlayOnLoad();}});window.SftLoginPopupOpenOverlay=function(){var own=Sys.Application.findComponent($("#SftLoginPopup")[0].ModuleControlID,null);own.loadLocalizedResources(SftLoginPopupAPI);}});
