	/*
	 boxmobi prototype;
	 Level 2;
	*/ 
	var Bm = {
	  _store : {
		ajax: {},
		data: {},
		method: {},
		variable: {}
	  },
	  _all_popup: {},
	  _show_popup : {},
	  _active_popup : function(popup_id, title, content, option) {
	
		  if (Bm.is_exists(Bm._all_popup[popup_id])) {
			var popup = Bm.get_ele(popup_id);
			jQuery(popup).remove();
		  }
	
		  var config = {
			background_image : 'style/images/boxmobi/buttons/close.png',
			auto_hide: 0,
			/*
			  default, center-center,
			  top-left, top-center, top-right,
			  bottom-left, bottom-center, bottom-right
			*/
			position : 'default',
			pos_type : 'absolute',
			/*
			  overlay, one-time, show-hide,
			*/
			type: 'show-hide',
			overlay: {
			  'background-color' : '#000000',
			  'opacity' : '0.9'
			},
			border: {
			  'background-color' : '#bebebe',
			  'padding' : '5px'
			},
			title : {
			  'background-color' : '#034b8a',
			  'color' : '#ffffff',
			  'status': 1,
			  'display' : 'block'
			},
			content : {
			  'width' : '500px',
			  'height': 'auto',
			  'padding' : '20px',
			  'display' : 'block'
			},
			before: function(){},
			release: function(){},
			onclose: function(){}
		  };
		  //load config;
		  if (Bm.is_exists(option)) {
			for(var o in option) {
			  if(!Object.prototype[o] && Bm.is_exists(option[o])) {
				if (Bm.is_func(option[o])) {
					config[o] = option[o];
				} else if (Bm.is_obj(option[o])) {
				  for (var i in option[o]) {
					var sub_opt = option[o];
					if (!Object.prototype[i] && Bm.is_exists(sub_opt[i])) {
					  config[o][i] = sub_opt[i];
					}
				  }
				} else {
				  config[o] = option[o];
				}
			  }
			}
		  }
		  Bm._all_popup[popup_id] = config.type;
	
		  //get site dimension;
		  var windowHeight = jQuery(window).height();
		  var windowWidth = jQuery(window).width();
		  var pageHeight = jQuery(document).height() ;
		  var pageWidth = jQuery(document).width();
		  //create overlay popup;
		  if (config.type == 'overlay') {
	
			var oPopup = jQuery('<div id=' + popup_id + '> </div>')
			.css({
			  'background-color' : config.overlay['background-color'],
			  'opacity': config.overlay['opacity'],
			  'position' : config.pos_type,
			  'top' : '0px',
			  'left' : '0px',
			  'z-index' : '332',
			  'width' : '100%'
			}).height(pageHeight).appendTo('body');
	
		  } else {
			//detect close button type;
			var close_button, close_button_hover;
			if (config.title.status == 1) {
			  close_button = 'popup-close-button pcb-blue-normal';
			  close_button_hover = 'popup-close-button pcb-blue-hover';
			} else if (config.title.status == -1){
			  close_button = 'popup-close-button pcb-red-normal';
			  close_button_hover = 'popup-close-button pcb-red-hover';
			} else {
			  close_button = 'popup-close-button pcb-orange-normal';
			  close_button_hover = 'popup-close-button pcb-orange-hover';
			}
			var oButton = jQuery('<div></div>')
			.addClass(close_button)
			.mouseover(function(){
			  this.className = close_button_hover;
			}).mouseout(function(){
			  this.className = close_button;
			}).click(function(){
			  Bm._hide_popup(popup_id);
			});

			var sTitle = jQuery('<div style="fload: left;">'+title+'</div>');
			var oTitle = jQuery('<div></div>')
			.css({
			  'padding-left' : '20px',
			  'font-size' : '16px',
			  'font-weight' : 'bold',
			  'height' : '33px',
			  'line-height' : '33px',
			  'cursor' : 'pointer',
			  'display' : config.title['display'],
			  'color' : config.title['color'],
			  'background-color' : config.title['background-color']
			}).append(oButton).append(sTitle).append('<div style="clear: both;"/></div>');
	
			var oContent = jQuery('<div id="popup-container" style="padding: 20px; color: black"></div>')
			.css({
			  'font-size' : '14px',
			  'height' : config.content['height'],
			  'padding' : config.content['padding'],
			  'display' : config.content['display']
			});
	
			var content_popup_id = null;
			var content_popup_state = null;
			if (Bm.is_str(content)) {
			  oContent.html(content);
			} else if (Bm.is_ele(content)) {
			  //store state content visibility;
			  content_popup_id = content.id;
			  content_popup_state = content.style.display;
			  oContent.append(content);
			  content.style.display = "block";
			}
	
			var blockContent = jQuery('<div style="background-color: white"></div>');
	
			var oPopup = jQuery('<div id=' + popup_id + '></div>')
			.css({
			  'background-color' : config.border['background-color'],
			  'position' : config.pos_type,
			  'padding' : config.border['padding'],
			  'opacity' : '0.4',
			  'z-index' : '333',
			  'width' : config.content['width']
			}).append(blockContent.append(oTitle).append(oContent)).appendTo('body').fadeTo("slow", 1);
	
			//store state of content popup;
			if (content_popup_id) {
			  Bm.get_ele(popup_id).content_popup = {
				id : content_popup_id,
				state : content_popup_state
			  };
			}
	
			config.before(oPopup);
			//display popup;
			switch (config.position ) {
			  case 'top-left':
				  oPopup.css({
					'top': 0,
					'left' : 0
				  });
				  break;
			  case 'top-center':
				 oPopup.css({
					'top': 0,
					'left' : (pageWidth - oPopup.width()) / 2
				  });
				  break;
			  case 'top-right':
				  oPopup.css({
					'top': 0,
					'right' : 0
				  });
				  break;
			  case 'center-center':
				 oPopup.css({
					'top':  (windowHeight - oPopup.height()) / 2,
					'left' : (pageWidth - oPopup.width()) / 2
				  });
				  break;
			  case 'bottom-left':
				  oPopup.css({
					'bottom': 0,
					'left' : 0
				  });
				  break;
			  case 'bottom-center':
				  oPopup.css({
					'bottom': 0,
					'left' : (pageWidth - oPopup.width()) / 2
				  });
				  break;
			  case 'bottom-right':
				  oPopup.css({
					'bottom': 0,
					'right' : 0
				  });
				  break;
			  case 'default':
				  oPopup.css({
					'top': Bm.get_top_page() + 92,
					'left' : (pageWidth - oPopup.width()) / 2
				  });
				  break;
			}// end of else;
		  }
	
		  //auto hide;
		  if (config.auto_hide) {
			setTimeout(function() {
				oPopup.fadeTo('show', 0, function() {
					if (config.type != 'show-hide') {
					  jQuery(this).remove();
					} else  {
					  jQuery(this).hide();
					}
				});
			  },
			  config.auto_hide);
		  }
		  Bm.get_ele(popup_id).onclose = config.onclose;
		  config.release(oPopup);
		  return oPopup;
		},
		_hide_popup: function(id) {
		  var popup = Bm.get_ele(id);
		  if (Bm.is_ele(popup)) {
			//remove overlay popup if it exists;
			Bm.hide_popup(popup.overlay_popup);
			//restore state visibility;
			if (Bm.is_exists(popup.content_popup)) {
			  var content_popup = Bm.get_ele(popup.content_popup.id);
			  content_popup.style.display = popup.content_popup.state;
			}
			//remove chaos popup;
			if (Bm._all_popup[id] == 'one-time' || Bm._all_popup[id] == 'overlay') {
			  Bm._all_popup[id] = null;
			  delete Bm._all_popup[id];
			  popup.parentNode.removeChild(popup);
			} else {
			  popup.style.display = "none";
			}
			var onclose = popup.onclose;
			if (Bm.is_func(onclose)) {
				onclose();
			} else if (Bm.is_str(onclose)) {
				eval(onclose);
			}
		  }
		}
	};

	//check every thing;
	Bm.is_arr = function(arr) {
	  return (arr != null && arr.constructor == Array);
	};
	
	Bm.is_str = function(str) {
	  return (str && (/string/).test(typeof str));
	};
	
	Bm.is_func = function(func) {
		return (func != null && func.constructor == Function);	
	};
	
	Bm.is_num = function(num) {
	  return (num != null && num.constructor == Number);
	};
	
	Bm.is_obj = function(obj) {
	  return (obj != null && obj instanceof Object);
	};
	
	Bm.is_ele = function(ele) {
	  return (ele && ele.tagName && ele.nodeType == 1);
	};
	
	Bm.is_exists = function(obj) {
	  return (obj != null && obj != undefined && obj != "undefined");
	};
	
	Bm.is_json = function(){};
	
	Bm.is_blank = function(str) {
	  return (Bm.util_trim(str) == "");
	};
	
	
	Bm.is_mail = function(str) {
	  return (/^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i).test(Bm.util_trim(str));
	};
	
	Bm.is_link = function(str){
	  return (/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/).test(Bm.util_trim(str));
	};
	
	Bm.is_image = function(imagePath){
	  var fileType = imagePath.substring(imagePath.lastIndexOf("."),imagePath.length).toLowerCase();
	  return (fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".jpeg");
	};
	
	Bm.is_flash = function(imagePath){
	  var fileType = imagePath.substring(imagePath.lastIndexOf("."),imagePath.length).toLowerCase();
	  return (fileType == ".swf") || (fileType == ".flv");
	};
	
	Bm.is_phone = function(num) {
	  return (/^(0121|0122|0123|0125|0126|0127|0166|0168|0169|0199|090|091|092|093|094|095|096|097|098)(\d{7})$/i).test(num);
	};
	
	Bm.is_ff  = function(){
	  return (/Firefox/).test(navigator.userAgent);
	};
	
	Bm.is_ie  = function() {
	  return (/MSIE/).test(navigator.userAgent);
	};
	
	Bm.is_ie6 = function() {
	  return (/MSIE 6/).test(navigator.userAgent);
	};
	
	Bm.is_ie7 = function() {
	  return (/MSIE 7/).test(navigator.userAgent);
	};
	
	Bm.is_ie8 = function() {
	  return (/MSIE 8/).test(navigator.userAgent);
	};
	
	Bm.is_chrome = function(){
		return (/Chrome/).test(navigator.userAgent);
	};

	Bm.is_opera = function() {
	  return (/Opera/).test(navigator.userAgent);
	};
	
	Bm.is_safari = function() {
	  return (/Safari/).test(navigator.userAgent);
	};
	
	Bm.is_permission = function() {
		if (!IS_LOGIN) {
			Bm.show_access_notify();
			return false;
		}	
		if(IS_BLOCK) {
			Bm.show_popup_message('Bạn không có quyền thực hiện chức năng này.', "Thông báo", -1);
			return false;
		}
		return true;
	};
	
	//working with ajax;
	Bm.ajax_get = function(){};
	Bm.ajax_post = function(){};
	
	Bm.ajax_popup = function(url, method, param, callback, option) {
	  if (!Bm.is_exists(url)) return;
	  var	data = '',
			opt = {
				loading: (Bm.is_obj(option) && Bm.is_func(option.loading)) ? option.loading : Bm.show_loading
			};
	  if(Bm.is_obj(param)) {
		  for (var key in param) {
			if (Object.prototype[key]) continue;
			data += '&' + key + '=' + param[key];
		  }
	  } else if (Bm.is_str(param)) {
		data = '&' + param;
	  }
	  var old_ajax = Bm._store.ajax[url];
	  if (Bm.is_exists(old_ajax) && old_ajax === data) {
		return;
	  } else {
		Bm._store.ajax[url] = data;
	  }
	  data += '&rand=' + Math.random();
	  jQuery.ajax({
		  beforeSend: opt.loading,
		  url : BASE_URL + 'ajax.php?' + url,
		  type: method ? method : 'POST',
		  data: data,
		  dataType: 'json',
		  success: function(xhr) {
			  Bm._store.ajax[url] = null;
			  delete Bm._store.ajax[url];
			  Bm.hide_loading();
			  if (xhr && Bm.is_exists(xhr.intReturn)) {
				switch(xhr.intReturn) {
				  case -1:
					Bm.show_popup_message(xhr.msg, "Thông báo lỗi!", -1);
					break;
				  case 0:
					Bm.show_popup_message(xhr.msg, "Cảnh báo", 0);
					break;
				  case 1:
					Bm.show_popup_message(xhr.msg, "Thông báo", 1);
					break;
				}
			  }
			  if (Bm.is_exists(xhr.script)) {
				eval(xhr.script);
			  }
			  if(Bm.is_exists(callback)) {
				callback(xhr);
			  }
		  },
		  error: function(xhr) {
			Bm._store.ajax[url] = null;
			delete Bm._store.ajax[url];
			Bm.hide_loading();
			//Bm.show_popup_message("Lỗi kết nối mạng", "Thông báo lỗi!", -1);
		  }
	  });
	};
	
	Bm.ajax_paging = function (url_path,div_id,curent_url_path) {
		jQuery.jCache.maxSize = 10;
		if(document.getElementById(div_id)) {
			var cache_key 			= escape(url_path);
			var current_cache_key 	= escape(curent_url_path);
	
			if (jQuery.jCache.hasItem(cache_key)) {
				if(current_cache_key!=cache_key) {
					jQuery.jCache.setItem(current_cache_key,document.getElementById(div_id).innerHTML);	
				}
				document.getElementById(div_id).innerHTML=jQuery.jCache.getItem(cache_key);
				return;
			}
	
			jQuery.ajax({
			  url: url_path,
			  cache: true,
			  success: function(html) {
				if (html!='' && html!='undefined') {
					if(current_cache_key!=cache_key) {
						jQuery.jCache.setItem(current_cache_key,document.getElementById(div_id).innerHTML);
					}
					jQuery.jCache.setItem(cache_key, html);
					document.getElementById(div_id).innerHTML = html;
				}
			  }
			});
		}
	};
	
	Bm.ajax_tab = function(){};

	Bm.show_loading = function (txt){
	  txt = Bm.is_str(txt) ? txt : 'Đang tải dữ liệu...';
	  jQuery('.float_loading').remove();
	  jQuery('body').append('<div class="float_loading">'+txt+'</div>');
	  jQuery('.float_loading').fadeTo("fast",0.9);
	  Bm.update_position();
	  jQuery(window).scroll(Bm.updatePosition);
	};
	
	Bm.update_position = function(){
	  if (Bm.is_ie()) {
		jQuery('.mine_float_loading').css('top', document.documentElement['scrollTop']);
	  }
	};
	
	Bm.hide_loading = function() {
	  jQuery('.float_loading').fadeTo("slow",0,function(){jQuery(this).remove();});
	};
	
	//working with popup;
	Bm.show_popup =  function(popup_id, title, content, option) {
	  Bm.hide_all_popup();
	  Bm._active_popup(popup_id, title, content, option);
	};
	
	Bm.hide_popup = function(id) {
		Bm._hide_popup(id);
	};
	
	Bm.show_next_popup = function(popup_id, title, content, option) {
	  Bm._active_popup(popup_id, title, content, option);
	};

	Bm.hide_all_popup = function() {
	  for(var i in Bm._all_popup) {
		if (Object.prototype[i]) continue;
		Bm._hide_popup(i);
	  }
	};
  
	//hide all popup when press esc;
	jQuery(document).keydown(
		function(event) {
			if (event.keyCode == 27) {
				Bm.hide_all_popup();
			}
		}
	);

	Bm.show_overlay_popup = function(popup_id, title, content, option) {
	  Bm.hide_all_popup();
	  Bm._active_popup(
		'overlay-popup',
		'',
		'',
		{
		  type: 'overlay',
		  overlay: Bm.is_exists(option) ? option.overlay : null
		}
	  );
	  Bm._active_popup(popup_id, title, content, option);
	  //store to remove;
	  Bm.get_ele(popup_id).overlay_popup = 'overlay-popup';
	  //update height;
	  Bm.get_ele('overlay-popup').style.height =  jQuery(document).height() + 92 + 'px';
	};
	
	Bm.hide_overlay_popup = function(id) {
	  Bm.hide_popup(id);
	  Bm.hide_popup('overlay-popup');
	};


	Bm.show_popup_message = function(message, title, type, width, height) {
	
	  var bg_color;
	  if (type == -1) {
		bg_color = '#ba0000';
	  } else if (type == 0) {
		bg_color = '#ec6f00';
	  } else {
		bg_color = '#034b8a';
	  }
	
	  var id_overlay = Bm.get_uuid();
	  Bm._active_popup(id_overlay, "", "", {
		type: "overlay",
		auto_hide: 3000,
		overlay : {
		  'opacity' : 0.3,
		  'background-color' : '#ffffff'
		}
	  });
	
	  var id_popup = Bm.get_uuid();
	  Bm._active_popup(id_popup, title, message, {
		type: 'one-time',
		auto_hide: 3000,
		title: {
		  'background-color' : bg_color,
		  'status' : type
		},
		content: {
		  'width' : width ? width : '300px',
		  'height' : height ? height : 'auto'
		}
	  });
	  //store to remove;
	  Bm.get_ele(id_popup).overlay_popup = id_overlay;
	  //update height;
	  Bm.get_ele(id_overlay).style.height =  jQuery(document).height() + 'px';
	};

	Bm.show_access_notify = function() {
	  Bm.show_overlay_popup(
		"popup_access_notify",
		"Thông báo",
		Bm.get_ele("access_notify"),
		{
		  title: {
			'background-color' : 'red',
			'status' : -1
		  },
		  content: {
			width: '400px'
		  }
		}
	  );
	};

	Bm.confirm = function(message, callback, callback_data) {
		//halm: update data for callback function :D
		Bm.show_next_popup(
			"popup_confirm",
			"Xác nhận",
			'<div style="font-weight: bold; margin: 6px 0px;">' + message + '</div>' +
			'<a class="bt_grey marginLeft10" style="margin-left: 0px;" href="javascript: Bm.confirm_ok();">' +
				'<div class="bg_left">' +
					'<div class="bg_right">' +
						'Đồng ý' +
					'</div>' +
				'</div>' +
			'</a>' +
			'<a class="bt_grey marginLeft10" href="javascript: Bm.hide_popup(\'popup_confirm\');">' +
				'<div class="bg_left">' +
					'<div class="bg_right">' +
						'Hủy' +
					'</div>' +
				'</div>' +
			'</a>' +
			'<div class="clear"></div>',
			{content: {width: "300px"}}
		);
		Bm._store.method["popup_confirm"] = callback;
		Bm._store.method["popup_confirm_data"] = callback_data;
	};

	Bm.confirm_ok = function(){
		//halm: update data for callback function :D
		Bm._store.method["popup_confirm"](Bm._store.method["popup_confirm_data"]);
		Bm.hide_popup("popup_confirm");
		Bm._store.method["popup_confirm"] = null;
		Bm._store.method["popup_confirm_data"] = null;
		delete Bm._store.method["popup_confirm"];
		delete Bm._store.method["popup_confirm_data"];
	};


	Bm.test_popup = function() {
	   Bm.confirm("test nha'", function(){alert(2)});
		/*
		//show earch popup;
		Bm.show_popup("mot", "mot", "mot", {position: 'top-right'});
		alert(2);
  
		Bm.show_popup("hai", "hai", "hai", {position: 'bottom-left'});
		K.discover(Bm._all_popup);
		alert(2);
  
		Bm.show_next_popup("ba", "ba", "ba", {position: 'bottom-right'});
		alert(2);
  
		//show overlay popup;
		Bm.show_overlay_popup("bon", "bon", "bon", {position: 'bottom-center'});
		alert(2);
  
		Bm.show_overlay_popup("nam", "nam", "nam", {overlay: {'background-color' : 'red'}});
		alert(2);
  
		Bm.show_next_popup("sau", "sau", "sau", {position: 'top-right', content:{width: '300px', height: '500px'}});
		alert(2);
  
		Bm.hide_all_poppup();
		alert(2);
  
		//show earch popup;
		Bm.show_popup("mot", "mot-mot", "mot-mot", {position: 'top-center', content: {width: '100px'}});
		alert(2);
  
		Bm.show_popup("loading", "Loading...", "", {position: 'top-right', content:{display: 'none'}});
		*/
	};

	//Working with something;
	Bm.util_trim = function(str) {
		return (/string/).test(typeof str) ? str.replace(/^\s+|\s+$/g, "") : "";
	};
	
	Bm.util_random = function(a, b) {
		return Math.floor(Math.random() * (b - a + 1)) + a;
	};
	
	Bm.get_ele = function(id) {
		return document.getElementById(id);
	};
	
	Bm.get_uuid = function() {
		return (new Date().getTime() + Math.random().toString().substring(2));
	};

	Bm.get_top_page = function() {
		if (Bm.is_exists(window.pageYOffset)) {
			return window.pageYOffset;
		}
		if (Bm.is_exists(document.compatMode) && document.compatMode != 'BackCompat') {
			return document.documentElement.scrollTop;
		}
		if (Bm.is_exists(document.body)) {
			scrollPos = document.body.scrollTop;
		}
		return 0;
	};

	Bm.get_form = function(form_id) {
		var form = Bm.get_ele(form_id);
	
		if (!Bm.is_ele(form)) return '';
	
		var arr = [];
	
		var inputs = form.getElementsByTagName("input");
	
		for (var i = 0; i < inputs.length; i ++) {
			var item = inputs[i];
			if (item.type != 'button') {
			  arr.push(item.name + "=" + encodeURIComponent(item.value));
			}
		}
	
		var selects = form.getElementsByTagName("select");
	
		for (var i = 0; i < selects.length; i ++) {
			var item = selects[i];
			var key = item.name;
			var value = item.options[item.selectedIndex].value;
			arr.push(key + "=" + encodeURIComponent(value));
		}
	
		var textareas = form.getElementsByTagName("textarea");
	
		for (var i = 0; i < textareas.length; i ++) {
			var item = textareas[i];
			arr.push(item.name + "=" + encodeURIComponent(item.value));
		}
	
		return arr.join("&");
	};




	/*
	  Level 3
	*/

    //message;
    Bm.show_form_sendmessage = function(to_id, to_name) {
	  if (!Bm.is_permission()) return;
	  var form = '<form id="BmSendMessageForm"><div id="bm-send-message"><div class="row"><span class="label">Gửi đến : </span><a onclick="Bm.chooseReceiver()" href="javascript:void(0)"><span class="name_to" id="bm-send-message-to">'+to_name+'</span></a></div><input type="hidden" value="'+to_id+'" name="to" /><div class="row"><span class="label"> Tiêu đề : </span></div><input class="field_input" type="text" name="title" /><div class="row"><span class="label"> Nội dung : </span></div> <textarea class="textarea"  name="content"></textarea> <div class="popup-footer"><a class="bt_grey marginRight5" href="javascript: Bm.send_message();" ><div class="bg_left"><div class="bg_right">Gửi tin</div></div></a><a class="bt_grey" href="javascript: Bm.cancel_message();" ><div class="bg_left"><div class="bg_right">Hủy bỏ</div></div></a><div class="clear"></div></div></div></form>';
      Bm.show_overlay_popup(
        'popup-sendmessage',
        'Gửi tin nhắn',
        form,
        {content: {'width' : '500px'}}
      );
    };

    Bm.cancel_message = function() {
       Bm.get_ele('bm-send-message').style.display = "none";
       Bm.hide_overlay_popup('popup-sendmessage');
    };

    Bm.send_message = function() {
      var form = Bm.get_ele('BmSendMessageForm');
      var valid = true;
      if (!Bm.is_permission() || Bm.is_blank(form['to'].value)) {
        Bm.show_access_notify();
        valid = false;
      }
      if (Bm.is_blank(form['title'].value)) {
        Bm.show_popup_message("Thiếu tiêu đề", "Thông báo !", -1);
        valid = false;
      }
      if (Bm.is_blank(form['content'].value)) {
        Bm.show_popup_message("Thiếu nội dung", "Thông báo !", -1);
        valid = false;
      }
      if (!valid) return;
      var data = Bm.get_form('BmSendMessageForm');
      Bm.ajax_popup('act=send_message', '', data);
      Bm.hide_overlay_popup('popup-sendmessage');
    };

    //follow;
    Bm.do_follow = function(id, name) {
	  var id = parseInt (id);
      if (!Bm.is_permission()) return;
	  if (id && Bm.is_exists(id) && !Bm.is_blank(name) && Bm.is_exists(name)) {
            Bm.ajax_popup(
                'act=follow&code=follow',
                '',
                {'id': id, 'name' : name},
                Bm.update_follow_button
            );
      } else {
        Bm.show_popup_message("Bạn cần đăng nhập để thực hiện chức năng này", "Thông báo", -1, 300);
      }
    };

    Bm.un_follow = function(id, name) {
	  var id = parseInt (id);
	  if (!Bm.is_permission()) return;
      if (id && Bm.is_exists(id) && !Bm.is_blank(name) && Bm.is_exists(name)) {
        Bm.confirm("Bạn muốn bỏ quân tâm đến: " + name, function() {
            Bm.ajax_popup(
                'act=follow&code=unfollow',
                '',
                {'id': id, 'name' : name},
                 Bm.update_follow_button
            );
        });
      } else {
        Bm.show_popup_message('Bạn cần đăng nhập để thực hiện chức năng này', 'Thông báo', -1, 300);
      }
    };

    Bm.update_follow_button = function(xhr) {
        var button = Bm.get_ele(Bm._store.variable["follow_update_button"]);
        button.innerHTML = xhr.data;
        Bm._store.variable["follow_update_button"] = null;
        delete Bm._store.variable["follow_update_button"];
    };

    Bm.store_follow_button = function(object) {
        object.id = Bm.get_uuid();
        Bm._store.variable["follow_update_button"] = object.id;
    };

    //login;
    Bm.show_login_form = function() {
      var login_form = Bm.get_ele('bm_login_form');
	  login_form.reset();
      Bm.show_overlay_popup(
        'popup_login_form',
        '',
        Bm.get_ele('bm_login_form'),
        {
          title: {
            'display' : 'none'
          },
          content: {
            'padding' : '0px',
            'width' : '670px'
          }
        }
      );
      login_form['user_name'].focus();
    };

    Bm.login_submit = function() {
      var login_form = Bm.get_ele('bm_login_form');
      var user = Bm.util_trim(login_form['user_name'].value);
      var pass = Bm.util_trim(login_form['password'].value);
	  var save = login_form['save_login'];
	  var cookie = save.checked ? 'on' : 'off';
      if (Bm.is_blank(user) || Bm.is_blank(pass)) {
        Bm.show_popup_message("Đăng nhập không thành công", "Thông báo", -1);
        return false;
      } else {
          jQuery.post("ajax.php?act=user&code=login_user",
            {
              'user': user,
              'pass': pass,
              set_cookie: cookie
            },
            function (msg) {
              if (msg == "success") {
                location.reload();
              } else {
                Bm.hide_popup('popup_login_form');
                Bm.show_popup_message("Đăng nhập không thành công", "Thông báo", -1);
              }
            }
          );
        return false;
      }
    };
	

	//set ussing mobile;
	Bm.set_using_mobile = function(id, mobileTypeId) {
		if (Bm.is_permission()) {
			Bm.ajax_popup('act=common&code=set_using_mobile&mobile_id=' + id + '&mobileTypeId='+mobileTypeId);	
		}
	};
	//set like mobile;
	
	Bm.like_mobile = function(id) {
		if (Bm.is_permission()) {
			Bm.ajax_popup('act=common&code=set_like_mobile&mobile_id=' + id);	
		}
	};
	
	//halm: fade image to hide loading
	Bm.fadeImageLoading = function(obj, speed, width, height) {
	  speed = speed ? speed : 400;
	  jQuery(obj).fadeTo(speed,1,function(){
		if(width){
		  jQuery(obj).parent().css({width:'auto'});
		}
		if(height){
		  jQuery(obj).parent().css({height:'auto'});
		}
	  });
	};
		
	// using to fix with for image;	
	Bm.fix_width_element = function(obj, limit) {
		var width = jQuery(obj).width(),
			height = jQuery(obj).height(),
			max_width = limit || 468;
		if (width > max_width) {
			var ratio = (height / width );
			var new_width = max_width;
			var new_height = (new_width * ratio);
			jQuery(obj).height(new_height).width(new_width);
		}
	};
	
	Bm.generate_price_input = function (textbox_id) {
		var input_string = document.getElementById(textbox_id).value;
		var sLength = input_string.length;
		var new_val = "";
		var str="0123456789";
		for(var j=0;j<sLength;j++)
		{
			if(str.indexOf(input_string.charAt(j))!=-1)
				new_val+=input_string.charAt(j);
		}
		var inputLength = new_val.length;
		input_string = new_val;
		new_val = "";
		var i = 0;
		for(var j=inputLength-1; j>=0; j--)
		{
			i++;
			if(i%3==0 && j>=1)
				new_val='.'+input_string.charAt(j)+new_val;
			else
				new_val=input_string.charAt(j)+new_val;
		}
		document.getElementById(textbox_id).value = new_val;
	};
