<?php 
$PageSecurity = 2;
$title = _('Employee Master') ;
include('includes/SQL_CommonFunctions.inc');
include ('cocoon_config.php');
include('includes/othrs.php');
date_default_timezone_set('Asia/calcutta');
$today=date('d/m/Y');
if(isset($_POST['Submit']))
{
	$dd=explode("/",$_REQUEST['dob']);
	if(strlen($dd[0])==1)
	{
		$dd[0]="0".$dd[0];
	}	
	if(strlen($dd[1])==1)
	{
		$dd[1]="0".$dd[1];
	}
	$dd1=$dd[2]."-".$dd[1]."-".$dd[0];

	$dob1= strtotime(date("Y-m-d",strtotime($dd1)));
    $current_date=strtotime(date('Y-m-d'));
    
    $datediff = $current_date - $dob1;
    $days = floor( $datediff / ( 3600 * 24 ) );

    if ($days >= 365) { // over a year
        $years = floor($days / 365);
        $days -= 365 * $years;
    }

    if ($days) {
        $months = floor( $days / 30 );
        if($months=='') $months=0;
        $days -= 30 * $months;
    }

    if ($days) {
        if($days=='') $days=0;
    }
    

    //$date1 = new DateTime($current_date);
    //$date2 = new DateTime($dob1);
    //$diff = $date1->diff($date2);

    //exit;
		
		//$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';
		//}
	
		
		$max_size='2000';
		$flag=0;
		function extension($filename)
		{
			$name_brk=explode('.',$filename);
			return  $name_brk[1];
		}
		
		$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_name=$FinempCode.'.'.$type;
			$path="uploaded_images/".$new_name;
			$file_copy=copy($tmp_name,$path);
			if(!$file_copy)
			{
				echo "Copy Unsuccessful";
				$flag=1;
			}
		}
		}

		$flag=0;
		
	    $qty=$_FILES['docmnt']['name'];
		
		for($i=0;$i<count($qty);$i++)
		{ 
		$name=$_FILES['docmnt']['name'][$i];
		$type=extension($name);
		
			if($type!='')
			{
			if($type!='pdf' && $type!='doc' && $type!='txt' && $type!='docx' && $type!='rtf' && $type!='jpeg'
			&& $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 $_FILES['photo']['size'];
				$new_name2[]=$FinempCode.'_'.$name;
				$path="uploaded_docs/".$new_name2[$i];
				$file_copy=move_uploaded_file($tmp_name,$path);
				if(!$file_copy)
				{
					echo "Copy Unsuccessful";
					$flag=1;
				}
			}
			$newname1=implode(",",$new_name2);
			}
		}

    //*****************************************************************************************************//
//echo "select Max(id) as id from employee_masters";
          $sql_cocoon=mysqli_query($link1, "select Max(id) as id from employee_masters");
          //$row_cocoon=mysql_fetch_array($sql_cocoon,$conn12);
            $row_cocoon=mysqli_fetch_array($sql_cocoon);
    //$row_cocoon=mysqli_fetch_assoc($sql_cocoon);
          $strFinal=$row_cocoon['id']+1;
          $empcode = str_pad($strFinal,6,"0",STR_PAD_LEFT);
  //********************************************************************************************************//

		$esi = $_REQUEST['ESI_employer_value'];
		$dataP['emp_site']=$_REQUEST['emp_site'];
		$dataP['employment_type']=$_REQUEST['employment_type'];
		$dataP['employee_type']=$_REQUEST['emp_shift'];
		$dataP['emp_code']=$empcode;
		$dataP['emp_name']=$_REQUEST['emp_name'];
		$dataP['fh_name']=$_REQUEST['fh_name'];
		$dataP['nationality']=$_REQUEST['nationality'];
		$dataP['religion']=$_REQUEST['religion'];
		$dataP['dob']=date("Y-m-d",strtotime($dd1));
		$dataP['bloodgroup']=$_REQUEST['bloodgroup'];
		$dataP['doj']=FormatDateForSQL($_REQUEST['doj']);
		$dataP['dol']=FormatDateForSQL($_REQUEST['dol']);
		$dataP['auth']=$_REQUEST['auth'];
		$dataP['status']=$_REQUEST['emp_status'];
		$dataP['department']=$_REQUEST['department'];
		$dataP['designation']=$_REQUEST['designation'];
		$dataP['emp_weekly_off']=$_REQUEST['emp_weekly_off'];
		$dataP['marital_status']=$_REQUEST['marital_status'];
		$dataP['marriage']=FormatDateForSQL($_REQUEST['marriage']);
		$dataP['wh_name']=$_REQUEST['wh_name'];
		$dataP['biomatric_id']=$_REQUEST['biomatric_id'];
		$dataP['sons']=$_REQUEST['sons'];
		$dataP['daughters']=$_REQUEST['daughters'];
		$dataP['sex']=$_REQUEST['sex'];
		$dataP['grade']=$_REQUEST['grade'];
		$dataP['personalEmail']=$_REQUEST['personalEmail'];
		$dataP['offEmail']=$_REQUEST['offEmail'];
		$dataP['PFno']=$_REQUEST['PFno'];
		$dataP['ESIno']=$_REQUEST['ESIno'];
		$dataP['bank_account']=$_REQUEST['bank_account'];
		$dataP['bank_name']=$_REQUEST['bank_name'];
		$dataP['payment_mode']=$_REQUEST['payment_mode'];
		$dataP['leave_eff_date']=FormatDateForSQL($_REQUEST['leave_eff_date']);
		$dataP['bachelor']=$_REQUEST['bachelor'];
		$dataP['course1']=$_REQUEST['course1'];
		$dataP['course2']=$_REQUEST['course2'];
		$dataP['course3']=$_REQUEST['course3'];
		$dataP['master']=$_REQUEST['pgcourse'];
		$dataP['other_master']=$_REQUEST['othercourse'];
		$dataP['basic_perc']=$_REQUEST['basic_perc'];
		$dataP['basic_salary']=$_REQUEST['basic_salary'];
		$dataP['pf_Reimbursement_per']=$_REQUEST['pf_Reimbursement_per'];
		$dataP['pf_Reimbursement']=$_REQUEST['pf_Reimbursement'];
		$dataP['medical_Reimbursement_per']=$_REQUEST['medical_Reimbursement_per'];
		$dataP['medical_Reimbursement']=$_REQUEST['medical_Reimbursement'];
		$dataP['allow_tot']=$_REQUEST['allow_tot'];
		$dataP['deduct_tot']=$_REQUEST['deduct_tot'];
		$dataP['gross_sal']=$_REQUEST['gross_sal'];
		$dataP['gross']=$_REQUEST['gross']+$esi;
	///////////....................................//////////////////
		$dataP['net_sal']=$_REQUEST['net_sal'];
		$dataP['eff_sal_date']=FormatDateForSQL($_REQUEST['eff_sal_date']);
		$dataP['pf_calculation']=$_REQUEST['pf_calculation'];
		$dataP['adv_amount']=$_REQUEST['adv_amount'];
		$dataP['adv_date']=FormatDateForSQL($_REQUEST['adv_date']);
		if($_REQUEST['otapplicable']!='')
		$otapplicable='Y';
		else
		$otapplicable='N';
		$datap['otapplicable']=$otapplicable;
		$dataP['ottype']=$_REQUEST['ottype'];
		
		$dataP['over_time']=$_REQUEST['over_time'];
		$dataP['overtime_salary']=$_REQUEST['overtime_salary'];
		$dataP['tenth_standard']=$_REQUEST['tenth_standard'];
		$dataP['tenthplus2_standard']=$_REQUEST['tenthplus2_standard'];
		$dataP['image']=$new_name;
		$dataP['document']=$newname1;
		$dataP['created_by']=$_SESSION['UserID'];
		$dataP['created_date']=FormatDateForSQL(date('d/m/Y'));
		$dataP['pending_wo']=$_REQUEST['weekly_off'];
		$dataP['CompanyId']=$_SESSION['ACGCompanyId'];
		$dataP['multi_site_att']=$_REQUEST['multi_site_att'];
		$dataP['staff_type']=$_REQUEST['staff_type'];
	//////////////////////////.....................................................//////////////////////			 
		
		//echo "<pre>";
		//print_r($dataP);
		//exit;
		$s->RecordInsert('empmaster',$dataP);

		$Lastemp_id = DB_Last_Insert_ID($db,'empmaster','id');

   //****************************  Inserting to Cocoon - Employee Master ************************************//
    
    $dept_id=$s->getField('deptmaster','id',$_REQUEST['department'],'dept_id');
    $desig_id=$s->getField('desigmaster','id',$_REQUEST['designation'],'desig_id');

   $data_cocoon['empid']                 =$empcode;
   $data_cocoon['current_date']          =date('Y-m-d H:i:s');
   $data_cocoon['emp_name']              =$_REQUEST['emp_name'];
   $data_cocoon['dob']                   =date("Y-m-d",strtotime($dd1));
   $data_cocoon['qualification']         =$_REQUEST['course1'];
   $data_cocoon['marital_status']        =$_REQUEST['marital_status'];
   $data_cocoon['a_year']                =$years;
   $data_cocoon['a_month']               =$months;
   $data_cocoon['a_day']                 =$days;
   $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']  =$dept_id;
   $data_cocoon['dept_code']             =$s->getField('deptmaster','dept_id ',$dept_id,'deptcode');
   $data_cocoon['dept_desc']             =$s->getField('deptmaster','dept_id ',$dept_id,'deptname');
   $data_cocoon['status']                =$_REQUEST['emp_status'];
   $data_cocoon['desigcode']             =$s->getField('desigmaster','desig_id',$desig_id,'desigcode');
   $data_cocoon['designation_id']        =$desig_id;
   $data_cocoon['description']           =$s->getField('desigmaster','desig_id',$desig_id,'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['biomatric_id']                   =$_REQUEST['biomatric_id'];
 //$data_cocoon['fax']                   =
 //$data_cocoon['pager']                 =
   $data_cocoon['created_date']          =date('y-m-d');
   $data_cocoon['auth']                  =$_REQUEST['auth'];
   $data_cocoon['nippon_emp_id']        =$Lastemp_id;
   $data_cocoon['locationname']        =trim($_REQUEST['emp_site']);


    $sql_insert_cocoon="Insert into 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++;
			}
	
	//echo "<br>*************INSERT***************************************************</br>"			;
	//echo $sql_insert_cocoon;exit;
	 

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

	$last_cocoon_insert_id=mysqli_insert_id($link1);

    if(!empty($last_cocoon_insert_id))
    {

    $inDocData = array('id' =>'',
									'employee_master_id' => $last_cocoon_insert_id,
									'empid' => $empcode,
									'date_from' => date("Y-m-d",strtotime($dd1)),
									'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'=>$dept_id,
									'dept_code'=>$s->getField('deptmaster','dept_id ',$dept_id,'deptcode'),
									'dept_desc'=>$s->getField('deptmaster','dept_id ',$dept_id,'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'],	
									'nippon_emp_id'=>$Lastemp_id,								
									'modified_by' => 0																	
							        );


        $sql_insert_cocoon_doctor="Insert into 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++;
			}

	$cocoon_query_doctor=mysqli_query($link1,$sql_insert_cocoon_doctor);
	//echo $sql_insert_cocoon_doctor;exit;
    }

  //***********************************************************************************************************//
				
		if($Lastemp_id!='')
		{
			$dataArr['emp_id']=$Lastemp_id;
			$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'];
			
			$s->RecordInsert('employee_address',$dataArr);

			$monthwo=date("n");
			$yearswo=date("Y");
			if($monthwo==01 || $monthwo==1)
			{
				$monthwo1=12;
				$yearwo1=$yearswo-1;
			}
			else
			{
				$monthwo1=$monthwo-1;
				$yearwo1=$yearswo;
			}				
				
			$dataWOff['emp_id']=$Lastemp_id;
			$dataWOff['year']=$yearwo1;
			$dataWOff['month']=$monthwo1;
			$dataWOff['pending_wo']=$_REQUEST['weekly_off'];
			
			$s->RecordInsert('weekly_off_emp',$dataWOff);
			
			for($k=1;$k<$_REQUEST['ctr'];$k++)
			{
				$dataEmpSal['emp_id']=$Lastemp_id;
				$dataEmpSal['allowance_deduction']=$_REQUEST['allid'][$k];
				$dataEmpSal['percentage']=$_REQUEST['aperc'][$k];
				$dataEmpSal['percentage_value']=$_REQUEST['allow'][$k];
				$dataEmpSal['all_ded_prefix']=$_REQUEST['prefix1'];
				$s->RecordInsert('emp_salary',$dataEmpSal);
			}
			
			$dataEmpSpeSal['emp_id']=$Lastemp_id;
			$dataEmpSpeSal['allowance_deduction']='100';
			$dataEmpSpeSal['percentage']='0.00';
			$dataEmpSpeSal['percentage_value']=$_REQUEST['special_allow'];
			$dataEmpSpeSal['all_ded_prefix']='A';
			$s->RecordInsert('emp_salary',$dataEmpSpeSal);
						
			$dataEmpSpeSal['emp_id']=$Lastemp_id;
			$dataEmpSpeSal['allowance_deduction']='101';
			$dataEmpSpeSal['percentage']=$_REQUEST['ltaper'];
			$dataEmpSpeSal['percentage_value']=$_REQUEST['lta'];
			$dataEmpSpeSal['all_ded_prefix']='A';
			$s->RecordInsert('emp_salary',$dataEmpSpeSal);
			
			$dataEmpSpeSal['emp_id']=$Lastemp_id;
			$dataEmpSpeSal['allowance_deduction']='102';
			$dataEmpSpeSal['percentage']=$_REQUEST['LWFper'];
			$dataEmpSpeSal['percentage_value']=$_REQUEST['LWF'];
			$dataEmpSpeSal['all_ded_prefix']='A';
			$s->RecordInsert('emp_salary',$dataEmpSpeSal);
			
//////////////////////////////////////////........ESI(Employer)..../////////////////////////////			
			$dataEmpSpeSal['emp_id']=$Lastemp_id;
			$dataEmpSpeSal['allowance_deduction']='103';
			$dataEmpSpeSal['percentage']=$_REQUEST['ESI_employer'];
			$dataEmpSpeSal['percentage_value']=$_REQUEST['ESI_employer_value'];
			$dataEmpSpeSal['all_ded_prefix']='A';
			$s->RecordInsert('emp_salary',$dataEmpSpeSal);
			
			for($K=1;$K<$_REQUEST['dctr'];$K++)
			{
				$dataEmpSalDed['emp_id']=$Lastemp_id; 
				$dataEmpSalDed['allowance_deduction']=$_REQUEST['dedid'][$K];
				$dataEmpSalDed['percentage']=$_REQUEST['dperc'][$K]; 
				$dataEmpSalDed['percentage_value']=$_REQUEST['deduction'][$K]; 
				$dataEmpSalDed['all_ded_prefix']=$_REQUEST['prefix2'];
				$s->RecordInsert('emp_salary',$dataEmpSalDed);
			}
			$cnt=$_REQUEST['cnt'];
			for($CR=0;$CR<$cnt;$CR++)
			{
				$leavetype=$s->getField('leavemaster','id',$_REQUEST['leave_type'][$CR],'leavecode');
				if($leavetype=='ML' && $_REQUEST['sex']=='Male'){ continue; }
			    else{				
				$dataLeave['emp_id']=$Lastemp_id;
				$dataLeave['leave_type']=$_REQUEST['leave_type'][$CR];
				$dataLeave['leave_days']=$_REQUEST['leave_days'][$CR];
				$s->RecordInsert('emp_leave',$dataLeave);}
			    
			   	
			}
		}

           for($cu=0;$cu<count($_REQUEST['allowance']);$cu++)
          {
            
           
				$dataallowance['emp_id']         =$_REQUEST['row_id'];
				$dataallowance['allowance_id']   =$_REQUEST['allowance'][$cu];
				$dataallowance['allowance_amt']  =$_REQUEST['allowanceamt'][$_REQUEST['allowance'][$cu]];
				$s->RecordInsert('emp_allowance_dtls',$dataallowance);
			


          }

$s->pageLocation("index.php?route=employee_list".$rurl);
}
?>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<link rel="stylesheet" href="css/new_mxerp.css">
<script type="text/javascript" src="js/function-ajax.js"></script>
<script>
function check_empcode(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 sha = xmlhttp.responseText;
		if(sha != "")
		{
		document.getElementById("empcode_exists").innerHTML=xmlhttp.responseText;
		document.getElementById("emp_code").innerHTML.value="";
		}
	  }
  }
	xmlhttp.open("GET","ajax_getempcode.php?empcode="+str,true);
	xmlhttp.send();	
}		
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=Math.round(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();
	
	}	
		}
		
}

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 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);	
}
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
			 
		}
	}	
</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]);
// }
</script>

<script language="javascript" type="text/javascript">

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


function cal_allvalue(str,j)
{
//alert(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 sha = document.getElementById("aperc_"+j).value;
	var basic=document.getElementById("basic_salary").value;
	var totvalue=Math.round((basic*str)/100);

	document.getElementById("allow_"+j).value=Math.round(totvalue);
	//document.getElementById("aperc_"+j).value=sha;
}

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


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


function cal_dedvalue(str,esi_id,j)
{
	
 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)
	{
		document.getElementById("esi_id").value='1.75';
		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=Math.round(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_state1').value = document.getElementById('pre_state1').value;
		document.getElementById('per_country1').value = document.getElementById('pre_country1').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_state1').value = '';
		document.getElementById('per_country1').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();
}




/************************CALCULATION OF GROSS SALARY****************************************************************/



function cal_alltot()
{
	var Basic_SAL=document.getElementById("basic_salary").value;
	var total_allowance=0;
	var count = document.getElementById("ctr").value;
	
	if(document.getElementById("special_applicable").checked==true)
	{        
              document.getElementById("special_allow").value=document.getElementById("special_allow_hidden").value;
			var sa = document.getElementById("special_allow").value;
			if(sa=='') { sa=0; }
    }
    else
    {
    	document.getElementById("special_allow").value=0.00;
    	document.getElementById("spc_allow").value=0.00;
    	var sa=0.00;

			if(sa=='') { sa=0; }
    }


	for(var j=1;j<count;j++)
	{
		
		   if(document.getElementById("allowapplicable_"+j))
		   {
		           if(document.getElementById("allowapplicable_"+j).checked==true)
		           {
		           	  
		                 document.getElementById("allow_"+j).value=document.getElementById("allowhidden_"+j).value;
		           }
		           else
		           {
		 
		           	 document.getElementById("allow_"+j).value=0;
		           }
           }

	   if(document.getElementById("allow_"+j).value!='')
		var allowance = document.getElementById("allow_"+j).value;
		else 
		allowance=0;
		total_allowance=parseFloat(total_allowance)+parseFloat(allowance);
	}
	//var pf_Reimbursement=document.getElementById("pf_Reimbursement").value;
	//var medical_Reimbursement=document.getElementById("medical_Reimbursement").value;
	//document.getElementById("allow_tot").value=(parseFloat(total_allowance)+parseFloat(Basic_SAL)+parseFloat(pf_Reimbursement)+parseFloat(medical_Reimbursement)).toFixed(2);

	
	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");
	}

	    var allow=document.getElementById("allow_tot").value;
	    var deduct_tot=document.getElementById("deduct_tot").value;
	    var net=parseFloat(allow)-parseFloat(deduct_tot);
	    document.getElementById("net_sal").value=parseFloat(net);

	 
}

/************************CALCULATION OF GROSS SALARY****************************************************************/


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=Math.round(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;
	alert(gsal);
	var deduct=document.getElementById("deduct_tot").value;
	if(gsal=='') { gsal=0; } if(deduct=='') { deduct=0; } 
	var net=parseFloat(gsal)-parseFloat(deduct);
	document.getElementById("net_sal").value=Math.round(net);
}








//function cal_dedvalue(str,j)
//{
//	// alert(str);
//	a=document.getElementById("empdedtype_"+j).value;
//	
//	var basic=document.getElementById("basic_salary").value;
//	//alert(a);
//	if( a!='PF')
//	{
//		var basic=document.getElementById("gross").value;
//		var totvalue=basic*((str)/100);
//		document.getElementById("deduction_"+j).value=totvalue.toFixed(2);
//	}
//	else
//	{
//	if(basic > 6501)
//	{
//		var basic=6500;
//		var totvalue=basic*((str)/100);
//		document.getElementById("deduction_"+j).value=totvalue.toFixed(2);
//	}
//	else
//	{
//		var basic=document.getElementById("basic_salary").value;
//		var totvalue=basic*((str)/100);
//		document.getElementById("deduction_"+j).value=totvalue.toFixed(2);
//	}
//	}	
//}


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 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=Math.round(totalbasic);
	
}
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=Math.round(totalbasic);
	
}

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="#bankDetails" aria-controls="bankDetails" role="tab" data-toggle="tab">Bank 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>
			<!--Employee Detail box-->
<div class="tab-content visits">
    <div role="tabpanel" class="tab-pane active" id="empDetails">
	<table width="99%" border="0" cellpadding="0" cellspacing="0" align="center">
	<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">Branch <font color="#FF0000" size="-1">*</font></td>
		  <td width="30%"><select name="emp_site" id="emp_site"  onchange="ShowDiv(this.value,'emp_shift','Empshift.php');">
		  <option value="000">---Select---</option>
		  <?php 
			$site_sql=DB_query("Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')",$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">Staff Type <font color="#FF0000" size="-1">*</font></td>
			<td><select name="employment_type" id="employment_type" >
				<option value="E"<?php echo($employment_type=='E'?'selected':'')?>>Employee</option>
				<option value="D"<?php echo($employment_type=='D'?'selected':'')?>>Doctor</option>
				<option value="N"<?php echo($employment_type=='N'?'selected':'')?>>Nurse</option>
			  </select>
			</td>
	  	</tr>
	    <tr class="row1">
			<td align="right">Employee Type <font color="#FF0000" size="-1">*</font></td>
			<td><select name="staff_type" id="staff_type" >
				<option value="R"<?php echo($staff_type=='R'?'selected':'')?>>Regular Employee</option>
				<option value="C"<?php echo($staff_type=='C'?'selected':'')?>>Contract Employee</option>
				<option value="P"<?php echo($staff_type=='P'?'selected':'')?>>Probation Employee</option>
			  </select>
			</td>
			<td align="right">Employee Shift <font color="#FF0000" size="-1">*</font></td>
			<td>
			 <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>
			</td>
	  	</tr>
	  	<tr class="row1">
			<td align="right">Employee Name <font color="#FF0000" size="-1">*</font></td>
			<td><input type="text" name="emp_name" id="emp_name" class="cap" /></td>
		   	<td align="right">Employee Code</td>
		   	<td><div id="hid-EmployeeID">
		   	<input type="text" name="emp_code" id="emp_code" readonly  value="Auto Generated"  onblur="check_empcode(this.value);"/><span id="empcode_exists" style="color:red;"></span></div></td>
		</tr>
		<tr class="row1">
		  	<td align="right">Multi Site Attendance</td>
		  	<td><input type="checkbox" name="multi_site_att" value="1"  /></td>
		  	<td colspan="2"></td>
		</tr>		
		<tr class="row1">
		  	<td align="right">Father's Name <font color="#FF0000" size="-1">*</font></td>
		  	<td><input type="text" name="fh_name" id="fh_name"  /></td>
		  	<td align="right">Nationality <font color="#FF0000" size="-1">*</font></td>
		  	<td><input type="text" name="nationality" id="nationality"  /></td>
		</tr>	
		<tr class="row1">
			<td align="right">Religion <font color="#FF0000" size="-1">*</font></td>
			<td><input type="text" name="religion" id="religion"  /></td>
		  	<td align="right">Gender <font color="#FF0000" size="-1">*</font></td>
		  	<td><input type="radio" name="sex" id="sex"  value="Male" />Male
		  	<input type="radio" name="sex" id="sex1" 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">Active</option>
             <option value="I">Inactive</option>
		  </select></td>
		  <td align="right">Authorized <font color="#FF0000" size="-1">*</font></td>
		  <td><select name="auth"> 	            
             <option value="no">No</option>
             <option value="yes">Yes</option>
		  </select></td>
		</tr>
		<tr class="row1">
			<td align="right">Date of Birth <font color="#FF0000" size="-1">*</font></td>
			<td><input name="dob" type="text" id="dob" class="datepicker"  class="datepicker" value="<?php if(isset($dob)){echo $dob;} else {echo date('d/m/Y');}?>"></td>
			<td align="right">Blood Group <font color="#FF0000" size="-1">*</font></td>
			<td><input type="radio" name="bloodgroup" id="bloodgroup"  value="A" />A
				<input type="radio" name="bloodgroup" id="bloodgroup1"  value="A+" />A+
				<input type="radio" name="bloodgroup" id="bloodgroup2"  value="B" />B
				<input type="radio" name="bloodgroup" id="bloodgroup3"  value="B+" />B+
				<input type="radio" name="bloodgroup" id="bloodgroup4"  value="AB" />AB
				<input type="radio" name="bloodgroup" id="bloodgroup5"  value="AB+" />AB+
				<input type="radio" name="bloodgroup" id="bloodgroup6"  value="O" />O
				<input type="radio" name="bloodgroup" id="bloodgroup7"  value="O+" />O+
				<input type="radio" name="bloodgroup" id="bloodgroup8"  value="NA" />NA</td>
		</tr>
		<tr class="row1"><!--onClick="javascript:NewCal(this.id,'ddmmyyyy')"-->
			<td align="right">Date of Joining <font color="#FF0000" size="-1">*</font></td>
			<td><input name="doj" type="text" id="doj"  class="datepicker"  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"  class="datepicker" value="<?php if(isset($dol)){echo $dol;} else {echo "";}?>"></td>
		</tr>
		<tr class="row1">
			<td align="right">Department <font color="#FF0000" size="-1">*</font></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 id, deptcode,deptname from deptmaster",$db); 
					while($rsdepart=DB_fetch_array($qdepart)){
			 ?>
			<option value="<?php echo $rsdepart['id'];?>"<?php echo($department==$rsdepart['id']?'selected':'')?>><?php echo $rsdepart['deptname'];?></option>
			<?php }?>
			</select></td>
			<td align="right">Designation <font color="#FF0000" size="-1">*</font></td>
			<td><div id='hid-desig'><select name="designation" id="designation"  onchange="show_shift(this.value);"  > 
			<option value="000">---Select---</option>
			<?php $qdesig=DB_query("select id ,desigcode,designame from desigmaster",$db);
				while ($rsdesig=DB_fetch_array($qdesig)){
			?>
			<option value="<?php echo $rsdesig['id'];?>" <?php echo ($designation==$rsdesig['id']?'selected':'')?>><?php echo $rsdesig['designame'];?></option>
			<?php }?>
			</select></div></td>
		</tr>		
		<tr class="row1">
	  		<td align="right">Weekly Off <font color="#FF0000" size="-1">*</font></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 <font color="#FF0000" size="-1">*</font></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" class="datepicker" 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<font color="#FF0000" size="-1">*</font></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"  onchange="show_sal(this.value);">
			  <option value="0">Select</option>
				  <?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">Biomatric Code <font color="#FF0000" size="-1">*</font></td>
		  	<td><input type="text" name="biomatric_id" id="biomatric_id"  value=""/></td>
		  	<td colspan="2"></td>
		</tr>
	</table>
	</td>
	<td valign="top" width="20%">
	<table width="100%" border="0" cellpadding="3" cellspacing="0" style="border:0;">
			<tr>
				<td>
				<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;"><img src="uploaded_images/default.png" width="100%" height="auto" id="image1" /></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</td>
		<td width="30%"><input type="checkbox" name="tenth_standard" id="tenth_standard" value="true"  /></td>
		<td colspan="2"></td>
	</tr>
	<tr class="row1">
		<td align="right">10+2 Standard</td>
		<td><input type="checkbox" name="tenthplus2_standard" id="tenthplus2_standard" value="true" /></td>
		<td colspan="2"></td>
	</tr>
	<tr class="row1">
	   <td align="right">Basic/Graduation</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 colspan="2"></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 colspan="2"></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 colspan="2"></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 colspan="2"></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 colspan="2"></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 colspan="2"></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%" valign="top" align="right" rowspan="3">Address<font color="#FF0000" size="-1">*</font></td>
					  <td><input name="pre_address1" type="text" id="pre_add1" /></td>
				</tr>
				<tr class="row1">
					<td><input name="pre_address2" type="text" id="pre_add2"  /></td>
				</tr>
				<tr class="row1">
					<td><input name="pre_address3" type="text" id="pre_add3"  /></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 $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"  />
					<input type="text" name="pre_state1" id="pre_state1"  />
					</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" style="width:150px;" />
					 <input type="text" name="pre_country1" id="pre_country1"  />
					 </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"  /></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"  /></td>
				</tr>
				<tr class="row1">
					 <td align="right">Phone </td>
					<td><input name="pre_phone" type="text" id="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" /></td>
				</tr>
				<tr class="row1">
					<td><input name="per_address2" type="text" id="per_add2"  /></td>
				</tr>
				<tr class="row1">
					<td><input name="per_address3" type="text" id="per_add3"  /></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 $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" style="width:150px;" />
					<input type="text" name="per_state1" id="per_state1"  /></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" style="width:150px;" />
					 <input type="text" name="per_country1" id="per_country1"  /></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"  /></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"  /></td>
				</tr>
				<tr class="row1">
					 <td align="right">Phone</td>
					<td><input name="per_phone" type="text" id="per_phone"  /></td>
				</tr>
			</table>
		</td>
	</tr>
	</table>
	</div>
			<!--end of Address box-->
			
			
	<div role="tabpanel" class="tab-pane" id="bankDetails">
	<table width="99%" cellpadding="3" cellspacing="0" border="0" align="center">
		<tr class="row1">
			<td width="13%" align="right">Payment Mode<font color="#FF0000" size="-1">*</font></td>
			<td width="20%"><select name="payment_mode"id="payment_mode" onchange="checkMode(this.value)" >
				<option value="Cheque">Cheque</option>
				<option value="Cash">Cash</option>
				</select></td>
			<td width="13%" align="right">Bank Name</td>
			<td width="20%"><input type="text" name="bank_name" id="bank_name"  /></td>
			<td width="13%" align="right">Bank Account</td>
			<td><input type="text" name="bank_account" id="bank_account"   /></td>
		</tr>
		<tr class="row1">
			<td align="right">PF No.</td>
			<td><input type="text" name="PFno" id="PFno" /></td>
			<td align="right">ESI No.</td>
			<td><input type="text" name="ESIno" id="ESIno"  /></td>
			<td colspan="2"></td>	
		</tr>
	</table>
	</div>		
			
			
			<!--Salary box-->
	<div role="tabpanel" class="tab-pane" id="salaryDetails">
	<div id="sal">
	<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" 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 class="text-center">Description</th>
			<th width="34%" class="text-center">%</th>
			<th width="34%" class="text-center">Value</th>
		  </tr>
		  <tr >
		  <td align="right">BASIC</td>
		  <td><input type="text" name="basic_perc" id="basic_perc" size="5" value="40"  /></td>
		  <td><input type="text" name="basic_salary" id="basic_salary" value="<?php echo trim($basic_salary);?>" size="10" onfocus="calculate_basic()"  /></td>
		  </tr><?php
		  $all_sql=DB_query("Select * from allowmaster",$db); 
		  $i=1;
		 	 while($all_row=DB_fetch_array($all_sql))
		  	 {
		  		if($all_row['allowcode']=='HRA')
		  		{
		  			$valueh=50;
		  		}
		  		else
		  		{
		  			$valueh='';
		  		}
		  		if($all_row['allowcode']=='CONV')
		  		{
		  			$conval=800;
		  		}
		  		else if($all_row['allowcode']=='WA')
		  		{
		  			$conval=600;
		  		}
		  		else
		  		{
		  			$conval='';
		  		}
		  ?>
		  <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 $valueh;?>" 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 $conval;?>" size="10" class="number" tabindex="48+<?php echo $i;?>"  /></td>
			<!--onfocus="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" onblur="cal_special_allow_1()" tabindex="48+<?php echo (2*$i);?>"  /></td>
		  <td><input type="text" name="special_allow" id="special_allow" value="<?php if(isset($special_allow)){echo $special_allow;}else{ echo '0';} ?>" size="10"  tabindex="48+<?php echo $i;?>" /></td>
		 </tr>
		  <tr >
		 <td align="right">Gross Salary<font color="#FF0000" size="-1">*</font></td>
		 <td colspan="2"><input name="allow_tot" type="text" id="allow_tot" value="<?php echo $allow_tot;?>" onfocus="cal_alltot();cal_esi(this.value);data_str(this.value);" readonly="true" /></td>
		 </tr>
		<!--<tr >
		 <td class="tabledata1" colspan="3"><div align="center">Allowances Part (B) </div></td>
		 </tr>
		 <tr >
		 	<td>LTA(Basic/12)</td>
			<td><input type="text" name="ltaper" id="ltaper" onblur="calltaAll(this.value)" size="5" value="12" /></td>
			<td><input type="text" name="lta" id="lta" size="10" value="" /></td>
		 </tr>
		 <tr >
		 	<td>LWF</td>
			<td><input type="text" name="LWFper" id="LWFper" onblur="calLWFAll(this.value)" size="5" value="" /></td>
			<td><input type="text" name="LWF" id="LWF" size="10" /></td>
		 </tr>
		 <tr >
		 	<td class="tabledata1">ESI(Employer).</td>
			<td><input type="text" name="ESI_employer" id="ESIemployer" style="width:50px;" value="4.75" onkeyup="calculate_esi(this.value);" readonly=""/></td>
			<td><input type="text" name="ESI_employer_value" id="esimployervalue" size="10" value="" readonly=""/></td>
		 </tr>
		 <tr >
		 	<td class="tabledata1">Monthly CTC</td>
			<td colspan="2"><input type="text" name="monthelyctc1" id="monthelyctc1" onfocus="calmothellysal()" size="15" /></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 width="20%" class="text-center">Description</th>
			<th width="40%" class="text-center">%</th>
			<th class="text-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,this.id,<?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(D)</td>
		 <td colspan="2"><input name="deduct_tot" type="text" id="deduct_tot" value="<?php echo $deduct_tot;?>" onfocus="cal_dedtot()" readonly="true" /></td>
		 </tr>
		</table>
		
		<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" />				
			<?php if($otapplicable=='N')
			$disable="disabled";
			?></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>
		    <td width="20%" align="right">Single</td>
		    <td width="30%"><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><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 >
		<td class="tabledata1">Salary Effective From </th>
		<td><input name="eff_sal_date" type="text" onClick="javascript:NewCal(this.id,'ddmmyyyy')" id="eff_sal_date" value="<?php echo date('d/m/Y');?>" style="width:150px;" /></td>
		<td class="tabledata1">Gross Salary<font color="#FF0000" size="-1">*</font></th>
		<td><input name="gross_sal" type="text" id="gross_sal"  style="width:150px;" onfocus="cal_gross()" readonly="true"/></td>
		</tr>-->
		<tr class="row1">
		<td width="12%" align="right">Net Salary (A-D) </td> <!--onfocus="cal_net()"-->
		<td><input name="net_sal" type="text" id="net_sal"  style="width:41%;"  readonly="true"/></td>
		</tr>
		</table>
		</td>
	  </tr>
	</table>
	</div>
	</div>
			<!--end of Salary box-->
			
			<!--Leave box-->
	<div role="tabpanel" class="tab-pane" id="leaveDetails">
	<table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
	 <tr class="row1">
		 <td width="20%" align="right">Effective Date<font color="#FF0000" size="-1">*</font></td>
		 <td width="20%"><input type="text" name="leave_eff_date" class="datepicker" value="<?php if(isset($leave_eff_date)){echo $leave_eff_date;} else {echo date('d/m/Y');}?>" tabindex="66"  /></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;?>" />
	</table>
	</div>
			<!--end of Leave box-->
			<!--Uploads box-->
	<div role="tabpanel" class="tab-pane" id="uploads">
	<table width="99%" border="0" cellpadding="3" cellspacing="0" align="center">
	<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="" tabindex="69" />
		<input type="hidden" name="docmnt1" id="docmnt1" value="<?php echo $document;?>" tabindex="70" /></td>
	</tr>
	</tbody>
	<input type="hidden" id="hiditemcount" />
	</table>
	</div>
</div>

<div style="width:100%; float:left;">
<p align="center">
  <input type="submit" name="Submit" value="Save" class="search" onclick="return validate()"  />
  <input type="button" name="Cancel" value="Cancel" class="search"  onclick="history.go()" /></p>
  </div>

</form>

</div>
</div>
<script type="text/javascript">
	// Element.cleanWhitespace('content');
	// init();
</script>
<?php
include('includes/footer.inc');
?>
<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;
	}
	
	if(document.getElementById("emp_weekly_off").value=='000')
	{
		alert("Please Select The Weekly Off First !");
		document.getElementById("emp_weekly_off").focus();
		return false;
	}
	
	if(document.getElementById("marital_status").value=='000')
	{
		alert("Please Select The Marital Status First !");
		document.getElementById("marital_status").focus();
		return false;
	}
	
	if(document.getElementById("marital_status").value='Married')
	{
		/*if(document.getElementById("marriage").value=='')
		{
			alert("Please Fill The Marriage Aniversary Date First !");
			document.getElementById("marriage").focus();
			return false;
		}*/
		if(document.getElementById("wh_name").value=='')
		{
			alert("Please Fill The Wife's/Husband's Name First !");
			document.getElementById("wh_name").focus();
			return false;
		}
		if(document.getElementById("biomatric_id").value=='')
		{
			alert("Please Fill Biomatric Code !");
			document.getElementById("biomatric_id").focus();
			return false;
		}
	}

	if(document.getElementById("grade").value=='0')
	{
		alert("Please Select grade");
		document.getElementById("grade").focus();
		return false;
	}
	
	/*if(document.getElementById("tenth_standard").checked==false)
	{
		alert("Please Check 10th Standard First !");
		document.getElementById("tenth_standard").focus();
		return false;
	}
	
	if(document.getElementById("tenthplus2_standard").checked==false)
	{
		alert("Please Check 10+2 Standard First !");
		document.getElementById("tenthplus2_standard").focus();
		return false;
	}*/
	
	if(document.getElementById("pre_add1").value=='')
	{
		alert("Please Fill The Present Address  First !");
		document.getElementById("pre_add1").focus();
		return false;
	}
	
	if(document.getElementById("pre_city").value=='')
	{
		alert("Please Fill The Present City  First !");
		document.getElementById("pre_city").focus();
		return false;
	}
	
	if(document.getElementById("pre_state1").value=='')
	{
		alert("Please Fill The Present State  First !");
		document.getElementById("pre_state1").focus();
		return false;
	}
	
	if(document.getElementById("pre_country1").value=='')
	{
		alert("Please Fill The Present Country  First !");
		document.getElementById("pre_country1").focus();
		return false;
	}
	
	if(document.getElementById("pre_pincode").value=='')
	{
		alert("Please Fill The Present Pin Code  First !");
		document.getElementById("pre_pincode").focus();
		return false;
	}
	
	if(document.getElementById("pre_mobile").value=='')
	{
		alert("Please Fill The Present Mobile No  First !");
		document.getElementById("pre_mobile").focus();
		return false;
	}
	
	
	if(document.getElementById("per_add1").value=='' || document.getElementById("per_city").value=='' || document.getElementById("per_state1").value=='' || document.getElementById("per_country1").value=='' || document.getElementById("per_pincode").value=='' || document.getElementById("per_mobile").value=='')
	{
		alert("Please Checke If Present Address Same As Permanent Address Or Fill All Permanent Address Details!");
		document.getElementById("copy_add").focus();
		return false;
	}
	
	if(document.getElementById("payment_mode").value=='')
	{
		alert("Please Select The Payment Mode  First !");
		document.getElementById("payment_mode").focus();
		return false;
	}
	
	/*if(document.getElementById("gross").value=='')
	{
		alert("Please Fill Monthly CTC  First !");
		document.getElementById("gross").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;}

			}

   function show_shift(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){	
	    document.getElementById("grade").innerHTML=xmlhttp.responseText;
        //show_sal(str);
	     }
	}

	xmlhttp.open("GET","ajax_sal_details.php?id="+str,true);
	xmlhttp.send();


   }

     function show_sal(str1)
   {
   	 var str=document.getElementById("designation").value;

    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("sal").innerHTML=xmlhttp.responseText;
      
	     }
	}

	xmlhttp.open("GET","ajax_sal_details1.php?id="+str+"&id1="+str1,true);
	xmlhttp.send();


   }

</script>
