// 汎用function _____________________________________________________
function error(stat, funcName, msg) {
	var statStr = "";
	switch(stat) {
		case 0:	statStr = "info"; break;
		case 1:	statStr = "warn"; break;
		case 2:	statStr = "error"; break;
	}
	alert(statStr + ": " + funcName + "() " + msg);
}


// searchClassには、パターンを許す。tagがnullもしくは、指定されないならtagはなんでもOK。
function getElementsByClassInUpper(searchClass, node, tag) {
	var currentNode = node;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	if (node == null)
		return(null);
	
	for (var i=0; i<1000; i++) {
		if (currentNode.parentNode.tagName.toLowerCase() == "body") {
			return(null);
		}
		if (pattern.test(currentNode.className)) {
			if (tag == null) {
				return(currentNode);
			}
			else {
				if (currentNode.tagName.toLowerCase() == tag) {
					return(currentNode);
				}
			}
		}
		currentNode = currentNode.parentNode;
	}
	return(null);
}



function getElementsByClass(searchClass,node,tag) {
//	alert("getElementsByClass("+searchClass+", "+ node.className + ", " + tag + ")");
	var classElements = new Array();
	if ( node == null || node == "undefined") {
		node = document;
	}
	if ( tag == null)
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


// ---
/*
	Copyright Robert Nyman, http://www.robertnyman.com
	Free to use if this text is included
*/
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}
// ---
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
// ---



// Name: Get Elements By Attribute
// Language: JavaScript
// Author: Travis Beckham | squidfingers.com
// Description: Returns an array of elements that match the arguments. If no elements are found, an empty array is returned.
// Compatibility: IE4+, NS6+, Safari
// Arguments: Attribute Name, Attribute Value (optional), Tag Name (optional)
// --------------------------------------------------

function getElementsByAttr (aName, aValue, tName) {
  var i, elms, attr, rslt = [];
  if(document.all || document.getElementsByTagName){
    if(tName){
      elms = document.all ? document.all.tags(tName.toUpperCase()) : document.getElementsByTagName(tName);
    }else{
      elms = document.all ? document.all : document.getElementsByTagName("*");
    }
    for(i = 0; i < elms.length; i++){
      // Note: in IE5/Mac, element.getAttribute("class") returns null 
      // even when the class attribute contains a value. 
      // However, element.className will return the correct value.
      attr = aName == "class" ? elms[i].className : elms[i].getAttribute(aName);
      if(attr){
        if(aValue && attr != aValue){
          continue;
        }
        rslt[rslt.length] = elms[i];
      }
    }
  }
  return rslt;
}


/*
function getNodeByNodeName(node, name, depth) {
	alert(node.className + ", " + depth + ", " + node.nodeName + ", " + node.nodeType + ", " + node.nodeValue);
	var resultNode;
	for (var i=0; i<node.childNodes.length; i++) {
		if (node.childNodes[i].hasChildNodes) {
			if ((resultNode = getNodeByNodeName(node.childNodes[i], name, depth+1)) != false){
				return resultNode;
			}
		}
		else {
			if (node.childNodes[i].nodeType == 1 && node.childNodes[i].nodeName == name) {
				return node.childNodes[i];
			}
		}
	}
	return false;
}
*/


function parseQueryString(resultAr) {
	if (location.search.length > 1) {
		var argSets = location.search.substr(1).split("&"); 
		for (var i in argSets) {
			resultAr[argSets[i].split("=")[0]] = argSets[i].split("=")[1];
		}
	}
}


function parseCookie(cookieStr, resultAr) {
	if (cookieStr.length > 1) {
		var argSets = cookieStr.split("&"); 
		for (var i in argSets) {
			resultAr[argSets[i].split("=")[0]] = argSets[i].split("=")[1];
		}
	}
}



//_________________________________________________________________

// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") + (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}
//_________________________________________________________________








function getActiveStyle( element, property, pseudo ) {
　if( element.currentStyle ) {          //IE
　　property = ( property.match( /-/ ) ) ? property.camelize( ) : property;
　　return element.currentStyle[ property.camelize( ) ];
　}
　else if( document.defaultView.getComputedStyle ) {    //Mozilla
　　property = ( property.match( /-/ ) == null ) ? property.deCamelize( ) : property;
　　return document.defaultView.getComputedStyle( element, pseudo ).getPropertyValue( property );
　}
　return "";
}

String.prototype.camelize = function( ) {
　return this.replace( /-([a-z])/g,
　　function( $0, $1 ) { return $1.toUpperCase( ) } );
}
String.prototype.deCamelize = function( ) {
　return this.replace( /[A-Z]/g,
　　function( $0 ) { return "-" + $0.toLowerCase( ) } );
}





//_________________________________________________________________

// 解答ボタンを押したときに日本語の意味を表示する
function answerVis(buttonElm) {
	var entryContentElm = buttonElm.parentNode.parentNode;	// @@@ HTMLの構造に依存している
	var entryBodyElm = getElementsByClass("entry-more", entryContentElm)[0];
	if (entryBodyElm.style.display != "block") {
		entryBodyElm.style.display = "block";
	}
	else {
		entryBodyElm.style.display = "none";
	}
	return false;
}

