1 (function(root) {
    2 	'use strict';
    3 
    4 	function _attr(e, attr, text)
    5 	{
    6 		if (null === e)
    7 			return;
    8 		e.setAttribute(attr, text);
    9 	}
   10 
   11 	function _attrcl(e, attr, name, text)
   12 	{
   13 		var list, i;
   14 		if (null === e)
   15 			return;
   16 		list = e.getElementsByClassName(name);
   17 		for (i = 0; i < list.length; i++)
   18 			_attr(list[i], attr, text);
   19 	}
   20 
   21 	function _repl(e, text)
   22 	{
   23 		if (null === e)
   24 			return;
   25 		while (e.firstChild)
   26 			e.removeChild(e.firstChild);
   27 		e.appendChild(document.createTextNode(text));
   28 	}
   29 
   30 	function _replcl(e, name, text)
   31 	{
   32 		var list, i;
   33 		if (null === e)
   34 			return;
   35 		list = e.getElementsByClassName(name);
   36 		for (i = 0; i < list.length; i++)
   37 			_repl(list[i], text);
   38 	}
   39 
   40 	function _hide(e)
   41 	{
   42 		if (null === e)
   43 			return(null);
   44 		if ( ! e.classList.contains('hide'))
   45 			e.classList.add('hide');
   46 		return(e);
   47 	}
   48 	
   49 	function _hidecl(e, name)
   50 	{
   51 		var list, i;
   52 		if (null === e)
   53 			return;
   54 		list = e.getElementsByClassName(name);
   55 		for (i = 0; i < list.length; i++)
   56 			_hide(list[i]);
   57 	}
   58 
   59 	function _show(e)
   60 	{
   61 		if (null === e)
   62 			return(null);
   63 		if (e.classList.contains('hide'))
   64 			e.classList.remove('hide');
   65 		return(e);
   66 	}
   67 	
   68 	function _showcl(e, name)
   69 	{
   70 		var list, i;
   71 		if (null === e)
   72 			return;
   73 		list = e.getElementsByClassName(name);
   74 		for (i = 0; i < list.length; i++)
   75 			_show(list[i]);
   76 	}
   77 
   78 	/**
   79 	 * Represent a "user" object for filling into a DOM tree.
   80 	 * @constructor
   81 	 * @param {Object} obj - The user object.
   82 	 */
   83 	function user(obj)
   84 	{
   85 		this.obj = obj;
   86 		/**
   87 		 * Fill in a "user" object at the given element in the DOM tree.
   88 		 * Elements having the following classes are manipulated as follows:
   89 		 * user-email-text: replace contents with email data
   90 		 * user-email-value: replace "value" attribute with email data
   91 		 * user-hash-text: replace contents with hash data
   92 		 * user-hash-value: replace "value" attribute with hash data
   93 		 * user-id-text: replace contents with id data
   94 		 * user-id-value: replace "value" attribute with id data
   95 		 * @param {Object} e - The DOM element.
   96 		 */
   97 		this.fill = function(e){
   98 			if (null === this.obj || null === e)
   99 				return;
  100 			_replcl(e, 'user-email-text', this.obj.email);
  101 			_attrcl(e, 'value', 'user-email-value', this.obj.email);
  102 			_replcl(e, 'user-hash-text', this.obj.hash);
  103 			_attrcl(e, 'value', 'user-hash-value', this.obj.hash);
  104 			_replcl(e, 'user-id-text', this.obj.id);
  105 			_attrcl(e, 'value', 'user-id-value', this.obj.id);
  106 		};
  107 	}
  108 
  109 	/**
  110 	 * Represent a "sess" object for filling into a DOM tree.
  111 	 * @constructor
  112 	 * @param {Object} obj - The sess object.
  113 	 */
  114 	function sess(obj)
  115 	{
  116 		this.obj = obj;
  117 		/**
  118 		 * Fill in a "sess" object at the given element in the DOM tree.
  119 		 * Elements having the following classes are manipulated as follows:
  120 		 * sess-user-obj: invoke user.fill() method with user data
  121 		 * sess-userid-text: replace contents with userid data
  122 		 * sess-userid-value: replace "value" attribute with userid data
  123 		 * sess-token-text: replace contents with token data
  124 		 * sess-token-value: replace "value" attribute with token data
  125 		 * sess-id-text: replace contents with id data
  126 		 * sess-id-value: replace "value" attribute with id data
  127 		 * @param {Object} e - The DOM element.
  128 		 */
  129 		this.fill = function(e){
  130 			var list, strct, i;
  131 			if (null === this.obj || null === e)
  132 				return;
  133 			list = e.getElementsByClassName('sess-user-obj');
  134 			strct = new user(this.obj.user);
  135 			for (i = 0; i < list.length; i++) {
  136 				strct.fill(list[i]);
  137 			}
  138 			_replcl(e, 'sess-userid-text', this.obj.userid);
  139 			_attrcl(e, 'value', 'sess-userid-value', this.obj.userid);
  140 			_replcl(e, 'sess-token-text', this.obj.token);
  141 			_attrcl(e, 'value', 'sess-token-value', this.obj.token);
  142 			_replcl(e, 'sess-id-text', this.obj.id);
  143 			_attrcl(e, 'value', 'sess-id-value', this.obj.id);
  144 		};
  145 	}
  146 
  147 	root.user = user;
  148 	root.sess = sess;
  149 })(this);