tieuthienma	= new TC_class();
tieuthienma.cancel_bubble_all	= function(obj){	return tieuthienma.cancel_bubble(obj, true);		};
tieuthienma.cancel_bubble_low	= function(obj){	return tieuthienma.cancel_bubble(obj, false);	};


/* **************************************************
* General class for all tieuthienma.com's scripts
* for (i in this.cookies) {	v += "\n" + this.cookies[i];	}
************************************************** */
function TC_class(){
	this.initialized	= false;
	
	this.userAgent		= navigator.userAgent.toLowerCase();
	this.ua_version		= parseInt(navigator.appVersion);
	this.browser_regexp	= (window.RegExp) ? true : false;
	this.browsers		= new Array();
	this.DOMtype		= '';
	
	//common ids /object/vars/editors
	this.ids			= new Array();
	this.objects		= new Array();
	this.vars			= new Array();
	this.editors		= new Array();
	
	
	//Hold checkboxes
	this.checked		= new Array();
	
	//holds cookies
	//this.cookies		= new Array();
	
	//Holds the show CSS
	this.shadow			= new Array();
	
	//Holds the screen dimension this.dimension['x'], this.dimension['y']
	this.dimension		= new Array();
	
	//Holds the scroll dimension
	this.scroll			= new Array();
	
	
	/* **************************************************
	* Set some common used variables
	*
	* @usage
	* this = new this();
	* this.init();
	************************************************** */
	this.init	= function(){
		this.initialized		= true;
		this.shadow['ie']		= 'shadow_ie';
		this.shadow['moz']		= 'shadow_moz';
	
		/*Detrmine the browser*/
		this.browsers['firefox']= ( this.userAgent.indexOf('firefox') != -1 )		?	true	:	false;
		this.browsers['kon']	= ( this.userAgent.indexOf('konqueror') != -1 )		?	true	:	false;
		this.browsers['moz']	= ( navigator.product == 'Gecko' )					?	true	:	false;
		this.browsers['opera']	= ( this.userAgent.indexOf('opera') != -1)			?	true	:	false;
		this.browsers['safari']	= ( ( this.userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."))?true:false; 
		this.browsers['webtv']	= ( this.userAgent.indexOf('webtv') != -1)			?	true	:	false;
		this.browsers['ie']		= ( ( this.userAgent.indexOf('msie') != -1) && ( !this.browsers['opera'] ) && ( !this.browsers['safari'] ) && ( !this.browsers['webtv'] ) )?true:false;
		this.browsers['ie4']	= ( ( this.browsers['ie'] ) && ( this.userAgent.indexOf("msie 4.") != -1 ) )?true:false;
		this.browsers['ie7']	= ( ( this.browsers['ie'] ) && ( this.userAgent.indexOf("msie 7.") != -1 ) )?true:false;
		this.browsers['ns']		= ( ( this.userAgent.indexOf('compatible') == -1) && (this.userAgent.indexOf('mozilla') != -1) && (!this.browsers['opera']) && (!this.browsers['webtv']) && (!this.browsers['safari']))?true:false;
		this.browsers['ns4']	= ( ( this.browsers['ns'] ) && ( parseInt(navigator.appVersion) == 4 ) )?true:false;
		this.browsers['version']= parseInt(navigator.appVersion);
	
		this.browsers['win']	= ( ( this.userAgent.indexOf("win") != -1 ) || ( this.userAgent.indexOf("16bit") != -1 ) )?true:false;
		this.browsers['mac']	= ( ( this.userAgent.indexOf("mac") != -1 ) || ( navigator.vendor=="Apple Computer, Inc." ) )?true:false;
		
	
		/*Determine the DOM type */
		if( document.getElementById){	this.DOMtype = "std";	}
		else if( document.all){ 		this.DOMtype = "ie4";	}
		else if( document.layers){		this.DOMtype = "ns4";	}
	
	
		//Get the screen dimensions
		if(typeof(parent.window.innerWidth) == 'number'){
			this.dimension['x']	= parent.window.innerWidth;
			this.dimension['y']	= parent.window.innerHeight;
		}
		else if( parent.document.documentElement && ( parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight ) ){
			this.dimension['x']	= parent.document.documentElement.clientWidth;
			this.dimension['y']	= parent.document.documentElement.clientHeight;
		}
		else if( parent.document.body && ( parent.document.body.clientWidth || parent.document.body.clientHeight ) ){
			this.dimension['x']	= parent.document.body.clientWidth;
			this.dimension['y']	= parent.document.body.clientHeight;
		}
		else {
			this.dimension['x'] = 0;
			this.dimension['y'] = 0;
		}
		
		
		//get cookies
		//this._get_cookies();
			
		//ids
		this.ids['confirm']	= 'tc_confirm';
		this.ids['loading']	= 'tc_loading';
	};
	
	
	
	/* **************************************************
	* Pop an element & remove it from the array (flexible than array.pop());
	*
	* @param	(array)		The array to be popped
	* @param	(int)		The index of the element in the array to be popped, if nothing provides, then last element is popped
	*
	* @return	(string)	The popped element
	************************************************** */
	this.array_pop		= function(array, index){
		var size		= array.length;
		var value		= '';
		var match		= false;
		
		if(isNaN(index)){
			index		= size - 1;
		}
		
		
		for(var i=0; i < size -1; i++){
			if( i == index ){
				value	= array[i];
				match	= true;
			}
			if(match == true){
				array[i]	= array[i+1];
			}
		}
		
		if(match == true){
			array.pop();
		}
		
		return value;
	};
	
	
	/* **************************************************
	* 
	************************************************** */
	this.cancel_bubble	= function(obj, extra){
		if( extra !== false){
			extra	= true;
		}
		
		if(!obj || this.isbrowser('ie') ){
			if(window.event){
				if(extra){
					window.event.returnValue	= false;
				}
				window.event.cancelBubble	= true;
				return window.event;
			}
		}
		else{
			obj.stopPropagation();
			if(extra){
				obj.preventDefault();
			}
			return obj;
		}
	};
	
	/* **************************************************
	* popup menu for color picker
	************************************************** */
	this.color_picker	= function(form, field){
		window.open(tieuthienma_url + 'ucp.'	+ php_ext + '?cmd=ezcolor_picker&form=' + form + '&field=' + field, '_color_picker', 'height=150, resizable=yes, scrollbars=no, width=636');
		return false;
	};
	
	
	/* **************************************************
	* Ajax call to generate a list of state/city for selectec country
	* Notice that you need to have the following at the end of your HTML file (to autoloading)
	* <div id="javascript" style="display:none">{S_JAVASCRIPT}</div>
	************************************************** */
	this.country	= function(country, state_name, city_name){
		eval('state_value = ' + state_name);
		eval('city_value = ' + city_name);
		
		do_request_function = function(){
		   if ( ajax.readystate_ready_and_ok() ){
				if(ajax.xmlhandler.responseText){
					txt		= ajax.xmlhandler.responseText.split('\n');
					state	= txt.pop();
					
					if(state==1){
						tieuthienma.set_display( state_name + '_div', '' );
						tieuthienma.set_display( city_name + '_div', 'none' );
						tieuthienma.set_innerHTML( state_name + '_text', tieuthienma.toString(txt, "\n") );
						
						//If this is a state, then we need to build its city, if there is a default value
						if(state_value){
							tieuthienma.state(country, state_value, city_name);
						}
					}
					else{
						tieuthienma.set_display( state_name + '_div', 'none' );
						tieuthienma.set_display( city_name + '_div', '' );
						tieuthienma.set_innerHTML( city_name + '_text', tieuthienma.toString(txt, "\n") );
					}
				}
		   }
		}
		
		
		ajax.onreadystatechange( do_request_function );
		ajax.process( tieuthienma_url + 'ucp.'	+ php_ext + SID + '&cmd=country&get=c&country=' + country + 
			'&state_name='	+ state_name	+ '&state='	+ state_value	+
			'&city_name='	+ city_name		+ '&city='	+ city_value);
	};
	
	
	/* **************************************************
	* Ajax call to get a list of cities for a selected country/state
	************************************************** */
	this.state	= function( country, state, city_name){
		do_request_function = function(){
		   if ( ajax.readystate_ready_and_ok() ){
				if(ajax.xmlhandler.responseText){
					txt		= ajax.xmlhandler.responseText.split('\n');
					city	= txt.pop();
					
					tieuthienma.set_display( city_name + '_div', '' );
					tieuthienma.set_innerHTML( city_name + '_text', tieuthienma.toString(txt, "\n") );
				}
		   }
		}
		eval('city_value = ' + city_name);
		ajax.onreadystatechange( do_request_function );
		ajax.process( tieuthienma_url + 'ucp.'	+ php_ext + SID + '&cmd=country&get=s&country=' + country + '&state=' + state + '&city=' + city_value  + '&city_name='	+ city_name  );
	};
	
	
	/* **************************************************
	* Popup a window to find a user
	************************************************** */
	this.find_user		= function(form, field, single, max_user){
		select	=	(single)	?	'single'	:	'multiple';
		max_user=	(max_user)	?	max_user	:	0;
		this.popup(tieuthienma_url + 'memberlist.'	+	php_ext	+	SID	+ '&form='	+ form	+	'&field='	+ field	+	'&select='	+ select	+	'&max_user='	+	max_user	+	'&popup=1',
			760, 570, '_find_user');
	}
	
	
	/* **************************************************
	* Get the bbcode bitfield for ajax posting
	* @param	(string)	bbcode bitfield prefix
	*
	* @param	(string)	bitfield value
	************************************************** */
	this.get_bbcode_bitfield		= function(prefix){
		prefix	= (prefix)	?	prefix	:	'';
		var bbcode_bitfield	= 0;
		bbcode_bitfield	+= (tieuthienma.get_object(prefix + 'disable_bbcode') && tieuthienma.get_object(prefix + 'disable_bbcode').checked)	?	1	:	0;
		bbcode_bitfield	+= (tieuthienma.get_object(prefix + 'disable_smiley') && tieuthienma.get_object(prefix + 'disable_smiley').checked)	?	2	:	0;
		bbcode_bitfield	+= (tieuthienma.get_object(prefix + 'disable_url') && tieuthienma.get_object(prefix + 'disable_url').checked)		?	4	:	0;
		
		return bbcode_bitfield;
	}
	
	
	/* **************************************************
	* Get cookie
	*
	* @param	(string)	cookie name
	*
	* @param	(string)	cookie value
	************************************************** */
	this.get_cookie		= function(name){
		return this.cookies[name];
	};
	
	
	/* **************************************************
	* Get the object of an ID. Object can be dynamic (created by createElement, AppendChild, etc)
	*
	* @param	(string)	the id of the object to get
	*
	* @return	(obj)		the object of the given ID
	************************************************** */
	this.get_object	= function (id){
	
		//alread an object
		if(typeof(id) == 'object'){
			return id;
		}
		
		if ( typeof( this.objects[id]) == "undefined" || this.objects[id] == null){
			if( this.DOMtype == 'std' ){
				this.objects[id] = document.getElementById(id);
			}
			else if ( this.DOMtype == 'ie4' ){
				this.objects[id] = document.all[id];
			}
			else if ( this.DOMtype == 'ns4' ){
				this.objects[id] = document.layers[id];
			}
		}
		
		return this.objects[id];
	};
	
	
	/* **************************************************
	* Get object's left position
	************************************************** */
	this.get_positionX	= function (obj){
		if(this.get_object(obj)){
			obj = this.get_object(obj);
		}
		
		var pos	= 0;
		if(obj.offsetParent){
			while(obj.offsetParent){
				pos	+= obj.offsetLeft;
				obj	= obj.offsetParent;
			}
		}
		else if(obj.x){
			pos	+= obj.x;
		}
		
		return pos;
	};
	
	
	/* **************************************************
	* Get object's top position
	************************************************** */
	this.get_positionY	= function (obj){
		if(this.get_object(obj)){
			obj = this.get_object(obj);
		}
		
		var pos	= 0;
		if(obj.offsetParent){
			while(obj.offsetParent){
				pos	+= obj.offsetTop;
				obj		= obj.offsetParent;
			}
		}
		else if(obj.y){
			pos	+= obj.y;
		}
		
		return pos;
	};
	
	
	/* **************************************************
	* Get Scroll dimension.... Scroll dimensions are stored inside this.scroll['y'] & this.scroll['x']
	************************************************** */
	this.get_scroll		= function(){
		if( parent.document.documentElement){
			this.scroll['y']	= parent.document.documentElement.scrollTop;
			this.scroll['x']	= parent.document.documentElement.scrollLeft;
		}
		else if( parent.document.body && parent.document.body.scrollTop){
			this.scroll['y']	= parent.document.body.scrollTop;
			this.scroll['x']	= parent.document.body.scrollLeft;
		}
		else if( parent.window.pageYOffset){
			this.scroll['y']	= parent.window.pageYOffset;
			this.scroll['x']	= parent.window.pageXOffset;
		}
		else if( parent.window.scrollY){
			this.scroll['y']	= parent.window.scrollY;
			this.scroll['x']	= parent.window.scrollX;
		}
		else {
			this.scroll['y']	= 0;
			this.scroll['x']	= 0;
		}
	};
	
	
	/* **************************************************
	* Hide the confirmation layer
	************************************************** */
	this.hide_confirm	= function(){
		clearInterval(this.vars['setinterval']);
		try{
			if(this.confirmdiv && this.confirmdiv.object){
				this.confirmdiv.hide();
			}
		}
		catch(e){}
	
		return;
	};
	
	
	/* **************************************************
	* Hide the Information layer
	************************************************** */
	this.hide_info	= function(){
		try{
			if(this.infodiv && this.infodiv.object){
				this.infodiv.hide();
			}
		}
		catch(e){}
	
		return;
	};
				
	
	/* **************************************************
	* Hide the loading layer
	************************************************** */
	this.hide_loading	= function(){
		clearInterval(this.vars['setinterval']);
		try{
			if(this.centerdiv && this.centerdiv.object){
				this.centerdiv.hide();
			}
		}
		catch(e){}
		
		this.loading_fired = 0;
		return;
	};
	
	
	/* **************************************************
	*  Hide common messages.... Layers to be hidden are 'tc_msg_box', 'tc_error_box', 'tc_warning_box', 'tc_loading'
	************************************************** */
	this.hide_messages	= function(){
		this.set_display('tc_msg_box', 'none');
		this.set_display('tc_error_box', 'none');
		this.set_display('tc_warning_box', 'none');
		this.hide_loading();
		return;
	};
		
	
	/******************************************************************
	* clean HTML codes
	*
	* @param	(string)	text to be parsed and cleaned
	*
	* @return	(string)	clean HTML
	******************************************************************/
	this.html_clean		= function(html){
		if( html == '' || typeof(html) == 'undefined' ){
			return html;
		}
		
		html	= html.replace( /<br>/ig,						'<br />');
		html	= html.replace( /<p>(\s+?)?<\/p>/ig,			'');
		html	= html.replace( /<p><hr \/><\/p>/ig,			'<hr />');
		html	= html.replace( /<p>&nbsp;<\/p><hr \/><p>&nbsp;<\/p>/ig, '<hr />');
		html	= html.replace( /<(p|div)([^&]*)>/ig,			'\n<$1$2>\n');
		html	= html.replace( /<\/(p|div)([^&]*)>/ig,			'\n</$1$2>\n');
		html	= html.replace( /<br \/>(?!<\/td)/ig,			'<br />\n');
		html	= html.replace( /<\/(td|tr|tbody|table)>/ig,	'</$1>\n');
		html	= html.replace( /<(tr|tbody|table(.+?)?)>/ig,	'<$1>\n');
		html	= html.replace( /<(td(.+?)?)>/ig,				'\t<$1>');
		html	= html.replace( /<p>&nbsp;<\/p>/ig,				'<br />');
		html	= html.replace( /<br \/>/ig,					'<br />\n');
		html	= html.replace( /<br>/ig,						'<br />\n');
		html	= html.replace( /<td><br \/>\n<\/td>/ig,		'<td><br /></td>');
		return html;
	};
	
	
	/* **************************************************
	* Encode the text
	*
	* @param	(string)	text to be encoded
	*
	* @return	(string)	encoded text
	************************************************** */
	this.html_encode	=	function(html){
		html	= html.replace( /&/g, '&amp;');
		html	= html.replace( /</g, '&lt;');
		html	= html.replace( />/g, '&gt;');
		html	= html.replace( /"/g, '&quot;');
		return html;
	};
	
	
	/* **************************************************
	* "Encode the text inside the textarea
	*
	* @param	(string)	textarea ID
	* @param	(string)	text to be encoded
	*
	* @return	(string)	encoded text
	************************************************** */
	this.html_encode_textarea	=	function(textarea_id, html){
		html	= html.replace( /</g, '&lt;');
		html	= html.replace( />/g, '&gt;');
		this.set_innerHTML(textarea_id, html);
		
		return html;
	};
	
	
	/* **************************************************
	* Decode the text
	*
	* @param	(string)	text to be decoded
	*
	* @return	(string)	decoded text
	************************************************** */
	this.html_decode			=	function(html){
		html	= html.replace( /&lt;/g, '<');
		html	= html.replace( /&gt;/g, '>');
		html	= html.replace( /&amp;/g, '&');
		html	= html.replace( /&quot;/g, '"');
		return html;
	};
	
	
	/******************************************************************
	*
	******************************************************************/
	this.html_strip				= function(html){
		html	= html.replace( /<\/?([^>]+?)>/ig, '');
		return html;
	};
	
	
	/******************************************************************
	*
	******************************************************************/
	this.html_strip_empty		= function(html){
		html	= html.replace('<([^>]+?)></([^>]+?)>', '');
		return html;
	};
	
	
	/* **************************************************
	* Check to see if a value is a member of an array ... Similar to PHP's in_array() function
	*
	* @param	(string)	value to be find
	* @param	(array)		array to look for value
	*
	* @return	(bool)		true if value is a member of the array, false otherwise
	************************************************** */
	this.in_array	= function(needle, haystack){
		if(!haystack.length){
			return false;
		}
		for( var i = 0; i < haystack.length; i++){
			if(haystack[i] === needle){
				return true;
			}
		}
		
		return false;
	};
	
	
	/* **************************************************
	* Check to see if the current browser matches input
	*
	* @param	(string)	the browser abbreviated name
	* @return	(bool)		true if this browser matches, false otherwise
	************************************************** */
	this.isbrowser	= function(browser){
		return this.browsers[browser];
		
	};
	
	
	/* **************************************************
	* Check to see if the enter key was pressed
	*
	* @param	(obj)	event handler
	* @return	(bool)	true if the enter key was pressed, false otherwise
	************************************************** */
	this.is_enter_key	= function (e){
		var keycode = (window.event)?window.event.keyCode:e.which;
		if (keycode == 13){		return true;	}
		else{					return false;	}
	};
	
	
	/* **************************************************
	* Take user to another URL
	*	
	* @param	(string)	The url to load
	* @param	(bool)		Is this URL the full URL??? If not FULL url then we add the tieuthienma_url to it
	************************************************** */
	this.jump			= function(url, full){
		url = url.replace( /&amp;/g, '&');
		if(!full){
			url	= tieuthienma_url + url;
		}
		
		window.location.href = url;
	};
	
	
	/* **************************************************
	* Jump to page
	************************************************** */
	this.page			= function(jump_page, current_page,page_jump_url, total_page, per_page){
		var page = prompt(jump_page, current_page);
			
		if(page == null || isNaN(page) ){
			return false;
		}
		page = parseInt(page);
		
		if( parseInt(page) < 0 || page > total_page){
			alert('The page number you requested is out of range');
			return false;
		}
		
		document.location.href = page_jump_url.replace(/&amp;/g, '&') + '&start=' + ((page - 1) * per_page);
	};
	
	
	/* **************************************************
	* popup a window
	* 
	* @param	(string)	URL to be displayed
	* @param	(string)	width of the popup window
	* @param	(string)	height of the popup window
	* @param	(string)	name of the popup window
	************************************************** */
	this.popup	= function(url, width, height, name){
		if(!width){
			width	= 600;
		}
		if(!height){
			height	= 400;
		}
		if(!name){
			name	= new Date().getTime();
		}
		
		var myPopup	= window.open(url.replace('&amp;', '&'), name, 'width=' + width + ', height=' + height + ', resizable=1, scrollbars=1, location=no, directories=no, status=no, menubar=no, toolbar=no');
		myPopup.focus();
		return false;
	};
	
	
	/* **************************************************
	* print the current page
	************************************************** */
	this.print	= function(width, height, name){
		var myPopup	= window.open(tieuthienma_url + 'print.'	+ php_ext + SID + '&action=template', name, 'width=' + width + ', height=' + height + ', resizable=1, scrollbars=1, location=no, directories=no, status=no, menubar=no, toolbar=no');
	};
	
	
	/* **************************************************
	* Select all check boxes (i.e.	this.select_all('acp', true, 'userids') : check all userids inside the id 'acp')
	*
	* @param	(string)	The parent id to look for checkboxes
	* @param	(bool)		true to check all checkboxes, false to uncheck the boxes
	************************************************** */
	this.select_all	= function(id, flag, name){
		var parent = this.get_object(id);
		if (!parent) {
			eval('parent = document.' + id);
		}
		if (!parent){
			return;
		}
		
		var boxes = parent.getElementsByTagName('input');
		for (var i = 0; i < boxes.length; i++){
			if(name && boxes[i].name.substr(0, name.length) != name){
				continue;
			}
			
			if( boxes[i].type == 'checkbox' && !boxes[i].disabled ){
				boxes[i].checked = flag;
			}
		}
	};
	
	
	/* **************************************************
	* Determine which checkboxes are selected.... 
	* If you want to access the values of the checked boxes, you can use this.checked[name] 
	*
	* @param	(string)	container id
	* @param	(string)	name of checkbox to count
	*
	* @return	(int)		The number of checked boxes
	*	Also, at the end of the call, the values of the checked boxes are stored in this.checked[name]
	************************************************** */
	this.selected_checkbox	= function (id, name) {
		this.checked[name]	= new Array();
		var count	= 0;
		var parent	= this.get_object(id);
		if (!parent) {
			eval('parent = document.' + id);
		}
		
		if (!parent){
			return count;
		}
		
		var boxes = parent.getElementsByTagName('input');
		for (var i = 0; i < boxes.length; i++){
			if(name){
				if (boxes[i].name.substr(0, name.length) != name){
					continue;
				}
			}
			
	   		if ( ( boxes[i].name != 'allbox') && ( boxes[i].type == 'checkbox' ) && ( boxes[i].checked ) ) {
				this.checked[name][count]	= boxes[i].value;
				count++;
			}
	    }
		
		return count;
	};
	
	
	/* **************************************************
	* Determine the value of the selected option in a LIST
	*
	* @param	(sring)		The ID or object to check for selected option  ( i.e 'document.form.selectame' or 'id')
	*
	* @return	(int)		The number of selected options
	*	Also, at the end of the call, the values of the checked boxes are stored in this.checked[id]
	************************************************** */
	this.selected_list	= function (id){
		var obj	= id;
		if( this.get_object(id) ){
			obj	= this.get_object(id);
		}
	
		this.checked[id]	= new Array();
		var count = 0;
			
		//In this case, obj is passed as 'document.form.selectame'
		for (var i=0; i < obj.length; i++){
			if (obj[i].selected){
				this.checked[id][count++]	= obj[i].value;
			}
		}
		
		return count;
	};
	
	
	/* **************************************************
	* Determine the value of the selected option in a MENU
	*
	* @param	(sring)		The ID or object to check for selected option  ( i.e 'document.form.selectame' or 'id')
	*
	* @return	(string)	The selected menu's value
	************************************************** */
	this.selected_menu	= function (id){
		this.selected_list(id);
		return this.checked[id][0];
	};
	
	
	/* **************************************************
	* Determine the value of the selected radio in a form
	*
	* @param	(sring)		The object to check for selected radio  ( i.e 'document.form.radioname' )
	*
	* @return	(string)	The selected radio's value
	************************************************** */
	this.selected_radio	= function (obj){
		if(!obj){
			return null;
		}
		
		for (var i=0; i < obj.length; i++){
			if (obj[i].checked){
	    		return obj[i].value;
			}
		}
		
		//check to see if radio is only 1 element
		if(obj.value && obj.checked){
			return obj.value;
		}
		
		return null;
	};
	
	
	/* **************************************************
	* set the the PROPERTY of an element to a new value (this element mUST have a UQNIUE ID
	*
	* @param	(string)	ID of the HTML element to set the inner HTML
	* @param	(string)	Element's property name
	* @param	(string)	Element's property new value
	* @param	(bool)		If true, then we append/ADD to existing value, If FALSE we assign it to its new value
	*
	* @return	(bool)		true on success, false on failure
	************************************************** */
	this.set	= function (id, property, value, append){
		obj	= this.get_object(id);
		if( obj == null || typeof(obj) != 'object'){
			return false;
		}
		
		value	= String(value);
		if(value.match(/"/)){
			value	= value.replace(/"/ig, '\\"');
		}
		
		return eval('obj.' + property + ((append==true)? '+="' : '="') + value 	+ '";');
	};
	
	
	/* **************************************************
	* Set a cookie into user harddisk
	*
	* @param	(string)	name of cookie
	* @param	(string)	value of cookie
	* @param	(bool)		If true, this cookie will have an expired date 15 years from now
	************************************************** */
	this.set_cookie		= function(name, value, sticky){
		var expire	= '';
		var domain	= '';
		var path	= '';
		if(sticky){
			expire	= ";expires=Sat, 1 Jan 2022 00:00:00 GMT";
		}
		if(cookie_domain != '' ){
			domain	= ';domain=' + cookie_domain;
		}
		
		if(cookie_path	!= ''){
			path	= ';path=' + cookie_path;
		}
		
		//@todo?? should we add the cookie_domain??? decide not to for now
		document.cookie	= cookie_name + name + "=" + value + expire + path;
		this.cookies[name] = value;
	};
	
	
	/* **************************************************
	* Set the css class of a HTML layer
	*
	* @param	(string)	ID of the HTML element to set the css class
	* @param	(string)	CSS class name to set
	************************************************** */
	this.set_className	= function (id, css){
		obj	= this.get_object(id);
		if( obj == null || typeof(obj) != 'object'){
			return false;
		}
		obj.className	= css;
	};
	
	
	/* **************************************************
	* Set the display of a HTML element
	*
	* @param	(string)	ID of the HTML element to set the css class, or an object
	* @param	(string)	The CSS display to be set (i.e. '', 'none', 'block', 'inline', etc )
							If this value is set to TRUE, then we check the current display value and
							set to display if it is hidden, and vice versa
							If this value is not set, then we display it, no matter what
	************************************************** */
	this.set_display	= function (id, display){
		obj	= this.get_object(id);
		if( obj == null || typeof(obj) != 'object'){
			return false;
		}
		
		//Get the reverse of what it is display
		if(display==true){
			value	= this.get_object(id).style.display;
			if( value == null || value == 'none' || value == 'undefined'){
				display	= '';
			}
			else{
				display	= 'none';
			}
		}
		else if (!display){
			display = '';
		}
		
		obj.style.display	= display;
		return display;
	};
	
	
	/* **************************************************
	* set the innner HTML of an element
	*
	* @param	(string)	ID of the HTML element to set the inner HTML
	* @param	(string)	The HTML content to be set
	* @param	(bool)		If true, then we append to existing HTML code, else we assign it to its new value
	************************************************** */
	this.set_innerHTML	= function (id, html, append){
		this.set_display(id, '');
		obj	= this.get_object(id);
		if( obj == null || typeof(obj) != 'object'){
			return false;
		}
		
		if(append){
			obj.innerHTML	+= html;
		}
		else{
			obj.innerHTML	= html;
		}
	};
	
	
	/* **************************************************
	*  Set an onject to not selectable
	************************************************** */
	this.set_unselectable = function(obj){
		if(!tieuthienma.isbrowser('ie4') && typeof(obj.tagName) != 'undefined'){
			if(obj.hasChildNodes()){
				for(var i=0; i < obj.childNodes.length; i++){
					this.set_unselectable(obj.childNodes[i]);
				}
			}
			obj.unselectable = 'on';
		}
	};
	
	
	/* **************************************************
	* set the value of an element
	*
	* @param	(string)	ID of the HTML element to set the inner HTML
	* @param	(string)	The value to be set
	************************************************** */
	this.set_value	= function (id, value){
		obj	= this.get_object(id);
		if( obj == null || typeof(obj) != 'object'){
			return false;
		}
		
		obj.value	= value;
	};
	
	
	/* **************************************************
	* Show the confirm Layer.... You should have 'tc_confirm' as an ID in an HTML element such as DIV
	*
	* @param	(string)	The form name that is to be submitted, if users choose to accept the confirmation
	* @param	(string)	The message to be displayed
	************************************************** */
	this.show_confirm	= function(formname, message){
		if(message){
			this.set_innerHTML('tc_confirm_text', message)
		}
		
		//set the form to be submit so that the javascript will know which one to submit
		document.tc_confirm_form.tc_confirm_form_name.value	= formname;
	
		this.confirmdiv	= new center_class('tc_confirm');
		this.confirmdiv.center();
		
		this.vars['setinterval'] = setInterval('tieuthienma.confirmdiv.center()', 10);
	};
	
	
	/* **************************************************
	* Show the Loading Layer.... You should have 'tc_loading' as an ID in an HTML element such as DIV
	*
	* @param	(string)	The message to be displayed
	* @param	(bool)		The default is to fade this loading box after 5 seconds. If you set this parameter to true, then it stays there until reload
	************************************************** */
	this.show_loading	= function(message, timeout){
		if(message){
			this.set_innerHTML('tc_loading_text', message)
		}
		
		this.centerdiv	= new center_class('tc_loading');
		this.centerdiv.center();
		this._add_shadow('tc_loading_shadow','tc_loading_inner');
		this._fade('tc_loading');
		
		if ( timeout ){
			setTimeout('this.centerdiv.hide()', timeout);
		}
		return;
	};
	
	
	/* **************************************************
	* Submit a form
	*
	* @param	(string)	formname or form ID to be submitted
	* @param	(bool)		True to show the loading box, false not to
	************************************************** */
	this.submit			= function (formname, show_loading, timeout){
		if(show_loading != false){ 
			this.show_loading(false, timeout);
		}
			
		for( var i=0; i < document.forms.length; i++ ){
			if(document.forms[i].name == formname ){
				document.forms[i].submit();
				return;
			}
		}
		
		//If we cannot find the formname, try using its id and submit
		this.get_object(formname).submit();
	};
	
	
	/* **************************************************
	* Similar to Javascript toString but we can choose the dilimiter we want
	*
	* @param	(array)		array to be converted into a string
	* @param	(string)	The string to seperated the array elements, typically ',' or "\n"
	*
	* @return	(string)	converted text
	************************************************** */
	this.toString		= function(array, delimiter){
		var string	= '';
		for(var i=0; i < array.length; i++){
			string += array[i] + delimiter;
		}
	
		return string;
	};
	
	
	/* **************************************************
	* Trim space before and after a text
	*
	* @param	(string)	text to be trimmed
	*
	* @return	(string)	trimmed text
	************************************************** */
	this.trim			= function(text){
		if(typeof(text)=='undefined'){
			return '';
		}
		
		text	= text.replace(/^\s+/, '');
		text	= text.replace(/\s+$/, '');
		
		return text;
	};
	
	
	
	/* **************************************************
	* truncate a string to a specified length
	* @param	(string)	text to be truncated
	* @param	(int)		length to keep
	* @return	(string)	truncated text
	************************************************** */
	this.truncate			= function(text, length){
		text	= (typeof(text)=='undefined')	?	''	:	text;
		length	= (!length)?	100	:	length;
		
		return text.substr(0, length);
	};
	
	
	/* **************************************************
	* 				PRIVATE FUNCTIONS
	************************************************** */
	
	
	
	
	
	/* **************************************************
	* 
	************************************************** */
	this._add_shadow		= function(wrapname, divname){
		var object	= this.get_object(divname);
		var wrapobj	= this.get_object(wrapname);
		
		if(object && wrapobj){
	
			if( this.browsers['ie'] ){
				wrapobj.className	= this.shadow['ie'];
				wrapobj.style.width	= object.offsetWidth + 1 + 'px';
				wrapobj.style.height= object.offsetHeight + 1 + 'px';
			}
			else{
				wrapobj.className	= this.shadow['moz'];
				wrapobj.style.width	= object.offsetWidth + 0 + 'px';
				wrapobj.style.height= object.offsetHeight + 0 + 'px';
			}
		}
	};
	
	
	/* **************************************************
	* 
	************************************************** */
	this._fade		= function(div){return false;
		if(!this.get_object(div)){
			return false;
		}
	
		this.set_display(div, '');
		
		var hash		= '#';
		var color_items	= "0123456789abcdef";
		var start_color	= '#ffff66';
		var orig_color	= tieuthienma.get_object(div).style.backgroundColor;
		var temp_end	= '#ffffff';
		var iter		= 20;
		var time		= 80;
		var rbeg		= color_items.indexOf(start_color.substr(1,1))*16+color_items.indexOf(start_color.substr(2,1));
		var gbeg		= color_items.indexOf(start_color.substr(3,1))*16+color_items.indexOf(start_color.substr(4,1));
		var bbeg		= color_items.indexOf(start_color.substr(5,1))*16+color_items.indexOf(start_color.substr(6,1));
		var rend		= color_items.indexOf(temp_end.substr(1,1))*16+color_items.indexOf(temp_end.substr(2,1));
		var gend		= color_items.indexOf(temp_end.substr(3,1))*16+color_items.indexOf(temp_end.substr(4,1));
		var bend		= color_items.indexOf(temp_end.substr(5,1))*16+color_items.indexOf(temp_end.substr(6,1));
		
		for(i=1,r=rbeg,g=gbeg,b=bbeg; i<=iter; r=Math.round(rbeg+i*((rend-rbeg)/(iter-1))),g=Math.round(gbeg+i*((gend-gbeg)/(iter-1))),b=Math.round(bbeg+i*((bend-bbeg)/(iter-1))),i++){
			hstr	= '#' + color_items.charAt(Math.floor(r/16)) + color_items.charAt(r%16) + color_items.charAt(Math.floor(g/16)) + color_items.charAt(g%16) + color_items.charAt(Math.floor(b/16)) + color_items.charAt(b%16);
			setTimeout('var div = tieuthienma.get_object("' + div + '");div.style.backgroundColor = "'+hstr+'";	', i*time);
		}
		
		setTimeout('var div = tieuthienma.get_object("' + div + '");div.style.backgroundColor = "' + orig_color + '";', (i+1)*time);
	};
	
	
	/* **************************************************
	* 
	************************************************** */
	/*this._get_cookies	= function(){
		var _tmp = document.cookie.split(';');
		if(_tmp.length <=0){
			return false;
		}
		
		for(i=0; i<_tmp.length; i++){
			
			if(_tmp[i].match(new RegExp(cookie_name + ".*$"))){
				var _data	= _tmp[i].split('=');
				var _key	= this.trim(_data[0]);
				var _value	= unescape(this.trim(_data[1]));
				if( _key ){
					this.cookies[_key.replace(cookie_name, '')]	= _value;
				}
			}
		}
	}*/
	
	
	/* **************************************************
	* 
	************************************************** */
	this.init();
};










/* **************************************************
* Center class
* put a given DIV at center of the screen
************************************************** */
function center_class(divname){
	this.parent		= '';
	
	this.divname	= divname;
	this.object		= tieuthienma.get_object(this.divname);
	this.shimobj	= '';
	
	
	/* **************************************************
	* Move an object from center
	* @param	string		An ID of an object
	* @param	int			How many pixels from center to move X direction
	* @param	int			How many pixels from center to move Y direction
	************************************************** */
	this.move	= function( obj, eleft, etop ){
		obj	= tieuthienma.get_object(obj);
		eleft	= (eleft)?	eleft	:	0;
		etop	= (etop)?	etop	:	0;
		
		x = tieuthienma.get_positionX(obj); // - obj.offsetWidth;
		y = tieuthienma.get_positionY(obj) + obj.offsetHeight;
		
		this.object.style.left	= x + eleft + "px";
		this.object.style.top	= y + etop + "px";
	}
	
	
	/* **************************************************
	* Move the current defined DIV to center
	************************************************** */
	this.center	= function(){
		if(!this.object){
			return;
		}
		
			
		this.object.style.position	= 'absolute';
		this.object.style.display	= 'block';
		this.object.style.zIndex	= 99;
		
		var divheight	= parseInt(this.object.style.height)	?	parseInt(this.object.style.height)	:	parseInt(this.object.offsetHeight);
		var divwidth	= parseInt(this.object.style.width)		?	parseInt(this.object.style.width)	:	parseInt(this.object.offsetWidth);
		divheight		= divheight	?	divheight	: 250;
		divwidth		= divwidth	?	divwidth	: 500;
			
		//set the scroll offset
		tieuthienma.get_scroll();
		
		var setX		= ( tieuthienma.dimension['x'] - divwidth)/4+ tieuthienma.scroll['x'];
		var setY		= ( tieuthienma.dimension['y'] - divheight)/10 + tieuthienma.scroll['y'];
		setX			= ( setX < 0 )	?	0	:	parseInt(setX);
		setY			= ( setY < 0 )	?	0	:	parseInt(setY);
		//alert('width is ' + setX + ' and height is ' + setY);	
		this.object.style.left	= setX + "px";
		this.object.style.top	= setY + "px";
		
		//alert(' scroll x is ' + tieuthienma.scroll['x'] + ' and scroll y is ' + tieuthienma.scroll['y']);
		//alert(' setX is ' + setX + ' and setY is ' + setY);
		
		/*if( tieuthienma.isbrowser('ie') ){
			this.object.innerHTML	= "<iframe id='" + this.divname + "-shim' src='" + iframe_html_url + "' class='iframeshim' scrolling='no' frameborder='0' style='position:absolute;top:0px;left:0px;right:0px;display: none;'></iframe>" +  this.object.innerHTML;
		
			this.shimobj				= tieuthienma.get_object( this.divname + "-shim" );
			this.shimobj.style.width	= (parseInt(this.object.offsetWidth)-5) + "px";
			this.shimobj.style.height	= this.object.offsetHeight;
			this.shimobj.style.zIndex	= this.object.style.zIndex - 1;
			this.shimobj.style.top		= this.object.style.top;
			this.shimobj.style.left		= this.object.style.left;
			this.shimobj.style.display	= "block";
		}*/
	};
	
	
	/* **************************************************
	* Hide the centered div
	************************************************** */
	this.hide	= function(){
		tieuthienma.set_display(this.object, 'none');
	};
	
	
	/* **************************************************
	*
	************************************************** */
};

/* **************************************************
* print debug information
************************************************** */
function PDI(obj){
	if( obj ){
		if( typeof(obj) == 'object' ){
			for( var i=0; i< obj.length; i++){
				this.set_innerHTML('javascript', this.html_encode(obj[i]) + '<br />', true);
			}
		}
		else{
			this.set_innerHTML('javascript', this.html_encode(obj) + '<br />', true);
		}
	}
	else{
		this.set_innerHTML('javascript', obj + '<br />', true);
	}
};
/*
function show_div(id){
	name = tieuthienma.get_object('save_id').value;
	tieuthienma.set_display(name,'none');
	tieuthienma.get_object('save_id').value = id;
	tieuthienma.set_display(id,'');	
}
/* **************************************************
* 
************************************************** */