<?php
$PageSecurity = 2;
$title = _('Employee Master');
include('includes/SQL_CommonFunctions.inc');
include('includes/othrs.php');
date_default_timezone_set('Asia/calcutta');
include('cocoon_config.php');
$today = date('d/m/Y');


if ($_REQUEST['Update'] != '') {


  $EmpCode = $s->GetFieldValue('empmaster', "id='" . $_REQUEST['id'] . "'", 'emp_code');
  function extension($filename)
  {
    $name_brk = explode('.', $filename);
    return  $name_brk[1];
  }

  if (!empty($_FILES['docmnt']['name']) && $_FILES['docmnt']['name'][0] != '') {
    $flag = 0;
    $qty = $_FILES['docmnt']['name'];
    if ($_REQUEST['docmnt1'] != '') {
      $TAS = explode(",", $_REQUEST['docmnt1']);
      $new_name1 = $TAS;
    }


    //print_r($new_name1);

    for ($i = 0; $i < count($qty); $i++) {
      $name = $_FILES['docmnt']['name'][$i];
      $type = extension($name);
      if ($type != 'pdf' && $type != 'doc' && $type != 'txt' && $type != 'docx' && $type != 'rtf' && $type != 'jpg' && $type != 'jpeg' && $type != 'JPEG' && $type != 'JPG' && $type != 'png' && $type != 'gif' && $type != 'gif') {
        echo "Invalid Extension! Kindly please check the image before uploading";
        $flag = 1;
      } else {
        $tmp_name = $_FILES['docmnt']['tmp_name'][$i];
        //echo $tmp_name;

        //echo $_FILES['photo']['size'];
        $new_name1[] = $EmpCode . '_' . $name;
        $new_name2[] = $EmpCode . '_' . $name;
        $path = "uploaded_docs/" . $new_name2[$i];

        $file_copy = copy($tmp_name, $path);
        if (!$file_copy) {
          echo "Copy Unsuccessful";
          $flag = 1;
        }
      }
    }
    //print_r($new_name1);
    //exit;
    if (!empty($new_name1)) {
      $new_name = implode(",", $new_name1);
    }

    if (!empty($new_name)) {
      $doc_sql = "Update empmaster SET document='" . $new_name . "' where id='" . $_REQUEST['id'] . "'";
      $doc_res = DB_query($doc_sql, $db);
    }
  }



  $name = $_FILES['photo']['name'];
  $type = extension($name);
  if ($type != '') {
    if ($type != 'jpg' && $type != 'jpeg' && $type != 'JPEG' && $type != 'JPG' && $type != 'png' && $type != 'gif' && $type != 'gif') {
      echo "Invalid Extension! Kindly please check the image before uploading";
      $flag = 1;
    } else {
      $tmp_name = $_FILES['photo']['tmp_name'];

      $new_name2 = $EmpCode . '.' . $type;
      $path = "uploaded_images/" . $new_name2;
      $file_copy = move_uploaded_file($tmp_name, $path);
      if (!$file_copy) {
        echo "Copy Unsuccessful";
        $flag = 1;
      }
    }
  }

  if ($name == '') {
    $newname4 = $_REQUEST['image_name'];
  } else {
    $newname4 = $new_name2;
  }


  if ($_REQUEST['emp_name_old'] == $_REQUEST['emp_name']) {
    $FinempCode = $_REQUEST['emp_code'];
  } else {
    $EmpName = $_REQUEST['emp_name'];
    $FirstChar = substr($EmpName, 0, 1);
    $FirstChar1 = strtoupper($FirstChar);
    $maxempcode = DB_query("SELECT MAX(emp_code) AS EMPCD FROM empmaster WHERE emp_code LIKE '$FirstChar1%'", $db);
    $MaxCodeEmp = DB_fetch_array($maxempcode);
    if ($MaxCodeEmp['EMPCD'] != '') {
      $numericval = substr($MaxCodeEmp['EMPCD'], 1);
      $nextdigit = $numericval + 1;
      $FinempCode = $FirstChar1 . str_pad($nextdigit, 4, "0", STR_PAD_LEFT);
    } else {
      $FinempCode = $FirstChar1 . '0001';
    }
  }

  $data['emp_site'] = $_REQUEST['emp_site'];
  $data['employment_type'] = $_REQUEST['employment_type'];
  $data['employee_type'] = $_REQUEST['emp_shift'];
  $data['emp_code'] = $FinempCode;
  $data['bloodgroup'] = $_REQUEST['bloodgroup'];
  $data['emp_name'] = $_REQUEST['emp_name'];
  $data['fh_name'] = $_REQUEST['fh_name'];
  $data['nationality'] = $_REQUEST['nationality'];
  $data['religion'] = $_REQUEST['religion'];
  $data['dob'] = FormatDateForSQL($_REQUEST['dob']);
  $data['doj'] = FormatDateForSQL($_REQUEST['doj']);
  $data['dol'] = FormatDateForSQL($_REQUEST['dol']);
  $data['department'] = $_REQUEST['department'];
  $data['emp_weekly_off'] = $_REQUEST['emp_weekly_off'];
  $data['designation'] = $_REQUEST['designation'];
  $data['marital_status'] = $_REQUEST['marital_status'];
  $data['marriage'] = FormatDateForSQL($_REQUEST['marriage']);
  $data['wh_name'] = $_REQUEST['wh_name'];
  $data['biomatric_id'] = $_REQUEST['biomatric_id'];
  $data['sons'] = $_REQUEST['sons'];
  $data['daughters'] = $_REQUEST['daughters'];
  $data['sex'] = $_REQUEST['sex'];
  $data['grade'] = $_REQUEST['grade'];
  $data['personalEmail'] = $_REQUEST['personalEmail'];
  $data['offEmail'] = $_REQUEST['offEmail'];
  $data['PFno'] = $_REQUEST['PFno'];
  $data['ESIno'] = $_REQUEST['ESIno'];
  $data['bank_name'] = $_REQUEST['bank_name'];
  $data['bank_account'] = $_REQUEST['bank_account'];
  $data['payment_mode'] = $_POST['payment_mode'];
  $data['leave_eff_date'] = FormatDateForSQL($_REQUEST['leave_eff_date']);
  $data['bachelor'] = $_REQUEST['bachelor'];
  $data['course3'] = $_POST['course3'];
  $data['course1'] = $_POST['course1'];
  $data['course2'] = $_POST['course2'];
  $data['tenth_standard'] = $_REQUEST['tenth_standard'];
  $data['tenthplus2_standard'] = $_REQUEST['tenthplus2_standard'];
  $data['master'] = $_REQUEST['pgcourse'];
  $data['other_master'] = $_POST['othercourse'];
  $data['basic_perc'] = $_POST['basic_perc'];
  $data['basic_salary'] = $_REQUEST['basic_salary'];
  $data['allow_tot'] = $_REQUEST['allow_tot'];
  $data['deduct_tot'] = $_REQUEST['deduct_tot'];
  $data['gross'] = $_REQUEST['gross'];
  $data['gross_sal'] = $_REQUEST['gross_sal'];
  $data['net_sal'] = $_REQUEST['net_sal'];
  $data['eff_sal_date'] = FormatDateForSQL($_REQUEST['eff_sal_date']);
  $data['pf_calculation'] = $_REQUEST['pf_calculation'];
  $data['adv_amount'] = $_REQUEST['adv_amount'];
  $data['adv_date'] = FormatDateForSQL($_REQUEST['adv_date']);
  $data['over_time'] = $_REQUEST['over_time'];
  if ($_REQUEST['otapplicable'] != '')
    $otapplicable = 'Y';
  else
    $otapplicable = 'N';
  $data['otapplicable'] = $otapplicable;
  $data['ottype'] = $_REQUEST['ottype'];
  $data['overtime_salary'] = $_REQUEST['overtime_salary'];
  $data['image'] = $newname4;
  $data['pending_wo'] = $_REQUEST['weekly_off'];
  $data['auth'] = $_REQUEST['auth'];
  $data['status'] = $_REQUEST['emp_status'];
  $data['multi_site_att'] = $_REQUEST['multi_site_att'];
  $Condi = "id='" . $_REQUEST['id'] . "'";
  //echo "<pre>";
  //print_r($data);
  //exit;
  $s->RecordEdit('empmaster', $data, $Condi);

  $dataArr['per_address1'] = $_REQUEST['per_address1'];
  $dataArr['per_address2'] = $_REQUEST['per_address2'];
  $dataArr['per_address3'] = $_REQUEST['per_address3'];
  $dataArr['per_country'] = $_REQUEST['per_country'];
  $dataArr['per_state'] = $_REQUEST['per_state'];
  $dataArr['per_city'] = $_REQUEST['per_city'];
  $dataArr['per_pincode'] = $_REQUEST['per_pincode'];
  $dataArr['per_mobile'] = $_REQUEST['per_mobile'];
  $dataArr['per_phone'] = $_REQUEST['per_phone'];
  $dataArr['per_alt_phone'] = $_REQUEST['per_alt_phone'];
  $dataArr['per_alt_mobile'] = $_REQUEST['per_alt_mobile'];
  $dataArr['pre_address1'] = $_REQUEST['pre_address1'];
  $dataArr['pre_address2'] = $_REQUEST['pre_address2'];
  $dataArr['pre_address3'] = $_REQUEST['pre_address3'];
  $dataArr['pre_country'] = $_REQUEST['pre_country'];
  $dataArr['pre_state'] = $_REQUEST['pre_state'];
  $dataArr['pre_city'] = $_REQUEST['pre_city'];
  $dataArr['pre_pincode'] = $_REQUEST['pre_pincode'];
  $dataArr['pre_mobile'] = $_REQUEST['pre_mobile'];
  $dataArr['pre_phone'] = $_REQUEST['pre_phone'];
  $dataArr['pre_alt_phone'] = $_REQUEST['pre_alt_phone'];
  $dataArr['pre_alt_mobile'] = $_REQUEST['pre_alt_mobile'];
  $Condi1 = "emp_id='" . $_REQUEST['id'] . "'";
  $s->RecordEdit('employee_address', $dataArr, $Condi1);


  //****************************  Inserting to Cocoon - Employee Master ************************************//  

  $empcode = str_pad($strFinal, 6, "0", STR_PAD_LEFT);
  $dob1 = date('Y-m-d', $_REQUEST['dob']);
  $current_date = Date('Y-m-d');
  $date1 = new DateTime($current_date);
  $date2 = new DateTime($dob1);
  $diff = $date1->diff($date2);

  $data_cocoon['emp_name']              = $_REQUEST['emp_name'];
  $data_cocoon['dob']                   = FormatDateForSQL($_REQUEST['dob']);
  $data_cocoon['qualification']         = $_REQUEST['course1'];
  $data_cocoon['marital_status']        = $_REQUEST['marital_status'];
  $data_cocoon['a_year']                = $diff->y;
  $data_cocoon['a_month']               = $diff->m;
  $data_cocoon['a_day']                 = $diff->d;
  $data_cocoon['gender']                = $_REQUEST['sex'];
  $data_cocoon['doj']                   = FormatDateForSQL($_REQUEST['doj']);
  $data_cocoon['blood_group']           = $_REQUEST['bloodgroup'];
  $data_cocoon['dol']                   = FormatDateForSQL($_REQUEST['dol']);
  $data_cocoon['father_sp']             = $_REQUEST['fh_name'];
  $data_cocoon['pf']                    = $_REQUEST['PFno'];
  $data_cocoon['relegion']              = $_REQUEST['religion'];
  $data_cocoon['location']              = $_REQUEST['emp_site'];
  $data_cocoon['staff_type']            = $_REQUEST['employment_type'];
  $data_cocoon['department_master_id']  = $_REQUEST['department'];
  $data_cocoon['dept_code']             = $s->getField('deptmaster', 'dept_id ', $_REQUEST['department'], 'deptcode');
  $data_cocoon['dept_desc']             = $s->getField('deptmaster', 'dept_id ', $_REQUEST['department'], 'deptname');
  $data_cocoon['status']                = $_REQUEST['emp_status'];
  $data_cocoon['desigcode']             = $s->getField('desigmaster', 'desig_id ', $_REQUEST['designation'], 'desigcode');
  $data_cocoon['designation_id']        = $_REQUEST['designation'];
  $data_cocoon['description']           = $s->getField('desigmaster', 'desig_id ', $_REQUEST['designation'], 'designame');
  $data_cocoon['house_no']              = $_REQUEST['per_address1'];
  $data_cocoon['street']                = $_REQUEST['per_address2'];
  $data_cocoon['a_location']            = $_REQUEST['per_address3'];
  // $data_cocoon['district']              =
  $data_cocoon['town']                  = $_REQUEST['per_city'];
  $data_cocoon['state']                 = $_REQUEST['per_state'];
  $data_cocoon['country']               = $_REQUEST['per_country'];
  $data_cocoon['pin']                   = $_REQUEST['per_pincode'];
  $data_cocoon['email']                 = $_REQUEST['personalEmail'];
  $data_cocoon['ph1']                   = $_REQUEST['per_phone'];
  //$data_cocoon['ph2']                   =$_REQUEST['per_phone'];
  //$data_cocoon['ph3']                   =
  $data_cocoon['mob']                   = $_REQUEST['per_mobile'];
  //$data_cocoon['fax']                   =
  //$data_cocoon['pager']                 =

  $data_cocoon['auth']                  = $_REQUEST['auth'];

  $cond2_cocoon = "nippon_emp_id='" . $_REQUEST['id'] . "'";
  $sql_insert_cocoon = "update  employee_masters set ";
  $i = 0;
  foreach ($data_cocoon as $key => $val) {
    if ($i == 0)
      $sql_insert_cocoon .= " " . $key . " = '" . $val . "'";
    else
      $sql_insert_cocoon .= ", " . $key . " = '" . $val . "'";
    $i++;
  }
  $sql_insert_cocoon .= " where  $cond2_cocoon";
  //echo "<br>*************INSERT***************************************************</br>"      ;
  // echo $sql_insert_cocoon;
  // exit;   

  $cocoon_query = mysqli_query($link1, $sql_insert_cocoon);

  if (!empty($_REQUEST['id'])) {
    $cond1_cocoon = "nippon_emp_id='" . $_REQUEST['id'] . "'";
    $inDocData = array(
      'date_from' => FormatDateForSQL($_REQUEST['dob']),
      'name' => $_REQUEST['emp_name'],
      'sex' => $_REQUEST['sex'],
      'age' => $diff->y,
      'qualification' => $_REQUEST['course1'],
      'date_to' => FormatDateForSQL($_REQUEST['dol']),
      'reg_houseno' => $_REQUEST['per_address1'],
      'department_master_id' => $_REQUEST['department'],
      'dept_code' => $s->getField('deptmaster', 'dept_id ', $_REQUEST['department'], 'deptcode'),
      'dept_desc' => $s->getField('deptmaster', 'dept_id ', $_REQUEST['department'], 'deptname'),
      'reg_street' => $_REQUEST['per_address2'],
      'reg_location' => $_REQUEST['per_address3'],
      'reg_city' => $_REQUEST['per_city'],
      'reg_state' => $_REQUEST['per_state'],
      'reg_country' => $_REQUEST['per_country'],
      'reg_email' => $_REQUEST['personalEmail'],
      'reg_phone1' => $_REQUEST['per_phone'],
      'reg_cellphone1' => $_REQUEST['per_mobile'],
      'modified_by' => 0
    );

    $sql_insert_cocoon_doctor = "update  doctor_masters set ";
    $i = 0;
    foreach ($inDocData as $key => $val) {
      if ($i == 0)
        $sql_insert_cocoon_doctor .= " " . $key . " = '" . $val . "'";
      else
        $sql_insert_cocoon_doctor .= ", " . $key . " = '" . $val . "'";
      $i++;
    }
    $sql_insert_cocoon_doctor .= " where  $cond1_cocoon";
    $cocoon_query_doctor = mysqli_query($link1, $sql_insert_cocoon_doctor);
  }

  //***********************************************************************************************************//  

  $dataWeof['pending_wo'] = $_REQUEST['weekly_off'];
  $Cond2 = "emp_id='" . $_REQUEST['row_id'] . "'";
  $s->RecordEdit('weekly_off_emp', $dataWeof, $Cond2);

  for ($acr1 = 1; $acr1 < $_REQUEST['ctr']; $acr1++) {
    $chkOtherAllwcId = DB_query("select * from emp_salary where emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction='" . $_REQUEST['allid'][$acr1] . "' and all_ded_prefix='" . $_REQUEST['prefix1'] . "'", $db);
    if (DB_num_rows($chkOtherAllwcId) > 0) {
      $dataEmpsal['percentage'] = $_REQUEST['aperc'][$acr1];
      $dataEmpsal['percentage_value'] = $_REQUEST['allow'][$acr1];
      $condsal = "emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction='" . $_REQUEST['allid'][$acr1] . "'
        and all_ded_prefix='" . $_REQUEST['prefix1'] . "'";
      $s->RecordEdit('emp_salary', $dataEmpsal, $condsal);
    } else {
      $dataEmpsal['emp_id'] = $_REQUEST['row_id'];
      $dataEmpsal['allowance_deduction'] = $_REQUEST['allid'][$acr1];
      $dataEmpsal['percentage'] = $_REQUEST['aperc'][$acr1];
      $dataEmpsal['percentage_value '] = $_REQUEST['allow'][$acr1];
      $dataEmpsal['all_ded_prefix'] = $_REQUEST['prefix1'];
      $s->RecordInsert('emp_salary', $dataEmpsal);
    }
  }
  //exit;  

  $chkspid = DB_query("select * from emp_salary where emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=100 and all_ded_prefix='A'", $db);
  if (DB_num_rows($chkspid) > 0) {
    $dataspecial['percentage'] = '0.00';
    $dataspecial['percentage_value'] = $_REQUEST['special_allow'];
    $CondSpecial = "emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=100 and all_ded_prefix='A'";
    $s->RecordEdit('emp_salary', $dataspecial, $CondSpecial);
  } else {
    $dataspecial['emp_id'] = $_REQUEST['row_id'];
    $dataspecial['allowance_deduction'] = '100';
    $dataspecial['percentage'] = '0.00';
    $dataspecial['percentage_value'] = $_REQUEST['special_allow'];
    $dataspecial['all_ded_prefix'] = 'A';
    $s->RecordInsert('emp_salary', $dataspecial);
  }

  $chklta = DB_query("select * from emp_salary where emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=101 and all_ded_prefix='A'", $db);
  if (DB_num_rows($chklta) > 0) {
    $dataslta['percentage'] = $_REQUEST['ltaper'];
    $dataslta['percentage_value'] = $_REQUEST['lta'];
    $Condlta = "emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=101 and all_ded_prefix='A'";
    $s->RecordEdit('emp_salary', $dataslta, $Condlta);
  } else {
    $dataslta['emp_id'] = $_REQUEST['row_id'];
    $dataslta['allowance_deduction'] = '101';
    $dataslta['percentage'] = $_REQUEST['ltaper'];
    $dataslta['percentage_value'] = $_REQUEST['lta'];
    $dataslta['all_ded_prefix'] = 'A';
    $s->RecordInsert('emp_salary', $dataslta);
  }

  $chklwf = DB_query("select * from emp_salary where emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=102 and all_ded_prefix='A'", $db);
  if (DB_num_rows($chklwf) > 0) {
    $dataslwf['percentage'] = $_REQUEST['LWFper'];
    $dataslwf['percentage_value'] = $_REQUEST['LWF'];
    $Condlwf = "emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction=102 and all_ded_prefix='A'";
    $s->RecordEdit('emp_salary', $dataslwf, $Condlwf);
  } else {
    $dataslwf['emp_id'] = $_REQUEST['row_id'];
    $dataslwf['allowance_deduction'] = '102';
    $dataslwf['percentage'] = $_REQUEST['LWFper'];
    $dataslwf['percentage_value'] = $_REQUEST['LWF'];
    $dataslwf['all_ded_prefix'] = 'A';
    $s->RecordInsert('emp_salary', $dataslwf);
  }

  //************************DEDUCTION PART*************AS*************START HERE************12-06-2013*****************  

  for ($acr2 = 1; $acr2 < $_REQUEST['dctr']; $acr2++) {
    $chkDeduct = DB_query("select * from emp_salary where emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction='" . $_REQUEST['dedid'][$acr2] . "' and all_ded_prefix='" . $_REQUEST['prefix2'] . "'", $db);
    if (DB_num_rows($chkDeduct) > 0) {
      $dataded['percentage'] = $_REQUEST['dperc'][$acr2];
      $dataded['percentage_value'] = $_REQUEST['deduction'][$acr2];
      $CondDed = "emp_id='" . $_REQUEST['row_id'] . "' and allowance_deduction='" . $_REQUEST['dedid'][$acr2] . "'
      and all_ded_prefix='" . $_REQUEST['prefix2'] . "'";
      $s->RecordEdit('emp_salary', $dataded, $CondDed);
    } else {
      $dataded['emp_id'] = $_REQUEST['row_id'];
      $dataded['allowance_deduction'] = $_REQUEST['dedid'][$acr2];
      $dataded['percentage'] = $_REQUEST['dperc'][$acr2];
      $dataded['percentage_value'] = $_REQUEST['deduction'][$acr2];
      $dataded['all_ded_prefix'] = $_REQUEST['prefix2'];
      //echo "<pre>";
      //print_r($dataded);
      $s->RecordInsert('emp_salary', $dataded);
    }
  } //exit;

  //************************DEDUCTION PART*************AS*************END HERE************12-06-2013*****************

  for ($CR = 0; $CR < $_REQUEST['cnt']; $CR++) {
    $Condlea = "emp_id='" . $_REQUEST['row_id'] . "' and leave_type='" . $_REQUEST['leave_type'][$CR] . "'";
    $ChkLe = DB_query("select * from emp_leave where $Condlea", $db);
    if (DB_num_rows($ChkLe) > 0) {
      $dataleave['leave_days'] = $_REQUEST['leave_days'][$CR];
      $s->RecordEdit('emp_leave', $dataleave, $Condlea);
    } else {
      $dataLeave['emp_id'] = $_REQUEST['row_id'];
      $dataLeave['leave_type'] = $_REQUEST['leave_type'][$CR];
      $dataLeave['leave_days'] = $_REQUEST['leave_days'][$CR];
      $s->RecordInsert('emp_leave', $dataLeave);
    }
  }
  //exit;
  $s->pageLocation("index.php?route=employee_list" . $rurl);
}

if ($_REQUEST['id'] != '' && $_REQUEST['action'] == 'edit') {
  $get_sql1 = DB_query("Select * from empmaster where id='" . $_REQUEST['id'] . "' ", $db);
  $get_row1 = DB_fetch_array($get_sql1);

  $get_sql2 = DB_query("Select * from employee_address where emp_id='" . $_REQUEST['id'] . "' ", $db);
  $get_row2 = DB_fetch_array($get_sql2);

  $get_sql3 = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='A' order by allowance_deduction ASC", $db);
  $k = 1;
  while ($get_row3 = DB_fetch_array($get_sql3)) {
    $aperc[$k] = $get_row3['percentage'];
    $allow[$k] = $get_row3['percentage_value'];
    $k++;
  }

  $get_sql10 = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='A' and allowance_deduction=100", $db);
  $get_row10 = DB_fetch_array($get_sql10);
  $spc_allow = $get_row10['percentage'];
  $special_allow = $get_row10['percentage_value'];

  $get_LTA = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='A' and allowance_deduction=101", $db);
  $get_LTAVAl = DB_fetch_array($get_LTA);
  $LTA_allow_Per = $get_LTAVAl['percentage'];
  $LTA_allow_Val = $get_LTAVAl['percentage_value'];

  $get_LWF = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='A' and allowance_deduction=102", $db);
  $get_LWFVAl = DB_fetch_array($get_LWF);
  $LWF_allow_Per = $get_LWFVAl['percentage'];
  $LWF_allow_Val = $get_LWFVAl['percentage_value'];

  $get_LWF = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='A' and allowance_deduction=103", $db);
  $get_LWFVAl = DB_fetch_array($get_LWF);
  $esi_per = $get_LWFVAl['percentage'];
  $esi_value = $get_LWFVAl['percentage_value'];

  $get_sql4 = DB_query("Select * from emp_salary where emp_id='" . $_REQUEST['id'] . "' and all_ded_prefix='D' order by allowance_deduction ASC", $db);
  $K = 1;
  while ($get_row4 = DB_fetch_array($get_sql4)) {
    $dperc[$K] = $get_row4['percentage'];
    $deduction[$K] = $get_row4['percentage_value'];
    $K++;
  }

  $emp_site = $get_row1['emp_site'];

  $uploadimage = $get_row1['image'];

  $emp_code = $get_row1['emp_code'];
  $emp_name = $get_row1['emp_name'];
  $fh_name = $get_row1['fh_name'];
  $nationality = $get_row1['nationality'];
  $religion = $get_row1['religion'];
  $bloodgroup = $get_row1['bloodgroup'];
  $dob = ConvertSQLDate($get_row1['dob']);
  $doj = ConvertSQLDate($get_row1['doj']);
  $dol = ConvertSQLDate($get_row1['dol']);
  $department = $get_row1['department'];
  $designation = $get_row1['designation'];
  $marital_status = $get_row1['marital_status'];
  $marriage = ConvertSQLDate($get_row1['marriage']);
  $wh_name = $get_row1['wh_name'];
  $biomatric_id = $get_row1['biomatric_id'];
  $sons = $get_row1['sons'];
  $daughters = $get_row1['daughters'];
  $sex = $get_row1['sex'];
  $grade = $get_row1['grade'];
  $emp_status = $get_row1['status'];
  $auth = $get_row1['auth'];
  $personalEmail = $get_row1['personalEmail'];
  $offEmail = $get_row1['offEmail'];
  $PFno = $get_row1['PFno'];
  $ESIno = $get_row1['ESIno'];
  $bank_name = $get_row1['bank_name'];
  $bank_account = $get_row1['bank_account'];
  $payment_mode = $get_row1['payment_mode'];
  $leave_eff_date = ConvertSQLDate($get_row1['leave_eff_date']);
  $bachelor = $get_row1['bachelor'];
  $course1 = $get_row1['course1'];
  $course2 = $get_row1['course2'];
  $tenthplus2_standard = $get_row1['tenthplus2_standard'];
  $tenth_standard = $get_row1['tenth_standard'];
  $master = $get_row1['master'];
  $course3 = $get_row1['course3'];
  $other_master = $get_row1['other_master'];
  $basic_perc = $get_row1['basic_perc'];
  $basic_salary = $get_row1['basic_salary'];
  $allow_tot = $get_row1['allow_tot'];
  $deduct_tot = $get_row1['deduct_tot'];
  $gross_sal = $get_row1['gross_sal'];
  $gross = $get_row1['gross'];
  $net_sal = $get_row1['net_sal'];
  $eff_sal_date = ConvertSQLDate($get_row1['eff_sal_date']);
  $pf_calculation = $get_row1['pf_calculation'];
  $adv_amount = $get_row1['adv_amount'];
  $adv_date = ConvertSQLDate($get_row1['adv_date']);
  $new_name = $get_row1['image'];
  $document = $get_row1['document'];
  $over_time = $get_row1['over_time'];
  $overtime_salary = $get_row1['overtime_salary'];
  $employment_type = $get_row1['employment_type'];
  $emp_shift = $get_row1['employee_type'];
  $emp_weekly_off = $get_row1['emp_weekly_off'];
  $per_address1 = $get_row2['per_address1'];
  $status = $get_row1['status'];
  $auth = $get_row1['auth'];
  $per_address2 = $get_row2['per_address2'];
  $per_address3 = $get_row2['per_address3'];
  $per_country = $get_row2['per_country'];
  $per_state = $get_row2['per_state'];
  $per_city = $get_row2['per_city'];
  $per_pincode = $get_row2['per_pincode'];
  $per_mobile = $get_row2['per_mobile'];
  $per_phone = $get_row2['per_phone'];
  $per_alt_phone = $get_row2['per_alt_phone'];
  $per_alt_mobile = $get_row2['per_alt_mobile'];
  $pre_address1 = $get_row2['pre_address1'];
  $pre_address2 = $get_row2['pre_address2'];
  $pre_address3 = $get_row2['pre_address3'];
  $pre_country = $get_row2['pre_country'];
  $pre_state = $get_row2['pre_state'];
  $pre_city = $get_row2['pre_city'];
  $pre_pincode = $get_row2['pre_pincode'];
  $pre_mobile = $get_row2['pre_mobile'];
  $pre_phone = $get_row2['pre_phone'];
  $pre_alt_phone = $get_row2['pre_alt_phone'];
  $pre_alt_mobile = $get_row2['pre_alt_mobile'];
  $pending_wo = $get_row1['pending_wo'];
  $multi_site_att = $get_row1['multi_site_att'];
  $otapplicable = $get_row1['otapplicable'];
  $ottype = $get_row1['ottype'];

  $get_sql4 = DB_query("Select * from emp_leave where emp_id='" . $_REQUEST['id'] . "' ", $db);
  $j = 0;
  while ($get_row4 = DB_fetch_array($get_sql4)) {
    $id[$j] = $get_row4['id'];
    $leave_type[$j] = $get_row4['leave_type'];
    $leave_days[$j] = $get_row4['leave_days'];
    $j++;
  }
}
?>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script type="text/javascript" src="js/function-ajax.js"></script>
<script>
  //function cal_esi(str)
  //{
  //  var gross_sal = str;
  //  if(gross_sal == 'NaN')
  //  {
  //  }
  //  else
  //  {
  //    var net_esi = ((4.75*(str))/100);
  //    document.getElementById("esimployervalue").value=net_esi;   
  //  }
  //}

  function cal_esi(str1) {
    var gross_sal = str1;
    if (gross_sal >= 0 && gross_sal <= 15000) {
      var net_esi = ((4.75 * (str1)) / 100);
      document.getElementById("esimployervalue").value = Math.round(net_esi);
      document.getElementById("ESIemployer").value = "4.75";
      document.getElementById("esimployervalue").removeAttribute("readonly");
      document.getElementById("ESIemployer").removeAttribute("readonly");
    } else {
      document.getElementById("esimployervalue").value = "0";
      document.getElementById("ESIemployer").value = "0";
      document.getElementById("esimployervalue").setAttribute("readonly", true);
      document.getElementById("ESIemployer").setAttribute("readonly", true);
    }
  }

  function chkbachlor(id) {
    if (id != '') {
      document.getElementById("other_bachelor").value = '';
    }

  }

  function chkmaster(id) {
    if (id != '') {
      document.getElementById("other_master").value = '';
    }

  }

  function chkother_master(id) {

    if (id != '') {
      document.getElementById("masterMA").checked = false
      document.getElementById("masterMSC").checked = false
      document.getElementById("masterMCOM").checked = false
      document.getElementById("masterMBA").checked = false
      document.getElementById("masterME").checked = false

    } else {
      document.getElementById("masterMA").checked = true
      document.getElementById("masterMSC").checked = true
      document.getElementById("masterMCOM").checked = true
      document.getElementById("masterMBA").checked = true
      document.getElementById("masterME").checked = true
    }
  }

  function chkother_bachelor(id) {

    if (id != '') {
      document.getElementById("bachelorBA").checked = false
      document.getElementById("bachelorBSC").checked = false
      document.getElementById("bachelorBCOM").checked = false
      document.getElementById("bachelorBBA").checked = false
      document.getElementById("bachelorLLB").checked = false
      document.getElementById("bachelorBE").checked = false
      //document.getElementById("other_bachelor").value=id;
    } else {
      document.getElementById("bachelorBA").checked = true
      document.getElementById("bachelorBSC").checked = true
      document.getElementById("bachelorBCOM").checked = true
      document.getElementById("bachelorBBA").checked = true
      document.getElementById("bachelorLLB").checked = true
      document.getElementById("bachelorBE").checked = true
    }
  }

  function data_str(str1) {
    var gross_sal = str1;

    var t = '';
    var count1 = document.getElementById("dctr").value;

    for (var i = 1; i < count1; i++) {
      if (document.getElementById("empdedtype_" + i).value == 'ESI') {
        t = i;
        if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
        } else { // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var data = xmlhttp.responseText.split("__");
            if (data[0] == 0) {
              document.getElementById("dperc_" + t).value = data[0];
              document.getElementById("deduction_" + t).value = data[1];
              document.getElementById("dperc_" + t).setAttribute("readonly", true);
              document.getElementById("deduction_" + t).setAttribute("readonly", true);
            } else {
              document.getElementById("dperc_" + t).value = data[0];
              document.getElementById("deduction_" + t).value = data[1];
              document.getElementById("dperc_" + t).removeAttribute("readonly");
              document.getElementById("deduction_" + t).removeAttribute("readonly");
            }
          }
        }
        var varsiteid = document.getElementById("emp_site").value;
        xmlhttp.open("GET", "ajax_getesi1.php?str=" + str1 + "&site=" + varsiteid, true);
        xmlhttp.send();
      }
    }
  }
</script>

<link type="text/css" media="screen" rel="stylesheet" href="css/file-upload.css">
<!-- <script type="text/javascript" src="js/prototype.lite.js"></script>
<script type="text/javascript" src="js/moo.fx.js"></script>
<script type="text/javascript" src="js/moo.fx.pack.js"></script> -->
<script type="text/javascript" src="js/min.js"></script>
<script type="text/javascript" src="js/file-upload.js"></script>
<script type="text/javascript">
  // function init(){
  //   var stretchers = document.getElementsByClassName('box');
  //   var toggles = document.getElementsByClassName('tab');
  //   var myAccordion = new fx.Accordion(
  //     toggles, stretchers, {opacity: false, height: true, duration: 600}
  //   );
  //   //hash functions
  //   var found = false;
  //   toggles.each(function(h4, i){
  //     var div = Element.find(h4, 'nextSibling');
  //       if (window.location.href.indexOf(h4.title) > 0) {
  //         myAccordion.showThisHideOpen(div);
  //         found = true;
  //       }
  //     });
  //     if (!found) myAccordion.showThisHideOpen(stretchers[0]);
  // }
  function calculate_esi(esi_percentage) {
    var gross_sal = document.getElementById("allow_tot").value;
    var net_esi = ((esi_percentage * gross_sal) / 100);
    document.getElementById("esimployervalue").value = Math.round(net_esi);
  }
</script>

<script language="javascript" type="text/javascript">
  //*****************FUNCTION FOR ALLOWNCES**********************************************************************

  //function cal_allvalue(j)
  //{
  //  var basic=document.getElementById("basic_salary").value;
  //  var allwper=document.getElementById("aperc_"+j).value;
  //  if(basic==''){basic=0;}
  //  if(allwper==''){allwper=0;}
  //  if(allwper!='' || allwper!='0.00')
  //  {
  //    var totvalue=basic*((allwper)/100);
  //    document.getElementById("allow_"+j).value=totvalue;
  //  }
  //  else
  //  {
  //    var allwval=document.getElementById("allow_"+j).value;
  //    if(allwval=='')
  //    {
  //      document.getElementById("allow_"+j).value='0';
  //    }
  //  }
  //}

  function cal_allvalue(str, j) {
    var basic = document.getElementById("basic_salary").value;
    var totvalue = Math.round((basic * str) / 100);
    document.getElementById("allow_" + j).value = Math.round(totvalue);
  }

  function reversecal_allvalue(str, j) {
    var basic = document.getElementById("basic_salary").value;
    var totvalue = (100 * str) / basic;
    document.getElementById("aperc_" + j).value = Math.round(totvalue);
  }

  //*****************FUNCTION FOR ALLOWNCES**********************************************************************

  //*****************FUNCTION FOR DEDUCTIONS**********************************************************************

  function cal_dedvalue(str, j) {
    // alert(str);
    a = document.getElementById("empdedtype_" + j).value;

    var basic = document.getElementById("basic_salary").value;
    var grosssal = document.getElementById("allow_tot").value;
    if (a == 'PF') {
      if (basic > 6501) {
        var basic = 6500;
        var totvalue = basic * ((str) / 100);
        document.getElementById("deduction_" + j).value = Math.round(totvalue);
      } else {
        var basic = document.getElementById("basic_salary").value;
        var totvalue = basic * ((str) / 100);
        document.getElementById("deduction_" + j).value = Math.round(totvalue);
      }
    } else if (a == 'ESI') {
      if (grosssal < 15001) {
        if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp = new XMLHttpRequest();
        } else { // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var data = xmlhttp.responseText.split("__");
            document.getElementById("dperc_" + j).value = data[0];
            document.getElementById("deduction_" + j).value = data[1];
          }
        }

        varsiteid = document.getElementById("emp_site").value;
        xmlhttp.open("GET", "ajax_getesi.php?str=" + grosssal + "&site=" + varsiteid, true);
        xmlhttp.send();
      } else {
        document.getElementById("deduction_" + j).value = '0.00';
      }
    } else {
      var basic = document.getElementById("gross").value;
      var totvalue = basic * ((str) / 100);
      document.getElementById("deduction_" + j).value = Math.round(totvalue);
    }

  }

  //*****************FUNCTION FOR DEDUCTIONS**********************************************************************

  function check_yn(str) {
    if (str == 'NO') {
      document.getElementById("adv_amount").disabled = true;
      document.getElementById("adv_date").disabled = true;
    } else {
      document.getElementById("adv_amount").disabled = false;
      document.getElementById("adv_date").disabled = false;
    }
  }

  function check_marriage(str) {
    if (str == 'Single') {
      document.getElementById("marriage").disabled = true;
      document.getElementById("wh_name").disabled = true;
      document.getElementById("sons").disabled = true;
      document.getElementById("daughters").disabled = true;
    } else if (str == 'Married' || str == '000') {
      document.getElementById("marriage").disabled = false;
      document.getElementById("wh_name").disabled = false;
      document.getElementById("sons").disabled = false;
      document.getElementById("daughters").disabled = false;
    }

  }

  function addressInfo() {

    if (document.getElementById("copy_add").checked == true) {
      document.getElementById('per_add1').value = document.getElementById('pre_add1').value;
      document.getElementById('per_add2').value = document.getElementById('pre_add2').value;
      document.getElementById('per_add3').value = document.getElementById('pre_add3').value;
      document.getElementById('per_city').value = document.getElementById('pre_city').value;
      document.getElementById('per_state').value = document.getElementById('pre_state').value;
      document.getElementById('per_country').value = document.getElementById('pre_country').value;
      document.getElementById('per_pincode').value = document.getElementById('pre_pincode').value;
      document.getElementById('per_mobile').value = document.getElementById('pre_mobile').value;
      document.getElementById('per_phone').value = document.getElementById('pre_phone').value;
      document.getElementById('per_alt_phone').value = document.getElementById('pre_alt_phone').value;
      document.getElementById('per_alt_mobile').value = document.getElementById('pre_alt_mobile').value;

    } else {
      document.getElementById('per_add1').value = '';
      document.getElementById('per_add2').value = '';
      document.getElementById('per_add3').value = '';
      document.getElementById('per_city').value = '';
      document.getElementById('per_state').value = '';
      document.getElementById('per_country').value = '';
      document.getElementById('per_pincode').value = '';
      document.getElementById('per_mobile').value = '';
      document.getElementById('per_phone').value = '';
      document.getElementById('per_alt_phone').value = '';
    }
  }

  function find_state(str) {
    if (str.length == 0) {
      document.getElementById("state_id").innerHTML = "";
      return;
    }
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("state_id").innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET", "emp_state.php?country=" + str, true);
    xmlhttp.send();
  }

  function find_city(str) {
    var cntry = document.getElementById("pre_country").value;
    if (str.length == 0) {
      document.getElementById("city_id").innerHTML = "";
      return;
    }
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("city_id").innerHTML = xmlhttp.responseText;
      }
    }
    xmlhttp.open("GET", "emp_city.php?state=" + str + "&country=" + cntry, true);
    xmlhttp.send();
  }

  function cal_alltot() {
    var Basic_SAL = document.getElementById("basic_salary").value;
    var total_allowance = 0;
    var count = document.getElementById("ctr").value;
    var sa = document.getElementById("special_allow").value;
    for (var j = 1; j < count; j++) {
      var allowance = document.getElementById("allow_" + j).value;
      total_allowance = parseFloat(total_allowance) + parseFloat(allowance);
    }

    document.getElementById("allow_tot").value = Math.round((parseFloat(total_allowance) + parseFloat(Basic_SAL) + parseFloat(sa)));

    var g = parseFloat(document.getElementById("gross").value);
    var totalallowance = parseFloat(total_allowance) + parseFloat(Basic_SAL) + parseFloat(sa);
    //if(totalallowance<g)
    //  {
    //  alert("The TOTAL ALLOWANCE is less than the GROSS SALARY. Please re-enter the values to make them equal");
    //  }
    if (totalallowance > g) {
      alert("The TOTAL ALLOWANCE is more than the GROSS SALARY. Please re-enter the values to make them equal");
    }
  }

  function calmothellysal() {
    var g = parseFloat(document.getElementById("gross").value);
    var sa = document.getElementById("special_allow").value;
    var Basic_SAL = document.getElementById("basic_salary").value;
    var total_allowance = 0;
    var count = document.getElementById("ctr").value;
    for (var j = 1; j < count; j++) {
      if (document.getElementById("allow_" + j).value != '')
        var allowance = document.getElementById("allow_" + j).value;
      else
        allowance = 0;
      total_allowance = parseFloat(total_allowance) + parseFloat(allowance);
    }
    var LTA = document.getElementById("lta").value;
    var LWF = document.getElementById("LWF").value;
    var ESI_employer_value = document.getElementById("esimployervalue").value;
    //alert(ESI_employer_value);

    if (g == '') {
      g = 0;
    }
    if (sa == '') {
      sa = 0;
    }
    if (Basic_SAL == '') {
      Basic_SAL = 0;
    }
    if (LTA == '') {
      LTA = 0;
    }
    if (LWF == '') {
      LWF = 0;
    }
    if (ESI_employer_value == '') {
      ESI_employer_value = 0;
    }
    var mothellyctc = parseFloat(total_allowance) + parseFloat(LTA) + parseFloat(LWF) + parseFloat(sa) + parseFloat(Basic_SAL) + parseFloat(ESI_employer_value);
    document.getElementById("monthelyctc1").value = Math.round(mothellyctc);

    if (mothellyctc != g) {
      alert("Monthelly CTC Must Be Equal");
      return false;
    }
  }

  function cal_special_allow() {
    var g = parseFloat(document.getElementById("gross").value);
    var Basic_SAL = document.getElementById("basic_salary").value;
    var total_allowance = 0;
    var count = document.getElementById("ctr").value;
    for (var k = 1; k < count; k++) {
      var allowance = document.getElementById("allow_" + k).value;
      total_allowance = parseFloat(total_allowance) + parseFloat(allowance);
    }

    var LTA = document.getElementById("lta").value;
    var LWF = document.getElementById("LWF").value;
    if (LTA == '') {
      LTA = 0;
    }
    if (LWF == '') {
      LWF = 0;
    }
    var allow_basic1 = (parseFloat(total_allowance) + parseFloat(Basic_SAL) + parseFloat(LTA) + parseFloat(LWF));
    var allow_basic2 = g - allow_basic1;
    if (allow_basic2 < 0) {
      allow_basic2 = 0.00;
    }
    document.getElementById("special_allow").value = allow_basic2;
  }

  function calLWFAll(val) {
    if (val != '') {
      var Basic_SAL = document.getElementById("basic_salary").value;
      var ltaamt = (Basic_SAL * val) / 100;
      document.getElementById("LWF").value = Math.round(ltaamt);
    } else {
      document.getElementById("LWF").value = '0';
    }
  }

  function calltaAll(val) {
    if (val != '') {
      var Basic_SAL = document.getElementById("basic_salary").value;
      var ltaamt = (Basic_SAL * val) / 100;
      document.getElementById("lta").value = Math.round(ltaamt);
    } else {
      document.getElementById("lta").value = '0';
    }
  }

  function cal_dedtot() {
    var tot_deduction = 0;
    var count = document.getElementById("dctr").value;
    for (var j = 1; j < count; j++) {
      var deduction = document.getElementById("deduction_" + j).value;
      tot_deduction = parseFloat(tot_deduction) + parseFloat(deduction);
    }
    document.getElementById("deduct_tot").value = Math.round(tot_deduction);
  }

  function cal_gross() {
    document.getElementById("gross_sal").value = document.getElementById("allow_tot").value;
  }

  function cal_net() {
    var gsal = document.getElementById("gross_sal").value;
    var deduct = document.getElementById("deduct_tot").value;
    var net = parseFloat(gsal) - parseFloat(deduct);
    document.getElementById("net_sal").value = Math.round(net);
  }

  function calculate_basic() {
    var gross = document.getElementById("gross").value;
    var basic_perc = document.getElementById("basic_perc").value;
    if (gross == '') {
      gross = 0;
    }
    if (basic_perc == '') {
      basic_perc = 0;
    }

    var totalbasic = gross * ((basic_perc) / 100);
    //alert(totalbasic);
    document.getElementById("basic_salary").value = Math.round(totalbasic);
  }

  //function calculate_basic()
  //{
  //  var gross=document.getElementById("gross").value;
  //  var basic_perc=document.getElementById("basic_perc").value;
  //  if(gross==''){gross=0;}
  //  if(basic_perc==''){basic_perc=0;}
  //  
  //  var totalbasic=gross*((basic_perc)/100);
  //  document.getElementById("basic_salary").value=totalbasic;
  //  
  //}

  function cal_pf_Reimbursement(str) {
    var basic = document.getElementById("basic_salary").value;
    //var basic_perc=document.getElementById("basic_perc").value;

    var totalbasic = basic * ((str) / 100);
    document.getElementById("pf_Reimbursement").value = totalbasic.toFixed(2);
  }

  function cal_medical_Reimbursement(str) {
    var basic = document.getElementById("basic_salary").value;
    //var basic_perc=document.getElementById("basic_perc").value;

    var totalbasic = basic * ((str) / 100);
    document.getElementById("medical_Reimbursement").value = totalbasic.toFixed(2);
  }

  function displaySalary(str) {
    if (str == 'Yes') {
      document.getElementById('overtime_salary').disabled = false;
    } else if (str == 'No') {
      document.getElementById('overtime_salary').disabled = true;
    }

  }

  function checkMode(str) {
    if (str == 'Cash') {
      document.getElementById("bank_name").disabled = true;
      document.getElementById("bank_account").disabled = true;
    } else if (str == 'Cheque') {
      document.getElementById("bank_name").disabled = false;
      document.getElementById("bank_account").disabled = false;
    }
  }

  function MekeEmpCode(str) {
    if (str.length = 0) {
      document.getElementById("emp_name").innerHTML = "";
    }
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("hid-EmployeeID").innerHTML = xmlhttp.responseText;
      }
    }
    var branch = document.getElementById("emp_site").value;
    xmlhttp.open("GET", "MakeEmpCode.php?EMPName=" + str + "&branch=" + branch, true);
    xmlhttp.send();
  }

  function GetSatateCountry(str) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var data = xmlhttp.responseText.split("__");
        document.getElementById("pre_state").value = data[0];
        document.getElementById("pre_country").value = data[1];
        document.getElementById("pre_state1").value = data[2];
        document.getElementById("pre_country1").value = data[3];
      }
    }
    xmlhttp.open("GET", "SateCountryName.php?CityId=" + str, true);
    xmlhttp.send();
  }

  function GetSatateCountry1(str) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var data = xmlhttp.responseText.split("__");
        document.getElementById("per_state").value = data[0];
        document.getElementById("per_country").value = data[1];
        document.getElementById("per_state1").value = data[2];
        document.getElementById("per_country1").value = data[3];
      }
    }
    xmlhttp.open("GET", "SateCountryName.php?CityId=" + str, true);
    xmlhttp.send();
  }
</script>
<script src="js/function-ajax.js" language="javascript"></script>

<style>
  .cap {
    text-transform: capitalize;
  }
</style>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
  <div class="tab_div">
    <h1>Employee Master</h1>
    <form method="post" name="empmasterfrm1" action="" enctype="multipart/form-data">

      <ul class="nav nav-tabs fl-lft">
        <li role="presentation" class="active"><a href="#empDetails" aria-controls="empDetails" role="tab" data-toggle="tab">Employee Details</a></li>
        <li role="presentation"><a href="#academicDetails" aria-controls="academicDetails" role="tab" data-toggle="tab">Academic Details</a></li>
        <li role="presentation"><a href="#addressDetails" aria-controls="addressDetails" role="tab" data-toggle="tab">Address Details</a></li>
        <li role="presentation"><a href="#salaryDetails" aria-controls="salaryDetails" role="tab" data-toggle="tab">Salary Details</a></li>
        <li role="presentation"><a href="#leaveDetails" aria-controls="leaveDetails" role="tab" data-toggle="tab">Leave Details</a></li>
        <li role="presentation"><a href="#uploads" aria-controls="uploads" role="tab" data-toggle="tab">Uploads</a></li>
      </ul>
      <div class="tab-content">
        <!--Employee Detail box-->
        <div role="tabpanel" class="tab-pane active" id="empDetails">
          <table width="100%" border="0" cellpadding="3" cellspacing="0">
            <tr>
              <td width="80%" valign="top">
                <table width="100%" border="0" cellpadding="3" cellspacing="0" style="border:0;">
                  <tr class="row1">
                    <td width="18%" align="right">Site</td>
                    <td width="30%"><select name="emp_site" id="emp_site" onchange="ShowDiv(this.value,'hid-staffdiv','Empshift.php');">
                        <option value="000">---Select---</option>
                        <?php
                        $site_sql = DB_query("Select loccode,locationname from locations", $db);
                        while ($site_row = DB_fetch_array($site_sql)) {
                        ?>
                          <option value="<?php echo $site_row['loccode']; ?>" <?php echo ($emp_site == $site_row['loccode'] ? 'selected' : '') ?>><?php echo $site_row['locationname']; ?></option>
                        <?php } ?>
                      </select></td>
                    <td width="18%" align="right">Employment Type</td>
                    <td><select name="employment_type" id="employment_type">
                        <option value="E" <?php echo ($employment_type == 'Employee' ? 'selected' : '') ?>>Employee</option>
                        <option value="D" <?php echo ($employment_type == 'Doctor' ? 'selected' : '') ?>>Doctor</option>
                        <option value="N" <?php echo ($employment_type == 'Nurse' ? 'selected' : '') ?>>Nurse</option>
                      </select></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Employee Shift</td>
                    <td>
                      <div id='hid-staffdiv'>
                        <select name="emp_shift" id="emp_shift">
                          <?php
                          if ($emp_site != '')
                            $emp_shift_sql = DB_query("Select * from shift_master where site='" . $emp_site . "'", $db);
                          while ($emp_shift_row = DB_fetch_array($emp_shift_sql)) {
                          ?>
                            <option value="<?php echo $emp_shift_row['id']; ?>" <?php echo ($emp_shift == $emp_shift_row['id'] ? 'selected' : '') ?>><?php echo $emp_shift_row['shift_for'] . '(' . $emp_shift_row['shift_category'] . ')-' . $emp_shift_row['shift_start'] . $emp_shift_row['start_AMPM'] . ' to ' . $emp_shift_row['shift_end'] . $emp_shift_row['end_AMPM']; ?></option>
                          <?php } ?>
                        </select>
                      </div>
                    </td>
                    <td align="right">Employee Name</td>
                    <td><input type="text" name="emp_name" id="emp_name" class="cap" value="<?php echo $emp_name; ?>" />
                      <input type="hidden" name="emp_name_old" id="emp_name_old" class="cap" style="width:150px;" value="<?php echo $emp_name; ?>" />
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Employee Code</td>
                    <td>
                      <div id="hid-EmployeeID"><input type="text" name="emp_code" id="emp_code" value="<?php if ($_REQUEST['action'] == 'edit') {
                                                                                                          echo $emp_code;
                                                                                                        } else {
                                                                                                          echo 'Generated';
                                                                                                        } ?>" /></div>
                    </td>
                    <td colspan="2"></td>
                  <tr class="row1">
                    <td align="right">Multi Site Attendance</td>
                    <td><input type="checkbox" name="multi_site_att" value="1" <?php if ($multi_site_att == 1) echo "checked"; ?> /></td>
                    <td colspan="2"></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Father's Name</td>
                    <td><input type="text" name="fh_name" id="fh_name" value="<?php echo $fh_name; ?>" /></td>
                    <td align="right">Nationality</td>
                    <td><input type="text" name="nationality" id="nationality" value="<?php echo $nationality; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Religion</td>
                    <td><input type="text" name="religion" id="religion" value="<?php echo $religion; ?>" /></td>
                    <td align="right">Gender</td>
                    <td><input type="radio" name="sex" id="sex" <?php echo ($sex == 'Male' ? 'checked' : ''); ?> value="Male" />Male
                      <input type="radio" name="sex" id="sex1" <?php echo ($sex == 'Female' ? 'checked' : ''); ?> value="Female" />Female
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Employee Status<font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><select name="emp_status">
                        <option value="0">Select</option>
                        <option value="A" <?php echo ($emp_status == 'A' ? 'selected' : ''); ?>>Active</option>
                        <option value="I" <?php echo ($emp_status == 'I' ? 'selected' : ''); ?>>Inactive</option>
                      </select></td>
                    <td align="right">Authorized<font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><select name="auth" style="width:98%">
                        <option value="no" <?php echo ($auth == 'no' ? 'selected' : ''); ?>>No</option>
                        <option value="yes" <?php echo ($auth == 'yes' ? 'selected' : ''); ?>>Yes</option>
                      </select></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Date of Birth</td>
                    <td><input name="dob" type="text" id="dob" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php if (isset($dob)) {
                                                                                                                        echo $dob;
                                                                                                                      } else {
                                                                                                                        echo date('d/m/Y');
                                                                                                                      } ?>" /></td>
                    <td align="right">Blood Group</td>
                    <td><input type="radio" name="bloodgroup" id="bloodgroup" <?php echo ($bloodgroup == 'A' ? 'checked' : ''); ?> value="A" />A
                      <input type="radio" name="bloodgroup" id="bloodgroup1" <?php echo ($bloodgroup == 'A+' ? 'checked' : ''); ?> value="A+" />A+
                      <input type="radio" name="bloodgroup" id="bloodgroup2" <?php echo ($bloodgroup == 'B' ? 'checked' : ''); ?> value="B" />B
                      <input type="radio" name="bloodgroup" id="bloodgroup3" <?php echo ($bloodgroup == 'B+' ? 'checked' : ''); ?> value="B+" />B+
                      <input type="radio" name="bloodgroup" id="bloodgroup4" <?php echo ($bloodgroup == 'AB' ? 'checked' : ''); ?> value="AB" />AB
                      <input type="radio" name="bloodgroup" id="bloodgroup5" <?php echo ($bloodgroup == 'AB+' ? 'checked' : ''); ?> value="AB+" />AB+
                      <input type="radio" name="bloodgroup" id="bloodgroup6" <?php echo ($bloodgroup == 'O' ? 'checked' : ''); ?> value="O" />O
                      <input type="radio" name="bloodgroup" id="bloodgroup7" <?php echo ($bloodgroup == 'O+' ? 'checked' : ''); ?> value="O+" />O+
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Date of Joining</td>
                    <td><input name="doj" type="text" id="doj" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php if (isset($doj)) {
                                                                                                                        echo $doj;
                                                                                                                      } else {
                                                                                                                        echo date('d/m/Y');
                                                                                                                      } ?>"></td>
                    <td align="right">Date of Leaving</td>
                    <td><input name="dol" id="dol" type="text" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php if (isset($dol)) {
                                                                                                                        echo $dol;
                                                                                                                      } else {
                                                                                                                        echo "";
                                                                                                                      } ?>"></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Department</td>
                    <td><select name="department" id="department" onchange="ShowDiv(this.value,'hid-desig','disp_designation.php')">
                        <option value="000">---Select---</option>
                        <?php $qdepart = DB_query("select dept_id, deptcode,deptname from deptmaster", $db);
                        while ($rsdepart = DB_fetch_array($qdepart)) {
                        ?>
                          <option value="<?php echo $rsdepart['dept_id']; ?>" <?php echo ($department == $rsdepart['dept_id'] ? 'selected' : '') ?>><?php echo $rsdepart['deptname']; ?></option>
                        <?php } ?>
                      </select></td>
                    <td align="right">Designation</td>
                    <td>
                      <div id='hid-desig'><select name="designation" id="designation">
                          <option value="000">---Select---</option>
                          <?php $qdesig = DB_query("select desig_id ,desigcode,designame from desigmaster", $db);
                          while ($rsdesig = DB_fetch_array($qdesig)) {
                          ?>
                            <option value="<?php echo $rsdesig['desig_id']; ?>" <?php echo ($designation == $rsdesig['desig_id'] ? 'selected' : '') ?>><?php echo $rsdesig['designame']; ?></option>
                          <?php } ?>
                        </select></div>
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Weekly Off</td>
                    <td>
                      <?php

                      $arr = array(1 => 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'); ?>
                      <select name="emp_weekly_off" id="emp_weekly_off">
                        <option value="000">---Select---</option>
                        <?php
                        for ($i = 1; $i <= count($arr); $i++) {
                          $p = '';
                          if ($i == $emp_weekly_off)
                            $p = 'selected';
                        ?>
                          <option value="<?php echo $i ?>" <?php echo $p ?>><?php echo $arr[$i]; ?></option>
                        <?php }
                        ?>
                      </select>
                    </td>
                    <td align="right">Marital Status</td>
                    <td><select name="marital_status" id="marital_status" onchange="check_marriage(this.value)">
                        <option value="000">---Select---</option>
                        <option value="Single" <?php echo ($marital_status == 'Single' ? 'selected' : ''); ?>>Single</option>
                        <option value="Married" <?php echo ($marital_status == 'Married' ? 'selected' : ''); ?>>Married</option>
                      </select></td>
                  </tr>
                  <?php
                  if ($marital_status == 'Single') {
                    $r = "disabled";
                  } else {
                    $r = '';
                  }
                  ?>
                  <tr class="row1">
                    <td align="right">Marriage Anniversary</td>
                    <td><input type="text" onClick="javascript:NewCal(this.id,'ddmmyyyy')" name="marriage" id="marriage" value="<?php if (isset($marriage)) {
                                                                                                                                  if ($marriage == '00/00/0000') {
                                                                                                                                    echo "N/A";
                                                                                                                                  } else echo $marriage;
                                                                                                                                } else {
                                                                                                                                  echo date('d/m/Y');
                                                                                                                                } ?>" <?php echo $r; ?> tabindex="18" /></td>
                    <td align="right">Wife's/Husband's Name</td>
                    <td><input type="text" name="wh_name" id="wh_name" value="<?php if ($wh_name == '') {
                                                                                echo "N/A";
                                                                              } else echo $wh_name; ?>" <?php echo $r; ?> /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Number of Children</td>
                    <td>Sons - <input type="text" name="sons" id="sons" style="width:20%;" value="<?php if ($sons == '0') {
                                                                                                    echo "N/A";
                                                                                                  } else echo $sons; ?>" <?php echo $r; ?> />&nbsp;&nbsp;&nbsp;Daughters -
                      <input type="text" name="daughters" id="daughters" style="width:20%;" value="<?php if ($daughters == '0') {
                                                                                                      echo "N/A";
                                                                                                    } else echo $daughters; ?>" <?php echo $r; ?> />
                    </td>
                    <td colspan="2"></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Grade</td>
                    <td><select name="grade" id="grade">
                        <?php $grade_sql = DB_query("Select * from emp_grade", $db);
                        while ($grade_result = DB_fetch_array($grade_sql)) {
                        ?>
                          <option value="<?php echo $grade_result['id']; ?>" <?php echo ($grade == $grade_result['id'] ? 'selected' : ''); ?>><?php echo $grade_result['grade_name']; ?></option>
                        <?php } ?>
                      </select></td>
                    <td colspan="2"></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Email Id (Personal)</td>
                    <td><input type="text" name="personalEmail" id="personalEmail" value="<?php echo $personalEmail; ?>" /></td>
                    <td align="right">Email Id (Official)</td>
                    <td><input type="text" name="offEmail" id="offEmail" value="<?php echo $offEmail; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Payment Mode</td>
                    <td>
                      <select name="payment_mode" id="payment_mode" onchange="checkMode(this.value)">
                        <option value="Cheque">Cheque</option>
                        <option value="Cash">Cash</option>
                      </select>
                    </td>
                    <td colspan="2"></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Bank Name</td>
                    <td><input type="text" name="bank_name" id="bank_name" value="<?php echo $bank_name; ?>" /></td>
                    <td align="right">Bank Account</td>
                    <td><input type="text" name="bank_account" id="bank_account" value="<?php echo $bank_account; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">PF No.</td>
                    <td><input type="text" name="PFno" id="PFno" value="<?php echo $PFno; ?>" /></td>
                    <td align="right">ESI No.</td>
                    <td><input type="text" name="ESIno" id="ESIno" value="<?php echo $ESIno; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Biomatric Code</td>
                    <td><input type="text" name="biomatric_id" id="biomatric_id" value="<?php if ($biomatric_id == '') {
                                                                                          echo "";
                                                                                        } else echo $biomatric_id; ?>" /></td>
                    <td colspan="2"></td>
                  </tr>
                </table>
              </td>
              <td valign="top" align="center" width="20%" style="padding:0;">
                <table width="100%" border="0" cellspacing="0" cellpadding="3" style="border:0;">
                  <tr>
                    <td style="text-align:center;">
                      <div class="field">
                        <label class="file-upload">
                          <span>Upload Image</span>
                          <input type="file" name="photo" id="photo" onchange="imageURL(this,'image1')" />
                        </label>
                      </div>
                      <input type="hidden" name="image_name" value="<?php echo $uploadimage; ?>" />
                    </td>
                  </tr>
                  <tr>
                    <td style="text-align:center;">
                      <div class="row1" style="width:50%; height:auto; float:left;">
                        <?php if ($new_name == '') {
                          if ($sex == 'M') { ?>
                            <img src="uploaded_images/default.png" width="100%" height="auto" id="image1" />
                          <?php } else { ?>
                            <img src="uploaded_images/default-girl.png" width="100%" height="auto" id="image1" />
                          <?php } ?>
                        <?php } else { ?>
                          <img src="uploaded_images/<?php echo $new_name; ?>" width="100%" height="auto" id="image1" />
                        <?php } ?>
                      </div>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </div>
        <!--end of Employee Detail box-->

        <!--Academic box-->
        <div role="tabpanel" class="tab-pane" id="academicDetails">
          <table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
            <tr class="row1">
              <td width="20%" align="right">10th Standard <font color="#FF0000" size="-1">*</font>
              </td>
              <td width="30%"><input type="checkbox" name="tenth_standard" id="tenth_standard" value="true" <?php if ($tenth_standard == 'true') { ?> checked="checked" <?php } ?> /></td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">10+2 Standard <font color="#FF0000" size="-1">*</font>
              </td>
              <td><input type="checkbox" name="tenthplus2_standard" id="tenthplus2_standard" value="true" <?php if ($tenthplus2_standard == 'true') { ?> checked="checked" <?php } ?> /></td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Basic/Graduation <font color="#FF0000" size="-1">*</font>
              </td>
              <td>
                <select name="bachelor" id="bachelor" tabindex="30">
                  <option value="">Select</option>
                  <option value="Not Pursuing Graduation" <?php if ($bachelor == "Not Pursuing Graduation") { ?> selected="selected" ; <?php } ?>>Not Pursuing Graduation</option>
                  <option value="B.A" <?php if ($bachelor == "B.A") { ?> selected="selected" ; <?php } ?>>B.A</option>
                  <option value="B.Arch" <?php if ($bachelor == "B.Arch") { ?> selected="selected" ; <?php } ?>>B.Arch</option>
                  <option value="BCA" <?php if ($bachelor == "BCA") { ?> selected="selected" ; <?php } ?>>BCA</option>
                  <option value="B.B.A" <?php if ($bachelor == "B.B.A") { ?> selected="selected" ; <?php } ?>>B.B.A</option>
                  <option value="B.Com" <?php if ($bachelor == "B.Com") { ?> selected="selected" ; <?php } ?>>B.Com</option>
                  <option value="B.Ed" <?php if ($bachelor == "B.Ed") { ?> selected="selected" ; <?php } ?>>B.Ed</option>
                  <option value="BDS" <?php if ($bachelor == "BDS") { ?> selected="selected" ; <?php } ?>>BDS</option>
                  <option value="BHM" <?php if ($bachelor == "BHM") { ?> selected="selected" ; <?php } ?>>BHM</option>
                  <option value="B.Pharma" <?php if ($bachelorr == "B.Pharma") { ?> selected="selected" ; <?php } ?>>B.Pharma</option>
                  <option value="B.Sc" <?php if ($bachelor == "B.Sc") { ?> selected="selected" ; <?php } ?>>B.Sc</option>
                  <option value="B.Tech/B.E" <?php if ($bachelor == "B.Tech/B.E") { ?> selected="selected" ; <?php } ?>>B.Tech/B.E.</option>
                  <option value="LLB" <?php if ($bachelor == "LLB") { ?> selected="selected" ; <?php } ?>>LLB</option>
                  <option value="MBBS" <?php if ($bachelor == "MBBS") { ?> selected="selected" ; <?php } ?>>MBBS</option>
                  <option value="Diploma" <?php if ($bachelor == "Diploma") { ?> selected="selected" ; <?php } ?>>Diploma</option>
                  <option value="BVSC" <?php if ($bachelor == "BVSC") { ?> selected="selected" ; <?php } ?>>BVSC</option>
                  <option value="Other" <?php if ($bachelor == "Other") { ?> selected="selected" ; <?php } ?>>Other</option>
                </select>
              </td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Post Graduation</td>
              <td>
                <select id="pgcourse" name="pgcourse" tabindex="31">
                  <option value="">Select</option>
                  <option value="CA" <?php if ($master == "CA") { ?> selected="selected" ; <?php } ?>>CA</option>
                  <option value="CS" <?php if ($master == "CS") { ?> selected="selected" ; <?php } ?>>CS</option>
                  <option value="ICWA" <?php if ($master == "ICWA") { ?> selected="selected" ; <?php } ?>>ICWA</option>
                  <option value="Integrated PG" <?php if ($master == "Integrated PG") { ?> selected="selected" ; <?php } ?>>Integrated PG</option>
                  <option value="LLM" <?php if ($master == "LLM") { ?> selected="selected" ; <?php } ?>>LLM</option>
                  <option value="M.A" <?php if ($master == "M.A") { ?> selected="selected" ; <?php } ?>>M.A</option>
                  <option value="M.Arch" <?php if ($master == "M.Arch") { ?> selected="selected" ; <?php } ?>>M.Arch</option>
                  <option value="M.Com" <?php if ($master == "M.Com") { ?> selected="selected" ; <?php } ?>>M.Com</option>
                  <option value="M.Ed" <?php if ($master == "M.Ed") { ?> selected="selected" ; <?php } ?>>M.Ed</option>
                  <option value="M.Pharma" <?php if ($master == "M.Pharma") { ?> selected="selected" ; <?php } ?>>M.Pharma</option>
                  <option value="M.Sc" <?php if ($master == "M.Sc") { ?> selected="selected" ; <?php } ?>>M.Sc</option>
                  <option value="M.Tech" <?php if ($master == "M.Tech") { ?> selected="selected" ; <?php } ?>>M.Tech</option>
                  <option value="MBA/PGDM" <?php if ($master == "MBA/PGDM") { ?> selected="selected" ; <?php } ?>>MBA/PGDM</option>
                  <option value="MCA" <?php if ($master == "MCA") { ?> selected="selected" ; <?php } ?>>MCA</option>
                  <option value="MS" <?php if ($master == "MS") { ?> selected="selected" ; <?php } ?>>MS</option>
                  <option value="PG Diploma" <?php if ($master == "PG Diploma") { ?> selected="selected" ; <?php } ?>>PG Diploma</option>
                  <option value="MVSC" <?php if ($master == "MVSC") { ?> selected="selected" ; <?php } ?>>MVSC</option>
                  <option value="MCM" <?php if ($master == "MCM") { ?> selected="selected" ; <?php } ?>>MCM</option>
                  <option value="Other" <?php if ($master == "Other") { ?> selected="selected" ; <?php } ?>>Other</option>
                </select>
              </td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Doctorate/Phd</td>
              <td>
                <select id="othercourse" name="othercourse" tabindex="32">
                  <option value="">Select</option>
                  <option value="Ph.D/Doctorate" <?php if ($other_master == "Ph.D/Doctorate") { ?>selected="selected" ; <?php } ?>>Ph.D/Doctorate</option>
                  <option value="MPHIL" <?php if ($other_master == "MPHIL") { ?>selected="selected" ; <?php } ?>>MPHIL</option>
                  <option value="Other" <?php if ($other_master == "Other") { ?>selected="selected" ; <?php } ?>>Other</option>
                </select>
              </td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Certification Course 1</td>
              <td><input type="text" name="course1" id="course1" value="<?php echo $course1; ?>" /></td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Certification Course 2</td>
              <td><input type="text" name="course2" id="course2" value="<?php echo $course2; ?>" /></td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">Certification Course 3</td>
              <td><input type="text" name="course3" id="course3" value="<?php echo $course3; ?>" /></td>
              <td></td>
            </tr>
          </table>
        </div>
        <!--end of Academic box-->

        <!--Address box-->
        <div role="tabpanel" class="tab-pane" id="addressDetails">
          <table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
            <tr>
              <td colspan="2"><input type="checkbox" name="copy_add" id="copy_add" onclick="addressInfo();" /> <strong>(Check if same as Present Address)</strong></td>
            </tr>
            <tr>
              <td width="50%" valign="top">
                <h3>Present Address</h3>
                <table width="100%" border="0" cellpadding="3" cellspacing="0">
                  <tr class="row1">
                    <td width="30%" align="right" valign="top" rowspan="3">Address <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="pre_address1" type="text" id="pre_add1" value="<?php echo $pre_address1; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td><input name="pre_address2" type="text" id="pre_add2" value="<?php echo $pre_address2; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td><input name="pre_address3" type="text" id="pre_add3" value="<?php echo $pre_address3; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">City <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td>
                      <select name="pre_city" id="pre_city" onchange="GetSatateCountry(this.value)">
                        <option value="">Select</option>
                        <?php
                        $city_sql = DB_query("select * from city_master order by city ASC", $db);
                        while ($city_row = DB_fetch_array($city_sql)) { ?>
                          <option value="<?php echo $city_row['id']; ?>" <?php echo ($pre_city == $city_row['id'] ? 'selected' : ''); ?>><?php echo $city_row['city']; ?></option>
                        <?php } ?>
                      </select>
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">State <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input type="hidden" name="pre_state" id="pre_state" value="<?php $pre_state; ?>" />
                      <input type="text" name="pre_state1" id="pre_state1" value="<?php echo $s->GetFieldValue('state_master', "id='" . $pre_state . "'", 'state'); ?>" />
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Country <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input type="hidden" name="pre_country" id="pre_country" value="<?php $pre_country; ?>" />
                      <input type="text" name="pre_country1" id="pre_country1" value="<?php echo $s->GetFieldValue('country_master', "id='" . $pre_country . "'", 'country'); ?>" />
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Pin Code <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="pre_pincode" type="text" id="pre_pincode" value="<?php echo $pre_pincode; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Mobile <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="pre_mobile" type="text" id="pre_mobile" value="<?php echo $pre_mobile; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Phone</td>
                    <td><input name="pre_phone" type="text" id="pre_phone" value="<?php echo $pre_phone; ?>" /></td>
                  </tr>
                </table>
              </td>
              <td valign="top">
                <h3>Permanent Address</h3>
                <table width="100%" border="0" cellpadding="3" cellspacing="0">
                  <tr class="row1">
                    <td width="30%" valign="top" align="right" rowspan="3">Address <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="per_address1" type="text" id="per_add1" value="<?php echo $per_address1; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td><input name="per_address2" type="text" id="per_add2" value="<?php echo $per_address2; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td><input name="per_address3" type="text" id="per_add3" value="<?php echo $per_address3; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">City <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td>
                      <select name="per_city" id="per_city" onchange="GetSatateCountry1(this.value)">
                        <option value="">Select</option>
                        <?php
                        $city_sql = DB_query("select * from city_master order by city ASC", $db);
                        while ($city_row = DB_fetch_array($city_sql)) { ?>
                          <option value="<?php echo $city_row['id']; ?>" <?php echo ($per_city == $city_row['id'] ? 'selected' : ''); ?>><?php echo $city_row['city']; ?></option>
                        <?php } ?>
                      </select>
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">State <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input type="hidden" name="per_state" id="per_state" value="<?php echo $per_state; ?>" />
                      <input type="text" name="per_state1" id="per_state1" value="<?php echo $s->GetFieldValue('state_master', "id='" . $per_state . "'", 'state'); ?>" />
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Country <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input type="hidden" name="per_country" id="per_country" value="<?php echo $per_country; ?>" />
                      <input type="text" name="per_country1" id="per_country1" value="<?php echo $s->GetFieldValue('country_master', "id='" . $per_country . "'", 'country'); ?>" />
                    </td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Pin Code <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="per_pincode" type="text" id="per_pincode" value="<?php echo $per_pincode; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Mobile <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="per_mobile" type="text" id="per_mobile" value="<?php echo $per_mobile; ?>" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Phone</td>
                    <td><input name="per_phone" type="text" id="per_phone" value="<?php echo $per_phone; ?>" /></td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </div>
        <!--end of Address box-->

        <!--Salary box-->
        <div role="tabpanel" class="tab-pane" id="salaryDetails">
          <table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
            <tr>
              <td>Monthly CTC <font color="#FF0000" size="-1">*</font><input name="gross" type="text" id="gross" value="<?php if (isset($gross)) echo $gross;
                                                                                                                        else echo $_REQUEST['gross']; ?>" style="width:50%;"></td>
              <td></td>
            </tr>
            <tr>
              <td width="50%" valign="top">
                <h3>Allowances Part (A)</h3><input type="hidden" name="prefix1" id="prefix1" value="A" />
                <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
                  <tr>
                    <th align="center">DESCRIPTION</th>
                    <th width="34%" align="center">%</th>
                    <th width="34%" align="center">VALUE</th>
                  </tr>
                  <tr>
                    <td align="right">BASIC</td>
                    <td><input type="text" name="basic_perc" id="basic_perc" value="<?php echo $basic_perc; ?>" size="5" tabindex="47" /></td>
                    <td><input type="text" name="basic_salary" id="basic_salary" value="<?php echo trim($basic_salary); ?>" size="10" class="number" onfocus="calculate_basic()" /></td>
                  </tr>
                  <?php
                  $all_sql = DB_query("Select * from allowmaster", $db);
                  $i = 1;
                  while ($all_row = DB_fetch_array($all_sql)) {
                  ?>
                    <tr>
                      <td align="right"><?php echo $all_row['allowname']; ?>
                        <input type="hidden" name="allow_code[<?php echo $i; ?>]" id="allow_code_<?php echo $i; ?>" value="<?php echo $all_row['allowcode']; ?>" />
                        <input type="hidden" name="allid[<?php echo $i; ?>]" id="allid_<?php echo $i; ?>" value="<?php echo $all_row['id']; ?>" />
                      </td>
                      <td><input name="aperc[<?php echo $i; ?>]" type="text" id="aperc_<?php echo $i; ?>" value="<?php echo $aperc[$i]; ?>" size="5" tabindex="48+<?php echo (2 * $i); ?>" onkeyup="cal_allvalue(this.value,<?php echo $i; ?>)" onblur="cal_allvalue(this.value,<?php echo $i; ?>);" /></td>
                      <td><input name="allow[<?php echo $i; ?>]" type="text" id="allow_<?php echo $i; ?>" value="<?php echo $allow[$i]; ?>" size="10" class="number" tabindex="48+<?php echo $i; ?>" /></td>
                      <!--onkeyup="reversecal_allvalue(this.value,<?php //echo $i; 
                                                                  ?>)"-->
                    </tr>
                  <?php $i++;
                  } ?>
                  <input type="hidden" name="ctr" id="ctr" value="<?php echo $i; ?>" />
                  <tr>
                    <td align="right">Special Allowance</td>
                    <td><input name="spc_allow" type="text" id="spc_allow" value="<?php echo $spc_allow; ?>" size="5" tabindex="48+<?php echo (2 * $i); ?>" /></td>
                    <td><input type="text" name="special_allow" id="special_allow" value="<?php echo $special_allow; ?>" size="10" class="number" tabindex="48+<?php echo $i; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right">Gross Salary</td>
                    <td colspan="2"><input name="allow_tot" type="text" id="allow_tot" value="<?php echo $allow_tot; ?>" size="15" onfocus="cal_alltot();cal_esi(this.value);data_str(this.value);" readonly="true" tabindex="53" /></td>
                  </tr>
                  <tr>
                    <td style="text-align:left;" colspan="3">
                      <h3>Allowances Part (B)</h3>
                    </td>
                  </tr>
                  <tr>
                    <td align="right">LTA</td>
                    <td><input type="text" name="ltaper" id="ltaper" onblur="calltaAll(this.value)" size="5" value="<?php echo $LTA_allow_Per; ?>" /></td>
                    <td><input type="text" name="lta" id="lta" size="10" value="<?php echo $LTA_allow_Val; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right">LWF</td>
                    <td><input type="text" name="LWFper" id="LWFper" onblur="calLWFAll(this.value)" size="5" value="<?php echo $LWF_allow_Per; ?>" /></td>
                    <td><input type="text" name="LWF" id="LWF" size="10" value="<?php echo $LWF_allow_Val; ?>" onfocus="calagainspecial()" /></td>
                  </tr>
                  <tr>
                    <td align="right">ESI(Employer)</td>
                    <td><input type="text" name="ESI_employer" id="ESIemployer" value="<?php echo $esi_per; ?>" onkeyup="calculate_esi(this.value);"
                        onblur="calculate_esi(this.value);" readonly="" /></td>
                    <td><input type="text" name="ESI_employer_value" id="esimployervalue" size="10" value="<?php echo $esi_value; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right">Monthly CTC</td>
                    <td colspan="2"><input type="text" name="monthelyctc1" id="monthelyctc1" onfocus="calmothellysal()" size="15" value="<?php echo $gross; ?>" /></td>
                  </tr>
                </table>
              </td>
              <td valign="top">
                <h3>DEDUCTION(D)</h3><input type="hidden" name="prefix2" id="prefix2" value="D" />
                <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
                  <tr>
                    <th align="center">DESCRIPTION</th>
                    <th width="34%" align="center">%</th>
                    <th width="34%" align="center">VALUE</th>
                  </tr>
                  <?php
                  $ded_sql = DB_query("Select * from deduction_master", $db);
                  $j = 1;
                  while ($ded_row = DB_fetch_array($ded_sql)) {
                  ?>
                    <tr>
                      <td align="right"><?php echo $ded_row['name']; ?> <input name="empdedtype[<?php echo $j; ?>]" id="empdedtype_<?php echo $j; ?>" type="hidden" value="<?php echo $ded_row['code']; ?>" />
                        <input type="hidden" name="ded_code[<?php echo $j; ?>]" id="ded_code_<?php echo $j; ?>" value="<?php echo $ded_row['code']; ?>" />
                        <input type="hidden" name="dedid[<?php echo $j; ?>]" id="dedid_<?php echo $j; ?>" value="<?php echo $ded_row['id']; ?>" />
                      </td>
                      <?php if ($ded_row['code'] != 'Coupon') { ?>
                        <td><input name="dperc[<?php echo $j; ?>]" type="text" id="dperc_<?php echo $j; ?>" value="<?php echo $dperc[$j]; ?>" size="5" onkeyup="cal_dedvalue(this.value,<?php echo $j; ?>)" class="number" tabindex="54+<?php echo (2 * $j); ?>" /></td> <?php } ?>
                      <td><input name="deduction[<?php echo $j; ?>]" type="text" id="deduction_<?php echo $j; ?>" value="<?php echo $deduction[$j]; ?>" size="10" class="number" tabindex="54+<?php echo $j; ?>" /></td>
                    </tr>
                  <?php $j++;
                  } ?>
                  <input type="hidden" name="dctr" id="dctr" value="<?php echo $j; ?>" />
                  <tr>
                    <td align="right">TOTAL DEDUCTION</td>
                    <td colspan="2"><input name="deduct_tot" type="text" id="deduct_tot" value="<?php echo $deduct_tot; ?>" size="15" onfocus="cal_dedtot()" readonly="true" tabindex="56" /></td>
                  </tr>
                </table>
                <br>
                <table width="100%" border="0" cellpadding="3" cellspacing="0" class="thborder">
                  <tr>
                    <td align="right">OT Applicable</td>
                    <td colspan="3"><input type="checkbox" name="otapplicable" value="Y" <?php if ($otapplicable == 'Y') { ?> checked="checked" <?php } ?> onclick="showapplicabe();" id="otapplicable" /></td>
                  </tr>
                  <tr>
                    <td align="right">Over time Hrs</td>
                    <td colspan="3"><select name="over_time" id="over_time">
                        <option value="0">Select</option>
                        <?php foreach ($othrs as $key => $value) {
                          $st = '';
                          if ($key == $over_time)
                            $st = "selected";
                        ?>
                          <option value="<?php echo $key; ?>" <?php echo $st; ?>><?php echo $value; ?></option>
                        <?php } ?>
                      </select></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Single</td>
                    <td width="24%"><input type="radio" name="ottype" id="ottype" value="S" <?php if ($ottype == 'S') { ?> checked="checked" <?php } ?> /></td>
                    <td width="20%" align="right">Double</td>
                    <td width="24%"><input type="radio" name="ottype" value="D" id="ottype1" <?php if ($ottype == 'D') { ?> checked="checked" <?php } ?> /></td>
                  </tr>
                </table>
              </td>
            </tr>

            <tr>
              <td colspan="2">
                <table width="100%" border="0" cellpadding="3" cellspacing="0" align="left">
                  <tr class="row1">
                    <td width="12%" align="right">Salary Effective From</td>
                    <td width="35%"><input name="eff_sal_date" type="text" onClick="javascript:NewCal(this.id,'ddmmyyyy')" id="eff_sal_date" value="<?php if (isset($eff_sal_date)) {
                                                                                                                                                      echo $eff_sal_date;
                                                                                                                                                    } else echo date('d/m/Y'); ?>" /></td>
                    <td width="20%" align="right">Gross Salary <font color="#FF0000" size="-1">*</font>
                    </td>
                    <td><input name="gross_sal" type="text" id="gross_sal" value="<?php echo $gross_sal; ?>" onfocus="cal_gross()" readonly="true" /></td>
                  </tr>
                  <tr class="row1">
                    <td align="right">Net Salary (Gross-D)</td>
                    <td><input name="net_sal" type="text" id="net_sal" value="<?php echo $net_sal; ?>" onfocus="cal_net()" readonly="true" /></td>
                    <td></td>
                    <td></td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </div>
        <!--end of Salary box-->

        <!--Leave box-->
        <div role="tabpanel" class="tab-pane" id="leaveDetails">
          <h3>Leave Details</h3>
          <table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
            <tr class="row1">
              <td width="20%" align="right">Effective Date</td>
              <td width="20%"><input type="text" name="leave_eff_date" onClick="javascript:NewCal(this.id,'ddmmyyyy')" value="<?php if (isset($leave_eff_date)) {
                                                                                                                                echo $leave_eff_date;
                                                                                                                              } else {
                                                                                                                                echo date('d/m/Y');
                                                                                                                              } ?>" tabindex="66" style="width:48%;" /></td>
              <td></td>
            </tr>
            <tr class="row1">
              <td align="right">
                <h3>Leave Type</h3>
              </td>
              <td>
                <h3>Number of Days</h3>
              </td>
              <td></td>
            </tr>
            <?php
            $leave_sql = "Select * from leavemaster";
            $leave_res = DB_query($leave_sql, $db);
            $num = DB_num_rows($leave_res);
            $i = 0;
            while ($leave_row = DB_fetch_array($leave_res)) {
              $leave_day = $s->GetFieldValue('emp_leave', "emp_id='" . $_REQUEST['id'] . "' and leave_type='" . $leave_row['id'] . "'", 'leave_days');
            ?>
              <tr class="row1">
                <td align="right"><input name="leave_type[<?php echo $i; ?>]" id="leave_type_<?php echo $i; ?>" type="hidden" value="<?php echo $leave_row['id']; ?> " />
                  <?php echo $leave_row['leavename']; ?>
                </td>
                <td><input name="leave_days[<?php echo $i; ?>]" type="text" id="leave_days_<?php echo $i; ?>" value="<?php echo  $leave_day; ?>" size="10" tabindex="67" /></td>
                <td></td>
              </tr>
            <?php $i++;
            } ?>
            <input type="hidden" name="cnt" id="cnt" value="<?php echo $i; ?>" />

            <?php
            if (isset($_REQUEST['id']) && $_REQUEST['action'] == 'edit') {
              $GetLMonthRecord = "Select count(*) AS rowcount from weekly_off_emp where emp_id='" . $_REQUEST['id'] . "'";
              $ResultLMonthData = DB_query($GetLMonthRecord, $db);
              $row_wo = DB_fetch_array($ResultLMonthData);
              if ($row_wo['rowcount'] < 2) {
            ?>
                <tr class="row1">
                  <td align="right">Weekly Off</td>
                  <td><input type="text" name="weekly_off" id="weekly_off" value="<?php echo $pending_wo; ?>" tabindex="68" /></td>
                  <td></td>
                </tr>
              <?php }
            } else { ?>
              <tr class="row1">
                <td width="12%" align="right">Weekly Off</td>
                <td><input type="text" name="weekly_off" id="weekly_off" value="" tabindex="68" /></td>
                <td></td>
              </tr>
            <?php } ?>
          </table>
        </div>
        <!--end of Leave box-->
        <!--Uploads box-->
        <div role="tabpanel" class="tab-pane" id="uploads">
          <table width="100%" border="0" cellpadding="3" cellspacing="0">
            <tr>
              <td colspan="3">
                <input type="button" onclick="addRow('dataTable')" class="search" value="Add More" />
                <input type="button" onclick="deleteRow('dataTable')" class="search" value="Delete Row" />
              </td>
            </tr>
            <tbody id="dataTable">
              <tr class="row1">
                <td width="5%"><input type="checkbox" name="chk" /></td>
                <td width="12%">Upload Document</td>
                <td><input type="file" name="docmnt[]" id="docmnt" value="" /></td>
              </tr>
            </tbody>
            <input type="hidden" id="hiditemcount" />
            <input type="hidden" name="docmnt1" id="docmnt1" value="<?php echo $document; ?>" />
            <?php
            if ($document != '') {
              $img_url = explode(",", $document);
              for ($im = 0; $im < count($img_url); $im++) {
                $Type = explode(".", $img_url[$im]);

                if ($Type[1] == 'doc') {
                  $DocImg = 'uploaded_docs/Default-wordpad.jpg';
                }
                if ($Type[1] == 'pdf') {
                  $DocImg = 'uploaded_docs/default-PDF.gif';
                }
                if ($Type[1] == 'jpg' || $Type[1] == 'png' || $Type[1] == 'gif') {
                  $DocImg = 'uploaded_docs/' . $img_url[$im];
                }


            ?>
                <tr class="row1">
                  <td><input type="checkbox" name="chk1" /></td>
                  <td><?php echo $img_url[$im]; ?></td>
                  <td><a href="uploaded_docs/<?php echo $img_url[$im]; ?>" target="_blank"><img src="<?php echo $DocImg; ?>" height="30" width="30" /></a></td>
                </tr>
            <?php }
            } ?>
          </table>
        </div>
      </div>

    </form>

  </div>
</div>
<script type="text/javascript">
  Element.cleanWhitespace('content');
  init();
</script>

<script>
  function AddPgElements() {
    document.getElementById("PG_LAYER").style.display = 'block';
    document.getElementById("pgel").style.display = 'none';

  }

  function AddPpgElements() {
    document.getElementById("doctor").style.display = 'block';
    document.getElementById("add_ppg").style.display = 'none';

  }

  function AddDipElements1() {
    document.getElementById("doctor1").style.display = 'block';
    document.getElementById("id_addCertAnc1").style.display = 'none';

  }

  function AddDipElements2() {
    document.getElementById("doctor2").style.display = 'block';
    document.getElementById("id_addCertAnc2").style.display = 'none';

  }

  function AddDipElements3() {
    document.getElementById("doctor3").style.display = 'block';
    document.getElementById("id_addCertAnc3").style.display = 'none';

  }


  function imageURL(input, i) {

    if (input.files && input.files[0]) {

      var reader = new FileReader();
      reader.onload = function(e) {
        document.getElementById(i).src = e.target.result;

      }
      reader.readAsDataURL(input.files[0]);
    }
  }

  function addRow(tableID) {
    if (document)
      var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    document.getElementById("hiditemcount").value = rowCount;
    var colCount = table.rows[0].cells.length;
    for (var i = 0; i < colCount; i++) {

      var newcell = row.insertCell(i);
      row.className = 'row1';
      //newcell.style.background='#e7e7e7';
      newcell.className = 'tabledata1';
      newcell.innerHTML = table.rows[0].cells[i].innerHTML;
      switch (newcell.childNodes[0].type) {
        case "text":
          newcell.childNodes[0].value = "";
          var nod_id = newcell.childNodes[0].id;
          newcell.childNodes[0].id = newcell.childNodes[0].id + '_' + rowCount;
          break;
        case "hidden":
          newcell.childNodes[0].value = "";
          var nod_id_hidden = newcell.childNodes[0].id;
          newcell.childNodes[0].id = newcell.childNodes[0].id + '_' + rowCount;
          break;
        case "button":
          var nod_id = newcell.childNodes[0].id;
          newcell.childNodes[0].id = newcell.childNodes[0].id + '_' + rowCount;
          break;
        case "checkbox":
          newcell.childNodes[0].checked = false;
          var nod_id_chk = newcell.childNodes[0].id;
          newcell.childNodes[0].id = newcell.childNodes[0].id + '_' + rowCount;
          break;
        case "select-one":
          newcell.childNodes[0].selectedIndex = 0;
          var nod_id = newcell.childNodes[0].id;
          newcell.childNodes[0].id = newcell.childNodes[0].id + '_' + rowCount;
          break;
      }
      //document.getElementById("stock_perunit_"+rowCount).value=1;
    }
    document.getElementById("stock_perunit_" + rowCount).value = '1';
  }


  function validate() {
    if (document.getElementById('photo').value != '') {
      var fup = document.getElementById('photo');
      var fileName = fup.value;
      var ext = fileName.substring(fileName.lastIndexOf('.') + 1);

      if (ext == "gif" || ext == "GIF" || ext == "GIF" || ext == "jpg" || ext == "JPEG" || ext == "PNG" || ext == "png") {
        return true;
      } else {
        alert("Upload GIF/PNG/JPEG  Images only");
        return false;
      }
    }
    if (document.getElementById("emp_site").value == '000') {
      alert("Please Select The Site First !");
      document.getElementById("emp_site").focus();
      return false;
    }
    if (document.getElementById("emp_name").value == '') {
      alert("Please Fill The Employee Name First !");
      document.getElementById("emp_name").focus();
      return false;
    }
    if (document.getElementById("fh_name").value == '') {
      alert("Please Fill The Employee Father Name First !");
      document.getElementById("fh_name").focus();
      return false;
    }
    if (document.getElementById("nationality").value == '') {
      alert("Please Fill The Nationality First !");
      document.getElementById("nationality").focus();
      return false;
    }
    if (document.getElementById("religion").value == '') {
      alert("Please Fill The Religion First !");
      document.getElementById("religion").focus();
      return false;
    }

    var flag = 0;
    if (document.getElementById("sex").checked == true || document.getElementById("sex1").checked == true) {
      flag = 1;
    }
    if (flag == 0) {
      alert("Please Select Sex First !");
      return false;
    }
    if (document.getElementById("dob").value == '') {
      alert("Please Select The Date Of Birth First !");
      document.getElementById("dob").focus();
      return false;
    }

    var flag1 = 0;

    if (document.getElementById("bloodgroup").checked == true || document.getElementById("bloodgroup1").checked == true || document.getElementById("bloodgroup2").checked == true || document.getElementById("bloodgroup3").checked == true || document.getElementById("bloodgroup4").checked == true || document.getElementById("bloodgroup5").checked == true || document.getElementById("bloodgroup6").checked == true || document.getElementById("bloodgroup7").checked == true) {
      flag1 = 1;
    }
    if (flag1 == 0) {
      alert("Please Select Blood Group First !");
      return false;
    }

    if (document.getElementById("doj").value == '') {
      alert("Please Select The Date Of Joining First !");
      document.getElementById("doj").focus();
      return false;
    }

    if (document.getElementById("department").value == '000') {
      alert("Please Select The Department First !");
      document.getElementById("department").focus();
      return false;
    }
    if (document.getElementById("designation").value == '000') {
      alert("Please Select The Desgination First !");
      document.getElementById("designation").focus();
      return false;
    }



  }

  function showapplicabe() {
    if (document.getElementById("otapplicable").checked == true) {
      document.getElementById("over_time").disabled = false;
      document.getElementById("ottype").disabled = false;
      document.getElementById("ottype1").disabled = false;
    } else {
      document.getElementById("over_time").disabled = true;
      document.getElementById("ottype").disabled = true;
      document.getElementById("ottype1").disabled = true;
    }

  }
</script>