﻿function CMainFrame(){
    this.inited=false;
}

CMainFrame.prototype={
 Init:function(selLang,selDom,svrUri,fbUri,hUri){
    if(this.inited)return;
    this.inited=true;
    
	this.selLang=$(selLang);
	this.selDom=$(selDom);
	this.svrUri=svrUri;
	this.fbUri=fbUri;
	this.hUri=hUri;

    this.frmSrc=$("frmSrc");
    this.frmTgt=$("frmTgt");
    this.frmHistory=$("frmHistory");
    this.tbAddress=$("tbAddress");
    
    var i=this.selLang.selectedIndex;
        if(i<0){
            this.selLang.selectedIndex=0;
            return;
        }
        var s=this.selLang.options[i].innerText;
        var a=s.split(" - ");
        $("lbWebSrc").innerText=a[0];
        $("lbWebTgt").innerText=a[1];
    
    this.tbAddress.attachEvent("onfocus",Util.CreateDelegate(this.tbAddress,this.tbAddressFocus));
    this.tbAddress.attachEvent("onkeypress",Util.CreateDelegate(this,this.tbAddressKeyPress));
 },
 Go:function(a){
	a=a.trim();
	if(a=="")return;
	if(a.indexOf("://")==-1)
		a="http://"+a;
	else{
		var s=a.substring(0,a.indexOf("://"));
		if(s!="http"&&s!="https"&&s!="ftp"){
			alert(Resources.NotSupportedScheme);
			return;
        }
    }

	var l=this.selLang.value;
    var d=this.selDom.value;
	this.frmHistory.contentWindow.location.href=this.hUri+"?l="+l+"&d="+d+"&a="+encodeURIComponent(a);
 },
 btnTransClicked:function(){
    if(this.tbAddress.value=="")
    {
        alert("请输入翻译网页地址");
        return;
    }
    this.Go(this.tbAddress.value);
 },
 tbAddressKeyPress:function(){
    if(window.event.keyCode!=13)return;
    this.btnTransClicked();
    window.event.returnValue=false;
 },
 tbAddressFocus:function(){
    if(this.createTextRange)
        this.createTextRange().select();
    else if(this.selectionStart){
        this.selectionStart=0;
        this.selectionEnd=this.value.length;
    }
 },
 Goto:function(a,l,d){
    this.tbAddress.value=a;
    this.selLang.value=l;
    this.selDom.value=d;

    this.frmSrc.contentWindow.location.replace(this.svrUri+"?n=src&l="+l+"&d="+d+"&a="+encodeURIComponent(a));
    this.frmTgt.contentWindow.location.replace(this.svrUri+"?n=tgt&l="+l+"&d="+d+"&a="+encodeURIComponent(a));
 }
}

mainFrame=new CMainFrame();

