/**
*	@name							Elastic
*	@descripton						Elastic is jQuery plugin that grow and shrink your textareas automatically
*	@version						1.6.11
*	@requires						jQuery 1.2.6+
*
*	@author							Jan Jarfalk
*	@author-email					jan.jarfalk@unwrongest.com
*	@author-website					http://www.unwrongest.com
*
*	@licence						MIT License - http://www.opensource.org/licenses/mit-license.php
*/

(function($){ 
	jQuery.fn.extend({  
		elastic: function() {
		
			//	We will create a div clone of the textarea
			//	by copying these attributes from the textarea to the div.
			var mimics = [
				'paddingTop',
				'paddingRight',
				'paddingBottom',
				'paddingLeft',
				'fontSize',
				'lineHeight',
				'fontFamily',
				'width',
				'fontWeight',
				'border-top-width',
				'border-right-width',
				'border-bottom-width',
				'border-left-width',
				'borderTopStyle',
				'borderTopColor',
				'borderRightStyle',
				'borderRightColor',
				'borderBottomStyle',
				'borderBottomColor',
				'borderLeftStyle',
				'borderLeftColor'
				];
			
			return this.each( function() {

				// Elastic only works on textareas
				if ( this.type !== 'textarea' ) {
					return false;
				}
					
			var $textarea	= jQuery(this),
				$twin		= jQuery('<div />').css({
					'position'		: 'absolute',
					'display'		: 'none',
					'word-wrap'		: 'break-word',
					'white-space'	:'pre-wrap'
				}),
				lineHeight	= parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'),
				minheight	= parseInt($textarea.css('height'),10) || lineHeight*3,
				maxheight	= parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE,
				goalheight	= 0;
				
				// Opera returns max-height of -1 if not set
				if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
					
				// Append the twin to the DOM
				// We are going to meassure the height of this, not the textarea.
				$twin.appendTo($textarea.parent());
				
				// Copy the essential styles (mimics) from the textarea to the twin
				var i = mimics.length;
				while(i--){
					$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
				}
				
				// Updates the width of the twin. (solution for textareas with widths in percent)
				function setTwinWidth(){
					var curatedWidth = Math.floor(parseInt($textarea.width(),10));
					if($twin.width() !== curatedWidth){
						$twin.css({'width': curatedWidth + 'px'});
						
						// Update height of textarea
						update(true);
					}
				}
				
				// Sets a given height and overflow state on the textarea
				function setHeightAndOverflow(height, overflow){
				
					var curratedHeight = Math.floor(parseInt(height,10));
					if($textarea.height() !== curratedHeight){
						$textarea.css({'height': curratedHeight + 'px','overflow':overflow});
					}
				}
				
				// This function will update the height of the textarea if necessary 
				function update(forced) {
					
					// Get curated content from the textarea.
					var textareaContent = $textarea.val().replace(/&/g,'&amp;').replace(/ {2}/g, '&nbsp;').replace(/<|>/g, '&gt;').replace(/\n/g, '<br />');
					
					// Compare curated content with curated twin.
					var twinContent = $twin.html().replace(/<br>/ig,'<br />');
					
					if(forced || textareaContent+'&nbsp;' !== twinContent){
					
						// Add an extra white space so new rows are added when you are at the end of a row.
						$twin.html(textareaContent+'&nbsp;');
						
						// Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height
						if(Math.abs($twin.height() + lineHeight - $textarea.height()) > 3){
							
							var goalheight = $twin.height()+lineHeight;
							if(goalheight >= maxheight) {
								setHeightAndOverflow(maxheight,'auto');
							} else if(goalheight <= minheight) {
								setHeightAndOverflow(minheight,'hidden');
							} else {
								setHeightAndOverflow(goalheight,'hidden');
							}
							
						}
						
					}
					
				}
				
				// Hide scrollbars
				$textarea.css({'overflow':'hidden'});
				
				// Update textarea size on keyup, change, cut and paste
				$textarea.bind('keyup change cut paste', function(){
					update(); 
				});
				
				// Update width of twin if browser or textarea is resized (solution for textareas with widths in percent)
				$(window).bind('resize', setTwinWidth);
				$textarea.bind('resize', setTwinWidth);
				$textarea.bind('update', update);
				
				// Compact textarea on blur
				$textarea.bind('blur',function(){
					if($twin.height() < maxheight){
						if($twin.height() > minheight) {
							$textarea.height($twin.height());
						} else {
							$textarea.height(minheight);
						}
					}
				});
				
				// And this line is to catch the browser paste event
				$textarea.bind('input paste',function(e){ setTimeout( update, 250); });				
				
				// Run update once when elastic is initialized
				update();
				
			});
			
        } 
    }); 
})(jQuery);

parseIntOld = parseInt
parseInt = function(str, base){return parseIntOld(str, base ? base : 10)}
var UHCfg = {BaseURL:'http://'+(window.location.href.split('/')[2])+'/',User : {}};
UH = {Storage : {Chk : function(){if(!localStorage || localStorage == undefined) return false;else return true;},
Set: function(k, v) {
  if(!localStorage || localStorage == undefined) return null;
  if (typeof v == "object" || typeof v == "array") {
    v = JSON.stringify(v);
  }
  localStorage.setItem(k, v);
  return true;
},Get : function(k) {
  if(!localStorage || localStorage == undefined) return null;
  var v = localStorage.getItem(k);
  if(v == null) return v;
  if (v[0] == "[" || v[0] == "{") {
    v = JSON.parse(v);
  }
  return v;
}}, Views : {}};
UH._Tpl = {};
UH.Tpl = function(tpl){
  if($(tpl).html()){UH._Tpl[tpl] = $(tpl).html(); $(tpl).remove();}
  return $(tpl).html() || UH._Tpl[tpl];
};

(function(g){g.fn.extend({elastic:function(){var h=["paddingTop","paddingRight","paddingBottom","paddingLeft","fontSize","lineHeight","fontFamily","width","fontWeight"];return this.each(function(){function i(c,j){curratedHeight=Math.floor(parseInt(c,10));a.height()!=curratedHeight&&a.css({height:curratedHeight+"px",overflow:j})}function k(){var c=a.val().replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/<|>/g,"&gt;").replace(/\n/g,"<br />"),j=b.html().replace(/<br>/ig,"<br />");if(c+"&nbsp;"!= j){b.html(c+"&nbsp;");if(Math.abs(b.height()+l-a.height())>3){c=b.height()+l;if(c>=d)i(d,"auto");else c<=e?i(e,"hidden"):i(c,"hidden")}}}if(this.type!="textarea")return false;var a=g(this),b=g("<div />").css({position:"absolute",display:"none","word-wrap":"break-word"}),l=parseInt(a.css("line-height"),10)||parseInt(a.css("font-size"),"10"),e=parseInt(a.css("height"),10)||l*3,d=parseInt(a.css("max-height"),10)||Number.MAX_VALUE,f=0;if(d<0)d=Number.MAX_VALUE;b.appendTo(a.parent());for(f=h.length;f--;)b.css(h[f].toString(), a.css(h[f].toString()));a.css({overflow:"hidden"});a.bind("keyup change cut paste",function(){k()});a.bind("blur",function(){if(b.height()<d)b.height()>e?a.height(b.height()):a.height(e)});a.live("input paste",function(){setTimeout(k,250)});k()})}})})(jQuery);

function UHBR2NL(id){
$(id).each(function(i){var str =$(this).html();str.replace(/\r\n/gi,'<br>').replace(/\n/gi,'<br>').replace(/\t/gi,'&nbsp;&nbsp;&nbsp;&nbsp;').replace(/\s\s/gi,'&nbsp;&nbsp;');});
}
function UHBBLikeParse(str){
return '<div class="notification information"><ul><li onclick="$(this).next().toggle();"><strong>顯示隱藏內容</strong></li><li style="display:none;">'+str+'</li></ul></div>';
}
function UHBBLike(str){
return str.replace(/\[like\]([\s\S.]*?)\[\/like\]/gim,function($0,$1){return UHBBLikeParse($1);});
}
function YTParse(url){
return url.match('http://(www.)?youtube|youtu\.be') ? url.split(/v\/|v=|embed\/|youtu\.be\//)[1].split(/[?&]|#/)[0] : url;

}

function UHBB2HTMLParse(str){
if(str == '') return '';
str=str.replace(/\r\n/g,'<br>').replace(/\n/g,'<br>').replace(/\t/g,'&nbsp;&nbsp;&nbsp;&nbsp;').replace(/\s\s/g,'&nbsp;&nbsp;').
replace(/\[nobb\]([\s\S.]*?)\[\/nobb\]/gim,function($0,$1){return $1.replace(/\[/g,'&#91;').replace(/\]/g,'&#93;');}).replace(/\[hr\]/gi,'<hr>');
var a =['h1','h2','h3', 'h4','h5','h6','address','pre','blockquote'];$.each(a,function(i){str = str.split('['+a[i]+']').join('<'+a[i]+'>').split('[/'+a[i]+']').join('</'+a[i]+'>');});
return UHBBLike(str)
.replace(/\[youtube\]([\s\S.]*?)\[\/youtube\]/gim,function($0,$1){return '<iframe src="http://www.youtube.com/embed/'+YTParse($1)+'" type="text/html" frameborder="0" height="390" width="480"></iframe>';})
.replace(/\[b\]([\s\S.]*?)\[\/b\]/gim,function($0,$1){return '<span style=\"font-weight: bold;\">'+$1+'</span>';})
.replace(/\[i\]([\s\S.]*?)\[\/i\]/gim,function($0,$1){return '<span style=\"font-weight: italic;\">'+$1+'</span>';})
.replace(/\[u\]([\s\S.]*?)\[\/u\]/gim,function($0,$1){return '<span style=\"text-decoration: underline;\">'+$1+'</span>';})
.replace(/\[(center|right|left)\]([\s\S.]*?)\[\/(center|right|left)\]/gim,function($0,$1,$2,$3){return '<div style="text-align:'+$1+';">'+$2+'</div>';})
.replace(/\[color=(\#[0-9A-Fa-f]{6}|[a-z]+)\]([\s\S.]*?)\[\/color\]/gim,function($0,$1,$2){return '<span style="color:'+$1+';">'+$2+'</span>';})
.replace(/\[bgcolor=(\#[0-9A-Fa-f]{6}|[a-z]+)\]([\s\S.]*?)\[\/bgcolor\]/gim,function($0,$1,$2){return '<span style="background:'+$1+';">'+$2+'</span>';})
.replace(/\[areabgcolor=(\#[0-9A-Fa-f]{6}|[a-z]+)\]([\s\S.]*?)\[\/areabgcolor\]/gim,function($0,$1,$2){return '<div style="background:'+$1+';">'+$2+'</div>';})
.replace(/\[size=([\.0-9]{1,3})\]([\s\S.]*?)\[\/size\]/gim,function($0,$1,$2){return '<span style="font-size:'+$1+'em;">'+$2+'</span>';})
.replace(/\[img\]([-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512})\[\/img\]/gim,function($0,$1){return '<img src="'+$1+'" alt=""/>';})
.replace(/\[img=(\S+?)\,(\S+?)\]([-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512})\[\/img\]/gim,function($0,$1,$2,$3){return '<img src="'+$3+'" width="'+$1+'" height="'+$2+'" alt=""/>';})
.replace(/\[email=([a-z0-9&\-_.]+?)\]([\w\-]+\.([\w\-\.]+\.)?[\w]+)\[\/email\]/gim,function($0,$1,$2){return '<a href="mailto:'+$1+'@'+$2+'">'+$1+'@'+$2+'</a>';})
.replace(/\[url=([-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512})\]([\s\S.]*?)\[\/url\]/gim,function($0,$1,$2){return '<a target="_blank" href="'+$1+'">'+$2+'</a>';})
.replace(/\[url\]([-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512})\[\/url\]/gim,function($0,$1){return '<a target="_blank" href="'+$1+'">'+$1+'</a>';})
.replace(/\[media=([0-9]{1,3}),([0-9]{1,3})\]([-;\/\?:@&=\+\$,_\.!~\*'\(\)%0-9a-z]{1,512})\[\/media\]/gim,function($0,$1,$2,$3){return '<a class="media {width: '+$1+', height: '+$2+'}" href="'+$3+'">'+$3+'</a>';})
.replace(/\[list\]([\s\S.]*?)\[\/list\]/gim,function($0,$1){return '<ul>'+$1.replace(/\[\*\]/g,'</li><li>').replace(/<\/li>/,'')+'</li></ul>';})
.replace(/\[listb\]([\s\S.]*?)\[\/listb\]/gim,function($0,$1){return '<ol>'+$1.replace(/\[\*\]/g,'</li><li>').replace(/<\/li>/,'')+'</li></ol>';});
}
function UHBB2HTML(id){
$(id).each(function(){
  $this = $(this);
  if($this.data('UHBBProcessed') != 'Yes'){
    $this.data('UHBBProcessed','Yes').html(UHBB2HTMLParse($this.html()));
  }
});
$(id+' .media').media();
}
jQuery.fn.UHBB2HTML = function(){
  return this.each(function() {
    $this = $(this);
    if($this.data('UHBBProcessed') != 'Yes'){
      $this.data('UHBBProcessed','Yes').html(UHBB2HTMLParse(($this.find('textarea').length == 1) ? $this.find('textarea').val() : $this.html()));
    }
  });
}
String.prototype.replaceMultiple = function(rep){
  var str = this;
  for(var x in rep){
    str = str.replace(x, rep[x]);
  }
  return str + '';
};
//html5 fix
document.createElement("article");
document.createElement("aside");
document.createElement("audio");
document.createElement("canvas");
document.createElement("command");
document.createElement("datalist");
document.createElement("details");
document.createElement("embed");
document.createElement("figcaption");
document.createElement("figure");
document.createElement("footer");
document.createElement("header");
document.createElement("hgroup");
document.createElement("keygen");
document.createElement("mark");
document.createElement("meter");
document.createElement("nav");
document.createElement("output");
document.createElement("progress");
document.createElement("rp");
document.createElement("rt");
document.createElement("ruby");
document.createElement("section");
document.createElement("source");
document.createElement("summary");
document.createElement("time");
document.createElement("video");
UHViewPass = function(id){
var i = $(id).prev('input');
  var v = i.val();
  var c = i.data('cookie');
  var u = i.data('url');
  if(v != '' && c){
    $.Cookie(c, v);
    location.reload();
  }
  return false;
}

jQuery.Cookie = function (key, value, options){
  if(arguments.length < 2){//get
    var allcookies = {};
    var val = '';
    if (document.cookie) {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
        var cookie = jQuery.trim(cookies[i]);
        if (arguments.length == 0) {
          var keyPos = cookie.indexOf('=');
          allcookies[ cookie.substr(0, keyPos)] = decodeURIComponent(cookie.substr(keyPos+1));
        } else if (cookie.substr(0, key.length + 1) == (key + '=')) {
          val = cookie.substr(key.length + 1);
          return val == '' ? '' : decodeURIComponent(val);
          break;
        }
      }
    }
    if(arguments.length == 1) return '';
    return allcookies;
  }
  options = jQuery.extend({expires : -1, path : '/', domain : window.location.href.split('/')[2], secure : ''}, options);
  if(options.domain != '127.0.0.1') options.domain = '.uhhooh.com';
  var time = new Date();
  time.setTime(time.getTime() + options.expires*1000);
  return document.cookie = encodeURIComponent(key)+'='+encodeURIComponent(String(value))+
  ((value !== null && value != '' && options.expires == -1) ? '' : '; expires=' + time.toUTCString())+
  '; path=' + options.path+
  '; domain=' + options.domain+
  '; '+options.secure;
};
jQuery.UHColSet = function(L,M,R){
  if(L == '') $('#UHSideLeft').hide();
  else{
    $('#UHSideLeft').show();
    $('#UHSideLeft').attr('class',L);
  }
  if(L == '') $('#UHMain').hide();
  else{
    $('#UHMain').show();
    $('#UHMain').attr('class',M);
  }
  if(L == '') $('#UHSideRight').hide();
  else{
    $('#UHSideRight').show();
    $('#UHSideRight').attr('class',R);
  }
}


var sid = $.Cookie('SID');
if(sid && sid != null && sid !='.'){
  $.get(UHCfg.BaseURL+'svc.php?m=UserSIDGet&SID='+sid, function(d) {
    eval("d = "+d+";");
    if(d['ErrorStr'] == ''){
      UHCfg.User = d.Data;
      UHCfg.User.UserLogin = 1;
      $('#UHLogout').show();
      $('#UHLogin').hide();$('#UHRegister').hide();
    }else{
      $.Cookie('SID','');
      UHCfg.User.UserLogin = 0;
      $('#UHLogout').hide();
      $('#UHLogin').show();$('#UHRegister').show();
    }
  });
}
jQuery.fn.LNGet = function(key, rep){
  var v = _LN[key];
  if(!v) return key;
  else if(rep == undefined) return v;
  else return v.replaceMultiple(rep) + '';
}
jQuery.fn.HTMLEsc = function(str){
  return str.replace('<','&lt;').replace('>','&gt;');
}
jQuery.fn.LN = function(){
  return this.each(function() {
    var obj = $(this);
    var v = _LN[obj.data('name')];
    obj.text(v && v != '' ? v : obj.data('name'));

    if(obj.data('options') && obj.data('options').length) obj.text(obj.text().replaceMultiple($.parseJSON(obj.data('options'))));
  });
}

Date.prototype.d = function() {
  return this.getDate() > 9 ? this.getDate() : '0'+this.getDate();
}
Date.prototype.m = function() {
  return this.getMonth() > 8 ? this.getMonth()+1 : '0'+(this.getMonth()+1);
}
Date.prototype.ym = function() {
  return this.getFullYear() + '-'+ (this.getMonth() > 8 ? this.getMonth()+1 : '0'+(this.getMonth()+1));
}
Date.prototype.ymd = function() {
  return this.ym()+'-'+this.d();
}
jQuery.pymd = function(str) {
  return new Date(str.substr(0,4), parseInt(str.substr(5,2), 10)-1, parseInt(str.substr(8,2), 10));
}
Date.prototype.ld = function(y, m ,d){
  if(y == undefined) y = this.getFullYear();
  if(m == undefined) m = this.getMonth()+1;
  var t = [31,28,31,30,31,30,31,31,30,31,30,31],
  ld = t[parseInt(m) - 1], ld = parseInt(y)%4 == 0 && ld == 28 ? 29 : ld;
  return d == undefined || parseInt(d) >= ld ? ld : parseInt(d);
}
jQuery.fn.Cal = function(cfg){
  var t = $(this),d = new Date(); def ={d : new Date(), date: d.ymd(), day : $.pymd(d.ym()+'-01').getDay(), days: d.ld(), th:['S','M','T','W','T','F','S'], URL: '',TARGET:''};
  d = $.extend(def, cfg);
  d.today = d.d.getDate();
  if(!t.data('date')) t.data('date', d.date);
  var e = { s : d,
    html : function(){
      var dd= t.data('date') || e.s.date;
      if(t.data('cal')) e.s = $.extend(e.s, typeof t.data('cal') == 'string' ?  JSON.parse(t.data('cal')) : t.data('cal'));
      if(d && dd.length == 10){
	e.s.date = dd;
	e.s.d =  $.pymd(dd);
	e.s.days = e.s.d.ld();e.s.day = $.pymd(e.s.d.ym()+'-01').getDay();
	e.s.today = e.s.d.getDate();
      }
      
      var o = '<caption>'+e.s.d.toDateString()+'</caption><thead><tr>';
    $.each(e.s.th, function(){o= o+'<th>'+this+'</th>';});
    o=o+'</tr></thead><tbody><tr>';
    for(var start = 0; start < e.s.day; start++){
      o=o+'<td></td>';
    }

    for(var i = 1; i <= e.s.days; i++){
      if(start >= 7){
	o+= '</tr><tr>';
	start = 0;
      }
      o=o+$.fn.tpl(UH.Tpl(e.s.TPL), {day : i, today : e.s.today, date : e.s.d.ym()+'-'+(i > 9 ? i : '0'+i)});
      start++;
    }
    for(var i = start; i <= 6; i++){
      o=o+'<td></td>';
    }
    var x = new Date();
    x.setTime($.pymd(e.s.d.getFullYear()+'-'+e.s.d.m()+'-01').getTime() - 86400000);
    e.s.p = x.ym();
    x.setTime($.pymd(e.s.d.getFullYear()+'-'+e.s.d.m()+ '-'+e.s.days).getTime() + 86400000);
    e.s.n = x.ym();
    t.html(o+'</tr></tbody><tfoot><tr><td colspan="3" class="prev"><a href="#" title="" data-month="'+
		 e.s.p+'">&laquo;</a></td><td></td><td colspan="3" class="next"><a href="#" title="" data-month="'+
		 e.s.n+'">&raquo;</a></td></tr></tfoot>').data('date', e.s.date);
    t.find('.next a').click(e.render);t.find('.prev a').click(e.render);
    
    e.get();
    },
    render : function(ev){ev.preventDefault();
      var d = $(this).parents('table').find('td.today').data('date'), m = $(this).data('month')+ d.substr(7,3);
      $(this).parents('table').data('date',m);
      e.html();
      return false;
    },
    get : function(){
      var uid = UHGlobalVarPublic.UHUID ||  UHGlobalVar.UHSELFUID;
      $.ajax({
	type: 'POST',
	url: UHCfg.BaseURL + 'svc.php?'+e.s.URL.replace(/\{UID\}/, uid).replace(/\{MONTH\}/, e.s.d.ym()),
	data: {FrmData : ''},
	success: function(d){
	  if(d.ErrorStr != '') alert($.fn.LNGet(d.ErrorStr));
	  else{
	    if(d.Data.length > 0){
	      $.fn.tpl(UH.Tpl(e.s.TPLENTRY), {t : t, data : d.Data, target : e.s.TARGET});return;
	    }
	  }
	},
	dataType: 'json'
	});
    }
  };
  e.html();
}
jQuery.fn.PrettyTime = function(){
  timeampm = function(d){
    if(d.getMinutes() == d.getHours() == 0) return '';
      var min = d.getMinutes() < 10 ? '0'+d.getMinutes() : d.getMinutes();
      return d.getHours() >= 12 ? _LN.TimePM.replace("%T%",(d.getHours() - 12) + ":"+ min)
      : _LN.TimeAM.replace("%T%",d.getHours() + ":"+ min);
  }
  return this.each(function() {
    $this = $(this);
    var d = $this.attr("datetime");
    if((d == '' || d == null) && $this.data("datetime")) d = $this.data("datetime");
    if(d == '' || d == null) return;
    else if (d.length == 14) d = d.substr(0,4)+'-'+d.substr(4,2)+'-'+d.substr(6,2)+' '+d.substr(8,2)+':'+d.substr(10,2)+':'+d.substr(4,2);
    var s = '';
    dstr = d;
    d = new Date(Date.parse(d.replace(' ','T')+'Z'));
    if(!d || !d.getTime()){
      d = new Date(Date.parse(dstr.replace('-','/')));
      if(!d || !d.getTime()) return;
    }
    var diff = ((new Date()).getTime()- d.getTime())/1000;
    if(diff > 0){
      if(diff < 60) s = _LN.TimeSecAgo.replace("%T%", Math.floor(diff).toString());
      else if(diff < 120) s = _LN.TimeMinAgo.replace("%T%", Math.floor(diff/60).toString());
      else if(diff < 3600) s = _LN.TimeMinsAgo.replace("%T%", Math.floor(diff/60).toString());
      else if(diff < 7200) s = _LN.TimeHrAgo.replace("%T%", Math.floor(diff/3600).toString());
      else if(diff < 86400) s = _LN.TimeHrsAgo.replace("%T%", Math.floor(diff/3600).toString());
      else if(diff < 86400*2) s = _LN.TimeYesterday.replace("%T%", timeampm(d));
      else s = _LN.TimeOther.replace("%T%", d.toLocaleDateString()+" "+timeampm(d));
    }else{
      diff = 0 - diff;
      if(diff < 60) s = _LN.TimeSec.replace("%T%", Math.floor(diff).toString());
      else if(diff < 120) s = _LN.TimeMin.replace("%T%", Math.floor(diff/60).toString());
      else if(diff < 3600) s = _LN.TimeMins.replace("%T%", Math.floor(diff/60).toString());
      else if(diff < 7200) s = _LN.TimeHr.replace("%T%", Math.floor(diff/3600).toString());
      else if(diff < 86400) s = _LN.TimeHrs.replace("%T%", Math.floor(diff/3600).toString());
      else if(diff < 86400*2) s = _LN.TimeTomorrow.replace("%T%", timeampm(d));
      else s = _LN.TimeOther.replace("%T%", d.toLocaleDateString()+" "+timeampm(d));
    }
    $this.text(s);
  });
};
jQuery.fn.serializeJSON=function() {
  var j = {};
  jQuery.map($(this).serializeArray(), function(n, i){j[n['name']] = n['value'];});
  return j;
};
jQuery.UHDataVar = function(d){
  for(var x in UHGlobalVarPublic){
    if(x.substr(0,2) == 'UH') eval("d = d.replace(/\{"+x+"\}/g, UHGlobalVarPublic[x]);");
  }
  for(var x in UHGlobalVar){
    if(x.substr(0,2) == 'UH') eval("d = d.replace(/\{"+x+"\}/g, UHGlobalVar[x]);");
  }
  return d;
}
jQuery.UHTplLoad = function(url,target,action,fn, fn2,fn3){
  if(target == undefined || target == '' || $(target).length == 0) target = '#UHSideLeft';
  if(action != undefined && action != '' && action != 'append' && action != 'prepend'){
    $(target).html('<div class="contentCenter"><img src="/images/loading.gif"/></div>');
  }
  $.get(url, function(data) {
    data = jQuery.UHDataVar(data);
    if(fn != undefined && fn != '') fn();
    if(action == undefined || action == '' || action == 'append') $(target).append(data);
    else if(action == 'prepend') $(target).prepend(data);
    else{
      $(target).html('');
      $(target).append(data);
    }
    $(target).find('.tpl').each(function(){
      UH._Tpl['#'+$(this).attr('id')] = $(this).html();
      $(this).remove();});
    if(fn2 != undefined && fn2 != '') fn2();
    if(fn3 != undefined && fn3 != '') fn3();
  });
}
jQuery.UHWidgetLoad = function(id,target,action,fn, fn2,fn3){
  if($('#UHWidget'+id).length == 0){
    jQuery.UHTplLoad(UHCfg.BaseURL+'widget.php?w='+id,target,action,fn, fn2,fn3);
  }else{
    $('#UHWidget'+id).show();
    if(fn2 != undefined && fn2 != '') fn2();
  }
}

jQuery.UHBlockLoad = function(id,target,action,fn, fn2,fn3){
  if($('#UHWidget'+id).length == 0){
    jQuery.UHTplLoad(UHCfg.BaseURL+'block.php?m='+id,target,action,fn, fn2,fn3);
  }else{
    $('#UHWidget'+id).show();
    if(fn2 != undefined && fn2 != '') fn2();
  }
}
jQuery.Age = function(id){
  var b = $(id).data('birthday');
  if($.trim(b).length < 10) return '';
  var d = new Date();
  var age = d.getFullYear() - parseInt(b.substr(0,4));
  var d1 = d.getFullYear() + (d.getMonth()+1)/12 + d.getDate()/365;
  var d2 = d.getFullYear() + parseInt(b.substr(5,2))/12 + parseInt(b.substr(8,2))/365;
  return (d1 < d2) ? age-1 : age;
}
jQuery.FormFill = function(id,data){
  for(var x in data){
    $(id +' input[name='+x+'],select[name='+x+'],textarea[name='+x+']').val(data[x]);
    //if($(id+x).length > 0) $(id+x).val(data[x]);
  }
}
jQuery.ZeroPad = function(v,n){
  var i = v.length;
  while(i <= n){
    v = '0'+v;
    n++;
  }
  return v;
}
jQuery.DateZeroRemove = function(v){
  return v.substr(0,1) == '0' ? v.substr(1,1) : v;
}
jQuery.SelectBuild = function(t){
  var o = '';
  var v = '';
  for(var i = 1; i <= t; i++){
    v = i < 10 ? '0'+i : i;
    o += '<option value="'+v+'">'+v+'</option>';
  }
  return o;
}
jQuery.SelectDay = function(id){
  $(id).html($.SelectBuild(31));
}
jQuery.SelectMonth = function(id){
  $(id).html($.SelectBuild(12));
}

jQuery.fn.tpl = function(str,data) {
  var c  = {evaluate    : /<%([\s\S]+?)%>/g,interpolate : /<%=([\s\S]+?)%>/g,escape      : /<%-([\s\S]+?)%>/g};
  var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
      'with(obj||{}){__p.push(\'' +
      str.replace(/\\/g, '\\\\')
      .replace(/'/g, "\\'")
      .replace(c.escape, function(match, code) {
        return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
      })
      .replace(c.interpolate, function(match, code) {
        return "'," + code.replace(/\\'/g, "'") + ",'";
      })
      .replace(c.evaluate || null, function(match, code) {
        return "');" + code.replace(/\\'/g, "'")
        .replace(/[\r\n\t]/g, ' ') + "__p.push('";
      }).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/\t/g, '\\t')
      + "');}return __p.join('');";
    var func = new Function('obj', tmpl);
    return data ? func(data) : func;
  };

$(document).ready(function() {
  $("tr:even").addClass("even");
  $(".canhide").click(function() {
    $(this).fadeOut(700);
  });
  $('#UHLogout').click(function(event){
    event.preventDefault();
    $.get(UHCfg.BaseURL+'svc.php?m=Logout',function(d){eval("d = "+d+";");
      if(d.ErrorStr == ''){
	$.Cookie('SID','');
	if(location.href != UHCfg.BaseURL) location.href = UHCfg.BaseURL;
	else location.reload();
      }
    });
    return false;
  });

$('time').PrettyTime();
setInterval(function(){$('time').PrettyTime();}, 1000);
});

