// JavaScript Document

google.load("language", "1");
    function translate(to,todiv){
        var source=document.getElementById("trancon").innerHTML
        var translated = document.getElementById("resulttrans");
		  translated.innerHTML = "正在翻译中. . . "
       var fromlang = document.getElementById('sourcelang').value;
       // var tolang = document.getElementById('to').value;
        //var tolang = document.getElementById(to).value; 
		tolang=to;
        google.language.translate(source, fromlang, tolang, function(result) {
            if (!result.error) {
              translated.style.cssText="color:green"
			  translated.innerHTML = "翻译内容为："+result.translation;
			  document.body.removeChild(todiv)
            }
        });
    }
	
function checktranslate(eve){
		var source=document.getElementById("trancon").innerHTML
        var translated = document.getElementById("resulttrans");
		translated.innerHTML = "正在翻译中. . . "
      	var fromlang = document.getElementById('sourcelang').value;
		
		var top=0;var left=0;
		if(eve.pageY||eve.pageX){
			top = eve.pageY +10;
			left = eve.pageX +10;
		}else{
			left = event.clientX + document.body.scrollLeft+ document.documentElement.scrollLeft +10;
			top = event.clientY + document.body.scrollTop + document.documentElement.scrollTop + 10;
		}
		todiv=document.createElement("div")
		todiv.innerHTML="";
		todiv.style.cssText="height:50px;width:240px;position:absolute; top:"+top+"px;left:"+left+"px; background:#fff;text-align:center;border:1px solid #999;filter:alpha(opacity=100);-moz-opacity:1; text-algin:center;padding-top:10px;"
		todiv.innerHTML="<p style=\"margin:0px;paddint:0px;\">请选的要翻译的语言</p> <input type=button name=button value='中文' onclick=translate('zh-CN',todiv) /> &nbsp;&nbsp;&nbsp;<input type=button name=button value='英文' onclick=translate('en',todiv) />"
		document.body.appendChild(todiv)
		
}

