﻿function textbaidu(id){
txt = getSelText()?getSelText():$('#'+id).text();
if($("#baidu").length==0)$("body").append("<form id=baidu action='http://www.baidu.com/s' target='baidu'><input type=hidden name=wd id=wd></form>");
$("#wd").val(txt);
document.charset='gb2312';
$("#baidu").submit();
document.charset='utf-8';
}

function textcopy(id){
txt = getSelText()?getSelText():$('#'+id).text();
window.clipboardData.setData("text", txt);
}

function textsearch(id){
txt = getSelText()?getSelText():$('#'+id).text();
url = "baidugoogle.php?domains=www.zaixian-fanyi.com&sitesearch=&client=pub-8514482118272713&forid=1&ie=utf-8&oe=utf-8&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A11&hl=zh-CN&q="+encodeURI(txt);
window.open(url,"google");
}

function textspeak(id)
{
	txt = getSelText()?getSelText():$('#'+id).text();
	if(txt.length>100)txt=txt.substring(0,100);
	$.getJSON("http://api.microsofttranslator.com/V2/Ajax.svc/Detect?appId=05DBC69E5594C137B9E22680F92F8E5E97BFAC7B&text="+encodeURI(txt)+"&oncomplete=?",function(lang){
	$("#rd").html("<embed src=\"http://api.microsofttranslator.com/V2/Http.svc/Speak?appId=05DBC69E5594C137B9E22680F92F8E5E97BFAC7B&text="+encodeURI(txt)+"&language="+lang+"&format=audio%2fwav\" width=0 height=0 type=audio/mpeg autostart=1 loop=0></embed>" );});
}


function textpaste(id){
$('#'+id).append(window.clipboardData.getData("text"));
}


function textdelete(){
	$('#q').empty();
}


function bookmarkit()
{
   window.external.addFavorite('http://www.zaixian-fanyi.com/','青云英汉互译网')
} 


function swap()
{
tl = $("#tl").val();	$("#tl").val($("#sl").val());		$("#sl").val(tl);
}

function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    return txt;
}

