function doAlignTxtArea(txt,direction){if((direction=="1033-1037-2" || direction=="1036-1037-2" || direction=="1034-1037-2" || direction=="1049-1037-2" || direction=="eng-ara-5" || direction=="fra-ara-5") && txt=="transtext"){document.trans.transtext.dir="rtl";}if((direction=="1037-1033-2" || direction=="1037-1036-2" || direction=="1037-1034-2" || direction=="1037-1049-2" || direction=="ara-eng-5" || direction=="ara-fra-5") && txt=="sourcetext"){document.trans.sourcetext.dir="rtl";}}
function doCancelAll(){document.trans.transtext.style.borderColor='#3366CC';document.trans.transtext.style.borderWidth='1px';var sel ;if(document.selection && document.selection.empty){document.selection.empty();} else if(window.getSelection){sel=window.getSelection();if(sel && sel.removeAllRanges) sel.removeAllRanges();}}
function doSelectAll(){document.trans.transtext.select();}
function doDelete(){document.trans.sourcetext.value ='';}
function doCopy(){doClipboard(document.trans.sourcetext,'Copy');}
function doCopyResult(){doClipboard(document.trans.transtext,'Copy');}
function doPaste(){doClipboard(document.trans.sourcetext,'Paste');}
function doFeedBack(val){if (val==1){document.getElementById("suggest_text").style.display="";document.getElementById("suggest_but1").style.display="none";document.getElementById("suggest_but2").style.display="";document.getElementById("new_edit_buttons").style.display="none";document.trans.transtext.focus();document.trans.transtext.style.borderColor='#3366CC';document.trans.transtext.style.borderWidth='3px';document.trans.transtext.select();}else{document.getElementById("suggest_text").style.display="none";document.getElementById("suggest_but1").style.display="";document.getElementById("suggest_but2").style.display="none";document.getElementById("new_edit_buttons").style.display="";document.trans.transtext.style.borderWidth='2px';}}
function accent_new(val){var sText=document.trans.sourcetext.value;document.trans.sourcetext.value=sText+val;document.trans.sourcetext.focus();}
function doDeleteTexts(){document.trans.sourcetext.value='';document.trans.transtext.value='';}
function addBookmarkForBrowser(){if(window.sidebar){window.sidebar.addPanel(lblAddToFavorites, document.location.href,"");}else if( document.all ){window.external.AddFavorite( document.location.href, lblAddToFavorites);}else if( window.opera && window.print ) {return true;}}
function doEmailText(){makeWindow("text_sendmail.asp?direction="+dir_translation+"&lang="+languagecode,"sendmail",600,560);}
function doPrintTranslation(){makeWindow("translation_print.asp?lang=" + languagecode,"translationprint",650,600);}
function doBackToTranslate(act){document.location.href="text_translation.asp?lang=" + languagecode +"&action="+act;}	
function submitTrans(){document.trans.action="text_translation.asp?lang="+ languagecode;document.trans.submit();}
function doSubmit(){
	lblDictionary=lblDictName;
	dir_trans=document.forms[0].list_directions.value;
	if(dir_trans==0){alert(msgDictLookup_dir_trans);return;}
	checkLexibasePairs_forSubmit(dir_trans,languagecode);
	lang_pairs=lang_pairs1.toLowerCase() + '-' + lang_pairs2.toLowerCase();
	sWord=document.forms[0].word.value;	
	if(dir_trans=="1040-1036-2" || dir_trans=="1036-1040-2"){
		if(dir_trans=="1040-1036-2" ){
			lang_pairs="italien-francais"
		}
		else{
			lang_pairs="francais-italien"
		}
		lblDictionary="dictionnaire"
	}
	var url = 'http://'+lblDictionary+'.reverso.net/'+lang_pairs+'/' +sWord;window.open(url,"dictLookup","height=600,width=800,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,titlebar=yes");
	return;}
	
function doSaveFeedback(direction){if(document.trans.email_feed.value=="" || document.trans.email_feed.value==lblEmailAddress){document.trans.email_feed.value="";}if(!isValidMailSuggest(document.trans.email_feed.value)){alert('Email address is not valid!');document.trans.email_feed.focus();return false}if(document.trans.transtext.value==""){alert(msgSuggestTranslation);document.trans.transtext.value="";return;}document.trans.direction_translation.value =direction;document.trans.action="text_translation.asp?lang=" +languagecode+"&action=save_feedback";document.trans.submit();}
function translate(obj){if(obj.selectedIndex>0)doTranslate(obj[obj.selectedIndex].value);}
function accent(objCombo){var sText=document.trans.sourcetext.value;if(objCombo.selectedIndex!=0){document.trans.sourcetext.value=sText+objCombo[objCombo.selectedIndex].text;document.trans.sourcetext.focus();}objCombo.selectedIndex=0;} 
function doHearTranslation(direction, target){
	
	if(target=="source"){
		strLen=document.trans.sourcetext.value
		ta = document.getElementById('sourcetext')
	}
	if(target=="translation"){
		strLen=document.trans.transtext.value
		ta = document.getElementById('transtext')
	}
	bits = getSelection(ta);
    if(bits){ 
        strLen= bits[2]
        if(target=="source"){
			document.trans.sourcetext_highlighted.value = bits[2]
        }
        if(target=="translation"){
			document.trans.transtext_highlighted.value = bits[2]
        }
    }
	//maxLength=voice_limit_char;
	//if(strLen.length>maxLength){alert(voice_limit_msg);}
	if(parseInt(n_voice_translation_per_browser) >= parseInt(max_voice_number_per_session)){alert(voice_limit_msg_per_browser);return}
	if(parseInt(n_voice_translation_per_month) >= parseInt(max_voice_number_per_month)){alert(voice_limit_msg_per_month);return;}
	document.trans.direction_translation.value =direction;document.trans.action="text_translation.asp?lang=" + languagecode+"&action=pronunce&target="+target;document.trans.action_form.value="translate";document.trans.submit();

}

function getSelection(ta){ 
	var bits = [ta.value,'','','']; 
    if(document.selection){ 
        var tr=document.selection.createRange()
        if(tr.parentElement()!=ta) return null;
        bits[2] = tr.text;
        tr.text = bits[2];
    }
    else{ 
		if(ta.selectionStart == ta.selectionEnd) 
			return null;
        bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
    }
    return bits;
}

function isValidMailSuggest(H){if(H.length>0){var E=0;var D=0;var G=0;var F=0;var A=H.length;var I=0;var B=0;for(var C=0;C<A;C++){if(H.charAt(C)=="@"){G=1;E=E+1;B=C}if(H.charAt(C)=="."){F=1;D=D+1;I=C}}if(B==0){return false}if(I<=B){return false}if(I>A-3){return false}if((E!=1)){return false}if((G!=1)||(F!=1)){return false}}return true}