/**
 * 文本框提示信息公共模塊
 * inputMsg.showRightY('regName','這是提示');  彈出輸入框右邊的提示
 * inputMsg.showRightN('regName','這是錯誤');  彈出輸入框右邊的錯誤提示
 * inputMsg.showLeftY('regName','這是提示');  彈出輸入框左邊的提示
 * inputMsg.showLeftN('regName','這是錯誤');  彈出輸入框左邊的錯誤提示
 * inputMsg.showIcon('regName','Y');    在文本框右邊定義一個圖片(Y=正確圖標,N=錯誤圖標)
 **/
var inputMsg = ({
	blueRightArrowImg:'http://statics.1796.com.tw/img/public/blue_03.gif',
	redRightArrowImg:'http://statics.1796.com.tw/img/public/red_03.gif',
    blueLeftArrowImg:'http://statics.1796.com.tw/img/public/blueR_03.gif',
	redLeftArrowImg:'http://statics.1796.com.tw/img/public/redR_03.gif',
	promptImg:'http://statics.1796.com.tw/img/public/prompt.gif',
	errorImg:'http://statics.1796.com.tw/img/public/error.gif',
	errorIcon:'http://statics.1796.com.tw/img/public/warning.gif',
	accessIcon:'http://statics.1796.com.tw/img/public/access.gif',
	maxWidth:200,
	minWidth:150,
	hideTime:5000,
    //創建信息窗口
    createRightBox:function(inputId, i){
		if( $("#"+inputId).length > 0  && $("#"+i).length == 0) {
			var offset =  $("#"+inputId).offset();
			var inputMsgBodyTop = offset.top;
			var inputMsgBodyLeft = offset.left + $("#"+inputId).width()+10;
			var inputMsgBodyCss = 'position: absolute;z-index: 101;top:'+inputMsgBodyTop+'px;left:'+inputMsgBodyLeft+'px;text-align:left';
			var inputMsgBodyHtml = '<div id="'+i+'" style="'+inputMsgBodyCss+'"></div>';       
			$("body").append(inputMsgBodyHtml);
		}
    },
    
    //刪除信息窗口
    removeRightBox:function(i){
		if( $("#"+i).length > 0 ) {
            $("#"+i).fadeOut("slow",function() {
				$("#"+i).remove();
			}); 
        }
    },
    //删除窗口
    removeAllBox:function(inputId) {
        var i = inputId+"MsgBodyY";
        var y = inputId+"MsgBodyN";
        if( $("#"+i).length > 0 ) {
            $("#"+i).fadeOut("slow",function() {
				$("#"+i).remove();
			}); 
        }
        if( $("#"+y).length > 0 ) {
            $("#"+y).fadeOut("slow",function() {
				$("#"+y).remove();
			}); 
        }
    },
    //檢查提示窗口是否存在
    chkRightBox:function(inputId, i) {
        if( $("#"+i).length == 0 ) {
            this.createRightBox(inputId, i);
        }
    },
    //顯示右邊提示窗口
    showRightY:function(inputId, msgText){
        var i = inputId+"MsgBodyY";
        var y = inputId+"MsgBodyN";
        this.chkRightBox(inputId, i);
		var inputWidth = $("#"+inputId).width() < this.minWidth ? this.minWidth :$("#"+inputId).width();
		var inputWidth = inputWidth > this.maxWidth ? this.maxWidth : inputWidth;
		var inputMsgArrowCss = 'position: absolute;z-index:103;width:10px;display:block;float:left;margin-top:7px;';
		var inputMsgMainCss = 'position: absolute;z-index:102;padding:5px;margin-left:9px;background-color:#e2f5ff;border:solid 1px #00a8ff;color:#000000;width:'+inputWidth+'px;line-height:18px;';
        var msgTextHtml = '<div id="inputMsgArrow" style="'+inputMsgArrowCss+'"><img src="'+this.blueRightArrowImg+'" /></div><div id="inputMsgMain" style="'+inputMsgMainCss+'"><img src="'+this.promptImg+'" align="top"> '+msgText+'</div>';
		$("#"+i).html(msgTextHtml);
        if ($("#"+y) != null ) {
            this.removeRightBox(y);
        }
	},
	//顯示右邊錯誤窗口
	showRightN:function(inputId, msgText) {
		var i = inputId+"MsgBodyN";
        var y = inputId+"MsgBodyY";
        this.chkRightBox(inputId, i);
		var inputWidth = $("#"+inputId).width() < this.minWidth ? this.minWidth :$("#"+inputId).width();
		var inputWidth = inputWidth > this.maxWidth ? this.maxWidth : inputWidth;
		var inputMsgArrowCss = 'position: absolute;z-index:105;width:10px;display:block;float:left;margin-top:7px;';
		var inputMsgMainCss = 'position: absolute;z-index:104;padding:5px;margin-left:9px;background-color:#fff2e9;border:solid 1px #ff6600;color:#000000;width:'+inputWidth+'px;line-height:18px;';
        var msgTextHtml = '<div id="inputMsgArrow" style="'+inputMsgArrowCss+'"><img src="'+this.redRightArrowImg+'" /></div><div id="inputMsgMain" style="'+inputMsgMainCss+'"><img src="'+this.errorImg+'" align="top"> '+msgText+'</div>';
		$("#"+i).html(msgTextHtml);
        if ($("#"+y) != null ) {
            this.removeRightBox(y);
        }
		window.setTimeout('inputMsg.removeRightBox(\''+i+'\');',this.hideTime);
	},
	//文本框后出現圖標
	showIcon:function(inputId, state) {
		var iconImg; 
		if (state == 'Y') {
			iconImg = this.accessIcon;
		} else {
			iconImg = this.errorIcon;
		}
		if ($("#"+inputId+"MsgIcon").length == 0) {
			var inputMsgIconCss = 'margin-left:12px;';
			var iconHtml = '<img src="'+iconImg+'" id="'+inputId+'MsgIcon" style="'+inputMsgIconCss+'" align="absmiddle"/>';
			$("#"+inputId).after(iconHtml);		
		} else {
			$("#"+inputId+"MsgIcon").attr("src",iconImg);
		}
		
	},
    //創建左边信息窗口
    createLeftBox:function(inputId, i){
		if( $("#"+inputId).length > 0  && $("#"+i).length == 0) {
			var offset =  $("#"+inputId).offset();
			var inputMsgBodyTop = offset.top;
			var inputMsgBodyLeft = offset.left - $("#"+inputId).width() - 50;
            var inputWidth = $("#"+inputId).width() < this.minWidth ? this.minWidth :$("#"+inputId).width();
            inputWidth = inputWidth > this.maxWidth ? this.maxWidth : inputWidth;
            inputWidth  = inputWidth + 10;
			var inputMsgBodyCss = 'overflow: hidden;position: absolute;z-index: 101;top:'+inputMsgBodyTop+'px;left:'+inputMsgBodyLeft+'px;width:200px;';
			var inputMsgBodyHtml = '<div id="'+i+'" style="'+inputMsgBodyCss+'"></div>';       
            $("body").append(inputMsgBodyHtml);
		}
    },
    //取输入框左边位置
    getMsgBoxLeft:function(inputId){
        var offset =  $("#"+inputId).offset();
        var inputMsgBodyLeft = offset.left - $("#"+inputId).width() - 50;
        return inputMsgBodyLeft;
    },
	//取输入框右边位置
	getMsgBoxRight:function (inputId){
			var offset =  $("#"+inputId).offset();
			var inputMsgBodyRight = offset.left + $("#"+inputId).width() + 40;
			return inputMsgBodyRight;
	},
    //刪除左边信息窗口
    removeLeftBox:function(i){
		if( $("#"+i).length > 0 ) {
            $("#"+i).fadeOut("slow",function() {
				$("#"+i).remove();
			}); 
        }
    },
    //檢查左边提示窗口是否存在
    chkLeftBox:function(inputId, i) {
        if( $("#"+i).length == 0 ) {
            this.createLeftBox(inputId, i);
        }
    },
    //顯示左边提示窗口
    showLeftY:function(inputId, msgText){
        var i = inputId+"MsgBodyY";
        var y = inputId+"MsgBodyN";
        this.chkLeftBox(inputId, i);
		var inputMsgArrowCss = 'width:10px;margin-top:7px;float:right;';
		var inputMsgMainCss = 'margin-right:9px;padding:5px;background-color:#e2f5ff;border:solid 1px #00a8ff;color:#000000;line-height:18px;';
        var msgTextHtml = '<div id="inputMsgArrow" style="'+inputMsgArrowCss+'"><img src="'+this.blueLeftArrowImg+'" /></div><div id="inputMsgMain" style="'+inputMsgMainCss+'"><img src="'+this.promptImg+'" align="top"> '+msgText+'</div>';
		$("#"+i).html(msgTextHtml);
        if ($("#"+y) != null ) {
            this.removeLeftBox(y);
        }
	},
	//顯示左边錯誤窗口
	showLeftN:function(inputId, msgText) {
		var i = inputId+"MsgBodyN";
        var y = inputId+"MsgBodyY";
        this.chkLeftBox(inputId, i);
		var inputMsgArrowCss = 'width:10px;margin-top:7px;float:right;';
		var inputMsgMainCss = 'margin-right:9px;padding:5px;background-color:#fff2e9;border:solid 1px #ff6600;color:#000000;line-height:18px;';
        var msgTextHtml = '<div id="inputMsgArrow" style="'+inputMsgArrowCss+'"><img src="'+this.redLeftArrowImg+'" /></div><div id="inputMsgMain" style="'+inputMsgMainCss+'"><img src="'+this.errorImg+'" align="top"> '+msgText+'</div>';
		$("#"+i).html(msgTextHtml);
        if ($("#"+y) != null ) {
            this.removeLeftBox(y);
        }
        window.setTimeout('inputMsg.removeRightBox(\''+i+'\');',this.hideTime);
	},
	//顯示空白窗口 author:zhi  date: 2009/03/10
    showAboutBlankWin:function(inputId, msgText){
        var i = inputId+"MsgBodyY";
        var y = inputId+"MsgBodyN";
        this.chkRightBox(inputId, i);
		var inputWidth = $("#"+inputId).width() < this.minWidth ? this.minWidth :$("#"+inputId).width();
		var inputWidth = inputWidth > this.maxWidth ? this.maxWidth : inputWidth;
        var msgTextHtml = '<div id="inputMsgArrow" >'+msgText+'</div>';
		$("#"+i).html(msgTextHtml);
        if ($("#"+y) != null ) {
            this.removeRightBox(y);
        }
	}
});