﻿//***********************************************************
// ThePortLogin Object.  
// Author: Steve Soares
// Copyright ThePort Inc.
// No longer Requires Prototype.js
//***********************************************************


function ThePortLogin() 
{
    this.m_sLoginServiceURL = "/apis/login/LoginService.asmx/";
    this.m_oPublicNameNode = null;
    this.m_oWelcomeNode = null;
    this.m_oInputNode   = null;
}


    //*********************************************************************
    //
    //*********************************************************************
    ThePortLogin.prototype.SendLoginUser = function (oWelcomeNode,oInputNode,oPublicNameNode) {
      var otxtLoginEmail = ThePort.Utils.GetObj("txtLoginEmail");
      var otxtLoginPassword = ThePort.Utils.GetObj("pwLoginPassword");
      // Lets make sure the values are good.
      if(otxtLoginEmail.value==ThePort.Common.CONST_EMPTY_STRING){alert("Please enter your email address.");return;}
      if(otxtLoginPassword.value==ThePort.Common.CONST_EMPTY_STRING){alert("Please enter your password.");return;}
      var ocbLoginRemember = ThePort.Utils.GetObj("cbLoginRemember");
      this.m_oPublicNameNode = oPublicNameNode;
      this.m_oWelcomeNode = oWelcomeNode;
      this.m_oInputNode   = oInputNode;
      this.OutputMessage(ThePort.Common.CONST_EMPTY_STRING);   // Clear the output message area...
      
      // Post the data.
      var sPostData = ThePort.Common.CONST_EMPTY_STRING;
      sPostData += "sLoginEmail="+encodeURIComponent(otxtLoginEmail.value);
      sPostData += "&sLoginPassword="+encodeURIComponent(otxtLoginPassword.value);
      sPostData += "&sLoginRememberMe="+encodeURIComponent(String(ocbLoginRemember.checked));
      eUrl = encodeURI(this.m_sLoginServiceURL+"SendLoginUser");
      this.OutputMessage(ThePort.Common.CONST_EMPTY_STRING);
      ThePort.Utils.Ajax('POST',eUrl,ThePort.Utils.Bind(this,"onSendLoginUserResponse"),sPostData);
      
    }


    //*********************************************************************
    //
    //*********************************************************************
    ThePortLogin.prototype.onSendLoginUserResponse = function(originalRequest) { 
        try {
            var bReturnValue = false;
            var oSR = new ThePort.ReplyObject(originalRequest.responseXML);
            // Call an EVENT.
            var boolResponse = false;
            if ((oSR.Response=="true")||(oSR.Response=="yes")||(oSR.Response=="1"))
               boolResponse = true;
            SMUserLogin.Event_LogInResponse(boolResponse,oSR.Data);
        } catch(e){}	 	         
        return bReturnValue;
    }


    //**********************************************************************
    // OPTION::SendEmailPassword  "email_UserPassword.xslt"
    //**********************************************************************
	ThePortLogin.prototype.SendEmailPassword = function(sXSLEmailPasswordFileName){
	    var otxtLoginEmail = ThePort.Utils.GetObj("txtLoginEmail");
	    if(otxtLoginEmail.value==ThePort.Common.CONST_EMPTY_STRING){alert("Please enter your email address.");}
	    else{
 		    eUrl = encodeURI(this.m_sLoginServiceURL+"SendEmailPassword?sLoginEmail="+otxtLoginEmail.value+"&sXSLEmailPasswordFileName="+sXSLEmailPasswordFileName)
            ThePort.Utils.Ajax("GET",eUrl,ThePort.Utils.Bind(this,"onSendEmailPasswordResponse"),null);
	        }
	    }


    //*********************************************************************
    //
    //*********************************************************************
    ThePortLogin.prototype.onSendEmailPasswordResponse = function(originalRequest) { 
        try {
            var bReturnValue = false;
            var oSR = new ThePort.ReplyObject(originalRequest.responseXML);
            // Call an EVENT.
            var boolResponse = false;
            if ((oSR.Response=="true")||(oSR.Response=="yes")||(oSR.Response=="1"))
               boolResponse = true;
            SMUserLogin.Event_SendEmailPasswordResponse(boolResponse,oSR.Data);
        } catch(e){}	 	         
        return bReturnValue;
    }


    //**********************************************************************
    // OPTION::SendResetPasswordEmail
    //**********************************************************************
	ThePortLogin.prototype.SendResetPasswordEmail = function(sXSLEmailResetFileName){
	    var otxtLoginEmail = ThePort.Utils.GetObj("txtLoginEmail");
	    if(otxtLoginEmail.value==ThePort.Common.CONST_EMPTY_STRING){alert("Please enter your email address.");}
	    else{
 		    eUrl = encodeURI(this.m_sLoginServiceURL+"SendResetPasswordEmail?sLoginEmail="+otxtLoginEmail.value+"&sXSLEmailResetFileName="+sXSLEmailResetFileName)
            ThePort.Utils.Ajax("GET",eUrl,ThePort.Utils.Bind(this,"onSendResetPasswordEmailResponse"),null);
	        }
	    }


    //*********************************************************************
    //
    //*********************************************************************
    ThePortLogin.prototype.onSendResetPasswordEmailResponse = function(originalRequest) { 
        try {
            var bReturnValue = false;
            var oSR = new ThePort.ReplyObject(originalRequest.responseXML);
            // Call an EVENT.
            var boolResponse = false;
            if ((oSR.Response=="true")||(oSR.Response=="yes")||(oSR.Response=="1"))
               boolResponse = true;
            SMUserLogin.Event_SendResetPasswordEmailResponse(boolResponse,oSR.Data);
        } catch(e){}	 	         
        return bReturnValue;
    }

	
    //**********************************************************************
    // OPTION::SendPasswordReminder
    //**********************************************************************
	ThePortLogin.prototype.SendPasswordReminder = function(){
	    var otxtLoginEmail = ThePort.Utils.GetObj("txtLoginEmail");
	    if(otxtLoginEmail.value==ThePort.Common.CONST_EMPTY_STRING){alert("Please enter your email address.");}
	    else{
 		    eUrl = encodeURI(this.m_sLoginServiceURL+"SendPasswordReminder?sLoginEmail="+otxtLoginEmail.value)
            ThePort.Utils.Ajax("GET",eUrl,ThePort.Utils.Bind(this,"onSendPasswordReminderResponse"),null);
	        }
	    }


    //*********************************************************************
    //
    //*********************************************************************
    ThePortLogin.prototype.onSendPasswordReminderResponse = function(originalRequest) { 
        try {
            var bReturnValue = false;
            var oSR = new ThePort.ReplyObject(originalRequest.responseXML);
            // Call an EVENT.
            var boolResponse = false;
            if ((oSR.Response=="true")||(oSR.Response=="yes")||(oSR.Response=="1"))
               boolResponse = true;
            SMUserLogin.Event_SendPasswordReminderResponse(boolResponse,oSR.Data);
        } catch(e){}	 	         
        return bReturnValue;
    }


    //**********************************************************************
    // Write output Message.
    //**********************************************************************
	ThePortLogin.prototype.OutputMessage = function(sMessage){
	    try {
		    var oMessage = ThePort.Utils.GetObj("loginOutputMessage");
		    oMessage.innerHTML = sMessage;
		    oMessage.style.display="block";	
    		} catch(e) {}
 		}


    //**********************************************************************
    // Write output Message.
    //**********************************************************************
	ThePortLogin.prototype.Register = function(){
	    window.location = "/community/app/reg/tptwiz/step.aspx";
	}


    //**********************************************************************
    // Keyboard handler for hitting <RETURN> in a text box.
    //**********************************************************************
    ThePortLogin.prototype.KeyDownHandler = function (e,c) {
        var ev = e || window.event;
        if (ev.keyCode == 13) {
		    // cancel the default submit
		    ev.returnValue=false;
		    ThePort.Utils.StopEvent(ev);
	        document.getElementById(c).click();
	        }
    }

