//--------------------------------------------------------
// 共通ライブラリ
//--------------------------------------------------------
var CommonLib = {
    //初期化
    init : function(id)
    {
        this.glayerID = id;
    },
    
    //ダイアログを表示する
    showDialog : function(id)
    {
        this.dialog             = $(id);
        var divSize             = Element.getDimensions(this.dialog);
        var pageSize            = Layer.getWindowSize();
        this.dialog.style.left  = (pageSize[0]/2 - divSize.width/2) + 'px';
        if(this.isIE()){
            window.onscroll = this.onScroll.bind(this);
            this.onScroll();
        } else {
            this.dialog.style.top   = '0px';
        }
        
        Layer.show(this.glayerID);
        Element.show(id);
    },
    
    //ダイアログを閉じる
    hideDialog : function(id)
    {
        Element.hide(id);
        Layer.hide(this.glayerID);
    },
    
    //待機状態開始（カーソルが砂時計になる）
    startWait : function(id)
    {
        Element.show(id);
    },
    
    //待機状態終了
    stopWait : function(id)
    {
        Element.hide(id);
    },
    
    isIE : function(){
        var ua = navigator.userAgent;
        return (ua.indexOf("MSIE") != -1 && ua.indexOf("Opera") == -1);
    },
    
    onScroll : function(){
        this.dialog.style.top = document.body.scrollTop || document.documentElement.scrollTop + 'px';
    },
	
    strToAJAX : function(txt)
    {
		while( txt.indexOf( "/" ) >= 0 ){
			txt = txt.replace( "/", "%2F" );
		}
		while( txt.indexOf( "?" ) >= 0 ){
			txt = txt.replace( "?", "%3F" );
		}
		while( txt.indexOf( "=" ) >= 0 ){
			txt = txt.replace( "=", "%3D" );
		}
		while( txt.indexOf( "&" ) >= 0 ){
			txt = txt.replace( "&", "%26" );
		}
		while( txt.indexOf( "\\" ) >= 0 ){
			txt = txt.replace( "\\", "%5C" );
		}
		return( txt );
	},
	
	strToHtml : function( txt ){
	    while( txt.indexOf( "&lt;" ) >= 0 ){
			txt = txt.replace( "&lt;", "&amp;lt;" );
		}
		while( txt.indexOf( "&gt;" ) >= 0 ){
			txt = txt.replace( "&gt;", "&amp;gt;" );
		}
		while( txt.indexOf( "&copy;" ) >= 0 ){
			txt = txt.replace( "&copy;", "&amp;copy;" );
		}
		while( txt.indexOf( "<" ) >= 0 ){
			txt = txt.replace( "<", "&lt;" );
		}
		while( txt.indexOf( ">" ) >= 0 ){
				txt = txt.replace( ">", "&gt;" );
		}
		while( txt.indexOf( "\"" ) >= 0 ){
			txt = txt.replace( "\"", "&quot;" );
		}
		return( txt );
	},
	
    //オブジェクトの中身表示（デバッグ用）
    showObj : function(obj)
    {
        var contents = "";
        for (var i in obj) {
            if (obj[i] != null) {
                contents += i + " : " + obj[i] + "\n";
            }
        }
        alert(contents);
    }
}

//--------------------------------------------------------
// 共通 エラーメッセージダイアログ
//--------------------------------------------------------
var ErrorDialog = {
    //初期化
    init: function(id)
    {
        this.errorDialogID = id;
    },
    
    //エラーメッセージダイアログを表示する
    show : function(msg)
    {
        var tmp = "";
        tmp += "<div class='inner'>";
        tmp += "<div class='dialogTitle'><h3>";
        tmp += msg;
        tmp += "</h3></div>";
        tmp += "</div>";
        tmp += "<a href='javascript:void(null)' class='backButton' onclick='ErrorDialog.hide(); return false;'><span class='replaceText'>戻る</span></a>";
        $(this.errorDialogID).innerHTML = tmp;
        CommonLib.showDialog(this.errorDialogID);
    },
    
    //エラーメッセージダイアログを閉じる
    hide : function()
    {
        CommonLib.hideDialog(this.errorDialogID);
    }
}
