var xmlHttp;
var loading = '<br /><img src="/images/loading.gif" /> <br />';
var loading_log = '<img src="/images/load_login.gif" />';
window.onresize = myResize;
var isToggleTrans = 0;
var isToggleFavHis = 0;
var isPaste = 0;
var meaning = "";
var similar = "";
function showcont(){
    jQuery("#show").show();
    isToggleTrans = 0;
    document.getElementById('dictNote').innerHTML = "";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    var para = document.getElementById('q').value;
    if (para.length > 50) {
        showTranslate();
    }
    else {
        para = encodeURIComponent(para);
        document.getElementById('q').focus();
        var url = "/?c=085kluv6802&device=pc&w=" + para + "&n=" + n;
        xmlHttp.onreadystatechange = stateChanged
        xmlHttp.open("GET", url, true)
        xmlHttp.send(null)
    }
}

function showkeycontent(){
    isToggleFavHis = 0;
    document.getElementById('q').onkeyup = processKeyUp;
}

var time = 0;
var t;
function stateChanged(){
    var hideshow;
    document.getElementById("loading").innerHTML = loading;
    document.getElementById("loading").style.visibility = "visible";
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        document.getElementById("loading").innerHTML = " ";
        var reponse = xmlHttp.responseText;
        idx_at = reponse.indexOf("@");
        idx_mark = reponse.indexOf("^");
        similar = reponse.substring(0, idx_at);
        meaning = reponse.substring(idx_at + 1, idx_mark);
        hideshow = reponse.substring(idx_mark + 1);
        $strWord = document.getElementById('q').value;
        if ($strWord.length > 0 && $strWord.length <= 25 && meaning == "" && similar == "") {
            showNote();
            document.getElementById("show").innerHTML = "";
        }
        else 
            if ($strWord.length > 25 && $strWord.length <= 50 && meaning == "" && similar == "") {
                showTranslate();
            }
            else 
                if ($strWord.length > 50) {
                    showTranslate();
                }
                else {
                    document.getElementById("con").innerHTML = similar;
                    document.getElementById("show").innerHTML = meaning;
                    document.getElementById("hidden").innerHTML = hideshow;
                    document.getElementById("loading").style.visibility = "hidden";
                }
    }
}

function GetXmlHttpObject(){
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function showword(word){
    var para = word;
    para = decodeURIComponent(para);
    document.getElementById('q').value = para;
    showcont();
}

function showdword(word){
    var oldW = "";
    var newW = "";
    if (isAddFav == true) {
        if (document.getElementById('favW').value != null) 
            oldW = document.getElementById('favW').value;
        newW = oldW + word;
        document.getElementById('favW').value = newW;
    }
    else {
        if (document.getElementById('q').value != null) 
            oldW = document.getElementById('q').value;
        newW = oldW + word;
        document.getElementById('q').value = newW;
        showcont();
    }
}

function show(){
    showcont();
}

function Exec(url){
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function callback(){
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        alert(xmlHttp.responseText);
    }
}

function doRemoveDict(id){
    alert(document.getElementById(id).className);
    document.getElementById(id).style.visibility = 'hidden';
}

var mySlider = "";
var myBox = "";
function doToggleDictDetail(id){
    document.getElementById("min" + id).innerHTML = "<a href='javascript:doShowHidden(" + id + ");'><img src='/images/icon_maximize.gif' border='0'/></a>";
    document.getElementById("up" + id).innerHTML = "";
    document.getElementById("favorite" + id).innerHTML = "";
    if (document.getElementById("edit" + id)) 
        document.getElementById("edit" + id).innerHTML = "";
    mybox = "#box" + id;
    jQuery(mybox).slideToggle("slow");
	document.getElementById("warning" + id).style.visibility = "hidden";
    var father = document.getElementById("box" + id);
    var n = father.childNodes[1];
	var m = father.childNodes[2];
    father.removeChild(n);
	father.removeChild(m);
    var title = document.getElementById("box" + id).innerHTML;
    title = "<div class='box' id='box" + id + "'>" + title + "</div><br />";
    var content = (document.getElementById("hidden").innerHTML) + title;
    document.getElementById("hidden").innerHTML = content;
    hideshowCok = getCookie('hideshow');
    if (hideshowCok != "" && hideshowCok != null) {
        hideshowCok = getCookie('hideshow');
        arrhideshowCok = hideshowCok.split(",");
    }
    else {
        hideshowCok = "1,1,1,1";
        arrhideshowCok = hideshowCok.split(",");
    }
    for (var i = 0; i < arrhideshowCok.length; i++) {
        var arr = arrhideshowCok[i].split("-");
        var idHideShow = arr[1];
        if (idHideShow == id) {
            arrhideshowCok[i] = "0-" + id;
            break;
        }
    }
    hideshowCok = arrhideshowCok.join(",");
    setCookie('hideshow', hideshowCok, 365);
    var url = "./?ex=ex&act=hide";
    Exec(url);
}

function doShowHidden(id){
    if (getCookie("hideshow") && getCookie("hideshow") != null) {
        hideshowCok = getCookie("hideshow");
        arrhideshowCok = hideshowCok.split(",");
    }
    else {
        hideshowCok = "1,1,1,1";
        arrhideshowCok = hideshowCok.split(",");
    }
    for (var i = 0; i < arrhideshowCok.length; i++) {
        var arr = arrhideshowCok[i].split("-");
        var idHideShow = arr[1];
        if (idHideShow == id) {
            arrhideshowCok[i] = "1-" + id;
            break;
        }
    }
    hideshowCok = arrhideshowCok.join(",");
    setCookie('hideshow', hideshowCok, 365);
    var url = "./?ex=ex&act=show";
    Exec(url);
    show();
    var father = document.getElementById("hidden");
    var child = document.getElementById("box" + id);
    var browserName = navigator.appName;
    if (browserName == "Microsoft Internet Explorer") 
        father.appendChild(child);
    else 
        father.removeChild(child);
}

function getCookie(c_name){
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) 
                c_end = document.cookie.length
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return ""
}

function setCookie(c_name, value, expiredays){
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
}

function delCookie(name, path, domain){
    if (getCookie(name)) 
        document.cookie = name + "=" +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var IE = document.all ? true : false
if (!IE) 
    document.captureEvents(Event.MOUSEMOVE)
var tempX = 0
var tempY = 0
var isAddFav = false;
document.onmousedown = getMouseXY;
function getMouseXY(e){
    if (IE) {
        tempX = event.clientX + document.body.scrollLeft
        tempY = event.clientY + document.body.scrollTop
    }
    else {
        tempX = e.pageX
        tempY = e.pageY
    }
    if (tempX < 0) {
        tempX = 0
    }
    if (tempY < 0) {
        tempY = 0
    }
}

function addFavoriteWord(word, id){
    isAddFav = true;
    var html = "";
    html += "<div class='fav_header'>";
    html += "<div class='addfav_title'>" + lang['titleFavorite'] + "</div>";
    html += "<div class='addfav_close'><a href='#' onclick='javascript:fav_close()' id='fav_close'>X</a></div>";
    html += "</div>";
    html += "<div class='favguide'>" + lang['addFavGuide'] + "</div>";
    html += "<div><input name='' type='text' style='width:300px;margin-bottom:5px;' id='favW'></div>";
    html += "<div><input type='button' value='" + lang['addFavCmd'] + "' style='float:right' onclick=\"javascript:doaddFavoriteWord(" + id + ",'" + word + "')\"></div>";
    document.getElementById('addfav').innerHTML = html;
    var posY = tempY + 10;
    jQuery('#addfav').css({
        left: tempX,
        top: posY
    }).toggle("slow");
    jQuery('#addfav').draggable();
}

function fav_close(){
    jQuery('#addfav').hide();
    isAddFav = false;
}

function saveHistory(word){
    var historyWord = getCookie("historyWordCok");
    if (historyWord != null && historyWord != "") {
        historyWord = getCookie("historyWordCok");
        arrHistoryWord = historyWord.split("|");
        if (arrHistoryWord.length <= 100) {
            var flag = 0;
            for (var i = 0; i < arrHistoryWord.length; i++) {
                if (arrHistoryWord[i] == word) {
                    flag = 1;
                    break;
                }
                else 
                    flag = 0;
            }
            if (flag == 0) 
                arrHistoryWord.push(word);
        }
        else {
            arrHistoryWord.splice(0, 1);
            var flag = 0;
            for (var i = 0; i < arrHistoryWord.length; i++) {
                if (arrHistoryWord[i] == word) {
                    flag = 1;
                    break;
                }
                else 
                    flag = 0;
            }
            if (flag == 0) 
                arrHistoryWord.push(word);
        }
    }
    else {
        historyWord = "";
        arrHistoryWord = Array();
        arrHistoryWord.push(word);
    }
    historyWord = arrHistoryWord.join("|");
    setCookie("historyWordCok", historyWord, 365);
    document.getElementById('favorite').innerHTML = '<a href="javascript:showFavHis();"><img src="/images/fav_on.gif" border="0" style="vertical-align:middle"/></a>';
}

function doaddFavoriteWord(id, word){
    var meaning = document.getElementById('favW').value;
    favoriteWord = getCookie('favoriteWordCok');
    var content = "";
    if (favoriteWord != null && favoriteWord != "") {
        favoriteWord = getCookie('favoriteWordCok');
        arrFavoriteWord = favoriteWord.split("|");
        var flag = 0;
        for (var i = 0; i < arrFavoriteWord.length; i++) {
            arr = arrFavoriteWord[i].split("-");
            if (arr[0] == word && arr[1] == id) {
                flag = 1
                break;
            }
            else 
                flag = 0
        }
        if (flag == 0) {
            meaning = encodeURIComponent(meaning);
            content = word + "-" + id + "-" + meaning;
            arrFavoriteWord.push(content);
        }
    }
    else {
        favoriteWord = "";
        arrFavoriteWord = Array();
        meaning = encodeURIComponent(meaning);
        content = word + "-" + id + "-" + meaning;
        arrFavoriteWord.push(content);
    }
    favoriteWord = arrFavoriteWord.join("|");
    setCookie('favoriteWordCok', favoriteWord, 365);
    if (getCookie('1tdEmail') != null && getCookie('1tdEmail') != "") {
        var url = "./?ex=ex&act=favorite";
        Exec(url);
    }
    document.getElementById('favorite' + id).innerHTML = "<a href='javascript:removeFavoriteWord(\"" + word + "\",\"" + id + "\",\"" + meaning + "\")'><img src='/images/star_on.gif' border='0'/></a>";
    document.getElementById('favorite').innerHTML = '<a href="javascript:showFavHis();"><img src="/images/fav_on.gif" border="0" style="vertical-align:middle"/></a>';
    jQuery('#addfav').hide();
    isAddFav = false;
}

function removeFavoriteWord(word, id, meaning){
    favoriteWord = getCookie('favoriteWordCok');
    var flag = 0;
    var idx = 0;
    if (favoriteWord != null && favoriteWord != "") {
        favoriteWord = getCookie('favoriteWordCok');
        arrFavoriteWord = favoriteWord.split("|");
        var flag = -1;
        for (i = 0; i < arrFavoriteWord.length; i++) {
            arr = arrFavoriteWord[i].split("-");
            if (arr[0] == word && arr[1] == id) {
                flag = i;
                idx = i + 1;
                break;
            }
            else 
                flag = -1
        }
        if (flag != -1) {
            arrFavoriteWord.splice(flag, 1);
        }
    }
    else {
        favoriteWord = "";
        arrFavoriteWord = Array();
    }
    favoriteWord = arrFavoriteWord.join("|");
    setCookie('favoriteWordCok', favoriteWord, 365);
    var url = "./?ex=ex&act=favorite";
    Exec(url);
    document.getElementById('favorite' + id).innerHTML = "<a href='javascript:addFavoriteWord(\"" + word + "\",\"" + id + "\",\"" + meaning + "\")'><img src='/images/star_off.gif' border='0'/></a>";
}

function upDict(id){
    var mybox = "#box" + id;
    jQuery(mybox).slideToggle("slow");
    order = getCookie('order');
    if (order != null && order != "") {
        order = getCookie('order');
        $arrOrder = order.split(",");
    }
    else {
        order = "1,2,3,4";
        $arrOrder = order.split(",");
    }
    idx = 0;
    for (var i = 0; i < $arrOrder.length; i++) {
        if ($arrOrder[i] == id) {
            idx = i;
            break;
        }
    }
    tmp = $arrOrder[0];
    $arrOrder[0] = $arrOrder[idx];
    for (i = idx; i > 0; i--) {
        if (i == 1) 
            $arrOrder[i] = tmp;
        else 
            $arrOrder[i] = $arrOrder[i - 1];
    }
    order = $arrOrder.join(",");
    setCookie('order', order, 365);
    var url = "./?ex=ex&act=order";
    Exec(url);
    show();
}

function showFavorite(){
    jQuery('#fav').addClass("current");
    jQuery('#his').removeClass("current");
    var myFavorite = getCookie('favoriteWordCok');
    if (myFavorite != null && myFavorite != "") {
        var arrFavorite = myFavorite.split('|');
        var html = "<table width='95%'>";
        var word = "";
        var d_name = "";
        var meaning = "";
        var str = new Array();
        var i = 0;
        for (i = 0; i < arrFavorite.length; i++) {
            str = arrFavorite[i].split('-');
            word = str[0];
            d_name = str[1];
            meaning = str[2];
            meaning = decodeURIComponent(meaning);
            favorite_id = "favorite" + (i + 1);
            html += "<tr><td><span id='" + favorite_id + "'><a href='javascript:removeFavoriteList(\"" + word + "\",\"" + d_name + "\",\"" + meaning + "\")'><img src='/images/star_on.gif' border='0'/></a></span></td><td width='30%'><a href='#' onclick=\"showword('" + word + "')\">" + word + "</a>:</td><td width='70%'>" + meaning + "</td></tr>";
        }
        html += "</table>";
        var favoriteBox = "";
        var fav = lang['titleFavorite'];
        var clearAll = lang['clearAll'];
        favoriteBox += "<div class='contenth' id=''>" + html + "</div>";
        favoriteBox += "<div style='float:right;'><span class='print' id=''><a href='print.html' target='_blank'>" + lang['print'] + "</a></span><span class='pa' style='float:left'> | </span><div class='clear' id=''><a href='javascript:doClear()'>" + clearAll + "</a></div></div>";
        document.getElementById("contentFavHis").innerHTML = favoriteBox;
    }
    else {
        document.getElementById("contentFavHis").innerHTML = "<br />" + lang['noFavorite'] + " " + lang['fav'] + "<br />";
    }
}

function showFavHis(){
    if (isToggleFavHis == 0) {
        jQuery("#show").hide();
        isToggleFavHis = 1;
    }
    var fav = lang['titleFavorite'];
    var clearAll = lang['clearAll'];
    var favhisBox = "<div class='box' id='$box_name' name='box' style='float:left'>";
    favhisBox += "<div class='contenth' id='contentFavHis'></div>";
    favhisBox += "<div class='clear' id=''><a href='javascript:doClear()'></a></div>";
    favhisBox += "</div><br />";
    var tab = "<div id='tabsG'>";
    tab += "<ul>";
    tab += "<li id='fav' class=''><a href='#' onclick='javascript:showFavorite()'><span>" + lang['titleFavorite'] + "</span></a></li>";
    tab += "<li id='his' class=''><a href='#' onclick='javascript:showHistory()'><span>" + lang['titleHistory'] + "</span></a></li>";
    tab += "</ul>";
    tab += "</div>";
    tab += favhisBox;
    document.getElementById("show").innerHTML = tab;
    jQuery("#show").toggle("slow");
    showFavorite();
}

function showHistory(){
    jQuery('#his').addClass("current");
    jQuery('#fav').removeClass("current");
    var myHistory = getCookie('historyWordCok');
    var arrHistory = myHistory.split('|');
    var html = "<table width='95%'>";
    var k = 0;
    for (var i = arrHistory.length - 1; i >= 0; i--) {
        var word = arrHistory[i];
        if (k % 3 == 0) 
            html += "<tr align='left'>";
        k++;
        html += "<td>";
        html += "<a href='#' onclick=\"showword('" + word + "')\">" + word + "</a></td>";
        if (k % 3 == 0) 
            html += "</tr>";
    }
    html += "</table>";
    var historyBox = "";
    historyBox += "<div class='contenth' id=''>" + html + "</div>";
    historyBox += "<div style='float:right'><div class='clear' id=''><a href='javascript:doClearHistory()'>" + lang['clearAll'] + "</a></div></div>";
    document.getElementById("contentFavHis").innerHTML = historyBox;
}

function showTranslate(){
    document.getElementById("dictNote").style.display = "none";
    if (isToggleTrans == 0) {
        jQuery("#show").hide();
        isToggleTrans = 1;
    }
    isToggleFavHis = 0;
    var country = getCookie('lang');
    var strWord = "";
    if (document.getElementById("q").value != "") {
		tmpStrWord = document.getElementById("q").value;
		preStrWord = tmpStrWord.substring(0, 1);
		preStrWord = preStrWord.toUpperCase();
		sufStrWord = tmpStrWord.substring(1);
		strWord = preStrWord + sufStrWord;
		
	}
	else 
		strWord = lang['welcomeTrans'];
    google.load("language", "1");
    var html = "";
    html += "<div class='box' id='translate' name='box'>";
    html += "<div class='headh' id=''><span class='dn'>" + lang['linkTranslate'] + "</span><a href='#' onclick='javascript:doHideTranslate();' style='float: right; margin-top: 0px; position: relative; margin-right: 4px;'>X</a></div>";
    html += "<div class='contenth' id=''>";
    html += "<table width='610' align='center' style='margin-left:8px;'>";
    html += "<tr>";
    html += "<td>" + lang['src'] + "</td>";
    html += "<td>";
    html += "<select name='from' id='from' onchange='javascript:translate()'>";
    for (var i in google.language.Languages) {
        var thisLangCode = google.language.Languages[i];
        if (country == "VN" && thisLangCode == "vi") 
            html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
        else 
            if (country == "US" && thisLangCode == "en") 
                html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
            else 
                if (country == "FR" && thisLangCode == "fr") 
                    html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
                else 
                    if (country == "JP" && thisLangCode == "ja") 
                        html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
                    else 
                        if (country == "CN" && thisLangCode == "zh") 
                            html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
                        else 
                            html += "<option value='" + thisLangCode + "'>" + i + "</option>";
    }
    html += "</select>";
    html += "</td>";
    html += "<td>" + lang['des'] + "</td>";
    html += "<td>";
    html += "<select name='to' id='to' onchange='javascript:translate()'>";
    for (var i in google.language.Languages) {
        var thisLangCode = google.language.Languages[i];
        if (thisLangCode == "vi") 
            html += "<option value='" + thisLangCode + "' selected='selected'>" + i + "</option>";
        else 
            html += "<option value='" + thisLangCode + "' >" + i + "</option>";
    }
    html += "</select>";
    html += "</td>";
    html += "<td><a href='#' onclick='javascript:swapLanguages()' title='" + lang['titleSwap'] + "'><img src='/images/swap.gif' border='0' /></a></td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td colspan='5'>";
    html += "<textarea name='text' id='text' rows='5'  onKeyUp='javascript:translate()' class='txt' style='width:604px'>" + strWord + "</textarea>";
    html += "</td>";
    html += "</tr>";
    html += "<tr>";
    html += "<td colspan='5'>";
    html += "<div class='headh' id=''><a href='#' style='float:left; margin-left:2px; margin-top:2px' onclick='javascript:translate()'><img  src='/images/refresh_icon.gif' border='0'/></a><span class='dn' id='titleTrans'>" + lang['res'] + "</span></div>";
    html += "<div class='contenth' id=''><div id='translation'></div><br /><a href='http://www.google.com' target='_blank'><img src='/images/powered_by_google.gif' border='0' style='margin-left:550px;'/></a></div>";
    html += "</div>";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "</div><br />";
    document.getElementById('show').innerHTML = html;
    if (isToggleTrans == 1) {
        jQuery("#show").toggle("slow");
    }
    var cbFrom = document.getElementById('from');
    var src = cbFrom.options[cbFrom.selectedIndex].value;
    var cbTo = document.getElementById('to');
    var des = cbTo.options[cbTo.selectedIndex].value;
    function initialize(){
        //var strWord = document.getElementById('q').value;
        if (strWord.length > 0) {
            cbFrom = document.getElementById('from');
            cbTo = document.getElementById('to');
            document.getElementById('text').value = strWord;
            google.language.detect(strWord, function(result){
                src = result.language;
                if (src == "vi") {
                    src = "vi";
                    des = "en";
                    for (var i = 0; i < cbFrom.length; i++) {
                        if (cbFrom.options[i].value == src) 
                            cbFrom.selectedIndex = i;
                    }
                    for (var i = 0; i < cbTo.length; i++) {
                        if (cbTo.options[i].value == des) 
                            cbTo.selectedIndex = i;
                    }
                    google.language.translate(strWord, src, des, function(result){
                        if (!result.error) {
                            var container = document.getElementById("translation");
                            container.innerHTML = result.translation;
                        }
                    });
                }
                else {
                    des = "vi";
                    for (var i = 0; i < cbFrom.length; i++) {
                        if (cbFrom.options[i].value == src) 
                            cbFrom.selectedIndex = i;
                    }
                    for (var i = 0; i < cbTo.length; i++) {
                        if (cbTo.options[i].value == des) 
                            cbTo.selectedIndex = i;
                    }
                    google.language.translate(strWord, src, des, function(result){
                        if (!result.error) {
                            var container = document.getElementById("translation");
                            container.innerHTML = result.translation;
                        }
                    });
                }
            });
        }
        else {
            google.language.translate(lang['welcomeTrans'], src, des, function(result){
                if (!result.error) {
                    var container = document.getElementById("translation");
                    container.innerHTML = result.translation;
                }
            });
        }
    }
    initialize();
}

function swapLanguages(){
    var cbFrom = document.getElementById('from');
    var src = cbFrom.options[cbFrom.selectedIndex].value;
    var cbTo = document.getElementById('to');
    var des = cbTo.options[cbTo.selectedIndex].value;
    for (var i = 0; i < cbFrom.length; i++) {
        if (cbFrom.options[i].value == des) 
            cbFrom.selectedIndex = i;
    }
    for (var i = 0; i < cbTo.length; i++) {
        if (cbTo.options[i].value == src) 
            cbTo.selectedIndex = i;
    }
    cbFrom = document.getElementById('from');
    src = cbFrom.options[cbFrom.selectedIndex].value;
    cbTo = document.getElementById('to');
    des = cbTo.options[cbTo.selectedIndex].value;
    var container = document.getElementById("translation").innerHTML;	
	container = container.replace(/<br>/gi,"\n")
	//alert(container);
    document.getElementById('text').value = container;
    translate();
}

function doHideTranslate(){
    jQuery("#show").toggle("slow");
}

function doHideDict(){
    document.getElementById('dictNote').innerHTML = "";
}

function translate(){
    var cbFrom = document.getElementById('from');
    var src = cbFrom.options[cbFrom.selectedIndex].value;
    var cbTo = document.getElementById('to');
    var des = cbTo.options[cbTo.selectedIndex].value;
    var tmpText = document.getElementById("text").value;
	var preText = tmpText.substring(0, 1);
	preText = preText.toUpperCase();
	var sufText = tmpText.substring(1);
	var text = preText + sufText;
    var container = document.getElementById("translation");
    var rs = "";
    var arrtext = text.split('\n');
    if (src == "") {
        google.language.detect(arrtext[0], function(result){
            src = result.language;
        });
    }
    for (var i in arrtext) {
        var x, s;
		//if(i < (arrtext.length - 1))
        	s = arrtext[i] + ".<br />"
        x = s.split(".");
        for (var j in x) {
            var y = trim(x[j]);
            if (y != "<br />" && y != "") 
                y += ".&nbsp;&nbsp;";
            if (y.length > 0) {
                google.language.translate(y, src, des, function(result){
                    if (!result.error) {
                        rs += result.translation + " ";
                        container.innerHTML = rs;
                    }
                });
            }
        }
    }
    var cbTo = document.getElementById('to');
    var des = cbTo.options[cbTo.selectedIndex].text;
    document.getElementById('titleTrans').innerHTML = des;
}

function ltrim(str){
    for (var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++) 
        ;
    return str.substring(k, str.length);
}

function rtrim(str){
    for (var j = str.length - 1; j >= 0 && isWhitespace(str.charAt(j)); j--) 
        ;
    return str.substring(0, j + 1);
}

function trim(str){
    return ltrim(rtrim(str));
}

function isWhitespace(charToCheck){
    var whitespaceChars = " \t\n\r\f";
    return (whitespaceChars.indexOf(charToCheck) != -1);
}

function removeFavoriteList(word, id, meaning){
    favoriteWord = getCookie('favoriteWordCok');
    var flag = 0;
    var idx = 0;
    if (favoriteWord != null && favoriteWord != "") {
        favoriteWord = getCookie('favoriteWordCok');
        arrFavoriteWord = favoriteWord.split("|");
        var flag = -1;
        if (arrFavoriteWord.length == 1) {
            delCookie('favoriteWordCok');
            var country = getCookie('lang');
            var content = lang['noFavorite'];
            var favoriteBox = "<div class='box' id='$box_name' name='box'>";
            favoriteBox += "<div class='headh' id=''><span class='dn'>Favorite</span></div>";
            favoriteBox += "<div class='contenth' id=''>" + content + "</div>";
            favoriteBox += "</div><br />";
            document.getElementById("show").innerHTML = favoriteBox;
            document.getElementById('favorite').innerHTML = '<a href="javascript:showFavoriteHelp();"><img src="/images/fav_off.gif" border="0" style="vertical-align:middle"/></a>';
        }
        else {
            for (i = 0; i < arrFavoriteWord.length; i++) {
                arr = arrFavoriteWord[i].split("-");
                if (arr[0] == word && arr[1] == id) {
                    flag = i;
                    idx = i + 1;
                    break;
                }
                else 
                    flag = -1
            }
            if (flag != -1) {
                arrFavoriteWord.splice(flag, 1);
            }
            favoriteWord = arrFavoriteWord.join("|");
            setCookie('favoriteWordCok', favoriteWord, 365);
            var url = "./?ex=ex&act=favorite";
            Exec(url);
            showFavorite();
        }
    }
    else {
        favoriteWord = "";
        arrFavoriteWord = Array();
    }
}

function doClear(){
    delCookie("favoriteWordCok");
    location.reload(true);
}

function doClearHistory(){
    delCookie("historyWordCok");
    location.reload(true);
}

var result = 1;
function checkKeyLogin(e){
    if (window.event) 
        e = window.event;
    var cc = (e.which) ? e.which : e.keyCode;
    var enter = typeof e.which == 'undefined' ? e.keyCode == 13 : e.which == 13;
    if (enter) {
        doLogin();
    }
}

function doLogin(){
    var frm = document.frmLogin;
    var email = document.getElementById('txtEmail');
    var pwd = frm.txtpwd;
    checkEmail(email);
    if (result != 1) {
        alert(result);
        email.focus();
        return false;
    }
    else {
        if (pwd.value == "") {
            result = "Chưa nhập mật khẩu !";
            alert(result);
            pwd.focus();
            return false;
        }
        else {
            var url = "./certify.php?a=a";
            var para = "e=" + email.value + "&p=" + pwd.value + "&do=login";
            showLogin(url, para);
			//AjaxPost(url,'boxlogin',para)
            //return true;
        }
    }
}

function showLogin(url_, para_){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    var url = url_;
    url += "&ack=" + date.getTime();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            var str = xmlHttp.responseText;           
			str = trim(str); 
			
            if (str == "1") {
                alert("Email hoáº·c máº­t kháº©u chÆ°a Ä‘Ãºng. Má»i nháº­p láº¡i !")
                return;
            }
            else if(str == "2") {				
               window.location = "./";
            }
			else{
				 window.location = str;
			}
        }
    }
    xmlHttp.open("POST", url);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", para_.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(para_);
}

function doRegistry(){
    var frm = document.frmLogin;
    var email = document.getElementById('txtEmail');
    var pwd = frm.txtpwd;
    var pwd2 = frm.txtpwd2;
    var captcha = frm.captcha;
    checkEmail(email);
    if (result != 1) {
        alert(result);
        email.focus();
        return false;
    }
    if (pwd.value == "") {
        result = "ChÆ°a Nháº­p Máº­t Kháº©u !";
        alert(result);
        pwd.focus();
        return false;
    }
    if (pwd2.value == "") {
        result = "ChÆ°a Nháº­p Máº­t Kháº©u Láº§n 2!";
        alert(result);
        pwd2.focus();
        return false;
    }
    if (pwd2.value != pwd.value) {
        result = "Máº­t kháº©u chÆ°a khá»›p !";
        alert(result);
        pwd2.focus();
        return false;
    }
    if (captcha.value == "") {
        alert('Báº¡n chÆ°a nháº­p MÃ£ xÃ¡c nháº­n !');
        captcha.focus();
        return false;
    }
    else {
        var para = "captcha=" + captcha.value + "&txtpwd=" + pwd.value + "&txtEmail=" + email.value;
        showRegistry('/Success.php?a=a', para);
    }
}

var date = new Date();
function showRegistry(url_, para_){
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    var url = url_;
    url += "&ack=" + date.getTime();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            var str = xmlHttp.responseText;
            str = str.substring(str.length, str.length - 1);
            if (str == "1") {
                window.location = "http://1tudien.com";
                return true;
            }
            if (str == "2") {
                alert('Email bá»‹ trÃ¹ng ! Má»i nháº­p Email khÃ¡c !');
                var frm = document.frmLogin;
                frm.txtEmail.focus();
            }
            else {
                alert('MÃ£ xÃ¡c nháº­n chÆ°a chÃ­nh xÃ¡c !');
                var frm = document.frmLogin;
                var captcha = frm.captcha;
                captcha.focus();
            }
        }
    }
    xmlHttp.open("POST", url);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", para_.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(para_);
}

function showcont1(url_, div_){
	
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    url += "&ack=" + date.getTime();
    var url = url_;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById(div_).innerHTML = xmlHttp.responseText;
            if (isToggWidgetCode == 1) {
                jQuery("#show").toggle("slow");
                isToggWidgetCode = 0;
            }
        }
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function AjaxPost(url_, div_, para_){
	
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    var url = url_;
    url += "&ack=" + date.getTime();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			
            document.getElementById(div_).innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("POST", url);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", para_.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(para_);
}

function doEdit(word, divName, num){
    var _divName = divName;
    var name = document.getElementById("hidWordName" + num).value;
    var nghia = document.getElementById("nghia" + num);
    var nghiavalue = encodeURI(nghia.value);
    var idDict = document.getElementById("hidDictID" + num).value;
    var capcha = document.getElementById("captcha");
    var url = "/exe.php?a=a";
    if (capcha == null) {
        var capchavalue = null;
    }
    else {
        var capchavalue = capcha.value;
    }
    if (nghiavalue == "") {
        alert("Tá»« chÆ°a cÃ³ nghÄ©a. Má»i nháº­p nghÄ©a !");
        nghia.focus();
        return;
    }
    if (capchavalue == "") {
        alert("ChÆ°a nháº­p mÃ£ xÃ¡c nháº­n. Má»i nháº­p !");
        capcha.focus();
        return;
    }
    var para = "idDict=" + idDict + "&nghia=" + nghiavalue + "&name=" + name + "&edit=ok&w=" + word + "&cap=" + capchavalue;
    xmlHttp = GetXmlHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    url += "&ack=" + date.getTime();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            var str = xmlHttp.responseText;
            str = str.substring(str.length, str.length - 1);
            if (str == "0") {
                alert('MÃ£ xÃ¡c nháº­n chÆ°a chÃ­nh xÃ¡c !');
                capcha.focus();
                return;
            }
            if (str == "1") {
                alert("Báº¡n chÆ°a Ä‘Äƒng nháº­p chÃ­nh thá»©c. Má»i báº¡n Ä‘Äƒng nháº­p !");
                return;
            }
            else {
                document.getElementById(_divName).innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open("POST", url);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", para.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(para);
}

function doUpdate(id, divName){
    var _id = id;
    var _divName = divName;
    document.frmCheckBox.checkSua.checked = false;
    var name = document.frmEdit.hidWordName.value;
    var nghia = document.frmEdit.nghia.value;
    var idDict = document.frmEdit.hidDictID.value;
    var url = "../exe.php?idDict=" + idDict + "&nghia=" + nghia + "&name=" + name + "&id=" + _id + "&update=ok";
    showcont1(url, _divName);
}

function doAdd(){
    var word = document.frmAdd.txtWord;
    var idDict = document.frmAdd.cboDict.value;
    var txtNghia = encodeURI(document.frmAdd.txtNghia.value);
    var url = "/exe.php?a=a";
    var capcha = document.frmAdd.captcha;
    if (capcha == null) {
        var capchavalue = null;
    }
    else {
        var capchavalue = capcha.value;
    }
    if (word.value == "") {
        alert('Báº¡n chÆ°a nháº­p tá»« !');
        word.focus();
        return false;
    }
    else 
        if (txtNghia == "") {
            alert('Tá»« má»›i chÆ°a cÃ³ nghÄ©a !')
            document.frmAdd.txtNghia.focus();
            return false;
        }
        else 
            if (capchavalue == "") {
                alert("ChÆ°a nháº­p mÃ£ xÃ¡c nháº­n !");
                capcha.focus();
                return false;
            }
            else {
                var para = "wordnew=" + word.value + "&idDict=" + idDict + "&txtNghia=" + txtNghia + "&cap=" + capchavalue;
                xmlHttp = GetXmlHttpObject()
                if (xmlHttp == null) {
                    alert("Browser does not support HTTP Request")
                    return
                }
                url += "&ack=" + date.getTime();
                xmlHttp.onreadystatechange = function(){
                    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
                        var str = xmlHttp.responseText;
                        str = str.substring(str.length, str.length - 1);
                        if (str == "0") {
                            alert('MÃ£ xÃ¡c nháº­n chÆ°a chÃ­nh xÃ¡c !');
                            capcha.focus();
                            return;
                        }
                        else {
                            document.getElementById("new").innerHTML = xmlHttp.responseText;
                        }
                    }
                }
                xmlHttp.open("POST", url);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", para.length);
                xmlHttp.setRequestHeader("Connection", "close");
                xmlHttp.send(para);
            }
}

function closeEdit(word, div, num){
    var idD = document.getElementById("hidDictID" + num).value;
    var url = '/exe.php?close=ok&w=' + word + '&idD=' + idD;
    showcont1(url, div);
}

function closeDiv(div){
    setVisible(div, "hidden", "none");
}

function setVisible(What, vis, hid){
    document.getElementById(What).style.visibility = vis;
    document.getElementById(What).style.display = hid;
}

function checkSpace(str){
    var space = "  ";
    var count = 0;
    for (var i = 0; i < str.length; i++) {
        if (space == str.substr(i, space.length)) {
            count++;
        }
    }
    if (count > 0) {
        return false;
    }
    else {
        return true
    }
}

function checkEmail(email){
    var loi = "- Báº¡n chÆ°a nháº­p ";
    var mail = "- Äá»‹a chá»‰ email khÃ´ng há»£p lá»‡ !";
    if (email.value == "") {
        loi = loi + " Email";
        result = loi;
        return result;
    }
    if (email.value.indexOf(" ") > 0) {
        result = mail;
        email.focus();
        return result;
    }
    if (email.value.indexOf("@") == -1) {
        result = mail;
        email.focus();
        return result;
    }
    var i = 1;
    var sLength = email.length;
    if (email.value.indexOf(".") == -1) {
        result = mail;
        email.focus();
        return result;
    }
    if (email.value.indexOf("..") != -1) {
        result = mail;
        email.focus();
        return result;
    }
    if (email.value.indexOf("@") != email.value.lastIndexOf("@")) {
        result = mail;
        email.focus();
        return result;
    }
    if (email.value.lastIndexOf(".") == email.value.length - 1) {
        result = mail;
        email.focus();
        return result;
    }
    var str = "abcdefghikjlmnopqrstuvwxyz-@._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (var j = 0; j < email.value.length; j++) 
        if (str.indexOf(email.value.charAt(j)) == -1) {
            result = mail;
            email.focus();
            return result;
        }
    return result = 1;
}

function doImage(obj){
    textarea = document.getElementById(obj);
    var url = prompt('Enter the Image URL:', 'http://');
    var scrollTop = textarea.scrollTop;
    var scrollLeft = textarea.scrollLeft;
    if (document.selection) {
        textarea.focus();
        var sel = document.selection.createRange();
        sel.text = '[img]' + url + '[/img]';
    }
    else {
        var len = textarea.value.length;
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        var sel = textarea.value.substring(start, end);
        var rep = '[img]' + url + '[/img]';
        textarea.value = textarea.value.substring(0, start) + rep + textarea.value.substring(end, len);
        textarea.scrollTop = scrollTop;
        textarea.scrollLeft = scrollLeft;
    }
}

function doURL(obj){
    textarea = document.getElementById(obj);
    var url = prompt('Enter the URL:', 'http://');
    var scrollTop = textarea.scrollTop;
    var scrollLeft = textarea.scrollLeft;
    if (document.selection) {
        textarea.focus();
        var sel = document.selection.createRange();
        if (sel.text == "") {
            sel.text = '[url]' + url + '[/url]';
        }
        else {
            sel.text = '[url=' + url + ']' + sel.text + '[/url]';
        }
    }
    else {
        var len = textarea.value.length;
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        var sel = textarea.value.substring(start, end);
        if (sel == "") {
            var rep = '[url]' + url + '[/url]';
        }
        else {
            var rep = '[url=' + url + ']' + sel + '[/url]';
        }
        textarea.value = textarea.value.substring(0, start) + rep + textarea.value.substring(end, len);
        textarea.scrollTop = scrollTop;
        textarea.scrollLeft = scrollLeft;
    }
}

function doAddTags(tag1, tag2, obj){
    textarea = document.getElementById(obj);
    if (document.selection) {
        textarea.focus();
        var sel = document.selection.createRange();
        sel.text = tag1 + sel.text + tag2;
    }
    else {
        var len = textarea.value.length;
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        var scrollTop = textarea.scrollTop;
        var scrollLeft = textarea.scrollLeft;
        var sel = textarea.value.substring(start, end);
        var rep = tag1 + sel + tag2;
        textarea.value = textarea.value.substring(0, start) + rep + textarea.value.substring(end, len);
        textarea.scrollTop = scrollTop;
        textarea.scrollLeft = scrollLeft;
    }
}

function doList(tag1, tag2, obj){
    textarea = document.getElementById(obj);
    if (document.selection) {
        textarea.focus();
        var sel = document.selection.createRange();
        var list = sel.text.split('\n');
        for (i = 0; i < list.length; i++) {
            list[i] = '[*]' + list[i];
        }
        sel.text = tag1 + '\n' + list.join("\n") + '\n' + tag2;
    }
    else {
        var len = textarea.value.length;
        var start = textarea.selectionStart;
        var end = textarea.selectionEnd;
        var i;
        var scrollTop = textarea.scrollTop;
        var scrollLeft = textarea.scrollLeft;
        var sel = textarea.value.substring(start, end);
        var list = sel.split('\n');
        for (i = 0; i < list.length; i++) {
            list[i] = '[*]' + list[i];
        }
        var rep = tag1 + '\n' + list.join("\n") + '\n' + tag2;
        textarea.value = textarea.value.substring(0, start) + rep + textarea.value.substring(end, len);
        textarea.scrollTop = scrollTop;
        textarea.scrollLeft = scrollLeft;
    }
}

processKeyEvent = function(e){
    if (window.event) 
        e = window.event;
    var cc = (e.which) ? e.which : e.keyCode;
    var ctrl = typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK;
    var v = typeof e.which == 'undefined' ? e.keyCode == 86 : e.which == 86;
    if (ctrl && v) {
        isPaste = 1;
        return true;
    }
    else {
        switch (cc) {
            case 38:
            case 37:
            case 40:
            case 39:
            case 32:
            case 17:
            case 86:
                return true;
                break;
        }
    }
    return false;
};
jQuery(document).ready(function(){
    jQuery('#q').bind('paste', function(e){
        setTimeout("showcont();", 500);
    });
});
function aaa(){
    strWord = document.getElementById('q').value;
    if ($strWord.length > 0 && $strWord.length <= 25 && meaning == "" && similar == "") {
        showNote();
    }
    else 
        if ($strWord.length > 25 && $strWord.length <= 50 && meaning == "" && similar == "") {
            document.getElementById("dictNote").innerHTML = "";
            showTranslate();
            isToggleTrans = 0;
        }
        else 
            if ($strWord.length > 50) {
                document.getElementById("dictNote").innerHTML = "";
                showTranslate();
                isToggleTrans = 0;
            }
            else 
                showcont();
}

function processKeyUp(event){
    if (!processKeyEvent(event)) {
        showcont();
        clearTimeout(t);
        var word = document.getElementById("q").value;
        if (!document.getElementById('content')) {
        }
        else 
            t = setTimeout("saveHistory('" + word + "')", 5000);
    }
    else {
        if (isPaste == 1) {
        }
    }
}

function reloadCaptcha(){
    now = new Date();
    var capObj = document.getElementById('phoca-captcha');
    if (capObj) {
        capObj.src = capObj.src + (capObj.src.indexOf('?') > -1 ? '&' : '?') + Math.ceil(Math.random() * (now.getTime()));
    }
}

function onOver(id){
    document.getElementById("min" + id).style.visibility = 'visible';
    document.getElementById("up" + id).style.visibility = 'visible';
	document.getElementById("warning" + id).style.visibility = 'visible';
    if (document.getElementById("edit" + id)) 
        document.getElementById("edit" + id).style.visibility = 'visible';
}

function onOut(id){
    document.getElementById("min" + id).style.visibility = 'hidden';
    document.getElementById("up" + id).style.visibility = 'hidden';
	document.getElementById("warning" + id).style.visibility = 'hidden';
    if (document.getElementById("edit" + id)) 
        document.getElementById("edit" + id).style.visibility = 'hidden';
}

function doAjaxReg(){
    showcont1('/registry.php?a=a', 'divReg');
}

function showFavoriteHelp(){
    var country = getCookie('lang');
    var content = lang[country]['nullFavorite'];
    var favoriteBox = "<div class='box' id='$box_name' name='box'>";
    favoriteBox += "<div class='headh' id=''><span class='dn'>Favorite</span></div>";
    favoriteBox += "<div class='contenth' id=''>" + content + "</div>";
    favoriteBox += "</div><br />";
    document.getElementById("show").innerHTML = favoriteBox;
}

function changeLang(lang){
    document.location.href = "?l=" + lang;
}

function doGetPas(){
    var email = document.getElementById('txtEmail');
    var frm = document.frmGetPas;
    checkEmail(email);
    if (result != 1) {
        alert(result);
        email.focus();
        return false;
    }
    else {
        var url = "/exe.php?p=p";
        var para = 'e=' + email.value;
        AjaxPost(url, 'show', para)
        setVisible('getP', "hidden", "none");
        return true;
    }
}

function doCheckW(){
    var w = document.frmAdd.txtWord;
    var idD = document.frmAdd.cboDict.value;
    if (w.value == "") {
        w.focus();
        return false;
    }
    else {
        var url = "/exe.php?word=" + w.value + "&idD=" + idD;
        showcont1(url, 'check');
    }
}

function doCustom(){
    var frm = document.frmCustom;
    frm.action = "/exe.php";
}

function doSavePas(){
    var p = document.getElementById("txtPas").value;
    var e = document.getElementById('hidEmail').value;
    AjaxPost('/exe.php?a=a', 'show', 'np=' + p + '&e=' + e);
}

function myResize(){
    var width = 0;
    var newWidth = 0;
    if (document.all) {
        width = document.body.clientWidth;
    }
    else {
        width = window.innerWidth;
    }
    newWidth = (width - 640) / 2;
    jQuery("#body").css({
        'left': newWidth
    });
}

function playSound(movieName){
    if (navigator.appName.indexOf("Microsoft") != -1) {
        window[movieName].TCallLabel('/', 'play');
    }
    else {
        if (document[movieName].length != undefined) {
            document[movieName][1].TCallLabel('/', 'play');
            ;
        }
        document[movieName].TCallLabel('/', 'play');
    }
}

function addOpenSearch(){
    if ((typeof window.external == "object") && ((typeof window.external.AddSearchProvider == "unknown") || (typeof window.external.AddSearchProvider == "function"))) {
        window.external.AddSearchProvider("http://1tudien.com/search.xml");
    }
    else {
        alert("You will need a browser which supports OpenSearch to install this plugin.");
    }
}

function CreateBookmarkLink(title){
    url = "javascript:void(window.open('http://www.1tudien.com/?w='%2bgetSelection()))";
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else 
        if (window.external) {
            window.external.AddFavorite(url, title);
        }
        else 
            if (window.opera && window.print) {
                return true;
            }
}

function showNote(){
    var html = "";
    html += "<div class='box' id='translate' name='box'>";
    html += "<div class='headh' id=''><span class='dn'>Tá»« Ä‘iá»ƒn</span><a href='#' onclick='javascript:doHideDict();' style='float: right; margin-top: 0px; position: relative; margin-right: 4px;'>X</a></div>";
    html += "<div class='contenth' id=''>" + lang['dictNote'] + "</div>";
    html += "</div><br />";
    document.getElementById("dictNote").innerHTML = html;
}

function listDict(){
    var textArea = document.getElementById('txtArea');
    textArea.value = CodeWidgetWed();
    var inputsize = document.getElementById("inputsize").value;
    var fSize = document.getElementById("fontsize").value;
    var html = ' <input align="center" class="tudieninput" name="1tudienInput" id="1tudienInput" type="text"  disabled="disabled" autocomplete="off" size=' + inputsize + ' style="font-size:' + fSize + 'px; background: url(/images/gadget_bg.gif)  left center no-repeat; border:#b7d6e9 solid 1px;">';
    document.getElementById('previewBox').innerHTML = html;
}

function CodeWidgetWed(){
    var js = "";
    var list = '';
    var idD, i;
    for (i = 0; i < 9; i++) {
        if (document.fListDict.cbDict[i].checked == true) {
            idD = document.fListDict.cbDict[i].value;
            list += idD;
        }
        if ((i + 1) < 9) {
            var next = document.fListDict.cbDict[i + 1].checked;
            if (next == true) {
                list += ",";
            }
        }
    }
    js += "<script type='text\/javascript'>";
    js += "var tudien_d = '" + list + "';";
    js += "var tudien_fontsize = '" + document.getElementById("fontsize").value + "' ; ";
    js += "var tudien_inputsize = '" + document.getElementById("inputsize").value + "' ; ";
    js += "var tudien_bordercolor = 'b7d6e9'; ";
    js += "<\/script>";
    js += "<script type='text\/javascript' src='http:\/\/1tudien.com\/js\/1tudien_widget.js'><\/script>";
    return js;
}

var isToggWidgetCode = 0
function showWidgetCode(){
    if (isToggWidgetCode == 0) {
        jQuery("#show").hide();
        isToggWidgetCode = 1;
    }
    var url = "/widget_server/web_widget_form.php";
    showcont1(url, "show");
}
