//------------------------------------------------
// 汎用ライブラリ
// LunarNight Lab.
// http://www.ln-lab.net/
//------------------------------------------------

var Class = {
	create : function(extent,func){
		var classObj = function(){
			if (this.init){
				this.init.apply(this,arguments);
			}
		};
		if (func){
			classObj.prototype = new extent();
			for(var i in func){
				classObj.prototype[i] = func[i];
			}
		}else{
			classObj.prototype = extent;
		}
		return(classObj);
	},
	// base = Object or Array （Arrayはちょっと重いから多用は厳禁！）
	createEx: function(type,func){
		var obj = null;
		if (type == 'Array'){ // Array
			obj = function(){
				var t = new Array();
				for(var i in func){
					t[i] = func[i];
				}
				if (t.init){ t.init.apply(t,arguments);}
				return(t);
			};
		}else{ // Object
			obj = function(){
				if (this.init){ this.init.apply(this,arguments);}
			};
			obj.prototype = func;
		}
		return(obj);
	}
};

var Escape = {
	tagDic : {
		'&' : '&amp;',
		'<' : '&lt;',
		'>' : '&gt;',
		"\r": '',
		"\n": '<br/>',
		' ' : '&nbsp;'
	},
	uriDic : {
		'+' : '%2b',
		'=' : '%3d',
		'&' : '%26'
	},
	ucsDic : {
		'%' : '%u0025',
		'<' : '%u003c',
		'>' : '%u003e',
		'=' : '%u003d',
		'&' : '%u0026',
		'+' : '%u002b',
		' ' : '%u0020',
		"\n": '%u000a',
		"\r": ''
	},
	tag : function(str){
		if (str == null){ return('');       }
		if (typeof(str) != 'string'){ str = String(str);}
		var out = str.replace(/([&<>\r\n ])/g,function($1){ return(Escape.tagDic[$1]) });
		return(out);
	},
	uri : function(str){
		if (str == null){ return('');       }
		if (typeof(str) != 'string'){ str = String(str);}
		var out = str.replace(/([\+=&])/g,function($1){ return(Escape.uriDic[$1]) });
		return(out);
	},
	ucs : function(str){
		if (str == null){ return('');       }
		if (typeof(str) != 'string'){ str = String(str);}
		var out = str.replace(/([%<>=&\+ \n\r])/g,function($1){ return(Escape.ucsDic[$1]) });
		return(out);
	}
}

function setClass(obj,name){
	obj.setAttribute('className',name);
	obj.setAttribute('class',name);
}
function setStyle(obj,styleName,styleVal){
	if (styleName == 'opacity'){
		var oVal = styleVal*100;
		obj.style['filter'] = 'alpha(opacity='+oVal+')';
	}
	obj.style[styleName] = styleVal;
}

function getUTC(){
	var today = new Date();
	return(Math.floor(today.getTime()/1000));
}


function dspError(title,msg,opt){
	if (opt == null){ opt = '';              }
	if (msg == null){ msg = 'メッセージなし';}
	window.alert('エラー:'+title+"\n"+msg+"\n"+opt);
}
function dspMsg(title,msg,opt){
	if (title == null){ title = '(不明)';      }
	if (opt   == null){ opt   = '';            }
	if (msg   == null){ msg = 'メッセージなし';}
	
	window.alert(title+"\n"+msg+"\n"+opt);
}

function preventEvent(e){
	if(e.preventDefault){
		e.preventDefault();
	}else{
		e.returnValue = false;
		e.cancelBubble = true;
	}
	return(false);
}


