function contains(obj, testNode){
	if(!testNode) return false;
	do{
		if(testNode == obj) return true;
		testNode = testNode.parentNode;
	} while (testNode);
	return false;
}
/*
function cumulativeOffset(element) {
	var valueT = 0;
	var valueL = 0;
	do {
		valueT += element.offsetTop  || 0;
		valueL += element.offsetLeft || 0;
		element = element.offsetParent;
	} while (element);
	return [valueL, valueT];
}
*/
//  座標取得
var cumulativeOffset;

function is_getBoundingClientRect(){
    var dummy = document.createElement("div");
    return (dummy.getBoundingClientRect) != undefined;
}

if(is_getBoundingClientRect()){
	cumulativeOffset =   function(el){
		var pos		= el.getBoundingClientRect();
		var html    = document.documentElement;
		var body    = document.body;
		return  [(pos.left +   (body.scrollLeft||html.scrollLeft)  -   html.clientLeft)
				,(pos.top  +   (body.scrollTop||html.scrollTop)    -   html.clientTop)];
	};
} else{
	if(window.opera){
		cumulativeOffset = function(el){
			var ex  =   0;
			var ey  =   0;
			do{ 
				ex  +=  el.offsetLeft;
				ey  +=  el.offsetTop;
			} while(el = el.offsetParent);
			return[ex, ey];
		};
	} else{
		cumulativeOffset =   function(target){
			var ex  =   0;
			var ey  =   0;
			//
			var el  =   target;
			do{ 
				ex  +=  el.offsetLeft   ||  0;
				ey  +=  el.offsetTop    ||  0;
			} while(el = el.offsetParent);
			//  要素内スクロール対応
			var el  =   target;
			var bd  =   document.body;
			do{
				ex  -=  el.scrollLeft   ||  0;
				ey  -=  el.scrollTop    ||  0;
				el  =   el.parentNode;
			} while(el!=bd);
			return[ex,ey];
		};
	}
}

var mousePositionX = 0;
var mousePositionY = 0;
function getMousePositionListener(){
	e = windowEvent();
	var mp = getMousePosition(e);
	mousePositionX = mp[0];
	mousePositionY = mp[1];
}

function getMousePosition(){
	e = windowEvent();
	if (!e.pageX) e.pageX = e.clientX + document.body.scrollLeft;
	if (!e.pageY) e.pageY = e.clientY + document.body.scrollTop;
	var x = e.pageX;
	var y = e.pageY;
	if (document.all){
		x += document.documentElement.scrollLeft;
		y += document.documentElement.scrollTop;
	}
	return [x, y];
}

// --------------------
//   Object
// --------------------
// Return Object IE/Other Compatible
function getObj(id, target){
	if(isString(id)){
		if(id.match(/^prev(.+)/)){
			if(!target) target = windowEvent().currentTarget || windowEvent().srcElement;
			return upSearchTagName(target, RegExp.$1);
		} else if(id.match(/^next(.+)/)){
			if(!target) target = windowEvent().currentTarget || windowEvent().srcElement;
			return downSearchTagName(target, RegExp.$1);
		} else if(id.match(/^parent(.+)/)){
			if(!target) target = windowEvent().currentTarget || windowEvent().srcElement;
			return parentsSearchTagName(target.parentNode, RegExp.$1);
		} else{
			return document.all && document.all(id) || document.getElementById && document.getElementById(id);
		}
	} else{
		return id;
	}
}

function getElementsByClassName2(obj, classname, tagname){
	var elements = obj.getElementsByTagName((tagname)?tagname:"*");
	var targets = Array();
	for(var i=0; i<elements.length; i++){
		if(getClass(elements[i]).match(classname)){
			targets.push(elements[i]);
		}
	}
	return targets;
}

// --------------------
//   Event
// --------------------
// EventListener IE/Other Compatible
function addEvent(eventTarget, eventName, func){
	if(eventTarget.addEventListener){
		eventTarget.addEventListener(eventName, func, false);
	} else if(window.attachEvent){
		eventTarget.attachEvent('on'+eventName, func);
	}
}

function removeEvent(eventTarget, eventName, func){
	if(eventTarget.removeEventListener){
		eventTarget.removeEventListener(eventName, func);
	} else if(window.detachEvent){
		eventTarget.detachEvent('on'+eventName, func);
	}
}

function getClass(e){
	var c;
	if(getBrowserName() == "Internet Explorer" && getBrowserVersion() <= 7) c = e.getAttribute("className");
	else c = e.getAttribute("class");
	return (!c)?"":c;
}

function setClass(e, c){
	if(getBrowserName() == "Internet Explorer" && getBrowserVersion() <= 7) return e.setAttribute("className", c);
	else return e.setAttribute("class" , c);
}

function addClass(e, c){
	if(!getClass(e).match(c)) c = getClass(e) + " " + c;
	else c = getClass(e);
	setClass(e, c);
}

function removeClass(e, c){
	if(getClass(e)) setClass(e, getClass(e).replace(c, ""));
}

function setOpacity(obj, n){
	if(obj.nodeName.toUpperCase() != "TR"){
		// IE Filter Border and ClearType problem
		var browser = getBrowserName();
		var version = getBrowserVersion();
		if(n < 1 || browser != "Internet Explorer" || version != 8){
			obj.style.MozOpacity = n;
			obj.style.filter = "alpha(opacity: " + (n * 100) + ")";
			obj.style.opacity = n;
			obj.style.zoom = "1";
		}
		
		if(n >= 1){
			obj.style.filter = "";
			if(document.all) obj.removeAttribute('filter');
			else{
				obj.style.MozOpacity = n;
				obj.style.opacity = n;
			}
			obj.style.visibility = 'hidden';
			obj.style.visibility = 'visible';
			obj.style.zoom = "1";
		}
	} else{
		// IE Filter TR problem
		var ths = obj.getElementsByTagName("TH");
		var tds = obj.getElementsByTagName("TD");
		for(var i=0; i<ths.length; i++) setOpacity(ths[i], n);
		for(var i=0; i<tds.length; i++) setOpacity(tds[i], n);
	}
}

function getOpacity(obj){
	return (isNaN(Number(obj.style.MozOpacity))?0:Number(obj.style.MozOpacity));
}

function getCookie(key, tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}

function registCookie(key, val, tmp) {
	if(document.all){
		var day = new Date();
		day.setYear(day.getYear() + 10);
		document.cookie = key + "=" + escape(val) + "; path=/; " + "expires=" + day.toGMTString() + ";";
	} else{
		tmp = key + "=" + escape(val) + "; ";
		tmp += "path=/; ";
		tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
		document.cookie = tmp;
	}
}

function clearCookie(key) {
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}


//Post condition: if childNodes[n] is refChild, than childNodes[n+1] is newChild.
function DOMNode_insertAfter(newChild,refChild){
  var parent=refChild.parentNode;
  if(parent.lastChild==refChild) return parent.appendChild(newChild);
  else return parent.insertBefore(newChild,refChild.nextSibling);
}



function registCurrentLocation(){
	registCookie("afitLocation", location.href);
}

function getByte(text){
	count = 0;
	for (i=0; i<text.length; i++){
		n = escape(text.charAt(i));
		if (n.length < 4) count++; else count+=2;
	}
	return count;
}

function parentsSearchTagName(obj, tagname){
	while(obj && obj.tagName && obj.tagName.toUpperCase() != tagname.toUpperCase()){
		obj = obj.parentNode;
	}
	if(obj && obj.parentNode)	return obj;
	else						return false;
}

function nextSearchTagName(obj, tagname){
	do{
		obj = obj.nextSibling;
	} while(obj && (!obj.tagName || obj.tagName.toUpperCase() != tagname.toUpperCase()));
	return obj;
}

function downSearchTagName(obj, tagname){
	do{
		if(!obj.nextSibling){
			while(obj && !obj.nextSibling){
				obj = obj.parentNode;
			}
		}
		obj = obj.nextSibling;
	} while(obj && (!obj.tagName || obj.tagName.toUpperCase() != tagname.toUpperCase()));
	return obj;
}

function upSearchTagName(obj, tagname){
	do{
		while(obj && !obj.previousSibling){
			obj = obj.parentNode;
		}
		obj = obj.previousSibling;
		while(obj && obj.lastChild){
			if(obj.nodeName.toUpperCase() == tagname.toUpperCase()) return obj;
			obj = obj.lastChild;
		}
	} while(obj && obj.nodeName.toUpperCase() != tagname.toUpperCase());
	return obj;
}

function checkAll(id, isCheck){
	var formObj = document.forms[id];
	var iframes = document.getElementsByTagName('iframe');
	for(var i=0; i<iframes.length; i++){
		if(formObj) break;
		if(document.all) formObj = iframes[i].Document.forms[0];
		else formObj = iframes[i].contentDocument.forms[id];
	}
	for(var i=0; i < formObj.elements.length; i++){
		if(formObj.elements[i].type == "checkbox"){
			formObj.elements[i].checked = isCheck;
		}
	}
}

function checkAllTable(){
	var e			= windowEvent();
	var target		= e.target || e.srcElement;
	var tableObj	= parentsSearchTagName(target, "TABLE");
	var inputs		= tableObj.getElementsByTagName("INPUT");
	for(var i=0; i < inputs.length; i++){
		if(inputs[i].type == "checkbox"){
			inputs[i].checked = target.checked;;
		}
	}
}

function cancelClick(){
	e = windowEvent();
	if(e.preventDefault){
//		e.preventDefault();
	} else{
//		e.returnValue = false;
	}
	if(e.stopPropagation){
		e.stopPropagation();
	} else if(typeof(e.cancelBubble) !== 'undefined'){
		e.cancelBubble = true;
	}
}


function incTime(h, m1, m2){
	sumTime(h, m1, m2, 1);
}
function decTime(h, m1, m2){
	sumTime(h, m1, m2, -1);
}
function sumTime(h, m1, m2, n){
	var hObj	= document.getElementById(h);
	var m1Obj	= document.getElementById(m1);
	var m2Obj	= document.getElementById(m2);
	var t		= parseInt(hObj.selectedIndex * 60 + m1Obj.selectedIndex * 10 + m2Obj.selectedIndex);
	t = (t + n + 60 * 24) % (60 * 24);
	hObj.selectedIndex = Math.floor(t / 60) % hObj.options.length;
	m1Obj.selectedIndex = Math.floor(t / 10) % m1Obj.options.length;
	m2Obj.selectedIndex = Math.floor(t % 10) % m2Obj.options.length;
}

function incDate(y, m, d){
	sumDate(y, m, d, 1);
}
function decDate(y, m, d){
	sumDate(y, m, d, -1);
}
function sumDate(y, m, d, n){
	var yObj	= (y)?document.getElementById(y):'';
	var mObj	= (m)?document.getElementById(m):'';
	var dObj	= (d)?document.getElementById(d):'';
	
	if(dObj) dObj.selectedIndex = (dObj.selectedIndex + n + dObj.options.length) % dObj.options.length;
	
	if(!dObj
	|| n > 0 && dObj.selectedIndex == 0
	|| n < 0 && dObj.selectedIndex == dObj.options.length-1){
		mObj.selectedIndex = (mObj.selectedIndex + n + mObj.options.length) % mObj.options.length;
		if(!dObj && !mObj
		|| n > 0 && mObj.selectedIndex == 0
		|| n < 0 && mObj.selectedIndex == mObj.options.length-1){
			yObj.selectedIndex = (yObj.selectedIndex + n + yObj.options.length) % yObj.options.length;
		}
	}
}


function isArray(array){
  return !(
    !array || 
    (!array.length || array.length == 0) || 
    typeof array !== 'object' || 
    !array.constructor || 
    array.nodeType || 
    array.item 
  );
}


function curve1(value, curve){
	return Math.pow(value, curve);
}

function curve2(value, curve){
	if(value == 1) return 1;
	return Math.sin(curve1(value, curve)) * 1.188395106;
}

function switchObjs(){
	var isAnimation = arguments[0];
	var btnObj		= arguments[1];
	var objs		= new Array();
	for(var i=2; i<arguments.length; i++){
		objs.push(arguments[i]);
	}
	switchObjs2(isAnimation, btnObj, objs);
}

function switchObjs2(){
	var isAnimation = arguments[0];
	var btnObj		= arguments[1];
	var objs		= arguments[2];
	var showObj;
	if(objs[0]) showObj = getObj(objs[0], btnObj);
	for(var i=1; i<objs.length; i++){
		if(objs[i] != ""){
			var obj = getObj(objs[i], btnObj);
			obj.style.display = "none";
		}
	}
	
	if(showObj){
//		showObj.style.display = "block";
		showObj.style.display = "";
		var tds = showObj.getElementsByTagName("TD");
		for(var i=0; i<tds.length; i++){
			tds[i].style.display = "table-cell";
		}
		if(isAnimation){
			if(isAnimation == "slide"){
				var h	= getNaturalHeight(showObj);
				var t	= h / 1500 + 0.1;
				showObj.style.overflow = "hidden";
				var showAnimation = new easyAnimation(showObj, 'height', 0, h, t, 0.8, bind(switchObjsEnd, [showObj]));
				showAnimation.start();
			} else{
				var showAnimation = new easyAnimation(showObj, 'opacity', 0, 1, 0.5, 1);
				showAnimation.start();
			}
		}
	}
	
	if(btnObj && btnObj.nodeType == 1 && btnObj.nodeName.toUpperCase() == "LI"){
		var ul	= parentsSearchTagName(btnObj, "UL");
		var lis	= ul.getElementsByTagName("LI");
		for(var i=0; i<lis.length; i++){
			if(lis[i] == btnObj){
				addClass(lis[i], "on");
			} else{
				removeClass(lis[i], "on");
			}
		}
	}	
}

function switchObjsEnd(obj){
	obj.style.overflow	= "";
	obj.style.height	= "";
}

function switchObjsCheck(){
	var isAnimation = arguments[0];
	var btnObj		= arguments[1];
	var id			= arguments[2];
	if(btnObj.checked){
		switchObjs(isAnimation, btnObj, id);
	} else{
		switchObjs(isAnimation, btnObj, '', id);
	}
}

function switchObjsRadio(){
	var isAnimation = arguments[0];
	var btnObj		= arguments[1];
	var ids			= arguments[2];
	var form		= parentsSearchTagName(btnObj, "FORM");
	var radios		= form[btnObj.name];
	for(var i=0; i<radios.length; i++){
		if(radios[i].checked){
			ids.unshift(ids.splice(i,1));
			break;
		}
	}
	switchObjs2(isAnimation, btnObj, ids);
}

function switchObjsSelect(){
	var isAnimation = arguments[0];
	var btnObj		= arguments[1];
	var id			= arguments[btnObj.selectedIndex + 2];
	var objs		= new Array();
	for(var i=2; i<arguments.length; i++){
		if(i == btnObj.selectedIndex + 2)	objs.unshift(arguments[i]);
		else								objs.push(arguments[i]);
	}
	switchObjs2(isAnimation, btnObj, objs);
}

function switchDefine(){
	var e		= windowEvent();
	var target	= e.target || e.srcElement;
	var dl		= parentsSearchTagName(target, "DL");
	var dt		= parentsSearchTagName(target, "DT");
	var s, e;
	var isOpen	= getClass(dl).match("open");
	dl.style.overflow = "hidden";
	if(isOpen){
		s = getNaturalHeight(dl);
		e = dt.offsetHeight;
	} else{
		removeClass(dl, "close");
		addClass(dl, "open");
		s = dt.offsetHeight;
		e = getNaturalHeight(dl);
	}
	var animation = new easyAnimation(dl, 'height', s, e, 0.15, 0.8, bind(switchDefineEnd,[dl, isOpen]));
	animation.start();
}

function switchDefineEnd(dl, isOpen){
	if(isOpen){
		removeClass(dl, "open");
		addClass(dl, "close");
	} else{
		dl.style.overflow = "";
		dl.style.height = "auto";
	}
}


function getNaturalHeight(obj){
	var disp			= obj.style.display;
	var pad				= obj.style.padding;
	var height			= obj.style.height;
	obj.style.display	= "block";
	obj.style.padding	= "0px";
	obj.style.height	= "auto";
	var h				= obj.offsetHeight;
	obj.style.display	= disp;
	obj.style.padding	= pad;
	obj.style.height	= height;
	return h;
}

function getNaturalSize(obj){
	var cssText			= obj.style.cssText;
	var width			= obj.style.width;
	var height			= obj.style.height;
	var border			= obj.style.border;
	obj.style.cssText	= "display:block !important; padding:0px !important; border:0px !important; height:auto !important; width:auto !important;";
	// auto指定後にh,wが0になることがある
	var h				= ((obj.offsetHeight)?obj.offsetHeight:height.replace("px",""));
	var w				= ((obj.offsetWidth)?obj.offsetWidth:width.replace("px",""))
	obj.style.cssText	= cssText;
	return {w:w, h:h};
}


function switchObj(id){
	var e		= windowEvent();
	var target	= e.target || e.srcElement;
	target		= parentsSearchTagName(target, "A");
	var obj		= getObj(id);
	var h		= getNaturalHeight(obj);
	var t		= h / 1500 + 0.1;
	var stat	= (obj.offsetHeight > 0);

	if(obj._animation){
		obj._animation.stop();
	}
	if(stat){
		removeClass(target, "open");
		addClass(target, "close");
		obj._animation = new easyAnimation(obj, 'height', h, 0, t, 0.5);
	} else{
		removeClass(target, "close");
		addClass(target, "open");
		obj._animation = new easyAnimation(obj, 'height', 0, h, t, 0.5, bind(switchObjEnd, [obj]));
	}
	obj.style.overflow	= "hidden";
	obj.style.display	= "";
	obj._animation.start();
	return !(stat);
}

function switchObjEnd(obj){
	obj.style.overflow	= "";
	obj.style.height	= "";
}

// -------------------
//   wipe open
// -------------------

function wipeOpen(id){
	var obj = getObj(id);
	if(!wipeIsOpen(obj)){
//		if(!obj._defaultStyle) obj._defaultStyle = obj.style.cssText;
		obj.style.overflow = "hidden";
		height = wipeGetHeight(obj);
		obj.style.display = "block";
		var showAnimation = new easyAnimation(obj, 'height', 0, height, 0.2, 0.8);
		showAnimation.start();
	}
}
function wipeClose(id){
	var obj = getObj(id);
	if(wipeIsOpen(obj)){
//		if(!obj._defaultStyle) obj._defaultStyle = obj.style.cssText;
		obj.style.overflow = "hidden";
		height = wipeGetHeight(obj);
		var showAnimation = new easyAnimation(obj, 'height', height, 0, 0.15, 2, bind(wipeCloseListener, [obj]));
		showAnimation.start();
	}
}
function wipeCloseListener(obj){
	obj.style.display = "none";
}

function wipeSwitch(id){
	var obj = getObj(id);
	if(!wipeIsOpen(obj)){
		wipeOpen(id);
	} else{
		wipeClose(id);		
	}
}

function wipeGetHeight(obj){
	var height;
	var defaultStyle = obj.style.cssText;
	obj.style.margin = "0px !important";
	obj.style.padding = "0px !important";
	if(wipeIsOpen(obj)){
		height = obj.offsetHeight;
	} else{
		obj.style.cssText	= "display:block !important;";
		obj.style.position	= "relative";
		obj.style.left		= "-10000px";
		obj.style.top		= "10000px";
		height				= obj.offsetHeight;
	}
	obj.style.cssText = defaultStyle;
	return height;
}

function wipeIsOpen(obj){
	return (obj.offsetHeight > 0);
}

function hitTest(here, there, gapX, gapY){
	if(!gapX) gapX = 0;
	if(!gapY) gapY = 0;
	var hp	= cumulativeOffset(here);
	var tp	= cumulativeOffset(there);
	var hW	= here.offsetWidth / 2;
	var hH	= here.offsetHeight / 2;
	var tW	= there.offsetWidth / 2;
	var tH	= there.offsetHeight / 2;
	var hX	= hp[0] + hW + gapX * tW;
	var hY	= hp[1] + hH + gapY * tH;
	var tX	= tp[0] + tW;
	var tY	= tp[1] + tH;
	return (Math.abs(tX-hX) < tW+hW && Math.abs(tY-hY) < tH+hH);
}

function mouseHitTest(there, gapX, gapY){
	if(!gapX) gapX = 0;
	if(!gapY) gapY = 0;
	var hp	= getMousePosition();
	var tp	= cumulativeOffset(there);
	var hW	= 4;
	var hH	= 8;
	var tW	= there.offsetWidth / 2;
	var tH	= there.offsetHeight / 2;
	var hX	= hp[0] + hW + gapX * tW;
	var hY	= hp[1] + hH + gapY * tH;
	var tX	= tp[0] + tW;
	var tY	= tp[1] + tH;
	return (Math.abs(tX-hX) < tW+hW && Math.abs(tY-hY) < tH+hH);
}

function unselect(bool){
	if(bool){
		document.body.style.MozUserSelect	= "none";
		document.body.style.KhtmlUserSelect	= "none";
		if(document.all) window.document.attachEvent("onselectstart", unselectIE);
	} else{
		document.body.style.MozUserSelect	= "all";
		document.body.style.KhtmlUserSelect	= "all";
		if(document.all) window.document.detachEvent("onselectstart", unselectIE);
	}
}

function isVisibleScrollBar(obj){
	var isScroll	= false;
	var browser = getBrowserName();
	var version = getBrowserVersion();
	if(browser == "Internet Explorer" && version < 9){
		isScroll = ((obj.scrollHeight - obj.offsetHeight) > 0);
	} else if(browser == "Internet Explorer" && version >= 9){
		if(obj.scrollTop <= 0)	obj.scrollTop = 1;
		if(obj.scrollTop > 0)	isScroll = true;
	} else{
		var scrollTop	= obj.scrollTop;
		obj.scrollTop	+= 1;
		if(obj.scrollTop > 0){
			isScroll = true;
		}
		obj.scrollTop = scrollTop;
	}
	return isScroll;
}

function unselectIE(){
	if(window.event){
		window.event.returnValue = false;
	} else{
//			arguments.callee.caller.arguments[0].preventDefault();
	}
	return false;
}


function windowEvent(){
	if(window.event) return window.event;
	var caller = arguments.callee.caller;
	while(caller){
		var ob = caller.arguments[0];
		if(ob && ob.constructor == MouseEvent) return ob;
		caller = caller.caller;
	}
	return null;
}

function getBrowserHeight(){
	if(window.innerHeight){
		return window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight != 0){
		return document.documentElement.clientHeight;
	} else if(document.body){
		return document.body.clientHeight;
	}
	return 0;
}

function getBrowserWidth(){
	if(window.innerWidth ){
		return window.innerWidth;
	} else if(document.documentElement && document.documentElement.clientWidth != 0 ){
		return document.documentElement.clientWidth;
	} else if(document.body){
		return document.body.clientWidth;
	}
	return 0;
}

function isString(obj){
  return ( typeof(obj) == "string" || obj instanceof String ) ;
}

function hasAttribute(obj, name){
	if(document.all)	return obj.getAttribute(name) != null;
	else				return obj.hasAttribute(name);
}

function showLabel(){
	var e		= windowEvent();
	var btn		= e.target || e.srcElement;
	var target	= parentsSearchTagName(btn, "A");
	var obj		= downSearchTagName(target, "SPAN");
	obj.getElementsByTagName("INPUT")[0].value = target.innerHTML;
	switchObjs2(false, this, [obj, target]);
}

function hideLabel(){
	var e		= windowEvent();
	var btn		= e.target || e.srcElement;
	var target	= parentsSearchTagName(btn, "SPAN");
	var obj		= upSearchTagName(target, "A");
	obj.innerHTML = target.getElementsByTagName("INPUT")[0].value;
	switchObjs2(false, this, [obj, target]);
}

/* popup */
function switchPopup(id, align){
	var obj		= getObj(id);
	if(obj.style.display != "block")	showPopup(id, align);
	else								hidePopup(id);
}
function showPopup(id, align){
	var e		= windowEvent();
	var target	= e.target || e.srcElement;
	target		= parentsSearchTagName(target, "A");
	var obj		= getObj(id);
	document.body.appendChild(obj);
	offset = cumulativeOffset(target);
	
	if(align == "right"){
		obj.style.left			= offset[0] + target.offsetWidth + popupGetOption(obj, "left") + "px";
		obj.style.top			= offset[1] + popupGetOption(obj, "top") + "px";
	} else{
		obj.style.left			= offset[0] + popupGetOption(obj, "left") + "px";
		obj.style.top			= offset[1] + popupGetOption(obj, "top") + target.offsetHeight + "px";
	}
	obj.style.display		= "block";
	obj.style.position		= "absolute";

	var windowHeight	= getBrowserHeight() + (document.documentElement.scrollTop || document.body.scrollTop);
	var windowWidth		= getBrowserWidth() + (document.documentElement.scrollLeft || document.body.scrollLeft);

	// over window width
	if(obj.offsetLeft + obj.offsetWidth > windowWidth){
		obj.style.left = document.documentElement.clientWidth - obj.offsetWidth + "px";
	}
	
	// over window height
	if(obj.offsetTop + obj.offsetHeight > windowHeight){
		obj.style.top = document.documentElement.clientHeight - obj.offsetHeight + "px";
//		obj.style.top = obj.offsetTop - obj.offsetHeight - target.offsetHeight + "px";
	}

	addEvent(obj, "mouseover", bind(suspendPopup,[obj]));
	addEvent(obj, "mouseout", bind(mouseoutPopup,[id,target]));
	addEvent(target, "mouseout", bind(mouseoutPopup,[id,target]));
}
function hidePopup(id){
	var obj		= getObj(id);
	obj.style.display		= "none";
}
function mouseoutPopup(id, target){
	var obj	= getObj(id);
	var e	= windowEvent();
	var out = e.relatedTarget || e.toElement;
	if(out && !contains(obj, out) && !contains(target, out)){
		clearTimeout(obj._hideHandler);
		obj._hideHandler = setTimeout(bind(this.hidePopup,[id]), (document.all)?300:600);
	}
}
function suspendPopup(obj){
	clearTimeout(obj._hideHandler);
}
function popupGetOption(obj, type){
	var rel	= obj.getAttribute("rel");
	if(rel){
		var types	= rel.split(";");
		for(var i=0; i<types.length; i++){
			var option = types[i].split(":");
			if(option[0] == type) return option[1];
		}
	}
	return 0;
}


function sleep(msec){
	var date = new Date();
	var time = date.getTime();
	ltime = time + msec;
	while(ltime > time){
		date = new Date();
		time = date.getTime();
	}
	return true;
}

function getAllChild(root, nodeType){
	var obj		= root;
	var objs	= new Array();
	while(true){
		if(obj.nodeType == nodeType) objs.push(obj);
		var nObj = obj.firstChild || obj.nextSibling || obj;
		if(obj == nObj){
			while(nObj && !nObj.nextSibling){
				nObj = nObj.parentNode;
				if(nObj == root) return objs;
			}
			nObj = nObj.nextSibling;
		}
		obj = nObj;
	}
}

var isIE = (navigator.appName.toLowerCase().indexOf('internet explorer')+1?1:0);

function getAreaRange(obj) {
	var pos = new Object();
	 
	if (isIE) {
		obj.focus();
		var range = document.selection.createRange();
		var clone = range.duplicate();
		 
		clone.moveToElementText(obj);
		clone.setEndPoint( 'EndToEnd', range );
		 
		pos.start = clone.text.length - range.text.length;
		pos.end = clone.text.length - range.text.length + range.text.length;
	} else if(window.getSelection()) {
		pos.start = obj.selectionStart;
		pos.end = obj.selectionEnd;
	}
	return pos;
}

function surroundHTML(openTag, closeTag, obj) {
	var target = document.getElementById(obj);
	var pos = getAreaRange(target);

	var val = target.value;
	var range = val.slice(pos.start, pos.end);
	var beforeNode = val.slice(0, pos.start);
	var afterNode = val.slice(pos.end);
	var insertNode;
	 
	if (range || pos.start != pos.end) {
		insertNode = '<' + openTag + '>' + range + '</' + closeTag + '>';
		target.value = beforeNode + insertNode + afterNode;
	} else if (pos.start == pos.end) {
		insertNode = '<' + tag + '>' + '</' + tag + '>';
		target.value = beforeNode + insertNode + afterNode;
	}
}

function insertTextArea(str, obj){
	if(typeof tinyMCE != "undefined"){
		if(tinyMCE.isIE){
			tinyMCE.activeEditor.focus();
			tinyMCE.activeEditor.selection.moveToBookmark(tinyMCE.activeEditor.windowManager.bookmark);
		}
		if(tinyMCE.activeEditor.selection.getNode().nodeType == 1){
			tinyMCE.execInstanceCommand(obj, 'mceInsertContent', false, str);
		} else{
			tinyMCE.activeEditor.setContent(str + tinyMCE.activeEditor.getContent());
		}
	} else{
		var target = document.getElementById(obj);
		var pos = getAreaRange(target);
	
		var val = target.value;
		var beforeNode = val.slice(0, pos.start);
		var afterNode = val.slice(pos.start);
		var insertNode;
	
		target.value = beforeNode + str + afterNode;
	}
}
/*
function insertTextArea(str, obj){
	var target = document.getElementById(obj);
	var pos = getAreaRange(target);

	var val = target.value;
	var range = val.slice(pos.start, pos.end);
	var beforeNode = val.slice(0, pos.start);
	var afterNode = val.slice(pos.end);
	var insertNode;

	target.value = beforeNode + str + afterNode;
}
*/

function getSelectValue(id){
	var obj = getObj(id);
	return obj.options[obj.selectedIndex].value;
}

function moveBorder(dragID, targetID, minHeight){
	var dragObj		= getObj(dragID);
	var targetObj	= getObj(targetID);
	addEvent(dragObj, "mousedown", bind(moveBorderDown, [dragObj]));
	addEvent(document, "mousemove", bind(moveBorderMove, [dragObj, targetObj, minHeight || 0]));
	addEvent(document, "mouseup", bind(moveBorderUp, [dragObj]));
}

function moveBorderDown(dragObj){
	dragObj._moveBorderIsDrag = true;
	unselect(true);
}

function moveBorderMove(dragObj, targetObj, minHeight){
	if(dragObj._moveBorderIsDrag){
		var mp	= getMousePosition();
		var pos	= cumulativeOffset(targetObj);
		targetObj.style.height = Math.min(targetObj.scrollHeight, Math.max(minHeight, mp[1] - pos[1] - dragObj.offsetHeight/2 - 12)) + "px";
	}
}

function moveBorderUp(dragObj){
	dragObj._moveBorderIsDrag = false;
	unselect(false);
}

// -------------
//  status
// -------------
function getOS(){
	var os;
	var ua = navigator.userAgent;
	if(ua.match(/Win(dows )?NT 6\.1/))					os = "Windows 7";
	else if (ua.match(/Win(dows )?NT 6\.0/))			os = "Windows Vista";
	else if (ua.match(/Win(dows )?NT 5\.2/))			os = "Windows Server 2003";
	else if (ua.match(/Win(dows )?(NT 5\.1|XP)/))		os = "Windows XP";
	else if (ua.match(/Win(dows)? (9x 4\.90|ME)/))		os = "Windows ME";
	else if (ua.match(/Win(dows )?(NT 5\.0|2000)/))		os = "Windows 2000";
	else if (ua.match(/Win(dows )?98/))					os = "Windows 98";
	else if (ua.match(/Win(dows )?NT( 4\.0)?/))			os = "Windows NT";
	else if (ua.match(/Win(dows )?95/))					os = "Windows 95";
	else if (ua.match(/CrOS/))							os = "Chrome OS";
	else if (ua.match(/Android/))						os = "Android";
	else if (ua.match(/iPhone/))						os = "iPhone OS";
	else if (ua.match(/Mac OS X/))						os = "MacOSX";
	else if (ua.match(/Mac|PPC/))						os = "MacOS";
	else if (ua.match(/Linux/))							os = "Linux";
	else if (ua.match(/(Free|Net|Open)BSD/))			os = RegExp.$1 + "BSD";
	else if (ua.match(/SunOS/))							os = "Solaris";
	else												os = "N/A";
	return os;
}

function getBrowserName(){
	var browser;
	var ua = navigator.userAgent.toLowerCase();//小文字

	if(ua.match(/netscape/))		browser = "Netscape";
	else if(ua.match(/msie/))		browser	= "Internet Explorer";
	else if(ua.match(/opera/))		browser = "Opera";
	else if(ua.match(/firefox/))	browser = "Firefox";
	else if(ua.match(/chrome/))		browser = "Google Chrome";
	else if(ua.match(/safari/))		browser = "Safari";
	
	return browser;
}

function getBrowserVersion(){
	return	window.opera ? (opera.version().replace(/\d$/, "") - 0)
			: parseFloat((/(?:IE |fox\/|ome\/|ion\/)(\d+\.\d)/.exec(navigator.userAgent) || [,0])[1]);
}

function getCookieEnabled(){
	return navigator.cookieEnabled;
}

function getFlashPlayerVersion(){
	var flashplayer_ver = 0;
	//IE以外
	if(navigator.plugins && navigator.mimeTypes['application/x-shockwave-flash']){
		var plugin = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
		//Flash Playerがインストールされている場合
		if(plugin){flashplayer_ver = parseInt(plugin.description.match(/\d+\.\d+/));}
	}
	//IEの場合、もしくはFlash Playerがインストールされていない場合
	else{
		//IEでFlash Playerがインストールされている場合
		try{
			var flashOCX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").match(/([0-9]+)/);
			if(flashOCX){flashplayer_ver = parseInt(flashOCX[0]);}
		}catch(e){}
	}
	//Flash Playerがインストールされていない、もしくはバージョンが6以下の場合
	if(flashplayer_ver <= 6){flashplayer_ver = 0;}
	return flashplayer_ver;
}


function bind(method,arg){
	var _this=this;var _arg=(arg)?arg:[];
	return function(){
		method.apply(_this,_arg);
	}
}

