/** MViet Combined - ver 7.8 
* MViet70.js or BViet  by SonPham ca46617@csun.edu 6/15/2002
* Combined and layout by HopLe hople@yahoo.com 9/19/2002
* Copyright (c) 1999, 2000,2001, 2002, 2003 MDSS Inc. All Rights Reserved.
**/

var MVOnButton = "<img name='onbutton' src='img/on.gif' onClick='offP = false;MVietOnOff.innerHTML=MVOffButton;'><br><img src='img/abc.gif' onClick='FontClick();'>";
var MVOffButton = "<img name='offbutton' src='img/off.gif'  onClick='offP = true;MVietOnOff.innerHTML=MVOnButton;'><br><img src='img/abc.gif' onClick='FontClick();'>";

var LoadChonDau  = "<APPLET code=VietInterfaceIE5.class height=1 width=1 NAME=VietInterface ARCHIVE = 'VT70.jar' ALT='Your browser understands the applet tag but is not displaying any applet.' codebase='"+cbase+"'><param name='code' value='VietInterfaceIE5.class'><param name='height' value='1'><param name='width' value='1'><param name='name' value='VietInterface'><param name='archive' value='VT70.jar'><param name='alt' value='our browser understands the applet tag but is not displaying any applet.'><param value='codebase' value='"+cbase+"'></APPLET>";

var LoadHoiNga  = "<applet code='HoiNga75.class' height='1' width='1' name='BViet75' archive='BViet75.jar' codebase='"+cbase+"' alt='Your browser understands the applet tag but is not displaying any applet.'><param name='code' value='HoiNga75.class'><param name='height' value='1'><param name='width' value='1'><param name='name' value='BViet75'><param name='archive' value='BViet75.jar'><param name='alt' value='Your browser understands the applet tag but is not displaying any applet.'><param name='codebase' value='"+cbase+"'>";

var LoadConv = "<APPLET code=HoanChuyen76.class  codebase='"+cbase+"' height=1 width=1 NAME=HoanChuyen ARCHIVE = 'BViet76.jar' ALT='Your browser understands the applet tag but isnot displaying any applet.'><param name='code' value='HoanChuyen76.class'><param name='height' value='1'><param name='NAME' value='HoanChuyen'><param name='ARCHIVE' value='BViet76.jar'><param name='ALT' value='Your browser understands the applet tag but isnnot displaying any applet.'><param name='codebase' value='"+cbase+"'></APPLET>";

// ------------- Toc Ky -----------

var TocKyDiv="<table align='center'><tr><td align='center' valign='top'><textarea name='KhungTK' cols='57' rows='5' Wrap='VIRTUAL' class='mvtable1'></textarea><br><font style='font-size:8pt'><input type=radio name='ChuVan' checked onFocus='tocKy=0;' ><b>Tắt</b>&nbsp;<input type=radio name='ChuVan' onFocus='tocKy=2;' ><b>Vần</b> <SELECT size=1 class='mvselect' name=selTK onChange='loadTK(0)'> <OPTION value=0>ThôngDụng</OPTION> <OPTION value=1>IM</OPTION> <OPTION value=2>ĐịaVị</OPTION> <OPTION value=3>Màu</OPTION> <OPTION value=4>NấuNướng</OPTION> </SELECT> <SELECT class='mvselect' size=1 name=selTK onChange='loadTK(1)'> <OPTION value=0>MViet</OPTION> <OPTION value=1>N/A</OPTION> <OPTION value=2>N/A</OPTION> <OPTION value=3>N/A</OPTION> <OPTION value=4>N/A</OPTION> <OPTION value=5>N/A</OPTION> </SELECT> <SELECT class='mvselect' size=1 name=selTK onChange='loadTK(2)'> <OPTION value=0>Phông</OPTION> <OPTION value=1>1</OPTION> <OPTION value=2>2</OPTION> <OPTION value=3>3</OPTION> <OPTION value=4>4</OPTION> <OPTION value=5>5</OPTION> </SELECT><input name='Button' type='button' value='Nhớ' style='position:relative;top:1' class='mvbutton2' onClick='JavaScript:SetTocKy();'></font></td></tr></table>";

// ------------- Dictionary -----------

var DictDiv = "<table cellpadding='1' align='left' valign='bottom' width='144' height='109'><tr><td valign='top' class='mvtable'><center><b>.:</b> <font style='font-size:10pt'><b>Từ Ðiển</b></font> <b>:.</b><br><br><input type='text' name='TimTu' class='mvtext1' size='15'><br><select class='mvselect' name='doTuDien' style='position:relative;top:3' onChange='if(document.MVietForm.doTuDien.options[document.MVietForm.doTuDien.selectedIndex].value) {DictSearch();}' > <option><font style='font-size:8pt' color='navy'>:: Xin chọn ::</font></option> <option name='DictType' value=0>1. Anh - Việt<br> <option name='DictType' value=1>2. Việt - Anh<br> <option name='DictType' value=2>3. Anh - Anh<br> <option name='DictType' value=3>4. Pháp - Việt<br> <option name='DictType' value=4>5. Việt - Pháp<br> </select><center></center></td></tr></table>";

// ------------- Font -----------

var FontDiv = "<table cellpadding='1' align='left' valign='bottom' width='144' height='109'><tr><td valign='top' class='mvtable'><center><b>.:</b> <font style='font-size:10pt'><b>Kiểu Chữ</b></font> <b>:.</b><br><br> <select class='mvselect' name='MVPhongChu' style='position:relative;top:3' onChange='SetFont();' > <option value=0>Verdana<br> <option value=1>Arial<br> <option value=2>Helvetica<br><option value=3>Tahoma<br><br> </select> <select class='mvselect' name='MVCoChu' style='position:relative;top:3' onChange='SetSize();' > <option value=0>8pt<br> <option value=1>9pt<br> <option value=2>10pt<br><option value=3>11pt<br><option value=4>12pt<br><option value=5>14pt<br><option value=6>15pt</select><br><select class='mvselect' name='MVKieuChu' style='position:relative;top:8' onChange='SetStyle();' > <option value=0>Thường<br> <option value=1>Ðậm<br> <option value=2>Nghiêng<br><br> <option value=3>Ðậm+Nghiêng<br><br></select> <center></center></td></tr></table>";

// ------------- Chon Dau -----------
var ChonDauDiv = " <table cellpadding='0' cellspacing='3' align='center' width='240' height='109' style='position=relative;top=2' class='mvtable'> <tr> <td align='center'><font style='font-weight:bold' size='1'>Sắc</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Huyền</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Hỏi</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Ngã</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Nặng</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Nón</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Móc</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Trăng</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> </tr><tr style='position:relative;top:-5'> <td align='center'><font style='font-weight:bold' size='1'>Gạch</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Xóa</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td align='center'><font style='font-weight:bold' size='1'>Thoát</font><br><input size='5' class='mvtext2' name='BD' maxlength='5'></td> <td colspan='4' align='center'><font size=1><b>Tổ Hợp Tắt Tạm</b></font><br><input name='MVTatTam' type='text' size='28' class='mvtext2' maxlength='30'> </td> <td align='center'><font size=1><b>Trở Về</b></font><br><input name='MVTroVe' type='text' size='5' class='mvtext2' maxlength='5'> </td> </tr><tr style='position:relative;top:-5'> <td colspan='4' align='center'><input type='radio' name='AmMy' class='mvradio' onFocus='thamMy=0;'><font size=1>Âm chính</font>&nbsp;<input type='radio' name='AmMy' class='mvradio' nFocus='thamMy=1;' checked><font size=1>Thẩm Mỹ</font></td> <td align='center' colspan='3'> <font size=1><b>Bộ Dấu Mẫu</b></font> <select name='loadMV' style='border: 1px solid' onChange='if(this.options[this.selectedIndex].value) SplitBoDau(DauMau[this.options[this.selectedIndex].value]);' class='mvtext2'> <option>--------<br><option value='0'>English<br> <option value='1'>Default<br> <option value='2'>MViet<br> <option value='3'>VIQR<br> <option value='4'>VNI<br> <option value='5'>Telex<br> <option value='6'>MVa<br> <option value='7'>MVã<br> </select> </td> <td align='center'> <input type='button' name='Nho' value='Nhớ' class='mvbutton2' onClick='javascript:onClick=SetBoDau();'></td> </tr></table>";

var DauMau = new Array(8);
DauMau[0] = "|||||||||||";
DauMau[1] = "1|\'1|`2|?3|~4|5.|^6|+*7|(8|d9-|z|\\";
DauMau[2] = "1|\'1s|`2f|?3r|~4x|5.j|^6aeo|+*7w|(<8w|d9-|z|\\";
DauMau[3] = "1|\'|`|?|~|.|^|+|(|d|z|\\";
DauMau[4] = "1|1|2|3|4|5|6|7|8|9|z|\\";
DauMau[5] = "1|s|f|r|x|j|aeo|w|w|d|z|\\";
DauMau[6] = "1|s|d|z|x|q|aeo|80|w|-|z|\\";
DauMau[7] = "1|1|2|s|d|z|q|80|w|f-|z|\\";

// ------------- Hoan Chuyen -----------
var ConvDiv = "<table cellpadding='1' width='239' height='109'><tr><td valign='top' class='mvtable'><center><b>.:</b> <font style='font-size:10pt'><b>Hoán chuyển</b></font> <b>:.</b></center><table align='center' style='position:relative;top:3'><tr><td align='right'><font style='font-size:8pt'>Từ</font>&nbsp;<select name='MVHoan' class='mvselect'> <option value='-1' style='color: blue' selected>Auto</option> <option value='0'>VietNet*</option> <option value='1' style='color: orange'>Unicode</option> <option value='2'>VNI</option> <option value='3'>VPS</option> <option value='4'>VISCII</option> <option value='5'>TCVN3</option> <option value='6'>Uni&#</option> <option value='7'>UTF8-Bal</option> <option value='8'>UTF8-Wes</option> <option value='9'>Hex</option> </select></td><td align='left'><input type='button' class='mvbutton2' name='selAll' onClick='TKSelAll();' value='Sellect All'></td></tr><tr><td align='right'><font style='font-size:8pt'>Sang</font>&nbsp;<select name='MVTarget' class='mvselect'> <option value='0'>VietNet*</option> <option value='1' selected style='color: orange'>Unicode</option> <option value='2'>VNI</option> <option value='3'>VPS</option> <option value='4'>VISCII</option> <option value='5'>TCVN3</option> <option value='6'>Uni&#</option> <option value='7'>UTF8-Bal</option> <option value='8'>UTF8-Wes</option> <option value='9'>Hex</option> </select></td><td align='left'><input type='button' name='MVChuyen' value='Chuyển mã' class='mvbutton2' onClick='HoanChuyenFn();'></td></tr></table><center><input type='text' name='hcerror' class='mverror1' value='Xin HiLight đoạn muốn chuyển' size='35'></center></td></tr></table>";

// ------------- Tim Kiem -----------
var TimKiemDiv = "<table cellpadding='2' align='left' width='239' height='109'><tr><td class='mvtable' valign='top'><center><b>.:</b> <font style='font-size:10pt'><b>Tìm & Thế</b></font> <b>:.</b></center><br><INPUT onclick=TimChuCu() type=button class='mvbutton2' value=Tìm style='position:relative;left:3'>&nbsp;&nbsp;<INPUT name=ChuCu class='mvtext1' type=text size=15><br><INPUT onclick=ThayChuMoi() class='mvbutton2' type=button value='Thay =' style='position: relative; top:3; left:3'>&nbsp;&nbsp;<INPUT style='position: relative; top:3' name=ChuMoi class='mvtext1' size='10'>&nbsp;<INPUT style='position: relative; top:3' onclick=ThayAll() class='mvbutton2' type=button value='Thay hết' name='thayall'><br><center><input type='text' name='mverror' class='mverror1' size='35'></center></td></tr></table>";

// ------------- Duyet Hoi Nga -----------

var HoiNgaDiv="<table align='center'><tr><td align='center' valign='top'><img src='img/hnb1.gif' onClick='TuDauHN()' style='position:relative;top:3'><br><img style='position:relative;top:3' src='img/hnb2.gif' onClick='TimHoiNga()'><br><img style='position:relative;top:3' src='img/hnb3.gif' onClick='ThayHN(0)'><br><img style='position:relative;top:3' src='img/hnb4.gif' onClick='ThayHN(1)'></td><td valign='top' align='center'><textarea name='HNMsg' cols='57' rows='6' Wrap='VIRTUAL' class='mvtable1'>\t              -: Duyệt Hỏi Ngã :- \n\n* Nút Hỏi/Ngã: đổi dấu của từ đang duyệt sang dấu Hỏi/Ngã</textarea><br><input type='text' class='mverror2' name='hnerror' size='51'></td></tr></table>";

// ------------- Buttons -------------------

function MVietOnOffButton (){
  if (offP) {
     MVietOnOff.innerHTML=MVOnButton;
   } else {
     MVietOnOff.innerHTML=MVOffButton;
   }
}

//-------------- Functions section ---------
var oldKhung1=DictDiv;
var oldKhung2=TimKiemDiv;

var Khung1="<table style='position:relative; top:15; left:5' align='center'><tr><td><DIV id='MVKhung1'></DIV></td><td><DIV id='MVKhung2'></DIV></td></tr></table>";
var Khung2="<table style='position:relative; top:15; left:5' align='center'><tr><td><DIV id='MVKhung3'></DIV></td></tr></table>";


function ChonDauClick() {
  MVietApplet.innerHTML=LoadChonDau; 
  MVietDiv.innerHTML=Khung2;
  MVKhung3.innerHTML=ChonDauDiv;
  GetBoDau();
}

function DictClick() {
  MVietDiv.innerHTML=Khung1;
  MVKhung1.innerHTML=DictDiv;
  MVKhung2.innerHTML=oldKhung2;
  oldKhung1=DictDiv;  
}

function FontClick() {
  MVietDiv.innerHTML=Khung1;
  MVKhung1.innerHTML=FontDiv;
  MVKhung2.innerHTML=oldKhung2;
  oldKhung1=FontDiv;  
  
  switch(PhongChuMV) {
    case 'Arial':
      document.MVietForm.MVPhongChu[1].selected=true;
      break;
    case '':
      document.MVietForm.MVPhongChu[2].selected=true;
      break;
    case 'Tahoma':
      document.MVietForm.MVPhongChu[3].selected=true;
      break;
    default: 
      document.MVietForm.MVPhongChu[0].selected=true;
  }

  switch(KieuChuMV) {
    case '0':
      document.MVietForm.MVKieuChu[0].selected=true;
      break;
    case '1':
      document.MVietForm.MVKieuChu[1].selected=true;
      break;
    case '2':
      document.MVietForm.MVKieuChu[2].selected=true;
      break;
    case '3':
      document.MVietForm.MVKieuChu[3].selected=true;
  }

  switch(CoChuMV) {
    case '8pt':
      document.MVietForm.MVCoChu[0].selected=true;
      break;
    case '9pt':
      document.MVietForm.MVCoChu[1].selected=true;
      break;
    case '11pt':
      document.MVietForm.MVCoChu[3].selected=true;
      break;
    case '12pt':
      document.MVietForm.MVCoChu[4].selected=true;
      break;
    case '14pt':
      document.MVietForm.MVCoChu[5].selected=true;
      break;
    case '15pt':
      document.MVietForm.MVCoChu[6].selected=true;
      break;
    default:
      document.MVietForm.MVCoChu[2].selected=true;
  }
}

function TimKiemClick() {
  MVietApplet.innerHTML=LoadChonDau;
  MVietDiv.innerHTML=Khung1;
  MVKhung1.innerHTML=oldKhung1;
  MVKhung2.innerHTML=TimKiemDiv;
  oldKhung2=TimKiemDiv;  
}

function ConvClick() {
  MVietApplet.innerHTML=LoadConv+LoadChonDau; 
  MVietDiv.innerHTML=Khung1;
  MVKhung1.innerHTML=oldKhung1;
  MVKhung2.innerHTML=ConvDiv;
  oldKhung2=ConvDiv;  
}

function HoiNgaClick() {
  MVietApplet.innerHTML=LoadHoiNga+LoadChonDau; 
  MVietDiv.innerHTML=Khung2;
  MVKhung3.innerHTML=HoiNgaDiv;
}

function TocKyClick() {
  MVietApplet.innerHTML=LoadChonDau; 
  MVietDiv.innerHTML=Khung2;
  MVKhung3.innerHTML=TocKyDiv;
  GetTocKy();
}

function DictSearch() {
   if (document.MVietForm.TimTu.value == '') {
      alert("Xin điền vào từ bạn muốn tìm"); 
      document.MVietForm.doTuDien[0].selected=true;
      return;
   }
   
   var dicttype0="English-Vietnamese&data=ENGLISH";
   var dicttype1="Vietnamese-English&data=VIETANH";
   var dicttype2="aa";
   var dicttype3="French-Vietnamese&data=FRENCH";
   var dicttype4="Vietnamese-French&data=VIETPHAP";
   var dicttype = dicttype0;
   
   var dictword=document.MVietForm.TimTu.value;
   dtype=document.MVietForm.doTuDien.value;

   if (dtype=='0') dicttype=dicttype0;
   else if (dtype=='1') dicttype=dicttype1;
   else if (dtype=='2') dicttype=dicttype2;
   else if (dtype=='3') dicttype=dicttype3;
   else if (dtype=='4') dicttype=dicttype4;

   if (dtype==2) {      
      var DictUrl="http://www.dictionary.com/search?q="+dictword+"#1";   } 
   else {     
      var DictUrl="http://www.tinhvan.com.vn/scripts/tvis/webdict/webdict.pl?typesearch=&link=YES&dataname="+dicttype+"&key="+dictword+"&func=on";   
   }
   dictionary_popup(DictUrl);
   document.MVietForm.doTuDien[0].selected=true;
}

function dictionary_popup(url)
{
	window.focus();
	dict_popupWin = window.open(url,"dict_popup_b31969018a8f69ff4444260b84496b92","width=650,height=400,resizable=yes,scrollbars=yes,top=0,left=0");
	dict_popupWin.focus();
}
// ------------- Toc Ky -------------
function GetTocKy(){ 
   var tocKy= getTocKy();
   TocKyMV=tocKy; 
   //split
   var indBar = tocKy.indexOf('|');
   if (tocKy.substring(0, indBar)=='2') document.MVietForm.ChuVan[1].checked=true;
   else document.MVietForm.ChuVan[0].checked=true;

   tocKy=tocKy.substring(indBar+1);
   document.MVietForm.KhungTK.value = tocKy; 
}

function SetTocKy(){ 
   var n='0|';
   if (document.MVietForm.ChuVan[1].checked==true) n='2|';
   setTocKy(n+document.MVietForm.KhungTK.value);
}

function loadTK(index) {     
  var box = document.MVietForm.selTK[index]; 
  var typeG = box.options[box.selectedIndex].value; 
  switch (index) {      
     case 0:
        if(typeG == 1) document.MVietForm.KhungTK.value = "ko=không|ng`=người|"; 
        else  if(typeG == 2) document.MVietForm.KhungTK.value = "bs=bác sĩ|gs=giáo sư|ks=kỹ sư|ôb=ông bà|ths=thạc sĩ|ts=tiến sĩ|";
        else if(typeG == 3) document.MVietForm.KhungTK.value = "b0=[blue]|b1=[/blue]|r0=[red]|r1=[/red]|y0=[yellow]|y1=[/yellow]|p0=[pink]|p1=[/pink]|g0=[green]|g1=[/green]|";
        else if(typeG == 4) document.MVietForm.KhungTK.value =  "bn=bầm nhuyễn|cb=chuẩn bị|cbn=chế biến|ch=chén|cl=cách làm|cm=cắt mỏng|cs=cắt sợi|đs=đun sôi|hb=hớt bọt|l=lon|ln=lửa nhỏ|lrr=lửa riu riu|lv=lột võ|lv=lửa vừa|mcf=muổng cà phê (cafe')|mc=muổng canh|ms=muổng súp|ncgc=nữ công gia chánh|nl=nguyên liệu|pk=phơi khô|pn=phơi nắng|rn=ráo nước|rs=rửa sạch|s=soong|tcf=thìa cà phê|th=thực hiện|thl=thái hạt lựu|ts=trụng sơ|tsn=thái sợi nhỏ|ttm=thái thật mỏng|ttn=án nhuyễn|vl=vật liệu|xm=xắt mỏng|xn=xé nhỏ|xnh=xắt nhuyễn|xs=xắt sợi|";
        break;
     case 1: if(typeG == 1) document.MVietForm.KhungTK.value = "ma=mai|"; 
        break;
     case 2: if(typeG == 1) document.MVietForm.KhungTK.value = "ha=hai|"; 
        break;
  }
  box.selectedIndex=false;
}

// ------------- Font -----------

function SetFont(){ 
   var selFont="Verdana";
   switch (document.MVietForm.MVPhongChu.value) {
      case '1': selFont="Arial"; break;
      case '2': selFont="Helvetica"; break;
      case '3': selFont="Tahoma"; break;
      default: selFont="Verdana"; 
   }
   setPhongChu(selFont);
   document.MVietForm.message.style.fontFamily=selFont;
}

function SetStyle(){ 
   var selStyle=document.MVietForm.MVKieuChu.value;

   switch (selStyle) {
      case '0': 
        document.MVietForm.message.style.fontStyle="normal";
        document.MVietForm.message.style.fontWeight="normal";
	break;
      case '1':
        document.MVietForm.message.style.fontWeight="bold";
        document.MVietForm.message.style.fontStyle="normal";
        break;
      case '2': 
        document.MVietForm.message.style.fontWeight="normal";
        document.MVietForm.message.style.fontStyle="italic";
        break;
      case '3': 
        document.MVietForm.message.style.fontWeight="bold";
        document.MVietForm.message.style.fontStyle="italic";
   }
   setKieuChu(selStyle);
}


function SetSize(){ 
   var selSize="10pt";
   switch (document.MVietForm.MVCoChu.value) {
      case '0': selSize="8pt"; break;
      case '1': selSize="9pt"; break;
      case '3': selSize="11pt"; break;
      case '4': selSize="12pt"; break;
      case '5': selSize="14pt"; break;
      case '6': selSize="15pt"; break;
      default: selSize="10pt"; 
   }
   setCoChu(selSize);
   document.MVietForm.message.style.fontSize=selSize;
}

function GetFont(){ 
   PhongChuMV=getPhongChu(); 
   CoChuMV=getCoChu();
   KieuChuMV=getKieuChu();
   document.MVietForm.message.style.fontSize=CoChuMV;
   document.MVietForm.message.style.fontFamily=PhongChuMV;
   switch(KieuChuMV) {
     case '0':
       document.MVietForm.message.style.fontWeight='normal';
       document.MVietForm.message.style.fontStyle='normal';
       break;
     case '1':
       document.MVietForm.message.style.fontWeight='bold';
       document.MVietForm.message.style.fontStyle='normal';
       break;
     case '2':
       document.MVietForm.message.style.fontWeight='normal';
       document.MVietForm.message.style.fontStyle='italic';
     case '3':
       document.MVietForm.message.style.fontWeight='bold';
       document.MVietForm.message.style.fontStyle='italic';
   }
}

// ------------- Chon Dau -----------

function GetBoDau(){
   var boDau= getBoDau();
   BoDauMV= boDau;
   SplitBoDau(boDau);

   var tatTam=getMVTatTam();
   var indTT=tatTam.indexOf('*');
   if (indTT>-1){
      TatTamMV= tatTam.substring(0, indTT);
      document.MVietForm.MVTatTam.value=tatTam.substring(0, indTT);
      TatTamW= tatTam.substring(0, indTT).split('|');
      TroVeMV= tatTam.substring(indTT+1);
      document.MVietForm.MVTroVe.value= tatTam.substring(indTT+1);
   } 
}

function SplitBoDau(boDau){
   var indBar = boDau.indexOf('|');
   if (boDau.substring(0, indBar)=='0') document.MVietForm.AmMy[0].checked=true; 
   else document.MVietForm.AmMy[1].checked=true; 
   boDau=boDau.substring(indBar+1);
   for (var i=0; i<10; i++){
      indBar = boDau.indexOf('|');
      if (indBar==-1) break;
         document.MVietForm.BD[i].value = boDau.substring(0, indBar);
      boDau=boDau.substring(indBar+1);
   }
   if (i==10) document.MVietForm.BD[10].value = boDau;
}

function SetBoDau(){
   var tempBD =0; if (document.MVietForm.AmMy[1].checked)  tempBD=1;
   for (var i=0; i<11; i++) tempBD += "|"+document.MVietForm.BD[i].value;
   if (tempBD != BoDauMV) {BoDauMV= tempBD;
   setBoDau(tempBD);}

   if(TatTamMV != document.MVietForm.MVTatTam.value  || TroVeMV != document.MVietForm.MVTroVe.value ) {
      TatTamMV= document.MVietForm.MVTatTam.value;
      TroVeMV= document.MVietForm.MVTroVe.value; 
      TatTamW= (document.MVietForm.MVTatTam.value).split('|'); 
      setMVTatTam(document.MVietForm.MVTatTam.value+'*'+document.MVietForm.MVTroVe.value);
   }
}


// ------------- Hoan Chuyen -----------

function TKSelAll() {
  document.MVietForm.message.select();
}

function HoanChuyenFn() {
   document.MVietForm.hcerror.value='';
   if (self.MVsrc)  self.MVsrc.select(); 
   if (self.MVsrc == null) {
      document.MVietForm.hcerror.value='Bạn cần Hilight đoạn văn'; 
      return;
   }
   else
   {  
      var maFrom = document.MVietForm.MVHoan.value; 
      var maTo = document.MVietForm.MVTarget.value; 

      if (maFrom == '-1') maFrom=-1;
      if (maFrom == '0') maFrom=0;
      if (maFrom == '1') maFrom=1;
      if (maFrom == '2') maFrom=2;
      if (maFrom == '3') maFrom=3;
      if (maFrom == '4') maFrom=4;
      if (maFrom == '5') maFrom=5;
      if (maFrom == '6') maFrom=6;
      if (maFrom == '7') maFrom=7;
      if (maFrom == '8') maFrom=8;
      if (maFrom == '9') maFrom=9;
      if (maTo == '0') maTo=0;
      if (maTo == '1') maTo=1;
      if (maTo == '2') maTo=2;
      if (maTo == '3') maTo=3;
      if (maTo == '4') maTo=4;
      if (maTo == '5') maTo=5;
      if (maTo == '6') maTo=6;
      if (maTo == '7') maTo=7;
      if (maTo == '8') maTo=8;
      if (maTo == '9') maTo=9;
      var text2 = self.MVsrc.text;
      if (text2==null || text2=='') {
         document.MVietForm.hcerror.value='Bạn cần Hilight đoạn văn muốn đổi qua dạng mới.'; 
         return;
      } 

      var MVOffset = document.HoanChuyen.countCR(text2);

      if (maFrom==-1){ 
         var dangViet = self.document.VietInterface.dangViet(text2);
         document.MVietForm.MVHoan[dangViet+1].selected = true; 
         maFrom=dangViet;
         var dvtxt='';   
         if (dangViet==0) dvtxt='VietNet*'; 
         if (dangViet==1) dvtxt='Unicode'; 
         if (dangViet==2) dvtxt='VNI'; 
         if (dangViet==3) dvtxt='VPS'; 
         if (dangViet==4) dvtxt='VISCII'; 
         if (dangViet==5) dvtxt='TCVN3'; 
         if (dangViet==6) dvtxt='Uni&#'; 
         if (dangViet==7) dvtxt='UTF8-Bal'; 
         if (dangViet==8) dvtxt='UTF8-Wes'; 
         document.MVietForm.hcerror.value='Mã trước khi đổi: '+dvtxt;
      }
 
      if (maFrom==0) {
         text2 =  self.document.VietInterface.getViet(text2, 1, 0, '\'|`|?|~|.|^|+*|(|d||\\', self.thamMy);

         if (maTo!=1) text2 = document.HoanChuyen.MVConvert(text2, 1 , maTo);

      } else
      if (maFrom != 0 && maFrom != maTo) {text2= document.HoanChuyen.MVConvert(text2, maFrom , maTo); }


      self.MVsrc.text=text2;
      self.MVsrc.collapse();
      self.MVsrc.moveStart('character', MVOffset-text2.length);
      self.MVsrc.select();
      maFrom=maTo;
      document.MVietForm.MVHoan[maFrom+1].selected = true;
   }
}


// ------------- Tim Kiem -----------

var ct = 0;
var found = false; var text;
function ThayAll() {
self.document.MVietForm.mverror.value="";
do{
    if (found) 
      {text.text= document.MVietForm.ChuMoi.value; 
        if (document.MVietForm.ChuMoi.value.toLowerCase().indexOf(document.MVietForm.ChuCu.value.toLowerCase()) == -1) ct--;}
    TimChuCu();
    }while(found);
}

function ThayChuMoi() {
self.document.MVietForm.mverror.value="";
    if (found) 
      {text.text= document.MVietForm.ChuMoi.value; 
        if (document.MVietForm.ChuMoi.value.toLowerCase().indexOf(document.MVietForm.ChuCu.value.toLowerCase()) == -1) ct--;}
    TimChuCu();
}
function TimChuCu() {
     self.document.MVietForm.mverror.value="";
     var src = document.MVietForm.message;

     if  (src == null  || (src.type != 'textarea')  )  { self.document.MVietForm.mverror.value="Xin bấm con trỏ chọn khung để duyệt"; return; } else { self.document.MVietForm.mverror.value=""; }
     if  (src == null  || (src.type != 'textarea')  )  { return; }

    text = src.createTextRange();

    if (document.MVietForm.ChuCu.value == '') {
        self.document.MVietForm.mverror.value="Xin Điền Chữ Để Tìm";
        return;
    }
    if (document.all) {
        found = false;

        for (var i=0; i<=ct && (found=text.findText(document.MVietForm.ChuCu.value)) != false; i++) {
            text.moveStart("character", 1);
            text.moveEnd("textedit");
        }
        if (found) {
            text.moveStart("character", -1);
            text.findText(document.MVietForm.ChuCu.value);
            text.select();
            
            text.scrollIntoView();
            ct++;
        }
        else {
            if (ct == '0')
                self.document.MVietForm.mverror.value='Chữ '+'"' + document.MVietForm.ChuCu.value +'" không có (hoặc đã thay)';
            else
                self.document.MVietForm.mverror.value='Chữ '+'"' +  document.MVietForm.ChuCu.value +'" đã tìm (hoặc thay) xong.';
            ct=0;
        }
    }
    else if (document.layers) {
        //self.find(document.MVietForm.ChuCu.value,false);
    }
}

// ------------- Duyet Hoi Nga -----------

var text;  var index = -1;

function TuDauHN(){
   self.document.MVietForm.hnerror.value="";
   index = -1;
   TimHoiNga();
}

function ThayHN(j){
   self.document.MVietForm.hnerror.value="";

   if (index >=document.MVietForm.message.value.length) { self.document.MVietForm.hnerror.value="Đã Tới Cuối Trang!"; }
   else {
      var baseHN = "ảẩẳẻểỉỏổởủửỷãẫẵẽễĩõỗỡũữỹ";

   if (text.text==null || text.text=='') { self.document.MVietForm.hnerror.value="Khung không có chữ !!!"; return;}

   var n = baseHN.indexOf(text.text);
   if (n==-1) document.MVietForm.HNMsg.value="TYPO";
   else text.text = baseHN.charAt(n%12+ j*12);
   TimHoiNga(); }
}

function TimHoiNga(){
self.document.MVietForm.hnerror.value="";

var src = document.MVietForm.message;
if  (src == null  || (src.type != 'textarea' && src.type != 'text' )  )  { self.document.MVietForm.hnerror.value="Xin bấm con trỏ chọn khung để duyệt."; return; }

text = src.createTextRange(); 
var trailCR = (src.value.length - text.text.length)/2;
var tempT=text.text;

if (text.text=="" || text.text==null) { self.document.MVietForm.hnerror.value="Khung không có chữ !!!"; return;}

var newText= document.BViet75.getIndexHN(text.text, index+1 ); //G

var nInx = newText.indexOf('|');  
index = parseInt(newText.substring(0,nInx)); 
newText=newText.substring(nInx+1); 
 
nInx = newText.indexOf('|');
var countCR  = parseInt(newText.substring(0,nInx)); 
newText=newText.substring(nInx+1); 

nInx = newText.indexOf('|');
var countCR2  = parseInt(newText.substring(0,nInx)); 
newText=newText.substring(nInx+1); 
  
document.MVietForm.HNMsg.value=newText;
//
if (index >=text.text.length) { self.document.MVietForm.hnerror.value="Đã Tới Cuối Trang! (hoặc không có dấu hỏi/ngã)"; }
else{  var offset1 = index-countCR;
  text.moveStart("character",  offset1);
  text.moveEnd("character", 1+countCR2 -text.text.length- trailCR);
  text.select(); text.scrollIntoView(); }
}

