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 mousePositionX = 0;
var mousePositionY = 0;
function getMousePositionListener(e){
	var mp = getMousePosition(e);
	mousePositionX = mp[0];
	mousePositionY = mp[1];
}

function getMousePosition(e){
	if(e == undefined) e = window.event;
	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){
	return document.all && document.all(id) || document.getElementById && document.getElementById(id);
}


function windowOpen(theURL,winName,features, protocol){
	if(theURL.indexOf("/") == 0){
		if(!protocol) protocol = "http";
		theURL = protocol + "://" + document.location.host + theURL;
	}
	window.open(theURL,winName,features);
}	

// --------------------
//   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(!document.all || document.documentMode >=8) c = e.getAttribute("class");
	else c = e.getAttribute("className");
	return (!c)?"":c;
}

function setClass(e, c){
	if(!document.all || document.documentMode >=8) return e.setAttribute("class" , c);
	else return e.setAttribute("className", 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"){
		obj.style.MozOpacity = n;
		obj.style.filter = "alpha(opacity: " + (n * 100) + ")";
		obj.style.opacity = n;
		obj.style.zoom = "1";
		// IE Filter Border problem
		if(n >= 1) obj.style.filter = "";
	} 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 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;";
}


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;
}

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

function surroundHTMLStrong(obj){
	surroundHTML("strong", "strong", obj);
}

function surroundHTMLRed(obj){
	surroundHTML("span style=color:red", "span", obj);
}

function surroundHTMLLink(obj, win){
	var href = prompt("リンクするURLを入力してください。");
	if(href){
		surroundHTML("a target="+win+" href="+href, "a", obj);
	}
}

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 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;
	}
	return obj;
}

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{
		if(!obj.previousSibling){
			while(obj && !obj.previousSibling){
				obj = obj.parentNode;
			}
		}
		obj = obj.previousSibling;
	} while(obj && (!obj.tagName || obj.tagName.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 cancelClick(e){
	if(e == undefined) e = window.event;
	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	= getObj(h);
	var m1Obj	= getObj(m1);
	var m2Obj	= getObj(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 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;
}

