/***********************************************************************************************************
 * com.oclib.javascript.security.authentication.20070210.RemoteAccount
 * Location: http://www.oclib.com/library/com/oclib/javascript/security/authentication/RemoteAccount.js
 * Version Location: http://www.oclib.com/library/com/oclib/javascript/security/authentication/remoteAccount/20070210/.js
 * Index Version Location: http://www.oclib.com/library/com/oclib/javascript/security/authentication/remoteAccount/20070210/index.html
 * © Open Class Library (http://www.oclib.com/)
***********************************************************************************************************/
if (typeof com == "undefined") {com = {};};
if (typeof com.oclib == "undefined") {com.oclib = {};};
if (typeof com.oclib.javascript == "undefined") {com.oclib.javascript = {};};
if (typeof com.oclib.javascript.security == "undefined") {com.oclib.javascript.security = {};};
if (typeof com.oclib.javascript.security.authentication == "undefined") {com.oclib.javascript.security.authentication = {};};

if (typeof com.oclib.javascript.security.authentication.RemoteAccount == "undefined") {
 com.oclib.javascript.security.authentication.RemoteAccount = function() {} 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype = new  com.oclib.javascript.lang.Root();

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.className = "RemoteAccount"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classNamespace = "com.oclib.javascript.security.authentication.RemoteAccount"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classCreated = "20070210"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classCreator = "http://www.oclib.com/"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classLocation = "http://www.oclib.com/library/com/oclib/javascript/security/authentication/RemoteAccount.js"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classIndexLocation = "http://www.oclib.com/library/com/oclib/javascript/security/authentication/remoteAccount/"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classVersion = "20070210"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classVersionLocation = "http://www.oclib.com/library/com/oclib/javascript/security/authentication/20070210/RemoteAccount.js"; 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.classVersionIndexLocation = "http://www.oclib.com/library/com/oclib/javascript/security/authentication/20070210/"; 

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.loader;
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.logged = false;
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getLogged = function () {return this.logged;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setLogged = function (logged) {this.logged = logged; return 1;};
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.method = "POST";
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getMethod = function () {return this.method;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setMethod = function (method) {this.method = method; return 1;};
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.registered = false;
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getRegistered = function () {return this.registered;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setRegistered = function (registered) {this.registered = registered; return 1;};
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.session;
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getSession = function () {return this.session;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setSession = function (session) {this.session = session; return 1;};
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.url;
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getUrl = function () {return this.url;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getURL = function () {return this.getUrl();};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setUrl = function (url) {this.url = url; return 1;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setURL = function (url) {return this.setUrl(url);};
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.user;
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.getUser = function () {return this.user;};
  com.oclib.javascript.security.authentication.RemoteAccount.prototype.setUser = function (user) {this.user = user; return 1;};

 /*
 *  newUserData - com.oclib.javascript.security.authentication.User - with all data
 */
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.changeUserData = function(newUserData, doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.change is runing...");};
  return 1;
 };

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.login = function(doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.login is runing...");};
  var data = "action=login"
            +"&uid="+escape(this.getUser().getId());
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.login data="+data);};
  var loader = new com.oclib.javascript.util.Loader();
  loader.setDebugging(this.getDebugging());
  loader.setLog(this.getLog());
  loader.setTracing(this.getTracing());
  loader.setDoIfError(doIfError);
  var the = this;
  var thisDoIfSuccess = function() {the.loginParseResponse(doIfSuccess, doIfError, loader);};
  loader.setDoIfSuccess(thisDoIfSuccess);
  loader.makeRequest(this.method, this.url, data);
  return 1;
 };

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.loginParseResponse = function(doIfSuccess, doIfError, loader) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.loginParseResponse is runing...");};
  var responseXML = loader.xml;  
  if(responseXML.getElementsByTagName("status") && responseXML.getElementsByTagName("status").item(0) && responseXML.getElementsByTagName("status").item(0).firstChild) {
   var status = responseXML.getElementsByTagName("status").item(0).firstChild.data;
   if(this.mustDebug()) {this.getLog().println("RemoteAccount.loginParseResponse: status="+status);};
   if(status == "success") {
    if(this.mustTrace()) {this.getLog().println("RemoteAccount.loginParseResponse: success...");};
    if(responseXML.getElementsByTagName("sid") && responseXML.getElementsByTagName("sid").item(0) && responseXML.getElementsByTagName("sid").item(0).firstChild) {
     var sid = responseXML.getElementsByTagName("sid").item(0).firstChild.data;
     if(this.mustDebug()) {this.getLog().println("RemoteAccount.loginParseResponse: sid="+sid);};
	 this.session.setSid(sid);
	};
    if(this.mustDebug()) {this.getLog().println("RemoteAccount.loginParseResponse: doIfSuccess="+doIfSuccess);};
    doIfSuccess();
   } else {
    if(this.mustTrace()) {this.getLog().println("RemoteAccount.loginParseResponse: error...");};
    if(this.mustDebug()) {this.getLog().println("RemoteAccount.loginParseResponse: doIfError="+doIfError);};
    doIfError();
   };
  };
  return 1;
 };

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.logout = function(doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.logout is runing...");};
  this.getSession().closeSession();
  return 1;
 };
 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.remind = function(doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.remind is runing...");};
  return 1;
 };
 
 com.oclib.javascript.security.authentication.RemoteAccount.prototype.register = function(doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.register is runing...");};
  return 1;
 };

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.testLogin = function(doIfSuccess, doIfError) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.testLogin is runing...");};
  var data = "action=testLogin"
            +"&sid="+escape(this.getSession().getSid());
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLogin data="+data);};
  var loader = new com.oclib.javascript.util.Loader();
  loader.setDebugging(this.getDebugging());
  loader.setLog(this.getLog());
  loader.setTracing(this.getTracing());
  loader.setDoIfError(doIfError);
  var the = this;
  var thisDoIfSuccess = function() {the.testLoginParseResponse(doIfSuccess, doIfError, loader);};
  loader.setDoIfSuccess(thisDoIfSuccess);
  loader.makeRequest(this.method, this.url, data);
  return 1;
 };

 com.oclib.javascript.security.authentication.RemoteAccount.prototype.testLoginParseResponse = function(doIfSuccess, doIfError, loader) {
  if(this.mustTrace()) {this.getLog().println("RemoteAccount.testLoginParseResponse is runing...");};
  var responseXML = loader.xml;  
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse responseXML="+responseXML);};
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse responseXML.getElementsByTagName(\"status\")="+responseXML.getElementsByTagName("status"));};
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse responseXML.getElementsByTagName(\"status\").item(0)="+responseXML.getElementsByTagName("status").item(0));};
  if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse responseXML.getElementsByTagName(\"status\").item(0).firstChild="+responseXML.getElementsByTagName("status").item(0).firstChild);};
  if(responseXML.getElementsByTagName("status") && responseXML.getElementsByTagName("status").item(0) && responseXML.getElementsByTagName("status").item(0).firstChild) {
   if(this.mustTrace()) {this.getLog().println("RemoteAccount.testLoginParseResponse parse...");};
   var status = responseXML.getElementsByTagName("status").item(0).firstChild.data;
   if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse: status="+status);};
   if(status == "success") {
    if(this.mustTrace()) {this.getLog().println("RemoteAccount.testLoginParseResponse: success...");};
    if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse: doIfSuccess="+doIfSuccess);};
    doIfSuccess();
   } else {
    if(this.mustTrace()) {this.getLog().println("RemoteAccount.testLoginParseResponse: error...");};
    if(this.mustDebug()) {this.getLog().println("RemoteAccount.testLoginParseResponse: doIfError="+doIfError);};
    doIfError();
   };
  };
  return 1;
 };
};
