var Account = function() {};

Account.prototype.accountLog; 
Account.prototype.accountURL = "";
Account.prototype.action = "";
Account.prototype.actionResponse = "";
Account.prototype.changePair = 1;
Account.prototype.cid = "";
Account.prototype.confirmation = 0;
Account.prototype.debugging = false;
Account.prototype.doIfError;
Account.prototype.doIfSuccess;
Account.prototype.doForObject;
Account.prototype.email = "";
Account.prototype.emailInfo = "";
Account.prototype.expire = "";
Account.prototype.languageOfInterface = "";
Account.prototype.login = 0;
Account.prototype.name = "";
Account.prototype.nameInfo = "";
Account.prototype.needConfirmed = 0;
Account.prototype.newName = "";
Account.prototype.newPassword = "";
Account.prototype.password = "";
Account.prototype.register = 0;
Account.prototype.remind = 0;
Account.prototype.sid = "";
Account.prototype.status = "";
Account.prototype.statusComment = "";

Account.prototype.responseEvent = function(httpRequest, obj) {obj.response(httpRequest);};
Account.prototype.response = function(httpRequest) {
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.response is running...");};
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.response: httpRequest.readyState="+httpRequest.readyState);};
 if (httpRequest.readyState == 4) {
  if (httpRequest.status && httpRequest.status == 200) {
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.response: httpRequest.responseXML: ok");};     
   this.parseResponse(httpRequest.responseXML); 
  } else {
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.response: There was a problem with the request.");};
  };
 } else {
  if(this.debugging && this.accountLog) {this.accountLog.println("Account.response: Not yet...");};
 };
};

Account.prototype.parseResponse = function(responseXML) {
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse...");}; 
 if(responseXML) {
  if(responseXML.getElementsByTagName("t") && responseXML.getElementsByTagName("t").item(0) && responseXML.getElementsByTagName("t").item(0).firstChild) {
   this.actionResponse = responseXML.getElementsByTagName("t").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.actionResponse="+this.actionResponse);};
  };
  if(responseXML.getElementsByTagName("s") && responseXML.getElementsByTagName("s").item(0) && responseXML.getElementsByTagName("s").item(0).firstChild) {
   this.status = responseXML.getElementsByTagName("s").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.status="+this.status);};
  };
  if(responseXML.getElementsByTagName("sc") && responseXML.getElementsByTagName("sc").item(0) && responseXML.getElementsByTagName("sc").item(0).firstChild) {
   this.statusComment = responseXML.getElementsByTagName("sc").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.statusComment="+this.statusComment);};
  };
  if(responseXML.getElementsByTagName("email") && responseXML.getElementsByTagName("email").item(0) && responseXML.getElementsByTagName("email").item(0).firstChild) {
   this.emailInfo = responseXML.getElementsByTagName("email").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.email="+this.email);};
  };
  if(responseXML.getElementsByTagName("name") && responseXML.getElementsByTagName("name").item(0) && responseXML.getElementsByTagName("name").item(0).firstChild) {
   this.nameInfo = responseXML.getElementsByTagName("name").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.name="+this.name);};
  };
  if(responseXML.getElementsByTagName("sid") && responseXML.getElementsByTagName("sid").item(0) && responseXML.getElementsByTagName("sid").item(0).firstChild) {
   this.sid = responseXML.getElementsByTagName("sid").item(0).firstChild.data;
   if(this.debugging && this.accountLog) {this.accountLog.println("Account.parseResponse: this.sid="+this.sid);};
  };  
  
  if(this.status == "success") {
   if(this.actionResponse == "cid") {this.confirmation = 1;};
   if(this.actionResponse == "changePair") {this.changePair = 1;};
   if(this.actionResponse == "login" || this.actionResponse == "sid") {this.login = 1;};
   if(this.actionResponse == "register") {this.register = 1;this.login = 1;};
   if(this.actionResponse == "remind") {this.remind = 1;};
   this.doIfSuccess(this.doForObject, this);
  } else {
   if(this.actionResponse == "cid") {this.confirmation = 0;};
   if(this.actionResponse == "changePair") {this.changePair = 0;};
   if(this.actionResponse == "login" || this.actionResponse == "sid") {this.login = 0;};
   if(this.actionResponse == "register") {this.register = 0;this.login = 0;};
   if(this.actionResponse == "remind") {this.remind = 0;};
   this.doIfError(this.doForObject, this);
  };
 };
};

Account.prototype.update = function() {
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.update is running...");}; 
 var data = "action="+this.action
            +"&sid="+escape(this.sid)+"&cid="+escape(this.cid)
			+"&email="+escape(this.email)+"&password="+escape(this.password)+"&name="+escape(this.name)+"&languageOfInterface="+escape(this.languageOfInterface)
			+"&newName="+escape(this.newName)+"&newPassword="+escape(this.newPassword)
            +"&expire="+escape(this.expire)+"&needConfirmed="+this.needConfirmed;
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.update: "+"url="+this.accountURL)};
 if(this.debugging && this.accountLog) {this.accountLog.println("Account.update: "+"data="+data);};
 var server = new Server();server.debugging = this.debugging;server.serverLog = this.accountLog;this.server = server; 
 server.makeRequest("POST",this.accountURL,data,this.responseEvent,this);
 return 1;
};