﻿function CWordShow()
{
	this.closeScript='parent.WordShow.dictClose()';
}
CWordShow.prototype=
{
    Show:function(eleId)
    {
        this.eleId=eleId;
        var elemText=this.doc2.getElementById(eleId).innerHTML;
        this.dictShow(elemText);
        this.btmDiv.style.display="none";
    },
    Hide:function()
    {
        try
        {
            if(this.FeedBack_Dlg!=null)
            {
                this.FeedBack_Dlg.style.display="none";
                this.btmDiv.style.display="none";
            }
         }
         catch(e)
         {}
    },
    Init:function(doc1,doc2)
    {
        this.doc1=doc1;
        this.doc2=doc2;
        this.dictInit();
    },
    dictInit:function()
    {
        this.FeedBack_Dlg = this.doc1.getElementById('FeedBack_Dlg');
        if(null!=this.FeedBack_Dlg)return;

        this.dict_is_ie = Util.MSIE;

        var h='<div style="border: 2px dotted #7E98D6; background-color: #FFFFCC; width: 280px;">\
	<div style="width: 100%; cursor: move; background-color: #C8DAF3;font-size: 12px; line-height: 20px;">\
	    <span style="float: right;"><a href="javascript:'+this.closeScript+'" target="_self">关闭</a></span>\
	    <span style="color: #1A9100;">华建在线翻译</span> \
	</div> \
	<div id="topFrame" style="height: 80px; overflow: scroll;width: 100%"></div> \
	<input id="sgtBtn" type="submit" value="更好的建议" style="width: 100px;border: 0px; padding:0px;margin:0px; float: right;"/> \
	<div id="bottomPart" style="float: right; width: 100%; background-color: #FFFFCC;"> \
	    <textarea id="ta" rows="3" style="width:100%; border: 1px solid #7E98D6; padding:0px;margin:0px;float: right; "></textarea> \
	    <input id="btnSend" type="submit" value="发送反馈信息"  style="width: 100px; border: 1px;padding:0px;margin:0px;float: right; "/> \
	</div> \
	</div>';
      
        var layer=this.doc1.createElement('div');
        layer.id='FeedBack_Dlg';
        layer.style.cssText='position:absolute;z-index:6000;display:none;background-color:#FFF;filter:Alpha(Opacity=96);';
        layer.innerHTML=h;
        this.doc1.body.appendChild(layer);
        this.FeedBack_Dlg = this.doc1.getElementById('FeedBack_Dlg');
        this.FeedBack_Dlg.onmouseover=function()
                                {
                                    Hover.OnOver(this.eleId);
                                }
        this.FeedBack_Dlg.onmouseout=function()
                                {
                                    Hover.OnOut(this.eleId);
                                }
        this.dict_startx=0;
        this.dict_starty=0;

        var btn=this.doc1.getElementById("sgtBtn");
        Util.AddEvent(btn,"click",Util.CreateDelegate(this,this.DstFrameUpdate));

        this.btmDiv=this.doc1.getElementById("bottomPart");
        this.ta=this.doc1.getElementById("ta");
        this.btmDiv.style.display="none";

        var sendBtn=this.doc1.getElementById("btnSend");
        Util.AddEvent(sendBtn,"click",Util.CreateDelegate(this,this.OnSendClick));
    },
    DstFrameUpdate:function()
    {
        if(this.btmDiv!=null)
        {
            if(this.btmDiv.style.display=="")
            {
                this.btmDiv.style.display="none";
            }
            else
            {
                this.btmDiv.style.display="";
                var ele=this.doc1.getElementById(this.eleId);
                this.topWordElem.innerHTML=this.GetSrcText();
                this.ta.value=this.GetTgtText();
            }
        }
    } ,
    dictDisplay:function()
    {
        var dx=262;
        var dy=264;
        this.dict_y += 8;
        this.dict_x += 16;
        if(this.dict_is_ie)
        {
            if (this.doc1.documentElement.offsetHeight && this.doc1.body.scrollTop+this.doc1.documentElement.scrollTop+this.doc1.documentElement.offsetHeight - this.dict_y < dy)
            {
                this.dict_y = this.doc1.body.scrollTop+this.doc1.documentElement.scrollTop + this.doc1.documentElement.offsetHeight - dy;
                this.dict_x += 14;
            }
            if (this.doc1.documentElement.offsetWidth && this.doc1.body.scrollLeft+this.doc1.documentElement.scrollLeft+this.doc1.documentElement.offsetWidth - this.dict_x < dx)
            {
                this.dict_x = this.doc1.body.scrollLeft+this.doc1.documentElement.scrollLeft + this.doc1.documentElement.offsetWidth - dx;
            }
        }
        else
        {
            dx-=1;
            dy+=11;
            if (self.innerHeight && this.doc1.body.scrollTop+this.doc1.documentElement.scrollTop + self.innerHeight - this.dict_y < dy) 
            {
                this.dict_y = this.doc1.body.scrollTop+this.doc1.documentElement.scrollTop + self.innerHeight - dy;
                this.dict_x += 14;
            }
            if (self.innerWidth && this.doc1.body.scrollLeft+this.doc1.documentElement.scrollLeft + self.innerWidth - this.dict_x < dx) 
            {
                this.dict_x = this.doc1.body.scrollLeft+this.doc1.documentElement.scrollLeft + self.innerWidth - dx;
            }
        }
        this.dict_cx = this.dict_x;
        this.dict_cy = this.dict_y;
        this.dict_startx = this.dict_x;
        this.dict_starty = this.dict_y;
        this.FeedBack_Dlg.style.left = this.dict_cx+'px';
        this.FeedBack_Dlg.style.top = this.dict_cy+'px';
        this.FeedBack_Dlg.style.display="";
        this.dict_moving = 1;
    },
    dictShow:function(word)
    {
        this.dictGetPos();
        this.dictDisplay();
        
        try
        {
            this.topWordElem = this.doc1.getElementById("topFrame");
            this.topWordElem.innerHTML=word;
        }
	    catch(x)
	    {
	        var t=null;
        }
    },
    dictClose:function()
    {
        try
        {
            this.dict_moving = 1;
    	    this.FeedBack_Dlg.style.display="none";
        }
        catch (x)
        {
        }
    },
    dictGetPos:function()
    {
        var b=this.doc1.getElementById(this.eleId);

      this.dict_x=Util.AbsXPos(b)+b.clientWidth+10;
      this.dict_y=Util.AbsYPos(b)+b.clientHeight+10;

    },
    OnSendClick:function()
    {
        var langPair=mainFrame.selLang.value;
        var dom=mainFrame.selDom.value;
        var src=this.GetSrcText();
        var tgt=this.ta.value;
        if(""==tgt)
        {
            alert("译文不能为空");
            return;
        }
        this.SendMessage(langPair,dom,src,tgt);
    },
    SendMessage:function(langPair,dom,srcText,destText)
    {
        this.x=new XMLHttpRequest;
        if(this.x.overrideMimeType) {
          this.x.overrideMimeType("text/xml")
        }
        this.x.onreadystatechange=Util.CreateDelegate(this,this.RunCallBack);
        this.x.open("POST",mainFrame.fbUri,true);
        this.x.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       
        var a=this.GetMessage(langPair,dom,srcText,destText);

        this.x.send(a);    
    },
    GetMessage:function(langPair,dom,srcText,destText)
    {
        var sb = new Sys.StringBuilder();
        sb.append("lng=");
        sb.append(langPair);
        sb.append("&dom=");
        sb.append(dom);
        sb.append("&src=");
        sb.append(encodeURIComponent(srcText));
        sb.append("&tgt=");
        sb.append(encodeURIComponent(destText));
        return sb.toString();
    },
    RunCallBack:function()
    {
        if(this.x.readyState!=4)return;
        if(this.x.status!=200)
            alert(Resources.FeedBackFailed);
        else
            alert(Resources.FeedBackOK);
    },
    GetSrcText:function()
    {
        var ele=Highlight.docSrc.getElementById(this.eleId);
        return ele.innerHTML;
    },
    GetTgtText:function()
    {
        var ele=Highlight.docTgt.getElementById(this.eleId);
        return Util.GetInnerText(ele);
    }
}
