﻿//*
//* --- Copyright 2010 Public Edge Inc. and Fumia, Fumiaki Takahashi --
//*
//*
String.prototype._GetLocalDate= function()
//*
//*
	{
	var	as_array=this.match(/[0-9]+/g);
	var	as_d=new Date();
	var	as_t = Date.UTC(parseInt(as_array[0],10), 
				parseInt(as_array[1],10)-1,
				parseInt(as_array[2],10),
				parseInt(as_array[3],10),
				parseInt(as_array[4],10),
				parseInt(as_array[5],10));
	as_d.setTime(as_t);
	return as_d;
	}
//*
//*
String.prototype._toLocal= function()
//*
//*
	{
	return this._GetLocalDate().toLocaleString();
	}
//*
//*
UnescapeUTF8=function(str)
//*
//*
	{
	return str.replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig,function(s){
		var c=parseInt(s.substring(1),16);
		return String.fromCharCode(c<128?c:c<224?(c&31)<<6|parseInt(s.substring(4),16)&63:((c&15)<<6|parseInt(s.substring(4),16)&63)<<6|parseInt(s.substring(7),16)&63)
	})
	};
//*
//*
String.prototype._toInput = function()
//*
//*
	{
	var	as_val = this.replace(/\+/g, ' ');
	return UnescapeUTF8(as_val);
	}
//*
//*
String.prototype._toHTML = function()
//*
//*
	{
	var	as_i = 0;
	var	as_src = UnescapeUTF8(this.replace(/\+/g, ' '));
	var	as_dst = "";
	while(as_i < as_src.length)
		{
		var	as_c=as_src.charAt(as_i++);
		if( as_c == '&' )
			{
			as_dst += "&amp;";
			}
		else if( (as_c == ' ')&&(as_i==1) )
			{
			as_dst += "&nbsp;";
			}
		else if( as_c == '\n' )
			{
			as_dst += "<BR>";
			}
		else if( as_c == '<' )
			{
			as_dst += "&lt;";
			}
		else if( as_c == '>' )
			{
			as_dst += "&gt;";
			}
		else if( as_c == '\"' )
			{
			as_dst += "\"";
			}
		else if( as_c == '\'' )
			{
			as_dst += "\'";
			}
		else {as_dst += as_c; }
		}
	return as_dst;
	}
//*
//*
String.prototype.Trim = function() { return this.replace(/^\s+|\s+$/g, ""); }
//*
//*
String.prototype.truncateTailInWidth = function(maxWidth, ruler)
	{
	if (this.length == 0) return '';
	ruler.innerHTML = this;
	if (ruler.offsetWidth <= maxWidth) return this;
	var	as_pro = (((ruler.offsetWidth)+maxWidth)/maxWidth)^0;
	var	as_hi = this.length-1;
	var	as_lo = ((as_hi / as_pro)/2)^0;
	var	as_s;
	while( as_hi >= as_lo )
		{
		var	as_k = ((as_hi+as_lo)/2)^0;
		as_s = this.slice(0, as_k);
		ruler.innerHTML = as_s;
		if (ruler.offsetWidth <= maxWidth) 
			{
			as_lo = as_k + 1;
			}
		else { as_hi =  as_k - 1; }
		}
	return as_s;
	}
//*
//*
CLASS_LIST_LABEL = function(arg_dat, arg_max, arg_rul)
	{
	var	as_data = arg_dat._toInput();
	this.TAG_TITLE = "";
	this.LABEL = as_data.truncateTailInWidth(arg_max, arg_rul);
	if( as_data.length != this.LABEL.length )
		{
		this.TAG_TITLE =  arg_dat._toHTML();
		this.LABEL += "...";
		}
	this.LABEL = this.LABEL._toHTML();
	}

