var TBJSLib, TBJS = TBJS || {};
TBJS.app = TBJS.app || {};

(function()
{

Function.prototype.__call = function()
{
	var args = arguments, params = [];
	if(!args[0] || args[0] === window)
	{
		return;
	}
	else
	{
    	for(var i=1, j=args.length; i<j; i++)
    	{
    		params[params.length] = args[i];
    	}
    	return this.apply(args[0], params);	    
	}
};

Function.prototype.__apply = function(scope, args)
{
	if(!scope || scope === window || !args)
	{
		return;
	}
	else
	    return this.apply(scope, args);
}; 

Array.prototype.__sort = function(fn)
{
	var res = this.sort();
	if(res == window)
	{
		return;
	}
	else
	    return res;
};

Array.prototype.__reverse = function()
{
	var res = this.reverse();
	if(res == window)
	{
		return;
	}
	else
	    return res;
};

var _YU = YAHOO.util, 
	_YL = YAHOO.lang,
	_W = window, 
	_D = document;

TBJS.errorConsole = {
	message: {
		isNotElement: "Text node can't do this operation.",
		missParameter: "Miss parameters.",
		errorURL: "It is not a valid url.",
		errorType: "Type of parameter is error.",
		errorEventType: "The event type is no support.",
		errorObject: "It is not a valid object.",
		errorHTMLTag: "The html tag is no support.",
		parseFail: "Data parsing failure."
	},
	log: function(errObj, target)
	     {
            if(!errObj)
            {
                return;
            }
            else
                throw new Error(errObj.name + " : " + errObj.message);
	     } 
};

TBJS.startUp = function()
{
	var args = arguments, app, ext, extCfg, modid;
	for(var i=0, j=args.length; i<j; i++)
	{
		modid = args[i];

		ext = TBJS.app["ex" + modid]; 
		app = TBJS.app["pg" + modid];

		if(!app)
		{
			continue;
		}
		else
		{
    		if(ext)
    		{
    			extCfg = {};
    			extCfg["ex" + modid] = {}; 
    			for(name in ext)
    			{
    				extCfg["ex" + modid][name] = ext[name]; 
    			}
    			app.$setExtTBJS(extCfg);
    		}
    
    		if(app.onLoad)
    		{
    			try
    			{
    				app.onLoad();
    			}
    			catch(_err)
    			{
    				if(!!app.$TBJSDebug)
    				{
    					TBJS.errorConsole.log(_err);
    				}
    			}
    		}		    
		}    
	}
};


TBJSLib = function(sModuleId, bDebugModeOn)
{
	if(!sModuleId)
	{
		return;
	}

	var  _config = {
		legalTags: ["div", "span", "a", "ul", "ol", "li", "dir", "dl", "dt", "dd", "img", "table", "caption", "th", "tr", "td", "p", "tbody", "tfoot", "col", "colgroup", "strike", "h1", "h2", "h3", "h4", "h5", "h6", "br", "hr", "abbr", "blockquote", "q", "b", "i", "font", "em", "big", "strong", "small", "sup", "sub", "bdo", "u", "pre", "code", "tt", "kbd", "dfn", "var", "samp", "acronym", "address", "center", "cite", "ins", "del", "s", "menu", "map", "area"],
		globalMethods: {
			Math: ["abs", "acos", "asin", "atan", "atan2", "ceil", "cos", "exp", "floor", "log", "max", "min", "pow", "random", "round", "sin", "sqrt", "tan"] 
		},
		modCSS: "mod_content",

		forbiddenKeys : {
			"call":        1,
			"apply":       1,
			"sort":        1,
			"constructor": 1,
			"eval":        1,
			"Function":    1,
			"Image":       1,
			"setTimeout":  1,
			"setInterval": 1,
			"execScript":  1,
			"valueOf":     1,
			"reverse":     1,
			"self":        1,
			"parent":      1,
			"top":         1,
			"write":       1,
			"writeln":     1,
			"innerHTML":   1,
			"__parent__":  1
		},

		supportEventType : {
			blur:      1,
			change:    1,
			click:     1,
			dblclick:  1,
			focus:     1,
			keydown:   1,
			keyup:     1,
			keypress:  1,
			mousedown: 1,
			mousemove: 1,
			mouseout:  1,
			mouseover: 1,
			mouseup:   1,
			reset:     1,
			resize:    1,
			select:    1,
			submit:    1
		}
	},

	_debugMode = bDebugModeOn || false,

	_error_console = TBJS.errorConsole,

	_moduleIdPrefix = "tp-",

	_moduleId = _moduleIdPrefix + sModuleId,

	_self = this,

	_fn = function(){},

	_createProperty = function(sName)
                	  {
                        if(!_W[sName])
                        {
                        	return;
                        }
                        else
                        {
                            var prop = {}, 
                                cfg = _config,
                                lst = cfg.globalMethods[sName];
                            for(var i = 0, j = lst.length; i<j; i++)
                            {
                            	prop[lst[i]] = _W[sName][lst[i]]; 
                            }
                            return prop;
                        }
                        
                	  },

	_createYUIProperty = function(sName)
                    	{
                    		if(!_YU[sName])
                    		{
                    			return;
                    		}
                    		else
                    		{
                        		var prop = {}, 
                        		    cfg = _config,
                        		    lst = cfg.YUIMethods[sName];
                        		for(var i = 0, j = lst.length; i<j; i++)
                        		{
                        			prop[lst[i]] = _YU[sName][lst[i]];
                        		}
                        		return prop;		
                    		}
                    	},

	_validTag = function(sTagName)
            	{
            		if(!sTagName)
            		{
            			return false;
            		}
            		else
            		{
                		var tags = _config.legalTags, 
                		    tag = sTagName.toLowerCase();
                		for(var i=0, j=tags.length; i<j; i++)
                		{
                			if(tags[i] === tag)
                			{
                				return true;
                			}
                		}
                		return false;		
            		}    
            	},

	_filterHTML = function(sHtml)
                {
                	if(!sHtml)
                	{
                		return;
                	}
                	else
                	    return sHtml.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quote;").replace(/\'/g,"&#39;");
                },

	_decodeHTML = function(str)
            	  {
            		  if(!str)
            		  {
            			  return;
            		  }
            		  else
            		      return str.replace(/&lt;/ig, "<").replace(/&gt;/ig, ">").replace(/&amp;/ig, "&"); 
            	  },

	_filterValue = function(sValue)
                   {
                       var s = _filterHTML(sValue).replace(/\n|\t|\r/g,"");
                       return s;
                   },

	_isUrl = function(str)
        	 {
        		var href_reg = /^(?:((https?|mailto|ftp|irc|gopher):\/\/)|(\/|#))([^\/?#]*)?([^?#]*)(\?([^#]*))?(#(.*))?/i;
        		return href_reg.test(str);
        	 },

	_userException = function(message)
                   	 {
                		this.message = message;
                		this.name = "UserException";
                	 },

	_wrapDomEl = function(node)
	{
    	if(!node)
    	{
    		return;
    	}
        else
        {
        	var _nodeEl = node,
            	_isElementNode = function()
            	{
            		return _nodeEl && (_nodeEl.nodeType === 1);
            	};

        	if(_isElementNode())
        	{
        		this.tagName = _nodeEl.tagName.toLowerCase();
        	}

        	this.getRootNode = function()
        	{
        		if(!_moduleId || !_isElementNode())
        		{
        			return;
        		}
        		else
        		{
            		var root = _YU.Dom.getAncestorByClassName(_nodeEl, _config.modCSS);
            		if(!root)
            		{
            			return;
            		}
            		else
            		    return new _wrapDomEl(_YU.Dom.getElementsByClassName("bd", "div", root)[0]);        		
        		}
        	};

        	this.getParentNode = function()
        	{
        		if(!_isElementNode())
        		{
        			return;
        		}
        		else
        		{
            		var root = _YU.Dom.getAncestorByClassName(_nodeEl, _config.modCSS), 
            		    pnode = _nodeEl.parentNode;
            		if(root && root != pnode)
            		{
            			return new _wrapDomEl(pnode);
            		}
            		else
            		    return null;        		    
        		}    
        	};

        	this.getHTML = function()
        	{
        		if(!_isElementNode())
        		{
        			return;
        		}
        		else
        		    return _nodeEl.innerHTML;
        	};

        	this.getTextValue = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_YL.isString(_nodeEl))
        			{
        				return _nodeEl;
        			}
        			else
        			    return;
        		}
        		else
        		{
            		var el = _nodeEl, 
            		    text = (el.innerText)? el.innerText : ((el.textContent)? el.textContent : el.innerHTML.replace(/<[^\>]{1,}>/g,""));
            		return text;            		    
        		}
        	};

        	this.setTextValue = function(sContent)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.innerHTML = _filterHTML(sContent);
        	};

        	this.getChildNodes = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		var nodes = [], 
            		    subNodes = _nodeEl.childNodes, 
            		    el;
            		    
            		if(!subNodes)
            		{
            			return nodes;
            		}
            		else
            		{
                		for(var i = 0, j = subNodes.length; i<j ; i++)
                		{
                			el = subNodes[i];
                			if(el.nodeType === 1)
                			{
                				nodes[nodes.length] = new _wrapDomEl(el);
                			}
                			else if(el.nodeType === 3)
                			{
                				nodes[nodes.length] = el.nodeValue;
                			}
                		}
                		return nodes;            		    
            		}
        		    
        		}    
        	};

        	this.getElementsByClassName = function(sClssName, sTagName)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!sClssName)
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.missParameter));
            			}
            			return;
            		}
            		else
            		{
                		sTagName = sTagName || "";
                		var nodes = [], 
                		    elms = _YU.Dom.getElementsByClassName(sClssName, sTagName, _nodeEl);
                		for(var i = 0, j = elms.length; i<j ; i++)
                		{
                			nodes[nodes.length] = new _wrapDomEl(elms[i]);
                		}
                		return nodes;        		                		    
            		}    
        		}

        	};

        	this.getElementsByTagName = function(sTagName)
        	{
        		if(!_isElementNode()){
        			if(_debugMode){
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		sTagName = sTagName || "*";
        		var nodes = [], elms = _nodeEl.getElementsByTagName(sTagName);
        		if(!elms){
        			return nodes;
        		}
        		for(var i = 0, j = elms.length; i<j ; i++){
        			nodes[nodes.length] = new _wrapDomEl(elms[i]);
        		}
        		return nodes;
        	};

        	this.getValue = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}        			
        			return;
        		}
        		else
        		{
            		if(_nodeEl.tagName.toLowerCase() === "select")
            		{
            			return _nodeEl.options[_nodeEl.selectedIndex].value;
            		}
            		return _nodeEl.value;        		
        		}    
        	};

        	this.setValue = function(sValue)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(_nodeEl.tagName.toLowerCase() === "select")
            		{
            			for(var i=0, j=_nodeEl.options.length; i<j; i++)
            			{
            				if(_nodeEl.options[i].value === sValue)
            				{
            					_nodeEl.options[i].selected = true;
            					return;
            				}
            			}
            			return;
            		}
            		_nodeEl.value = sValue;        		
        		}    

        	};	        

        	this.getHref = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.href;
        	};

        	this.setHref = function(sUrl)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!_isUrl(sUrl))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorURL));
            			}
            			return;
            		}
            		else
            		    _nodeEl.href = _filterValue(sUrl);        		
        		}    
        	};

        	this.getTarget = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.target;
        	};

        	this.setTarget = function(sTarget)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.target = _filterValue(sTarget);
        	};

        	this.getSrc = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.src;
        	};

        	this.setSrc = function(sUrl)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!_isUrl(sUrl))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorURL));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.src = _filterValue(sUrl);        		    
        		}   
        	};

        	this.getClassName = function()
        	{  
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.className;
        	};

        	this.setClassName = function(sName)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!sName && sName !== "")
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.missParameter));
            			}
            			return;
            		}
            		else
                        {
            		    if( sName == "" )
            		    {
            		        _nodeEl.className = "";
            		    }
            		    else
            		        _nodeEl.className = _filterValue(sName);            		    


                         } 
        		}    
        	};

            /* append by brenda.*/
            
            this.setDisplay = function( sDisplay )
            {
                if( !_isElementNode() )
                {
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;                    
                }
                else
                {
            		if( !sDisplay && sDisplay != "" )
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.missParameter));
            			}
            			return;
            		}
            		else
            		{            		    
            		    if( sDisplay == "" )
            		    {
            		        _nodeEl.style.display = "";
            		    }
            		    else
            		    {
            		        sDisplay = _filterValue(sDisplay); 
            		        var regExt = /^(block|inline|list-item|none|inline-block|table-header-group|table-footer-group)$/;
            		        if( regExt.test( sDisplay ) )
            		        {
            		            _nodeEl.style.display = sDisplay;           		    
            		        }
            		        else
            		        {
            			        if(_debugMode)
            			        {
            				        _error_console.log(new _userException(_error_console.message.missParameter));
            			        }
            			        return;
            		        
            		        }    
            		    }    
            		}                 
                } 
            };
             
            this.getDisplay = function()
            {
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.style.display;                
            };

        	this.getId = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.id.replace(_moduleId + "-", "");
        	};

        	this.setId = function(sId)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		sId = _moduleId + "-" + sId;
            		_nodeEl.id = _filterValue(sId);        		    
        		}    
        	};

        	this.getDir = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else        		    
        		    return _nodeEl.dir;
        	};

        	this.setDir = function(sDir)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.dir = _filterValue(sDir);
        	};

        	this.getChecked = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.checked;
        	};

        	this.setChecked = function(bValue)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.checked = !!bValue;
        	};

        	this.getTabIndex = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.tabIndex;
        	};

        	this.setTabIndex = function(num)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		num = parseInt(num);
            		if(!_YL.isNumber(num))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorType));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.tabIndex = num;            		    
        		}    
        	};        

        	this.getTitle = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.title;
        	};

        	this.setTitle = function(sTitle)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.title = _filterValue(sTitle);
        	};

        	this.getName = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.name;
        	};

        	this.setName = function(sName)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.name = _filterValue(sName);
        	};

        	this.getCols = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.cols;
        	};

        	this.setCols = function(num)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		num = parseInt(num);
            		if(!_YL.isNumber(num))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorType));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.cols = num;        		    
        		}    

        	};

        	this.getWidth = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode){
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.width;
        	};

        	this.setWidth = function(num)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		num = parseInt(num);
            		if(!_YL.isNumber(num))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorType));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.width = num;        		
        		}    
        	};

        	this.getHeight = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.height;
        	};

        	this.setHeight = function(num)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		num = parseInt(num);
            		if(!_YL.isNumber(num))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorType));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.height = num;        		    
        		}    
        	};

        	this.getRows = function()
        	{
        		if(!_isElementNode())
        		{
        			return;
        		}
        		else
        		    return _nodeEl.rows;
        	};

        	this.setRows = function(num)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		num = parseInt(num);
            		if(!_YL.isNumber(num))
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.errorType));
            			}
            			return;		
            		}
            		else
            		    _nodeEl.rows = num;        		    
        		}    
        	};

        	this.getDisabled = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.disabled;
        	};

        	this.setDisabled = function(bValue)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.disabled = !!bValue;
        	};

        	this.getReadOnly = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.readOnly;
        	};

        	this.setReadOnly = function(bValue)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.readOnly = !!bValue;
        	};

        	this.getType = function()
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    return _nodeEl.type;
        	};        

        	this.setType = function(sType)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		    _nodeEl.type = _filterValue(sType);
        	};

        	this.appendChild = function(node)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!node)
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.missParameter));
            			}
            			return;		
            		}
            		else
            		{
                		var el = _YU.Dom.get(_moduleId + "-" + node.getId()); //why? --brenda
                		_YU.Dom.setStyle(el, "display", "");                  //why? --brenda 
                		_nodeEl.appendChild(el);            		    
            		}            		    
        		}    
        	};

        	this.addListener = function(sType, fn, obj, override)
        	{
        		if(!_isElementNode())
        		{
        			if(_debugMode)
        			{
        				_error_console.log(new _userException(_error_console.message.isNotElement));
        			}
        			return;
        		}
        		else
        		{
            		if(!sType || !fn || !obj)
            		{
            			if(_debugMode)
            			{
            				_error_console.log(new _userException(_error_console.message.missParameter));
            			}
            			return;		
            		}
            		else
            		{
                		sType = sType.toLowerCase().replace(/^on/,""); 
                		if(!_config.supportEventType[sType])
                		{
                			if(_debugMode)
                			{
                				_error_console.log(new _userException(_error_console.message.errorEventType));
                			}
                			return;
                		}
                		else
                		{
                    		if(!_YL.isFunction(fn))
                    		{
                    			if(_debugMode)
                    			{
                    				_error_console.log(new _userException(_error_console.message.errorType));
                    			}
                    			return;
                    		}
                    		else
                    		{
                        		if(!_YL.isObject(obj) || obj === window)
                        		{
                        			if(_debugMode)
                        			{
                        				_error_console.log(new _userException(_error_console.message.errorObject));
                        			}
                        			return;
                        		}
                        		else
                        		{
                            		var handler = function(ev)
                            		{
                            			var objEv = new _wrapEvent(ev), 
                            			args = arguments;
                            			args[0] = objEv;
                            			fn.apply(this, args);
                            		};
                            		_YU.Event.on(_nodeEl, sType, handler, obj, true);        		    
                        		
                        		}    
                    		
                    		}    
                		
                		}    
            		    
            		}
        		}    

        	};
            	        
        	this.on = this.addListener;
        	
        }    
    },
    
	
	_wrapEvent = function(ev)
	{
		if(!ev)
		{
			return;
		}
		else
		{
    		var event = _YU.Event;
    
    		this.altKey = ev.altKey;
    
    		this.button = ev.button;
    
    		this.ctrlKey = ev.ctrlKey;
    
    		this.metaKey = ev.metaKey;
    
    		this.shiftKey = ev.shiftKey;
    
    		this.type = ev.type;
    
    		this.getCharCode = function()
    		{
    			return event.getCharCode(ev);
    		};

    		this.getPageX = function()
    		{
    			return event.getPageX(ev);
    		};
    
    		this.getPageY = function()
    		{
    			return event.getPageY(ev);
    		};
    
    		this.getRelatedTarget = function()
    		{
    			return new _wrapDomEl(event.getRelatedTarget(ev));
    		};
    
    		this.getTarget = function()
    		{
    			return new _wrapDomEl(event.getTarget(ev));
    		};
    
    		this.getXY = function()
    		{
    			return event.getXY(ev);
    		};

    		this.preventDefault = function()
    		{
    			event.preventDefault(ev);
    		};

    		this.stopEvent = function()
    		{
    			event.stopEvent(ev);
    		};

    		this.stopPropagation = function()
    		{
    			event.stopPropagation(ev);
    		};
		    
		}    
	};

	this.getModuleId = function()
	{
		return _moduleId.replace(_moduleIdPrefix, "");
	};

	/** check the scope object ensure that it isn't window object */
	this.$ = function(obj)
	{
		if(obj === window)
		{
			return;
		}
		else
		    return obj;
	};

	/** convert the key, if it is a reservation keyword */
	this.f = function(sKey)
	{
		if(!_YL.isString(sKey) && !_YL.isNumber(sKey))
		{
			return;
		}
		else
		{
    		if(_config.forbiddenKeys[sKey])
    		{
    			return "__" + sKey;
    		}
    		else
    		    return sKey;		
		}    
	};

	this.app = {};

	this.Math = _createProperty("Math"); 

	this.parseFloat = parseFloat;

	this.parseInt = parseInt;

	this.escape = escape;

	this.unescape = unescape;

	this.isFinite = isFinite;

	this.isNaN = function(value)
	{
		return !_YL.isNumber(value);
	};

	this.encodeURIComponent = function(sUri)
	{
		return (encodeURIComponent)? encodeURIComponent(sUri) : escape(sUri);
	};

	this.decodeURIComponent = function(sUri)
	{
		return (decodeURIComponent)? decodeURIComponent(sUri) : unescape(sUri);
	};

	this.document = {
		getElementById: function(sId)
		{
			if(!sId)
			{
				if(_debugMode)
				{
					_error_console.log(new _userException(_error_console.message.missParameter));
				}
				return;
			}
            else
            {
    			if(typeof sId !== "string")
    			{
    				if(_debugMode)
    				{
    					_error_console.log(new _userException(_error_console.message.errorType));
    				}
    				return;
    			}
                else
                {
        			sId = _moduleId + "-" + sId;       
        			return new _wrapDomEl(_YU.Dom.get(sId));                
                }        
                
            }    
		},

		createElement: function(sTagName)
		{
			if(!sTagName || !_validTag(sTagName))
			{
				if(_debugMode)
				{
					_error_console.log(new _userException(_error_console.message.missParameter));
				}
				return;
			}
			else
			{
    			if(!_validTag(sTagName))
    			{
    				if(_debugMode)
    				{
    					_error_console.log(new _userException(_error_console.message.errorHTMLTag));
    				}
    				return;
    			}
                else
                {
        			var el = _D.createElement(sTagName), 
        			    id = _moduleId + "-tmp-mod-" + Math.floor(Math.random()*1000);
        			    
        			_YU.Dom.setStyle(el, "display", "none");  // how append --brenda.
        			el.id = id;
        			_D.body.appendChild(el);
        			return new _wrapDomEl(_YU.Dom.get(id));			                
                }    			
			}    

		}
	};

	this.window = {
		alert : function(sContent, callBackFn)
		{
			if(callBackFn && !_YL.isFunction(callBackFn))
			{
				if(_debugMode)
				{
					_error_console.log(new _userException(_error_console.message.errorType));
				}
				return;
			}
			else
			    alert(sContent);
		},

		confirm : function(sContent, userConfig)
		{
			return confirm(sContent);
		}
	};

	this.alert = this.window.alert;

	this.confirm = this.window.confirm;

	this.navigator = navigator;

	this.Object = function()
	{
		Object.apply(this, arguments);
	};	
	_fn.prototype = Object.prototype;
	this.Object.prototype = new _fn();

	this.Array = function()
	{
		return Array.apply(this, arguments);
	};

	this.String = function(s)
	{
		String.apply(this, arguments);
		this.toString = function()
		{
			return s;
		};
		this.valueOf = this.toString();
	};
	_fn.prototype = String.prototype;
	this.String.prototype = new _fn();

	this.Boolean = function(b)
	{
		var b = !!b || false;
		Boolean.call(this, b);
		this.toString = function()
		{
			return b;
		};
		this.valueOf = this.toString;
	};
	_fn.prototype = Boolean.prototype;
	this.Boolean.prototype = new _fn();

	this.Number = function(n)
	{
		var _number = new Number(n);
		this.toExponential = function(x)
		{
			return _number.toExponential(x);
		};
		this.toFixed = function(x)
		{
			return _number.toFixed(x);
		};
		this.toPrecision = function(x)
		{
			return _number.toPrecision(x);
		};
		this.valueOf = function()
		{
			return _number;
		};
	};

	this.Date = function()
	{
		var args = arguments;
		if(!args[0])
		{
			return new Date();
		}
		else if(args.length === 1 && _YL.isString(args[0]))
		{
			return new Date(args[0]);
		}
		else
		{
			var y = args[0],
			m = args[1] || 0,
			d = args[2] || 0,
			h = args[3] || 0,
			i = args[4] || 0,
			s = args[5] || 0,
			ms = args[6] || 0;
			return new Date(y, m, d, h, i, s, ms);
		}
	};

	this.RegExp = function(sPattern, sFlag)
	{
		if(!sPattern)
		{
			if(_debugMode)
			{
				_error_console.log(new _userException(_error_console.message.missParameter));
			}
			return;
		}
		sFlag = sFlag || "";
		return new RegExp(sPattern, sFlag);
	};

	this.responseData = function(data)
	{
		var _data = data, 
		_objName = "TBJS responseData Object",
		_obj = this;

		this.getField = function(sFieldName)
		{
			if(!sFieldName)
			{
				return;
			}
			var v = _data[_YL.trim(sFieldName)];
			if(_YL.isBoolean(v) || _YL.isNumber(v) || _YL.isString(v))
			{
				return v;
			}
			else if(_YL.isArray(v))
			{
				for(var i=0,j=v.length; i<j; i++)
				{
					v[i] = new _self.responseData(v[i]);
				}
				return v;
			}
			else if(_YL.isNull(v) || _YL.isUndefined(v))
			{
				return "";
			}
			return  new _self.responseData(v);
		};

		this.query = function(sPath)
		{
			if(!sPath)
			{
				if(_debugMode)
				{
					_error_console.log(new _userException(_error_console.message.missParameter));
				}
				return;
			}
			var fields = sPath.split(/\>|\//), result = _obj, da, i=0;
			while(result.toString() === _objName && (da = result.getField(fields[i])))
			{
				result = da; 
				i++;
			}
			return result;
		};
		
		this.toString = function()
		{
			return _objName;
		};
	};

	this.Data = function(userConfig)
	{

		//internal properties 
		this._proxyHost = "/ynproxy/ProxyServerURL"; 
		this._connector = null;
		this._defaultResponseType = "json";
		this._defaultProxyType = "ajax";
		this._defaultRequestMethod = "get";
		this._defaultClientCacheTime = 0;
		this._defaultTimeout = 5000;

		var _obj = this;

		//extenal properties
		this.responseType = _obj._defaultResponseType;
		this.proxyType = _obj._defaultProxyType;
		this.requestMethod = _obj._defaultRequestMethod;
		this.cache = _obj._defaultClientCacheTime;
		this.onDone = null;
		this.onError = null;

		//init
		if(userConfig && userConfig.proxyHost)
		{
			this._proxyHost = userConfig.proxyHost;
		}

		if(userConfig && userConfig.responseType)
		{
			this.responseType = userConfig.responseType;
		}

		if(userConfig && userConfig.proxyType)
		{
			this.proxyType = userConfig.proxyType;
		}

		if(userConfig && userConfig.requestMethod)
		{
			this.requestMethod = userConfig.requestMethod;
		}

		if(userConfig && userConfig.cache)
		{
			this.cache = userConfig.cache;
		}

		if(userConfig && userConfig.onDone)
		{
			this.onDone = userConfig.onDone;
		}

		if(userConfig && userConfig.onError)
		{
			this.onError = userConfig.onError;
		}

	};

	//external method
	this.Data.prototype.send = function(sUrl, sParam)
	{
		var _obj = this;
		if(!sUrl || !_isUrl(sUrl))
		{
			if(_debugMode)
			{
				_error_console.log(new _userException(_error_console.message.missParameter));
			}
			return;
		}
		
		var encodeURL = function(url)
		{
			return encodeURIComponent? encodeURIComponent(url) : escape(url);
		},

		handleSuccess = function(resp)
		{
			var type = resp.argument, 
			    da;
			if(!_obj.onDone)
			{
				return;
			}
			try
			{
				if(type === "json")
				{
					da = _YL.JSON.parse(_decodeHTML(resp.responseText));
					//_obj.onDone(new _self.responseData(da));
					_obj.onDone(da);
				}
				else if(type === "text")
				{
					da = _decodeHTML(resp.responseText);
					_obj.onDone(da);
				}
			}
			catch(_err)
			{
				if(_debugMode)
				{
					_error_console.log(new _userException(_error_console.message.parseFail));
				}
			}
		},

		handleError = function(resp)
		{
			if(!_obj.onError)
			{
				return;
			}
			_obj.onError(resp);
		};

		var param = sParam || null,
		crumb = (crumb = _YU.Dom.get("yact-crumb"))? crumb.value : "",
		type = _obj.responseType.toLowerCase(),
		method = _obj.requestMethod, 
		proxy = _obj.proxyType.toLowerCase(),
		url = _obj._proxyHost + "?url=" + encodeURL(sUrl) + "&datatype=" + type + "&proxytype=" + proxy + "&_crumb=" + crumb, 
		callback = {
			success: handleSuccess,
			failure: handleError, 
			timeout: _obj._defaultTimeout,
			argument: type
		}, 
		postdata = param;

		if(proxy === "ajax")
		{
			_obj._connector = _YU.Connect.asyncRequest(method, url, callback, postdata);
		}
	};

	this.Data.prototype.abort = function()
	{
		var _obj = this;
		if(_obj._connector)
		{
			_YU.Connect.abort(_obj.connector);
		}
	};
};

})();


