function checkcurrency(form,name,namenext){
  if ((event.keyCode >47 && event.keyCode < 58) ||event.keyCode==46){
    return true;
  }else if(event.keyCode == 13){ 
    name_focus="document."+form+"."+namenext+".focus();";
    eval(name_focus);  
    return true;
  }else{
    alert("คีย์เฉพาะเลข");
    event.keyCode = 0;
    return false;
  }
}
function addRowToTable(cn){
  //-----------------------Arm-design
  var tbl = document.getElementById('tblSample');
  var lastRow    = tbl.rows.length;
  var iteration    = lastRow;
  var row        = tbl.insertRow(lastRow);
  FormApp.NumrowEDU.value=lastRow;
  row.className  = 'tex_tr';
  var cellRight1    = row.insertCell(0);
  var cellRight2    = row.insertCell(1);
  var cellRight3    = row.insertCell(3);
  var cellRight4    = row.insertCell(4);
  var cellRight5    = row.insertCell(5);
  var cellRight6    = row.insertCell(6);
  var el1          = document.createElement('input');
  var el2          = document.createElement('input');
  var el3          = document.createElement('input');
  var el4          = document.createElement('input');
  var el5          = document.createElement('input');
  var el6          = document.createElement('input');

  el1.type      = 'text';
  el1.name      = 'hisedu_ysstart' + iteration;
  el1.id        = 'hisedu_ysstart' + iteration;
  el1.size      = 5;
  el1.className = cn;
  
  el2.type      = 'text';
  el2.name      = 'hisedu_ysend' + iteration;
  el2.id        = 'hisedu_ysend' + iteration;
  el2.size      = 5;
  el2.className = cn;

  el3.type      = 'text';
  el3.name      = 'hisedu_name' + iteration;
  el3.id        = 'hisedu_name' + iteration;
  el3.size      = 32;
  el3.className = cn;

  el4.type      = 'text';
  el4.name      = 'hisedu_degree' + iteration;
  el4.id        = 'hisedu_degree' + iteration;
  el4.size      = 25;
  el4.className = cn;

  el5.type      = 'text';
  el5.name      = 'hisedu_major' + iteration;
  el5.id        = 'hisedu_major' + iteration;
  el5.size      = 30;
  el5.className = cn;

  el6.type      = 'text';
  el6.name      = 'hisedu_grade' + iteration;
  el6.id        = 'hisedu_grade' + iteration;
  el6.size      = 10;
  el6.className = cn;

  cellRight1.appendChild(el1);
  cellRight2.appendChild(el2);
  cellRight3.appendChild(el3);
  cellRight4.appendChild(el4);
  cellRight5.appendChild(el5);
  cellRight6.appendChild(el6);
}
function keyPressTest(e, obj)
{
  var validateChkb = document.getElementById('chkValidateOnKeyPress');
  if (validateChkb.checked) {
    var displayObj = document.getElementById('spanOutput');
    var key;
    if(window.event) {
      key = window.event.keyCode; 
    }
    else if(e.which) {
      key = e.which;
    }
    var objId;
    if (obj != null) {
      objId = obj.id;
    } else {
      objId = this.id;
    }
    displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  }
}
function removeRowFromTable(){
  var tbl = document.getElementById('tblSample');
  var lastRow = tbl.rows.length;
  if (lastRow > 3){
    tbl.deleteRow(lastRow - 1);
    var delRows=FormApp.NumrowEDU.value;
    delRows=delRows-1;
    FormApp.NumrowEDU.value=delRows;
  }
}
function openInNewWindow(frm){
  var aWindow = window.open('', 'TableAddRowNewWindow','scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400'); 
  frm.target = 'TableAddRowNewWindow';
  frm.submit();
}
function validateRow(frm){
  var chkb = document.getElementById('chkValidate');
  if (chkb.checked) {
    var tbl = document.getElementById('tblSample');
    var lastRow = tbl.rows.length - 1;
    var i;
    for (i=1; i<=lastRow; i++) {
      var aRow = document.getElementById('txtRow' + i);
      if (aRow.value.length <= 0) {
        alert('Row ' + i + ' is empty');
        return;
      }
    }
  }
  openInNewWindow(frm);
}
function addRowToTable2(){
  //-----------------------Arm-design
  var tbl = document.getElementById('tblSample2');
  var lastRow  = tbl.rows.length;
  var iteration  = lastRow;
  var row        = tbl.insertRow(lastRow);
  FormApp.NumrowWorkhistory.value=lastRow;
  row.className  = 'tex_tr';
  //var cellLeft = row.insertCell(0);
  //var textNode = document.createTextNode(iteration);
  //cellLeft.appendChild(textNode);
  var cellRight1    = row.insertCell(0);
  var cellRight2    = row.insertCell(1);
  var cellRight3    = row.insertCell(3);
  var cellRight4    = row.insertCell(4);
  var cellRight5    = row.insertCell(5);
  var cellRight6    = row.insertCell(6);
  var cellRight7    = row.insertCell(7);
  var el1          = document.createElement('input');
  var el2          = document.createElement('input');
  var el3          = document.createElement('input');
  var el4          = document.createElement('input');
  var el5          = document.createElement('input');
  var el6          = document.createElement('input');
  var el7          = document.createElement('input');

  el1.type        = 'text';
  el1.name        = 'tfcompany' + iteration;
  el1.id          = 'tfcompany' + iteration;
  el1.size        = 27;
  el1.className   = 'tex_box1';
  
  el2.type        = 'text';
  el2.name        = 'tfForm' + iteration;
  el2.id          = 'tfForm' + iteration;
  el2.size        = 10;
  el2.className   = 'tex_box1';

  el3.type        = 'text';
  el3.name        = 'tfto' + iteration;
  el3.id          = 'tfto' + iteration;
  el3.size        = 10;
  el3.className   = 'tex_box1';

  el4.type        = 'text';
  el4.name        = 'tfposition' + iteration;
  el4.id          = 'tfposition' + iteration;
  el4.size        = 29;
  el4.className   = 'tex_box1';

  el5.type        = 'text';
  el5.name        = 'tfreason' + iteration;
  el5.id          = 'tfreason' + iteration;
  el5.size        = 20;
  el5.className   = 'tex_box1';

  el6.type        = 'text';
  el6.name        = 'tfStart' + iteration;
  el6.id          = 'tfStart' + iteration;
  el6.size        = 9;
  el6.className   = 'tex_box1';

  el7.type        = 'text';
  el7.name        = 'tfFinish' + iteration;
  el7.id          = 'tfFinish' + iteration;
  el7.size        = 9;
  el7.className   = 'tex_box1';

  cellRight1.appendChild(el1);
  cellRight2.appendChild(el2);
  cellRight3.appendChild(el3);
  cellRight4.appendChild(el4);
   cellRight5.appendChild(el5);
  cellRight6.appendChild(el6);
  cellRight7.appendChild(el7);
}
function removeRowFromTable2()
{
  var tbl = document.getElementById('tblSample2');
  var lastRow = tbl.rows.length;
  if (lastRow > 2){
    tbl.deleteRow(lastRow - 1);
    var delRows=FormApp.NumrowWorkhistory.value;
    delRows=delRows-1;
    FormApp.NumrowWorkhistory.value=delRows;
  }
}
function Hidden_TotalStatus(){
  Hidden_WorkhistoryStatus();
  Hidden_spousStatus();
}
function Hidden_WorkhistoryStatus(){
  if(FormApp.WorkhistoryStatus.value=="N"){
    WorkhistoryStatus_row.style.display='none';
    WorkhistoryStatus_row1.style.display='none';
  }
}
function Open_WorkhistoryStatus(r1){
  if(r1.value=="N"){
    WorkhistoryStatus_row.style.display='none';
    WorkhistoryStatus_row1.style.display='none';
  }else{
    WorkhistoryStatus_row.style.display='';
    WorkhistoryStatus_row1.style.display='';
  }
}
function idthai_type_test(obj){
  var tt = new String("");
  var nm = new String("");
  tt = obj.value;
  bbb=obj.name
  nm = obj.id;
  nm = nm.slice(0,nm.length - 1) + (parseInt(nm.slice(nm.length - 1,nm.length))+1);
  aaa=nm.split('_');
  if(tt.length  == obj.maxLength){
  if(isNaN(tt) || (tt <= 0)){
  alert("กรุณากรอกข้อมูลเฉพาะตัวเลขเท่านั้น หรือต้องมีค่ามากกว่า 0");
  yyy="FormApp."+bbb+".value=''";
  eval(yyy);
  }else{
  if(aaa[2]=="2"){
  if(parseInt(tt)>31){
  alert("ท่านกรอกวันที่เกิน 31 วันกรุณากรอกใหม่ด้วย");
  yyy="FormApp."+bbb+".value=''";
  eval(yyy);
  }else{
  document.all.item(nm).focus();
  document.all.item(nm).select();
  }
  }else if(aaa[2]=="3"){
  if(parseInt(tt)>12){
  alert("ท่านกรอกเดือนเกิน 12 เดือนกรุณากรอกใหม่ด้วย");
  yyy="FormApp."+bbb+".value=''";
  eval(yyy);
  }else{
  document.all.item(nm).focus();
  document.all.item(nm).select();
  }
  }
  }
  }
  }
function Check_year_type(r1,r2){
  mmm=r1.name;
  nnn=r1.value;
  if(nnn.length=="4"){
    if(isNaN(nnn) || (nnn <= 0)){
        alert("กรุณากรอกข้อมูลเฉพาะตัวเลขเท่านั้น หรือต้องมีค่ามากกว่า 0");
        yyy="FormApp."+mmm+".value=''";
        eval(yyy);
      }else{
        if(nnn < parseInt(2272)){
          xxx=parseInt(nnn)+parseInt(543);
          yyy="FormApp."+mmm+".value="+xxx;
          vvv="FormApp."+r2+".focus();";
          eval(yyy);
          eval(vvv);
        }else{
          vvv="FormApp."+r2+".focus();";
          eval(vvv);
        }
    }
  }
}
function idthai_type(obj){
  var tt = new String("");
  var nm = new String("");
  tt = obj.value;
  nm = obj.id;
  nm = nm.slice(0,nm.length - 1) + (parseInt(nm.slice(nm.length - 1,nm.length))+1);
  aaa=nm.split('_');
  if(aaa[2]=="6"){
    document.FormApp.crad_place.focus();
  }else{
    if (tt.length  == obj.maxLength){
      document.all.item(nm).focus();
      document.all.item(nm).select();
    }
  }
}
function Hidden_spousStatus(){
  if(FormApp.spousStatus.value=="S"){
    MilitaryStatusrows.style.display='none';
  }
}
function Show_spousStatus(r1){
  if(r1.value=="S"){
    MilitaryStatusrows.style.display='none';
  }else if(r1.value=="M"){
    MilitaryStatusrows.style.display='';
  }else if(r1.value=="D"){
    MilitaryStatusrows.style.display='none';
  }
}
function Openpopup_Technical(r1,r2) {
  exp = "page_Technical.php?type="+r1.value+"&emp_id="+r2;
  wd = window.open(exp,"Technical_data","toolbar=no,directories=no,menubar=no,width=350,height=450,top=0,left=0,resizable=1,scrollbars=1");
  setTimeout('wd.focus()', 100); 
}
function addRowToTable3(){
  //-----------------------Arm-design
  var tbl = document.getElementById('tblSample3');
  var lastRow  = tbl.rows.length;
  var iteration  = lastRow;
  var row        = tbl.insertRow(lastRow);
  FormApp.NumrowBusiness.value=lastRow;
  row.className  = 'tex_tr';
  var cellRight1    = row.insertCell(0);
  var cellRight2    = row.insertCell(1);
  var cellRight3    = row.insertCell(3);
  var cellRight4    = row.insertCell(4);

  var el1          = document.createElement('input');
  var el2          = document.createElement('input');
  var el3          = document.createElement('input');
  var el4          = document.createElement('input');

  el1.type          = 'text';
  el1.name          = 'businessreferees_name' + iteration;
  el1.id            = 'businessreferees_name' + iteration;
  el1.size          = 22;
  el1.className     = 'tex_box1';
  
  el2.type        = 'text';
  el2.name        = 'businessreferees_position' + iteration;
  el2.id          = 'businessreferees_position' + iteration;
  el2.size        = 29;
  el2.className   = 'tex_box1';

  el3.type        = 'text';
  el3.name        = 'businessreferees_present' + iteration;
  el3.id          = 'businessreferees_present' + iteration;
  el3.size        = 38;
  el3.className   = 'tex_box1';

  el4.type        = 'text';
  el4.name        = 'businessreferees_nature' + iteration;
  el4.id          = 'businessreferees_nature' + iteration;
  el4.size        = 30;
  el4.className   = 'tex_box1';

  cellRight1.appendChild(el1);
  cellRight2.appendChild(el2);
  cellRight3.appendChild(el3);
  cellRight4.appendChild(el4);
}
function removeRowFromTable3(){
  var tbl = document.getElementById('tblSample3');
  var lastRow = tbl.rows.length;
  if (lastRow > 1){
    tbl.deleteRow(lastRow - 1);
    var delRows=FormApp.NumrowWorkhistory.value;
    delRows=delRows-1;
    FormApp.NumrowBusiness.value=delRows;
  }
}
function idthai_type_time(obj){
  var tt = new String("");
  var nm = new String("");
  tt = obj.value;
  bbb=obj.name
  nm = obj.id;
  nm = nm.slice(0,nm.length - 1) + (parseInt(nm.slice(nm.length - 1,nm.length))+1);
  aaa=nm.split('_');
  if(tt.length  == obj.maxLength){
    if(isNaN(tt) || (tt <= 0)){
      alert("กรุณากรอกข้อมูลเฉพาะตัวเลขเท่านั้น หรือต้องมีค่ามากกว่า 0");
      yyy="FormApp."+bbb+".value=''";
      eval(yyy);
    }else{
      if(aaa[1]=="2"){
        if(parseInt(tt)>24){
          alert("ท่านกรอกจำนวนชั่วโมงเกิน 24 ชั่วโมงกรุณากรอกใหม่ด้วย");
          yyy="FormApp."+bbb+".value=''";
          eval(yyy);
        }else{
          document.all.item(nm).focus();
          document.all.item(nm).select();
        }
      }
    }
  }
}
function idthai_type_time_s(obj){
  var tt = new String("");
  var nm = new String("");
  tt = obj.value;
  bbb=obj.name
  nm = obj.id;
  nm = nm.slice(0,nm.length - 1) + (parseInt(nm.slice(nm.length - 1,nm.length))+1);
  aaa=nm.split('_');
  if(tt.length  == obj.maxLength){
    if(isNaN(tt)){
    alert("กรุณากรอกข้อมูลเฉพาะตัวเลขเท่านั้น");
    yyy="FormApp."+bbb+".value=''";
    eval(yyy);
    }else{
      if(aaa[1]=="3"){
        if(parseInt(tt)>59){
        alert("ท่านกรอกจำนวนนาทีเกิน 59 นาทีกรุณากรอกใหม่ด้วย");
        yyy="FormApp."+bbb+".value=''";
        eval(yyy);
        }else{
        document.FormApp.Department.focus();
        }
      }
    }
  }
}

