/* AJAX Functions */ function errorHandler(message) { $("DivProgress").style.display = "none"; disableForm("FrmMain", false); alert(message); } try { dwr.engine.setErrorHandler(errorHandler); } catch (e) { /* ignore */ } function translateComplete(result){ var selTxt1 = DWRUtil.getText("SelSrcLang"); var selTxt2 = DWRUtil.getText("SelTrgLang"); var selVal2 = DWRUtil.getValue("SelTrgLang"); $("LblTrans").innerHTML = "Translation (" + selTxt2 + "):"; $("LblOrig").innerHTML = "Original (" + selTxt1 + "):"; if ($("DivResults").style.display == "none") fxShow("DivResults"); $("TxtTrans").style.textAlign = ""; if (selVal2 == "AR") $("TxtTrans").style.textAlign = "right"; $("TxtTrans").value = result; $("DivProgress").style.display = "none"; disableForm("FrmMain", false); } function doTranslate(token) { var theForm = $("FrmMain"); if (!validate(theForm)) return false; var selVal1 = DWRUtil.getValue("SelSrcLang"); var selVal2 = DWRUtil.getValue("SelTrgLang"); var text = DWRUtil.getValue("TxtOrig"); disableForm("FrmMain", true); $("DivProgress").style.display = ""; var res = ServiceApi.translate(token, selVal1, selVal2, text, translateComplete); return false; } /* Effects Functions */ function getDimensions(element) { var pos = !/Safari|KHTML/.test(navigator.userAgent); var els = element.style; if (els.display != "none") return {width: element.clientWidth, height: element.clientHeight}; var originalVisibility = els.visibility; var originalPosition = els.position; els.visibility = "hidden"; if (pos) els.position = "absolute"; els.display = ""; var originalWidth = element.clientWidth; var originalHeight = element.clientHeight; els.display = "none"; if (pos) els.position = originalPosition; els.visibility = originalVisibility; return {width: originalWidth, height: originalHeight}; } function fxShow(id){ var ele = $(id); var d = getDimensions(ele); ele.style.height = "0px"; ele.style.display = ""; fxEle = new Fx.Styles(id) fxEle.custom({"opacity":[0,1], "height":[0,d.height]}); } function fxHide(id){ var ele = $(id); var d = getDimensions(ele); var fxEle = new Fx.Styles(id, { onComplete: function() { ele.style.display = "none"; ele.style.height = d.height + "px"; }}); fxEle.custom({"opacity":[1,0], "height":[d.height,0]}); } function fxFadeOut(id) { var ele = $(id); new Fx.Style(ele, "opacity").custom(1,0); } function showhide(id){ if ($(id).style.display == "none") fxShow(id); else fxHide(id); } function setBtnDisabled(id, state) { var n = 1; var e = $(id + n++); while (e) { e.disabled = state; e = $(id + n++); } } /* Form Functions */ function validate(theForm) { var selIndex1 = theForm["wl_srclang"].selectedIndex; var selIndex2 = theForm["wl_trglang"].selectedIndex; var selVal1 = theForm["wl_srclang"].options[selIndex1].value; var selVal2 = theForm["wl_trglang"].options[selIndex2].value; if (selVal1 == selVal2) { alert("Please select two different languages."); theForm["wl_trglang"].focus(); return false; } if (theForm["wl_text"].value == "") { alert("Type text to translate."); theForm["wl_text"].focus(); return false; } return true; } function handleListChange(theList) { var numSelected = theList.selectedIndex; if (numSelected != 0) { textValue = document.textform.wl_text.value; textValue = textValue + theList.options[numSelected].value; document.textform.wl_text.value = textValue; theList.selectedIndex = 0; } } var clear = 0; function checkClear(theEle) { if (clear == 0) { clear = 1; theEle.value = ""; } } function disableForm(name, disable){ var el = $(name).elements; for (i=0; i < el.length; i++) el[i].disabled = disable; } function swap_langs() { var selIndex1 = document.getElementById("SelSrcLang").selectedIndex; var selIndex2 = document.getElementById("SelTrgLang").selectedIndex; var selValsrc = document.getElementById("SelSrcLang").options[selIndex1].value; var selValtrg = document.getElementById("SelTrgLang").options[selIndex2].value; var cbo=document.getElementById("SelTrgLang"); for(var i=0; i