document.getElementsByClassName = function(className, pElement, tagName){
         var d = document, nodes = [], item;
         try { // XPathをサポートしているならこれを使う
          var xp = d.evaluate(
           './/'+(tagName || '*')+'[contains(concat(" ", @class, " "), " '+className+' ")]',
           (pElement || d), null, XPathResult.ANY_TYPE, null
          );
          for (item = xp.iterateNext(); item; item = xp.iterateNext()){
           nodes.push(item);
          }
         } catch(e){ // そうでなければ地道にDOM解析
          var cls, items = (pElement || d).getElementsByTagName((tagName || '*'));
          for(var i = 0, l = items.length; i < l; i++){
           item = items[i];
           if(item.className){
                cls = item.className.split(/¥s+/);
                for(var j = 0, k = cls.length; j < k; j++){
                 if(cls[j]==className){
                  nodes[nodes.length] = item; break;
                 }
                }
           }
          }
         }
         return nodes.length > 0 ? nodes : null;
}

function selectBoxLimitTo(current, limit){
        var options = current.options;
        var count = 0;
        for(i=0; i<options.length; i++){
                if(options[i].selected==true) count ++;
                if(count > limit){
                        window.alert("チェックできる条件は項目毎に最大 "+limit+"個 までです。");
                        options[i].selected = false;
                        return false;
                }
        }
        return true;
}
// チェックボックスのチェック数を制限
// onClick="checkBoxLimitTo(this, $('親要素（この子から探す）', 'チェックボックスのクラス名', 5))"
function checkBoxLimitTo(current, parent, searchClass, limit){
        var checkBoxes;
        if(parent == null){
                checkBoxes = document.getElementsByClassName(searchClass, document.body, 'input')
        }else{
                checkBoxes = document.getElementsByClassName(searchClass, parent, 'input')
        }

        var count = 0;
        for(i=0; i<checkBoxes.length; i++){
                if(checkBoxes[i].checked==true) count ++;
                if(count > limit){
                        window.alert("チェックできる条件は項目毎に最大 "+limit+"個 までです。");
                        current.checked = false;
                        return false;
                }
        }
        return true;
}

function jumpWithRadio(form){
        var flag = false;
        for(i=0; i<form.url.length; i++){
                if(form.url[i].checked){
                        flag = true;
                        form.action = form.url[i].value;
                }
        }
        if(! flag) form.action = form.url[0].value;

        return true;
}

function openImageNode(e, parentID, url){
        var iWindow = $('imageNode');
        if(!isDefined(iWindow)) iWindow = document.createElement("center");
        iWindow.setAttribute('id', 'imageNode')
        iWindow.innerHTML = '<img src="'+url+'" />';
        $(parentID).appendChild(iWindow);
}
function closeImageNode(){
        var iWindow = $('imageNode');
        if(isDefined(iWindow)) Element.remove(iWindow);
}

function openImageWindow(e, url){
        var iWindow = $('imageWindow');
        if(!isDefined(iWindow)) iWindow = document.createElement("div");
        iWindow.setAttribute('id', 'imageWindow')
        iWindow.style.position = 'absolute';
        if(getMouseX(e) - 350 > 0){
               iWindow.style.left = getMouseX(e) - 350 + 'px';
        }else{
               iWindow.style.left = getMouseX(e) + 20 + 'px';
        }

        iWindow.style.top = getMouseY(e) - 100 + 'px';

        iWindow.style.border = "1px solid #000000";
        iWindow.style.background = "#FFFFFF"
        iWindow.innerHTML = '<img src="'+url+'" />';
        document.body.appendChild(iWindow);
}
function closeImageWindow(){
        var iWindow = $('imageWindow');
        if(isDefined(iWindow)) Element.remove(iWindow);
}

function createPopupWindow(url, w, h) {
        switch (arguments.length) {
   case 1: w = 800;
   case 2: h = 600;
 }

        x = (screen.width - w) / 2;
        y = (screen.height - h) / 2;
  obj = window.open(url, "popup", 'width='+w+',height='+h+',scrollbars=yes');
        obj.moveTo(x,y);
  obj.focus();

  return false;
}

// submitを押した結果をポップアップウインドウに表示
function withPopupWindow(obj) {
        switch (arguments.length) {
   case 1: w = 800;
   case 2: h = 600;
 }
 x = (screen.width - w) / 2;
        y = (screen.height - h) / 2;
  wobj = window.open("", "popup", 'width='+w+',height='+h+',scrollbars=yes');
  obj.target = "popup";
  wobj.focus();
  return false;
}

// フォーム（DIV OK）の内容を別のフォームにコピー
function copyForm(sourceId, destId){
        var children = document.getElementsByClassName('copied-field', document.body);
        if(children != null){
                for(i=0; i<children.length; i++){
                        Element.remove(children[i]);
                }
        }
        var params = (Form.serialize(sourceId)).split('&');
        for(i=0; i<params.length; i++){
                var parts = params[i].split('=');
                var name = decodeURI(parts[0]);
                var id = name.replace(/\[\]/g, '').replace(/\[/g, '_').replace(/\]/g, '');
                var value = decodeURIComponent(parts[1]);

                var field = document.createElement('input');
                field.type = 'hidden';
                field.name = name;
                field.value = value;
                field.className = 'copied-field';
                $(destId).appendChild(field);
        }
}

// チェックボックスの選択状態を反転させる
// 引数: 反転させるチェックボックスのクラス名
function check_box_reverse(className){
        var elements = getElementsByClass(className);
        for (i = 0; i < elements.length; i++) {
                elements[i].checked = ! elements[i].checked;
        }
}
function checkBoxReverse(className){
        check_box_reverse(className)
}

function checkBoxSelect(className){
        var elements = getElementsByClass(className);
        for (i = 0; i < elements.length; i++) {
                elements[i].checked = true;
        }
}

function checkBoxUnSelect(className){
        var elements = getElementsByClass(className);
        for (i = 0; i < elements.length; i++) {
                elements[i].checked = false;
        }
}

function getElementsByClass(searchClass) {
        /*
    var classElements = new Array();
    var allElements = $$("*");

    for (i = 0; i < allElements.length; i++) {
                        if(allElements[i].className.split(/\s+/).indexOf(searchClass) > -1){
                                classElements.push(allElements[i]);
                        }
    }
    return classElements;
  */
        return document.getElementsByClassName(searchClass, document.body)
}

var startLoading = function(){
        $('loading').style.display = 'block';
};
var endLoading = function(){
        $('loading').style.display = 'none';
}

//--マウスカーソル位置のX座標を返す関数
  function getMouseX(e){
    if(navigator.userAgent.indexOf("MSIE 7") > -1)
			return window.event.clientX + document.documentElement.scrollLeft;
		else if(navigator.userAgent.indexOf("MSIE") > -1)                             //IE用
            return window.event.clientX + document.body.scrollLeft;
    else if(document.layers||document.getElementById) //N4,N6,Mozilla用
            return e.pageX
  }


  //--マウスカーソル位置のY座標を返す関数
  function getMouseY(e){
		if(navigator.userAgent.indexOf("MSIE 7") > -1)
			return window.event.clientY + document.documentElement.scrollTop;
		else if(navigator.userAgent.indexOf("MSIE") > -1) //IE用
        return window.event.clientY + document.body.scrollTop;
    else if(document.layers||document.getElementById) return e.pageY;
  }

//  onMouseOver="popUpOn(event, 'メッセージ')" onMouseOut="popUpOff()"
function popUpOn(event, PopMsg){
        popUpOff();

        var x,y;
        var msgX=+10,msgY=-30;
        x=getMouseX(event);
        y=getMouseY(event);

        var div = document.createElement("div");
        div.setAttribute("id","pop_up");
        div.style.position = 'absolute';
        div.style.left = x+msgX+'px';
        div.style.top = y+msgY+'px';
        div.innerHTML = PopMsg;
        div.style.zIndex = 1000000;
        document.body.appendChild(div);
}

function popUpOff(){
        var div = $('pop_up');
        if(div != null){
          Element.remove("pop_up");
        }
}

function keyCode(e){
        var keycode = null;
        if (e != null) {
                keycode = e.which;
                e.preventDefault();
                e.stopPropagation();
        }else{
                keycode = event.keyCode;
                event.returnValue = false;
                event.cancelBubble = true;
        }
        return keycode;
}

function ctrlKey(e){
                var ctrl;
    if (e != null) {
        keycode = e.which;
        ctrl = typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK;
                        e.preventDefault();
                        e.stopPropagation();
                } else {
                                ctrl = event.ctrlKey;
                                event.returnValue = false;
                                event.cancelBubble = true;
    }
                return ctrl;
}

function shiftKey(e){
                var shift;
    if (e != null) {
        keycode = e.which;
        shift = typeof e.modifiers == 'undefined' ? e.shiftKey : e.modifiers & Event.SHIFT_MASK;
        e.preventDefault();
                        e.stopPropagation();
                } else {
        shift = event.shiftKey;
                                event.returnValue = false;
                                event.cancelBubble = true;
    }
                return shift;
}

//Netscape 6 以降の場合は真
isNN6 = (document.getElementById) ? true : false;
//InternetExplorer 4 以降の場合は真
isIE4 = (document.all) ? true : false;
function isDefined(data){
        //文字列がヌル文字や,空白文字でない事を確認
        if(data!=""||data!=null){
                //IE6や、NN6の場合
                if(isIE4||isNN6){
                        //IE6や、NN6から対応された未定義値であるかを調べ、その逆の値を返す
                        return !(data==undefined);
                } else {
                        return true;
                }
        } else {
                return false;
        }
}

// オブジェクト保持用
// Ajax用
var globalObjects = new Object;

