Methods

  • BrainJS: u.method()
  • BrainXML: <u>method()</u>
function User( ) {
this.addBuddy = function(uid, name) {
  
     this.buddies[uid] = name;
  
};
this.adQueryReady = function( ) {
  
     if (this.app != 'en' && this.app != 'cn') {
       return false;
     }
     
     var span = (this.adCount + 1) * 5;
     if (span > 25) {
       span = 25;
     }
     if (this.msgCount - this.adQuery > span) {
       if (this.adCredits > 0) {
         this.adCredits --;
         this.adQuery = this.msgCount;
         return false;
       }
       else {
         this.adCount ++;
         return true;
       }
     }
     else {
       return false;
     }
  
};
this.calculateAge = function(birthyear) {
  if (birthyear === undefined) {
      return '';
    }
    var year = parseInt(birthyear);
    if (isNaN(year)){
      return '';
    }
    var d = new Date();
    age = d.getFullYear() - year;
    if(age === 0) {
      return 1;
    }
    if (age > 0){
      return age;
    }
    else{
      return '';
    }  
};
this.charAt = function(str, idx) {
  return str.charAt(parseInt(idx) - 1);
};
this.cityCountryKnown = function( ) {
  
     if (this.location.city && this.location.country) {
       return 1;
     }
     else {
       return 0;
     }
  
};
this.clearTimedTopic = function( ) {
  this.timedTopic = null;
};
this.countA2B = function(from, to, result, order, count) {
  if(!result) {
  		result = from.toString();
  	}
  	
  	var isNumber = parseInt(from);
  	if(isNumber || isNumber === 0) {
  		from = parseInt(from);
  		to = parseInt(to);
  	} else {
  		from = from.charCodeAt(0);
  		to = to.charCodeAt(0);
  	}
  	
  	
  	if(!order) {
  		if(from < to) {
  			order = 1;
  		} else {
  			order = 2;
  		}
  		count = 1;
  	}
  	
  	
  	if(order === 1 && from >= to) {
  		return result;
  	} else if(order === 2 && from <= to){
  		return result;
  	} else {
  		
  			if(isNumber || isNumber === 0) {
  				if(order === 1) {
  					from += 1;
  				} else {
  					from -= 1;
  				}
  			} else {
  				if(order === 1) {
  					from = String.fromCharCode(from + 1);
  				} else {
  					from = String.fromCharCode(from - 1);
  				}
  				to = String.fromCharCode(to);
  			}
  			
  			if(count >= 99) {
  			  if(from == to) {
  			    return result.concat(to);
  			  } else {
  				  return result.concat(" ... ").concat(to);
  			  }
  			} else {
  			  count++;
  				return this.countA2B(from, to, result.concat(" ").concat(from), order, count);
  			}
  		
  	}
};
this.countLetters = function(arg) {
  return arg.length;
};
this.countProfile = function( ) {
     var count = 0;
     if (this.name) {
       count ++;
     }
     if (this.getAge()) {
       count ++;
     }
     if (this.gender) {
       count ++;
     }
     if (this.getLocation()) {
       count ++;
     }
     return count;
  
};
this.daysUntil = function(str) {
     var today = new Date();
     var dateStr;
     if (this.wordCount(str) < 3){
       dateStr = str + ', ' + today.getFullYear();
     }
     else {
       dateStr = str;
     }
     var d = new Date(dateStr);
     var days = Math.floor(( d - today ) / 86400000);
     if (days < 0){
       dateStr = str + ', ' + (today.getFullYear()+1);
       d = new Date(dateStr);
       days = Math.floor(( d - today ) / 86400000);
     }
     return days;
  
};

Pages