﻿//  何となく使えそうな関数をまとめとく
//
//  prototype.jsと同じ$()の実装。
//    まだ何も関連付けられていなければ、関連付ける。
//    一応、PAFuncLib.$()にも作成しておくのでライブラリ内では、衝突を避けるためこっちを使用する。
//
// Memo
//   styleのtopとかwidthとか指定するときは 'px' or '%' を付ける
//   自分より前の関数しか呼べないみたい。。。なので、書く順番注意！！
//     と思ったけど、単純に読み込み前に実行されてただけだった。
//   removeNodeはIEのみ？Firefoxでは使えない


//コレクション
var PACommon = new Array();
PACommon.Collections = {
    //リンクリストにしたほうが高速になるけど、とりあえず配列で
    ArrayList : function() {
        this.Items = new Array();
        this.Count = 0;
        this.add = function(Vobj) {
            var Result = this.Count;
            this.Items[this.Count] = Vobj;
            this.Count++;
            return Result;
        };
        this.indexOf = function(Vobj) {
            var Result = -1;
            for (var i = 0; i < this.Items.length; i++) {
                if (Vobj === this.Items[i]) {
                    Result = i;
                    break;
                }
            }
            return Result;
        };
        this.lastIndexOf = function(Vobj) {
            var Result = -1;
            for (var i = this.Items.length - 1; i >= 0; i--) {
                if (Vobj === this.Items[i]) {
                    Result = i;
                    break;
                }
            }
            return Result;
        };
        this.removeAt = function(VintIndex) {
            if ((VintIndex >= 0) && (VintIndex < this.Count)) {
                this.Items.splice(VintIndex, 1);
                this.Count--;
            }
        };
        this.remove = function(Vobj) {
            var intLen = this.Items.length;
            for (var i = intLen - 1; i >= 0; i--) {
                if (Vobj === this.Items[i]) {
                    this.removeAt(i);
                }
            }
        };
    }
    
};

var PAFuncLib = {
    MOUSE_LEFT_BUTTON : 0,
    MOUSE_CENTER_BUTTON : 1,
    MOUSE_RIGHT_BUTTON : 2,
    PAisSHIFT : false,
    PAisCTRL : false,
    PAisALT : false,
    PA_KEY_CODE : "",
    WindowDocument : window.document,

    IsIE : navigator.userAgent.indexOf('MSIE') >= 0,
    IsFF : navigator.userAgent.indexOf('Firefox') >= 0,
    IsSF : navigator.appVersion.indexOf('Safari') >= 0,
    IsWin : navigator.userAgent.indexOf('Windows') >= 0,
    IsMac : navigator.userAgent.indexOf('Mac OS') >= 0,

    //  関数の説明 ///////////////////////////////////////////////////////////////////////////////////////
    //
    //  以下の関数で引数にVobjWindowがあるものは、省略可。その場合は、windowを利用する。
    //
    //サイズ取得
    //  ・表示領域の取得
    //    getClientSize(VobjWindow) return { Width, Height }
    //
    //  ・ページ全体のサイズ取得
    //    getDocumentSize(VobjWindow) return { Width, Height }
    //
    //  ・オブジェクト
    //    getObjectSize(VobjElement) return { Width, Height }
    //
    //チェック
    //  ・IEかチェック。Firefoxかチェック    ・undefinedかチェック。
    //    isIE(), isFF()                       isUndefined(Vobj), isnotUndefined(Vobj)
    //  ・functionかチェック
    //    isFunction(Vfnc)
    //  ・タグ名をチェック
    //    isNodeName(VobjElement, VstrNodeName)
    //
    //スクロール量を取得
    //  getScroll(VobjWindow) return { Top, Left } 
    //
    //マウスの座標を取得 - 絶対座標
    //  getMousePoint(VobjWindow) return { X, Y }
    //
    //マウスの座標を取得 - 親エレメントからの相対座標
    //  getEventElementMousePoint(VobjWindow) return { X, Y }
    //
    //マウスのボタンを取得
    //  getMouseButton()
    //    return PAFuncLib.MOUSE_LEFT_BUTTON or PAFuncLib.MOUSE_RIGHT_BUTTON or PAFuncLib.MOUSE_CENTER_BUTTON
    //
    //オブジェクト取得
    //  ・document.getElementById(VstrId)の代わり
    //    $(VstrId)
    //
    //  ・iframeのwindowオブジェクト、documentオブジェクトを取得
    //    getFrameWindow(VstrFrameId), getFrameDocument(VstrFrameId)
    //
    //  ・イベントオブジェクトを取得     ・イベント発生元を取得
    //    getEvent(VobjWindow)             getEventTarget(VobjWindow)
    //
    //  ・選択中の文字列を取得           ・指定したノードの親をたどり、引数2で指定したノード名をもつノードを取得
    //    getSelectionText(VobjWindow)     getParentOf(VobjElement, VstrTargetNodeName)
    //
    //  ・指定したノードの子から、引数2で指定したノード名をもつノードを取得
    //    getChildOf(VobjElement, VstrTargetNodeName)
    //
    //  ・リクエスト文字                 ・文字分割
    //    getRequestQuery(VobjWindow)      getParameter(VstrParameter, VstrFirstSep, VstrSecondSep)
    //
    //　・2点間の距離
    //    getDistance(VintX1, VintY1, VintX2, VintY2)
    //
    //命令
    //  ・イベントアタッチ、除去
    //    addListener(VobjElement, VstrType, VobjFunc)    removeListener(VobjElement, VstrType, VobjFunc)
    //
    //  ・オブジェクトのclickイベントを実行          ・エレメントを取り除く
    //    clickButton(VstrObjectId, VobjWindow)        removeElement(VobjElement)
    //    clickElement(VobjElement)
    //   
    //
    //  ・イベントキャンセル - IEとFirefoxで違う。あとeventの取り方も違う。
    //      IE: event.returnValue = false; FF: event.preventDefault();
    //    returnValueFalse(VobjWindow)
    //
    //  ・画面内のテキストボックスのfocusイベントで、文字列を選択させる。「input type='text'」全部。
    //    setTextBoxSelectByFocus
    //
    //  ・bodyにjsファイルを動的挿入。クロスドメイン通信とかでも使える。
    //    insertScript(VobjOption)
    //      引数1 option = {
    //              Src : string
    //            }
    //
    //エフェクト
    //  ・スタイルの透明度をセット。値は0～100。0で透明。引数1個なら、Valueは50とする。
    //    setOpacity(VobjElement, VintValue)
    //
    //  ・指定オブジェクトをフェードイン、アウト - 引数2は省略可
    //    fadeIn(VobjElement, VobjOption), fadeOut(VobjElement, VobjOption)
    //      引数2 option = {
    //              Speed : int,           //変化スピード default : 15
    //              Change : int           //変化量       default : 10
    //              Limit : int            //fade_in時の限界値
    //            }
    //
    //  ・エレメントのスタイルを、画面を覆うカバーにする - 引数2は省略可
    //    setCoverStyle(VobjElement, VobjOption)
    //      引数2 option = {
    //              ZIndex : int,          //divに設定するz-index    default : 1000
    //              CoverOpacity : int,    //背景色                  default : #FFFFFF
    //              CoverColor : string,   //背景透過度 0 - 100      default : 50
    //              Window : element       //対象windowエレメント    default : window
    //            }
    //
    //  ・ドラッグ移動を実装 - 引数2は省略可。Option.EventElementにmousedown、window.documentにmouseupとmousemoveを実装する。
    //  ※未完成
    //    Draggable(VobjElement, VobjOption)
    //      引数2 option = {
    //              Opacity : int,           //移動時の透過度                 default : 100 (透過なし)
    //              EventElement : element   //mousedownを実装するエレメント  default : VobjElement
    //            }
    //      使用方法
    //        new Draggable(element, { Opacity : 50 });
    //
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////////

    //追加されたイベントの記憶
    MlstEvent : new PACommon.Collections.ArrayList(),
    
    //イベントアタッチ
    addListener : function(VobjElement, VstrType, VobjFunc) {
            if (VobjElement) {
                if(VobjElement.addEventListener) {
                    //その他のブラウザ
                    VobjElement.addEventListener(VstrType, VobjFunc, false);
                    //PAFuncLib.MlstEvent.add({ Target : VobjElement, Type : VstrType, Event : VobjFunc });
                } 
                else if(VobjElement.attachEvent) {
                    //IE
                    VobjElement.attachEvent("on" + VstrType, VobjFunc);
                    //PAFuncLib.MlstEvent.add({ Target : VobjElement, Type : VstrType, Event : VobjFunc });
                }
            }
    },
    //イベント除去
    removeListener : function(VobjElement, VstrType, VobjFunc) {
            if (VobjElement) {
                if(VobjElement.removeEventListener) {
                    //その他のブラウザ
                    VobjElement.removeEventListener(VstrType, VobjFunc, false);
                }
                else if(VobjElement.detachEvent) {
                    //IE
                    VobjElement.detachEvent("on" + VstrType, VobjFunc);
                }
            }
    },

    window_unload : function() {
        for (var i = 0; i < PAFuncLib.MlstEvent.Count; i++) {
            var obj = PAFuncLib.MlstEvent.Items[i];
            PAFuncLib.removeListener(obj.Target, obj.Type, obj.Event);
        }
        PAFuncLib.MlstEvent = null;
    },
    
    
    
    getClientSize : function(VobjWindow) {
        var Result = new Array();
        Result.Width = PAFuncLib.getClientWidth(VobjWindow);
        Result.Height = PAFuncLib.getClientHeight(VobjWindow);
        return Result;
    },
    getDocumentSize : function(VobjWindow) {
        var Result = new Array();
        Result.Width = PAFuncLib.getDocumentWidth(VobjWindow);
        Result.Height = PAFuncLib.getDocumentHeight(VobjWindow);
        return Result;
    },
    
    //表示領域の高さ取得 - 場合によって0になる場合がある？
    //  引数0ならwindowを使う
    getClientHeight : function(VobjWindow) {
        var Result = "0";
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        if (objWindow) {        
            if (objWindow.document.documentElement && objWindow.document.documentElement.clientHeight) {
                //IE 標準モード
                Result = objWindow.document.documentElement.clientHeight;
            } 
            else if (objWindow.document.body) {
                //IE 互換モード
                Result = objWindow.document.body.clientHeight;    
            } 
            else {
                //その他のブラウザ
                Result = objWindow.innerHeight;
            }
        }
        return Result;    
    },

    getDocumentHeight : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var yScroll;
        
        if (objWindow.innerHeight && objWindow.scrollMaxY) {    
            yScroll = objWindow.innerHeight + objWindow.scrollMaxY;
        } 
        else if (objWindow.document.body.scrollHeight > objWindow.document.body.offsetHeight){ // all but Explorer Mac
            yScroll = objWindow.document.body.scrollHeight;
        } 
        else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            yScroll = objWindow.document.body.offsetHeight;
        }
        
        var windowWidth, windowHeight;
        if (self.innerHeight) {    // all except Explorer
            windowHeight = self.innerHeight;
        } 
        else if (objWindow.document.documentElement && objWindow.document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowHeight = objWindow.document.documentElement.clientHeight;
        } 
        else if (objWindow.document.body) { // other Explorers
            windowHeight = objWindow.document.body.clientHeight;
        }    
        
        // for small pages with total height less then height of the viewport
        var Result;
        if(yScroll < windowHeight) {
            Result = windowHeight;
        } 
        else { 
            Result = yScroll;
        }

        return Result;
    },

    //表示領域の幅取得
    //  引数0ならwindowを使う
    getClientWidth : function(VobjWindow) {
        var Result = "0";
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        if (objWindow) {
            if (objWindow.document.documentElement && objWindow.document.documentElement.clientWidth) {
                //IE 標準モード
                Result = objWindow.document.documentElement.clientWidth;
            } 
            else if (objWindow.document.body) {
                //IE 互換モード
                Result = objWindow.document.body.clientWidth;    
            } 
            else {
                //その他のブラウザ
                Result = objWindow.innerWidth;
            }
        }
        return Result;
    },
    
    getDocumentWidth : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var xScroll;
        
        if (objWindow.innerHeight && objWindow.scrollMaxY) {    
            xScroll = objWindow.document.body.scrollWidth;
        } 
        else if (objWindow.document.body.scrollHeight > objWindow.document.body.offsetHeight){ // all but Explorer Mac
            xScroll = objWindow.document.body.scrollWidth;
        } 
        else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = objWindow.document.body.offsetWidth;
        }
        
        var windowWidth;
        if (self.innerHeight) {    // all except Explorer
            windowWidth = self.innerWidth;
        } 
        else if (objWindow.document.documentElement && objWindow.document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = objWindow.document.documentElement.clientWidth;
        } 
        else if (document.body) { // other Explorers
            windowWidth = objWindow.document.body.clientWidth;
        }    
        
        // for small pages with total width less then width of the viewport
        var Result;
        if(xScroll < windowWidth) {    
            Result = windowWidth;
        } 
        else {
            Result = xScroll;
        }

        return Result;
    },

    getObjectSize : function(VobjElement) {
        var Result = new Array();
        Result.Width = VobjElement.offsetWidth;
        Result.Height = VobjElement.offsetHeight;
        return Result;
    } ,
    
    isNull : function(Vobj) {
        return Vobj == null;
    },
    
    isUndefined : function(Vobj) {
        return typeof(Vobj) == 'undefined';
    },
    
    isnotUndefined : function(Vobj) {
        return typeof(Vobj) == 'undefined' ? false : true;
    },

    isFunction : function(Vfnc) {
        return typeof(Vfnc) == 'function';
    },
    
    isNodeName : function(VobjElement, VstrNodeName) {
        return (VobjElement && VobjElement.nodeName && (VobjElement.nodeName.toLowerCase() == VstrNodeName));
    },
    
    isClosedWindow : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        var ua = navigator.userAgent
        if(!!objWindow) {
            if((ua.indexOf('Gecko')!=-1 || ua.indexOf('MSIE 4')!=-1) &&
               ua.indexOf('Win')!=-1) { 
               return objWindow.closed
            }
            else {
                return typeof objWindow.document  != 'object'
            }
        }
        else {
            return true
        }
    },
    
    getMousePoint : function(VobjWindow) {
        var Result = new Array();
        Result.X = PAFuncLib.getMouseX(VobjWindow);
        Result.Y = PAFuncLib.getMouseY(VobjWindow);
        return Result;
    },
    
    getMouseX : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var e = PAFuncLib.getEvent(objWindow);
        
        if (e) {
            if (objWindow.opera) {
                return e.clientX;
            }
            else if (objWindow.document.all) {
                return objWindow.document.body.scrollLeft + e.clientX;
            }
            else if (objWindow.document.layers || objWindow.document.getElementById) {
                return e.pageX;
            }
        }
    },

    getMouseY : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        var e = PAFuncLib.getEvent(objWindow);

        if (e) {
            if (objWindow.opera) {
                return e.clientY;
            }
            else if (objWindow.document.all) {
                return objWindow.document.body.scrollTop + e.clientY;
            }
            else if (objWindow.document.layers || objWindow.document.getElementById) {
                return e.pageY;
            }
        }
    },

    getEventElementMousePoint : function(VobjWindow) {
        var Result = new Array();
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        var e = PAFuncLib.getEvent(objWindow);

        if (e) {
            if (PAFuncLib.IsIE) {
                Result.X = e.offsetX;
                Result.Y = e.offsetY;
            }
            else {
                Result.X = e.layerX;
                Result.Y = e.layerY;
            }
        }
        else {
            Result.X = 0;
            Result.Y = 0;
        }
        return Result;
    },
    
    getMouseButton : function() {
        var e = PAFuncLib.getEvent();
        if (e) {
            var b = e.button;
            if (PAFuncLib.IsIE || PAFuncLib.IsSF) {
                if ((b & 1) != 0) return PAFuncLib.MOUSE_LEFT_BUTTON;
                if ((b & 2) != 0) return PAFuncLib.MOUSE_RIGHT_BUTTON;
                if ((b & 4) != 0) return PAFuncLib.MOUSE_CENTER_BUTTON;
            }
            else {
                return b;
            }
        }
        return -1;
    },
    
    getScroll : function(VobjWindow) {
        var Result = new Array();
        Result.Top = PAFuncLib.getScrollTop(VobjWindow);
        Result.Left = PAFuncLib.getScrollLeft(VobjWindow);
        return Result;
    },
    
    getScrollTop : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        return objWindow.body.scrollTop  || objWindow.documentElement.scrollTop;
    },
    getScrollLeft : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        return objWindow.body.scrollLeft || objWindow.documentElement.scrollLeft;
    },

    //非同期通信用Xmlオブジェクト
    getXmlObj : function() {
        var Result;
        
	    if (window.XMLHttpRequest) {
            try { Result = new XMLHttpRequest(); }
            catch (e) { Result = false; }

        }
        else if (window.ActiveXObject) {
            try { Result = new ActiveXObject("Msxml2.XMLHTTP"); }
            catch (e) {
                try { Result = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch (ex) {Result = false; }
            }
	    }
        return Result;
    },

    $ : function(VstrId) {
        return PAFuncLib.WindowDocument.getElementById(VstrId);    
    },    

    //IFrameのWindow取得
    getFrameWindow : function(VstrFrameId) {
        var Result = null;
        var objFra = document.getElementById(VstrFrameId);
        
        if (objFra) {
            Result = objFra.contentWindow;
        }
        
        return Result;
    },
    //IFrame内のドキュメント取得
    getFrameDocument : function(VstrFrameId) {
        var Result = null;
        var objFra = document.getElementById(VstrFrameId);
        
        if (objFra) {
            if (objFra.contentDocument) {
                //Mozilla系
                Result = objFra.contentDocument;
            }
            else {
                //IE系
                Result = objFra.contentWindow.document;
            }
        }
        
        return Result;
    },

    
    //Shift, Ctrl, Altを押しているかのチェック用、キープレスイベントセット
    setKeyDownEvent : function() {
        PAFuncLib.addListener(document, 'keydown', PAFuncLib.KeyDownHandler);
        PAFuncLib.addListener(document, 'keyup', PAFuncLib.KeyUpHandler);
    },

    KeyDownHandler : function() {   
        var x = ''; 
        var e = PAFuncLib.getEvent();  
        if (e) {    
            x = e.keyCode;   
        }
        PAFuncLib.DetectKeys(x, true);   
    },
      
    KeyUpHandler : function() {   
        var x = ''; 
        var e = PAFuncLib.getEvent();  
        if (e) {    
            x = e.keyCode;   
        }
        PAFuncLib.DetectKeys(x, false);   
    },

    DetectKeys : function(KeyCode, IsKeyDown) {               
        if (KeyCode == '16') {   
            PAFuncLib.PAisSHIFT = IsKeyDown;   
        }   
        else if (KeyCode == '17') {   
            PAFuncLib.PAisCTRL = IsKeyDown;   
        }   
        else if (KeyCode == '18') {   
            PAFuncLib.PAisALT = IsKeyDown;   
        }    
        else {
            if (IsKeyDown) {
                PAFuncLib.PA_KEY_CODE = KeyCode;
            }
            else {
                PAFuncLib.PA_KEY_CODE = -1;    
            }
        } 
    },


    //ボタンを押す。VobjWindowなしなら、windowを使う。
    clickButton : function(VstrObjectId, VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        if (objWindow && objWindow.document) {
            PAFuncLib.clickElement(objWindow.document.getElementById(VstrObjectId));
        }
    },

    clickElement : function(VobjElement) {
        if (VobjElement) {
            if (PAFuncLib.IsFF) {
                // Firefox
                var e = objWindow.document.createEvent("MouseEvents");
                e.initEvent("click", true, true);
                VobjElement.dispatchEvent(e);
            }
            else {
                VobjElement.click();
            }
        }
    },

    //引数0なら、VobjWindowの変わりにwindowを使う
    getEvent : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        if (objWindow.event) {
            return objWindow.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;
    },


    getEventTarget : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var e = PAFuncLib.getEvent(objWindow);
        var Result = null;
        
        if (e) {
            if (e.target) {
                Result = e.target;        
            }
            else if (e.srcElement) {
                Result = e.srcElement;
            }
            if (Result.nodeType == 3) { // Safariのバグ？
                Result = Result.parentNode;
            }
        }
        
        return Result;
    },


    //IE: e.returnValue = false;
    //FF: e.preventDefault();
    //引数0なら、windowを使用する
    returnValueFalse : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;

        var e = PAFuncLib.getEvent(objWindow);
        if (e) {
            e.returnValue = false;
            if (typeof(e.preventDefault) == 'function') {
                e.preventDefault();
            }
        }
    },

    //選択中の文字列を取得
    getSelectionText : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var Result = '';
        if (objWindow.document) {
            if ((objWindow.document.selection) && (objWindow.document.selection.createRange)) {
                Result = objWindow.document.selection.createRange().text;
            }
            else if (objWindow.document.getSelection) {
                Result = objWindow.document.getSelection();
            }
        }
        
        return Result;
    },

    //指定したノードの親をたどり、引数2で指定したノード名をもつノードを取得
    getParentOf : function(VobjElement, VstrTargetNodeName) {
        var objParent = VobjElement.parentNode;
        while (objParent) {
            var obj = objParent.parentNode;
            if (obj && obj.nodeName && (obj.nodeName.toLowerCase() == VstrTargetNodeName.toLowerCase())) {
                return obj;
            }
            objParent = obj;
        }  
        return null;
    },
    
    //指定したノードの子から、引数2で指定したノード名をもつノードを取得
    getChildOf : function(VobjElement, VstrTargetNodeName) {
        if (VobjElement.hasChildNodes()) {
            var arr = VobjElement.childNodes;
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] && arr[i].nodeName && (arr[i].nodeName.toLowerCase() == VstrTargetNodeName.toLowerCase())) {
                    return arr[i];
                }
            }
        }
        return null;
    },
    
    //リクエスト文字を取得
    getRequestQuery : function(VobjWindow) {
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjWindow)) objWindow = VobjWindow;
        
        var Result = new Array();
        if (objWindow.location.search) {
            //先頭の?を除去
            var strString = objWindow.location.search.substring(1);
            var arr = strString.split('&');
            for (var i = 0; i < arr.length; i++) {
                var arr2 = arr[i].split('=');
                var strKey = arr2[0];
                var strVal = undefined;
                if (arr2.length > 1) {
                    strVal = arr2[1];
                }
                Result[strKey] = strVal;
            }
        }
        return Result;
    },
    
    //文字分割
    getParameter : function(VstrParameter, VstrFirstSep, VstrSecondSep) {
        var Result = new Array();
        var arr1 = VstrParameter.split(VstrFirstSep);
        for (var i = 0; i < arr1.length; i++) {
            var arr2 = arr1[i].split(VstrSecondSep);
            if (arr2[0]) {
                var strValue = null;
                if (arr2.length >= 2)
                    strValue = arr2[1];
                Result[arr2[0]] = strValue;
            }
        }
        return Result;
    },
    
    //２点間の距離
    getDistance : function(VintX1, VintY1, VintX2, VintY2) {
        return Math.floor(Math.sqrt(Math.pow(VintX1 - VintX2, 2) + Math.pow(VintY1 - VintY2)));
    },
    
    //スタイルの透明度をセット。値は0～100。0で透明。
    setOpacity : function(VobjElement, VintValue) {
        var intValue = 50;
        if (arguments.length == 2) {
            intValue = parseInt(VintValue, 10);
        }
        if ((intValue >= 0) && (VintValue <= 100)) {
            if (VobjElement.style.filter) {
                var reg = /alpha\(opacity=.*\)/gi;
                VobjElement.style.filter = VobjElement.style.filter.replace(reg, '').replace('  ', ' ');
            }
            VobjElement.style.filter += ' alpha(opacity=' + intValue + ')';
            var fltValue = parseFloat("" + (VintValue / 100));
            if ((fltValue >= 0) && (fltValue <= 1)) {
                VobjElement.style.MozOpacity = fltValue;//FireFox, Netscape
                VobjElement.style.opacity = fltValue;//Opera, Safari
            }
        }
    },
    
    //フェードインさせる
    Fade_Value : 0,
    Fade_Speed : 15,
    Fade_Change : 10,
    Fade_Object : null,
    Fade_Limit : 0,
    initFade : function(VobjOption) {
        PAFuncLib.Fade_Value = 0;
        PAFuncLib.Fade_Speed = 15;
        PAFuncLib.Fade_Change = 10;
        PAFuncLib.Fade_Object = null;
        PAFuncLib.Fade_Limit = 100;
        if (PAFuncLib.isnotUndefined(VobjOption)) {
            if (PAFuncLib.isnotUndefined(VobjOption.Speed)) PAFuncLib.Fade_Speed = VobjOption.Speed;
            if (PAFuncLib.isnotUndefined(VobjOption.Change)) PAFuncLib.Fade_Change = VobjOption.Change;
            if (PAFuncLib.isnotUndefined(VobjOption.Fade_Limit)) PAFuncLib.Fade_Limit = VobjOption.Fade_Limit;
        }
    },
    fadeIn : function(VobjElement, VobjOption) {
        PAFuncLib.initFade(VobjOption);
        PAFuncLib.Fade_Value = 0;
        PAFuncLib.Fade_Object = VobjElement;
        if (PAFuncLib.Fade_Object) {
            PAFuncLib.Fade_Object.style.visibility = 'visible';
            PAFuncLib.setOpacity(PAFuncLib.Fade_Object, PAFuncLib.Fade_Value);
            PAFuncLib.fadeInReflexive();
        }
    },
    fadeInReflexive : function() {
        if (PAFuncLib.Fade_Object) {
            PAFuncLib.Fade_Value += PAFuncLib.Fade_Change;
            PAFuncLib.setOpacity(PAFuncLib.Fade_Object, PAFuncLib.Fade_Value);
            if(PAFuncLib.Fade_Value >= PAFuncLib.Fade_Limit) {
                PAFuncLib.setOpacity(PAFuncLib.Fade_Object, PAFuncLib.Fade_Limit);
                PAFuncLib.Fade_Object = null;
                return;
            }
            setTimeout(PAFuncLib.fadeInReflexive, PAFuncLib.Fade_Speed);
        }
    },   
    //フェードアウトさせる
    fadeOut : function(VobjElement, VobjOption) {
        PAFuncLib.initFade(VobjOption);
        PAFuncLib.Fade_Value = 100;
        PAFuncLib.Fade_Object = VobjElement;
        if (PAFuncLib.Fade_Object) {
            PAFuncLib.setOpacity(PAFuncLib.Fade_Object, PAFuncLib.Fade_Value);
            PAFuncLib.fadeOutReflexive();
        }
    },
    fadeOutReflexive : function() {
        if (PAFuncLib.Fade_Object) {
            PAFuncLib.Fade_Value -= PAFuncLib.Fade_Change;
            PAFuncLib.setOpacity(PAFuncLib.Fade_Object, PAFuncLib.Fade_Value);
            if(PAFuncLib.Fade_Value <= 0) {
                PAFuncLib.setOpacity(PAFuncLib.Fade_Object, 0);
                PAFuncLib.Fade_Object.style.visibility = 'hidden';
                PAFuncLib.Fade_Object = null;
                return;
            }
            setTimeout(PAFuncLib.fadeOutReflexive, PAFuncLib.Fade_Speed);
        }
    },
    
    removeElement : function(VobjElement) {
        if (VobjElement) {
            var objChild = VobjElement.firstChild;
            while (objChild) {
                PAFuncLib.removeElement(objChild);
                objChild = objChild.nextSibling;
            }
            //イベント削除
            for(var obj in VobjElement){
                if (typeof VobjElement[obj] === 'function') {
                    VobjElement[obj] = null;
                }
            }
            VobjElement.parentNode.removeChild(VobjElement);
        }
    },
    
    //divエレメントを引数として渡す
    setCoverStyle : function(VobjElement, VobjOption) {
        var intZIndex = 1000;
        var strCoverColor = '#FFFFFF';
        var intCoverOpacity = 50;
        var objWindow = window;
        if (PAFuncLib.isnotUndefined(VobjOption)) {
            if (PAFuncLib.isnotUndefined(VobjOption.ZIndex)) intZIndex = parseInt(VobjOption.ZIndex, 10);
            if (PAFuncLib.isnotUndefined(VobjOption.CoverColor)) strCoverColor = VobjOption.CoverColor;
            if (PAFuncLib.isnotUndefined(VobjOption.CoverOpacity)) intCoverOpacity = parseInt(VobjOption.CoverOpacity, 10);
            if (PAFuncLib.isnotUndefined(VobjOption.Window)) objWindow = VobjOption.Window;
        }
    
        if (VobjElement) {
            VobjElement.style.width = PAFuncLib.getDocumentWidth(objWindow) + 'px';
            VobjElement.style.height = PAFuncLib.getDocumentHeight(objWindow) + 'px';
            VobjElement.style.position = 'absolute';
            
            VobjElement.style.top = '0px';
            VobjElement.style.left = '0px';
            VobjElement.style.zIndex = intZIndex;
            VobjElement.style.visibility = 'visible';

            //半透明処理
            VobjElement.style.backgroundColor = strCoverColor;
            PAFuncLib.setOpacity(VobjElement, intCoverOpacity);
            
            //右クリック禁止
            PAFuncLib.addListener(VobjElement, 'contextmenu', function() {
                    PAFuncLib.returnValueFalse(objWindow);
                });
        }
    },
    
    setTextBoxSelectByFocus : function() {
        var arr = document.getElementsByTagName('input');
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].type == 'text') {
                PAFuncLib.addListener(arr[i], 'focus', function() {
                        var objEvent = PAFuncLib.getEventTarget();
                        objEvent.select();
                    });
            }
        }

    },
    
    //bodyにjsファイルを動的挿入
    insertScript : function(VobjOption) {
        var objBody = document.getElementsByTagName('body')[0];
        if (objBody) {
            var objScript = document.createElement('script');
            objScript.setAttribute('type', 'text/javascript');
            objScript.setAttribute('language', 'javascript');
            objScript.setAttribute('src', VobjOption.Src);
            
            objBody.appendChild(objScript);
        }
    },
    
        
    Draggable : function(VobjElement, VobjOption) {
        this.Element = VobjElement;
        this.IsDragging = false;
        this.MouseDownX = 0;
        this.MouseDownY = 0;
        this.ElementTop = 0;
        this.ElementLeft = 0;
        this.Option = {
            Opacity : 100,
            EventElement : VobjElement
        };
        if (PAFuncLib.isnotUndefined(VobjOption)) {
            if (PAFuncLib.isnotUndefined(VobjOption.Opacity)) this.Option.Opacity = VobjOption.Opacity;
            if (PAFuncLib.isnotUndefined(VobjOption.EventElement)) this.Option.EventElement = VobjOption.EventElement;
        }

        var objThis = this;        
        objThis.Element.style.position = 'absolute';
        
        PAFuncLib.addListener(objThis.Option.EventElement, 'mousedown', function() {
                if (objThis.Option.EventElement.setCapture) {
                    objThis.Option.EventElement.setCapture(false);
                }
                objThis.Element.style.top = objThis.Element.offsetTop + 'px';
                objThis.Element.style.left = objThis.Element.offsetLeft + 'px';
                objThis.Element.style.right = '';
                objThis.Element.style.bottom = '';
                
                var udtPos = PAFuncLib.getMousePoint();
                objThis.IsDragging = true;
                objThis.ElementLeft = 0;
                objThis.ElementTop = objThis.Element.offsetTop;
                objThis.ElementLeft = objThis.Element.offsetLeft;
                objThis.MouseDownX = parseInt(udtPos.X, 10);
                objThis.MouseDownY = parseInt(udtPos.Y, 10);
                PAFuncLib.returnValueFalse();
            });
        PAFuncLib.addListener(window.document, 'mouseup', function() {
                if (objThis.Option.EventElement.releaseCapture) {
                    objThis.Option.EventElement.releaseCapture(false);
                }

                objThis.IsDragging = false;
            });
        PAFuncLib.addListener(window.document, 'mousemove', function() {
                if (objThis.IsDragging) {
                    var udtPos = PAFuncLib.getMousePoint();
                    var intDeltaX = udtPos.X - objThis.MouseDownX;
                    var intDeltaY = udtPos.Y - objThis.MouseDownY;
                    var intLeft = objThis.ElementLeft + intDeltaX;
                    var intTop = objThis.ElementTop + intDeltaY;
                    objThis.Element.style.left = intLeft + 'px';
                    objThis.Element.style.top = intTop + 'px';
                    PAFuncLib.returnValueFalse();
                }
            });
    },
    
    toDOM : function(VstrXml) {

	    var dom,serial,parser

	    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		    dom = new ActiveXObject("Msxml2.DOMDocument.3.0");
		    dom.async = false;
	    }
	    else {
		    dom = document.implementation.createDocument("", "", null);
		    dom.async = false;
		    serial = new XMLSerializer();
		    parser = new DOMParser();
	    }

	    var node = dom.createProcessingInstruction("xml", "version='1.0'");
	    dom.appendChild(node);
	    
	    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		    dom.loadXML(VstrXml);
            return dom;
	    }
	    else {
		    return parser.parseFromString(VstrXml, "text/xml");
	    }
    }
    
};



//window.unloadでイベントを消す
//PAFuncLib.addListener(window, 'unload', PAFuncLib.window_unload);


//Prototype.jsにある'$()'と同じもの
//  割り当てられていなければ、割り当てる
if (PAFuncLib.isUndefined(window.$)) {
    window.$ = function(VstrId) { return PAFuncLib.$(VstrId); }
}

//評価送信
function postData(v_url, v_faqId, v_estId, v_reason, v_detailorder) {
	var Result = null;
	var objXml = PAFuncLib.getXmlObj();
	if (objXml) {
		objXml.open('post', v_url, false);
		objXml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		objXml.send('faqid=' + v_faqId + '&estid=' + v_estId + '&reason=' + escape(v_reason) + '&detailorder=' + v_detailorder);
		if (objXml.responseText) {
			Result = objXml.responseText;
		}
	}
	return Result;
}

function setCookie(VstrKeywords){
//	createCookie("PAKeywords",escape(VstrKeywords),1);
	var strKeywords = getConvertString(VstrKeywords);
	createCookie("PAKeywords",encodeURIComponent(strKeywords),1);
}

// 2010/02/10 - add by hayashi - start : Medical Finder Step2対応
function setCookieMF(VstrKeywords){
	var strKeywords = getConvertString(VstrKeywords);
	createCookie("MFKeywords",encodeURIComponent(strKeywords),1);
}

function setCookieDI(VstrKeywords){
	var strKeywords = getConvertString(VstrKeywords);
	createCookie("DIKeywords",encodeURIComponent(strKeywords),1);
}

function setCookieNI(VstrKeywords){
	var strKeywords = getConvertString(VstrKeywords);
	createCookie("NIKeywords",encodeURIComponent(strKeywords),1);
}
// 2010/02/10 - add by hayashi - end

function getConvertString(VstrText){
	var strText = VstrText;
	strText = strText.toUpperCase();
	strText = strText.replace(/;/g,"；");
	strText = strText.replace(/</g,"＜");
	strText = strText.replace(/>/g,"＞");
	strText = strText.replace(/\(/g,"（");
	strText = strText.replace(/\)/g,"）");
	strText = strText.replace(/\'/,"’");
	strText = strText.replace(/\"/g,"”");
	strText = strText.replace(/\*/g,"＊");
	strText = strText.replace(/\+/g,"＋");
	strText = strText.replace(/\-/g,"－");
	strText = strText.replace(/\//g,"／");
	strText = strText.replace(/%/g,"％");
	strText = strText.replace(/\$/g,"＄");
	strText = strText.replace(/&/g,"＆");
	strText = strText.replace(/\|/g,"｜");
	strText = strText.replace(/\!/g,"！");
	strText = strText.replace(/\{/g,"｛");
	strText = strText.replace(/\}/g,"｝");
	strText = strText.replace(/\[/g,"［");
	strText = strText.replace(/\]/g,"］");
	strText = strText.replace(/\./g,"．");
	strText = strText.replace(/\\/g,"￥");

	return strText;
}


if(document.domain.toLowerCase() ==　"testqa.eisai.jp" || document.domain.toLowerCase() == "test.eisai.jp"){
	document.title = "テスト環境 ! " + document.title;
}


