<?php
 $con=mysql_connect("localhost","root","");
 mysql_select_db("M01000",$con); 
 include ("emenux.php"); 
 $sw=$_POST['hdsw'];
 $sw2=$_POST['hdsw'];
 $rut=strtoupper($_POST['rut']);
 $nombre="";
 $fechanac="";
 $sexo="x";
 $direccion="";
 $codcomuna="";
 $telefono="";
 $celular="";
 $email="";
 $cantidad_cargas="";
 $porc_comis="";
 $codafp="";
 $codisapre="";
 $cont=0;
 $error2= "0";
 $recomendacion2="0";
 if ($sw=="buscar"){
  $sqlb="select * from m05001 where rut = '$rut' ;";
  $resb=mysql_query($sqlb,$con);
  if (mysql_num_rows($resb)>0){ 
   $sw="encontrado";
   $sw2="encontrado";
   while ($filab = mysql_fetch_row($resb)){
    $nombre=$filab[1];
    $fechanac=$filab[2];
    $sexo=$filab[3];
    $direccion=$filab[4];
    $codcomuna=$filab[5];
    $telefono=$filab[6];
    $celular=$filab[7];
    $email=$filab[8];
    $cantidad_cargas=$filab[9];
    $porc_comis=$filab[10];
    $codafp=$filab[11];
    $codisapre=$filab[12];     
    }//while
  }else{
   $error2= "Rut no encontrado.";
   $recomendacion2="->Agregar.";
  }//fin si
 }//fin de buscar
  if ($sw=="grabar"){
   $rut=strtoupper($_POST['rut']);
   $nombre=$_POST['nombre'];
   $fechanac=$_POST['fecha_nac'];
   $sexo=$_POST['hdsexo'];
   $direccion=$_POST['direccion'];
   $codcomuna=$_POST['hdcom'];
   $telefono=$_POST['telefono'];
   $celular=$_POST['celular'];
   $email=$_POST['email'];
   $cantidad_cargas=$_POST['cantidad_cargas'];
   $porc_comis=$_POST['porc_comis'];
   $codafp=$_POST['hdcodafp'];
   $codisapre=$_POST['hdcodisapre']; 
   $sqlg="replace into m05001   (rut,nombre,fecha_nac,sexo,direccion, cod_comuna,telefono,celular,email,cantidad_carga,porc_comis, cod_afp, cod_isapre)
   values ('$rut','$nombre','$fechanac','$sexo','$direccion','$codcomuna','$telefono','$celular','$email','$cantidad_cargas','$porc_comis','$codafp','$codisapre');";
 $resg=mysql_query($sqlg,$con) or die('error' . mysql_error()) ; 
 $rut="";
 $nombre="";
 $fechanac="";
 $sexo="";
 $direccion="";
 $codcomuna="";
 $telefono="";
 $celular="";
 $email="";
 $cantidad_cargas="";
 $porc_comis="";
 $codafp="";
 $codisapre=""; 
 $sw=""; 
  }//fin grabar 
 if ($sw=="eliminar"){
  $sqle="delete from m05001 where rut='$rut';";
  mysql_query($sqle,$con);
  $rut="";
  $nombre="";
  $fechanac="";
  $sexo="";
  $direccion="";
  $codcomuna="";
  $telefono="";
  $celular="";
  $email="";
  $cantidad_cargas="";
  $porc_comis="";
  $codafp="";
  $codisapre=""; 
  $sw="";
 }//fin si de eliminar
 if (strlen($codcomuna)==0){$codcomuna="5406";}
 if (strlen($codcpago)==0){$codcpago="001";}
 //if (strlen($sexo)==0){$sexo="1";}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Maestro Empleados</TITLE>
<style>
TD{font-family:arial,helvetica; font-size:10pt}
BODY{background-color:white}
A{color:Navy; text-decoration:none}
A:hover{color:red}
A:visited:{color:#808080}
DIV{font-family:arial,helvetica; font-size:12pt; font-weight:bold}
</style>
<script>
/********************************************************************************
This script is made by and copyrighted to Thomas Brattli at www.bratta.com
Visit for more great scripts. 
This may be used freely as long as this msg is intact!
********************************************************************************
Browsercheck:*/
ie=document.all?1:0
n=document.layers?1:0

//These are the variables you have to set:

//How much of the layer do you wan't to be visible when it's in the upstate?
lshow=20

//How many pixels should it move every step? 
var move=10;

//At what speed (in milliseconds, lower value is more speed)
menuSpeed=40

//Do you want it to move with the page if the user scroll the page?
var moveOnScroll=true

/********************************************************************************
You should't have to change anything below this.
********************************************************************************/
//Defining variables
var tim;

//Object constructor
function makeMenu(obj,nest){
    nest=(!nest) ? '':'document.'+nest+'.'
    this.css=(n) ? eval(nest+'document.'+obj):eval(obj+'.style')					
	this.state=1
	this.go=0
	this.height=n?this.css.document.height:eval(obj+'.offsetHeight')
	this.top=b_gettop
    this.obj = obj + "Object"; 	eval(this.obj + "=this")	
}
//Get's the top position.
function b_gettop(){
	var gleft=(n) ? eval(this.css.top):eval(this.css.pixelTop);
	return gleft;
}
/********************************************************************************
Deciding what way to move the menu (this is called onmouseover, onmouseout or onclick)
********************************************************************************/
function moveMenu(){
	if(!oMenu.state){
		clearTimeout(tim)
		mIn()	
	}else{
		clearTimeout(tim)
		mOut()
	}
}
//Menu in
function mIn(){
	if(oMenu.top()>eval(scrolled)-oMenu.height+lshow){
		oMenu.go=1
		oMenu.css.top=oMenu.top()-move
		tim=setTimeout("mIn()",menuSpeed)
	}else{
		oMenu.go=0
		oMenu.state=1
	}	
}
//Menu out
function mOut(){
	if(oMenu.top()<eval(scrolled)){
		oMenu.go=1
		oMenu.css.top=oMenu.top()+move
		tim=setTimeout("mOut()",menuSpeed)
	}else{
		oMenu.go=0
		oMenu.state=0
	}	
}
/********************************************************************************
Checking if the page is scrolled, if it is move the menu after
********************************************************************************/
function checkScrolled(){
	if(!oMenu.go)oMenu.css.top=(!oMenu.state)?eval(scrolled):eval(scrolled)-oMenu.height+lshow
	if(n) setTimeout('checkScrolled()',30)
}
/********************************************************************************
Inits the page, makes the menu object, moves it to the right place, 
show it..
********************************************************************************/
function menuInit(){
	oMenu=new makeMenu('divMenu')
	scrolled=n?"window.pageYOffset":"document.body.scrollTop"
	oMenu.css.top=eval(scrolled)-oMenu.height+lshow
	oMenu.css.visibility='visible'
	if(moveOnScroll) ie?window.onscroll=checkScrolled:checkScrolled();
}

//Initing menu on pageload
onload=menuInit;
</script>

<script language="javascript" src="fstandar.js"></script>
<script language="javascript">
function ponecomuna(){
 document.form1.hdcom.value=document.form1.cmbcom.value;
// window.alert(document.form1.hdcom.value);
 }
function ponesexo(){
 document.form1.hdsexo.value=document.form1.cmbsexo.value;
 //window.alert(document.form1.hdsexo.value);
 }
function poneafp(){
 document.form1.hdcodafp.value=document.form1.cmbafp.value;
 //window.alert(document.form1.hdcodafp.value);
 }
function poneisapre(){
 document.form1.hdcodisapre.value=document.form1.cmbisapre.value;
 //window.alert(document.form1.hdcodisapre.value);
 } 
function valida(){ 
 if (document.form1.rut.value.length > 0){
  err=0;
  document.form1.hdsw.value="grabar";
  if (modulo11(document.form1.rut.value)==-1  ){
   window.alert("El rut ingresado es incorrecto" );
   err=1;
   document.form1.rut.style.backgroundColor="#FFFFCC";
   document.form1.rut.focus();  
   }
  if (verificaMail(document.form1.email,"")==false){
   err=1;
   document.form1.email.style.backgroundColor="#FFFFCC";
   document.form1.email.focus();
   }
  if (document.form1.nombre.value.length==0){
   err=1;
   window.alert("debe ingresar nombre");
   document.form1.nombre.style.backgroundColor="#FFFFCC";
   document.form1.nombre.focus();
   } 
  if (document.form1.direccion.value.length==0){
   err=1;
   window.alert("debe ingresar direccion");
   document.form1.direccion.style.backgroundColor="#FFFFCC";
   document.form1.direccion.focus();
   }  
  if (err==0){
   document.form1.action="M0501001.php"
   document.form1.method="post";
   document.form1.submit();
   }  
 }//fin si  
}  
function buscarut(){
 if (modulo11(document.form1.rut.value)==0){
  document.form1.rut.style.backgroundColor="#FFFFFF";
  document.form1.hdsw.value="buscar";
  document.form1.action="M0501001.php";
  document.form1.method="post";
  document.form1.submit();
 // window.alert("si");
  }else{
   window.alert("El rut ingresado es incorrecto" );
   document.form1.rut.style.backgroundColor="#FFFFCC";
   document.form1.rut.focus();  
  }//si 
 } 
 function limpiar(){
  document.form1.rut.value="";
  document.form1.hdrut.value="";
  document.form1.nombre.value="";  
  document.form1.direccion.value="";
  document.form1.comuna.value="";
  document.form1.hdcom.value="";
  document.form1.telefono1.value="";
  document.form1.telefono2.value="";
  document.form1.fax.value="";
  document.form1.contacto.value="";
  document.form1.email.value="";
  document.form1.cmbcondpag.value="";
  document.form1.hdcodcpag.value="";
 }//fin limpiar
 function eliminar(){
 if(window.confirm("Seguro desea eliminar?")==true){
  document.form1.hdsw.value="eliminar";
  document.form1.action="M0501001.php";
  document.form1.method="post";
  document.form1.submit();
  }
 }//fin eliminar 
</script>
<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {color: #FF0000}
.Estilo2 {color: #0000FF}
-->
</style>
</HEAD>
<BODY <?php
 if ($sw2=="buscar"){
  echo "onload='javascript:(document.form1.nombre.focus())'";
  }
 if ($sw2=="grabar" || $sw2=="eliminar"){
  echo "onload='javascript:(document.form1.rut.focus())'";
  } 
 if ($sw2=="encontrado" ){
  echo "onload='javascript:(document.form1.cmdgra.focus())'";
  }  
  ?>>
  <div id="divMenu" style="position:absolute; top:0; left:400; height:100; width:80; visibility:hidden; z-index:2">
	<a href="http://www.htmlpoint.com">HOME</a>	
	<br>
	<br>
	<a href="http://www.htmlpoint.com/jscript">Script</a>	
	<br><br>
	<a href="http://www.htmlpoint.com/xml">XML</a>	
	<br><br>
	<a href="http://www.htmlpoint.com/asp">ASP</a>	
	<br><br>
	<a href="http://www.htmlpoint.com/java">Applet</a>	
	<br><br>
	<a href="http://www.htmlpoint.com/grafica">Gráfica</a>	
	<br><br>
	<a href="javascript://" onclick="moveMenu()">MENÚ</a>	
</div>

<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG src="images/xc_left.gif" alt="Inicio" width=24 
                  height=22 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="715" 
              border=0>
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD vAlign=top align=left width=180 height=18>&nbsp;</TD>
                <TD width=12 height=18>&nbsp;</TD>
                <TD width="461" height=18 class=MainMenuHead>Empleados:</TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD vAlign=top align=left width=180 height="100%">
                  <TABLE cellSpacing=0 cellPadding=0 width="150" border=0>
                    <TBODY>
                    <TR>
                      <TD width=10 valign="top"><IMG height=12 
                        src="images/xc_dotgrey.gif" width=10></TD>
                      <TD width=4>&nbsp;</TD>
                      <TD class=LeftMenu noWrap><p>Ingreso de Empleados:<br />
  -&gt;Agregar.<br />
  -&gt;Modificar.<br />
  -&gt;Eliminar.</p>                        </TD>
                    </TR>
                    
                    <TR>
                      <TD valign="top"><img height="12" 
                        src="images/xc_dotgrey.gif" width="10" /></TD>
                      <TD>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>Alertas:<span class="Estilo1"><br />
                          <?php echo $error2 ?></span></TD>
                    </TR>
                    <TR>
                      <TD width=10 valign="top"><img height="12" 
                        src="images/xc_dotgrey.gif" width="10" /></TD>
                      <TD>&nbsp;</TD>
                      <TD class=LeftMenu noWrap>Se recomienda:<span class="Estilo2"><br />
                          <?php echo $recomendacion2 ?></span></TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=12 height="100%">&nbsp;</TD>
                <TD class=contentcell vAlign=top align=middle width=461 
                height="100%">
                  <TABLE width="100%">
                    <TBODY>
                    <TR>
                      <TD>
                        <form name="form1" method="post" action="">
                          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <th scope="col"><div align="right" class="Emphasize">Rut:</div></th>
                              <th scope="col"><div align="left">
                                <input name="rut" type="text" id="rut" onblur="buscarut()" value="<?php echo $rut ?>" size="10" maxlength="9" />
                                <input name="hdsw" type="hidden" id="hdsw" value="nada" />
                              </div></th>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Nombre:</div></th>
                              <td><input name="nombre" type="text" id="nombre"  value="<?php echo $nombre ?>" size="50" maxlength="100"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Fecha Nacimiento: </span></div></th>
                              <td><input name="fecha_nac" type="text" id="fecha_nac" value="<?php echo $fechanac ?>" size="9" maxlength="8"/>
							  </td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Sexo:</div></th>
                              <td>
                                <select name="cmbsexo" class="Emphasize" id="cmbsexo" onchange="ponesexo()">
								<?php
									if ($sexo=="x"){
									 echo "<option value='x' selected='selected'>Seleccione sexo</option>";
									 echo "<option value='1'>Masculino</option>";
									 echo "<option value='0'>Femenino</option>";
									 } elseif ($sexo=="0"){
									  echo "<option value='x'>Seleccione sexo</option>";
									  echo "<option value='1'>Masculino</option>";
									  echo "<option value='0' selected='selected'>Femenino</option>";
									 }else{
									  echo "<option value='x' >Seleccione sexo</option>";
									  echo "<option value='1' selected='selected'>Masculino</option>";
									  echo "<option value='0'>Femenino</option>";
									  }	
								?>
                                        </select>
                                <input name="hdsexo" type="hidden" id="hdsexo" value="<?php echo $codsexo ?>"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Direccion:</span></div></th>
                              <td><label>
                                <input name="direccion" type="text" id="direccion" value="<?php echo $direccion ?>" size="50" maxlength="100" />
                              </label></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Comuna:</div></th>
                              <td>
							  <div align="left">
							  	<?php
									$sqlcom="select * from m01003 order by 2;";
									$rescom=mysql_query($sqlcom,$con) ;				
								?>
								<select name="cmbcom" class="Emphasize" id="cmbcom" onchange="ponecomuna()">
								<?php 
									while ($fila=mysql_fetch_row($rescom)){
									if ($fila[0]==$codcomuna){
				                  	echo "<option value=$fila[0] selected='selected'>$fila[1]</option>";
									}else{
									 echo "<option value=$fila[0]>$fila[1]</option>";
									 }//si
									}
								?>
								</select>
								<input name="hdcom" type="hidden" id="hdcom" value="<?php echo $codcomuna ?>"/>				
                              </div></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right" class="Emphasize">Tel&eacute;fono:</div>
                              </label></th>
                              <td><input name="telefono" type="text" id="telefono" value="<?php echo $telefono ?>" size="16" maxlength="15" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Celular</span>:</div>
                              </label></th>
                              <td><input name="celular" type="text" id="celular" value="<?php echo $celular ?>" size="16" maxlength="15" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Email</span>:</div>
                              </label>                                </th>
                              <td><input name="email" type="text" id="email" value="<?php echo $email ?>" size="50" maxlength="100" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><label>
                                <div align="right"><span class="Emphasize">Cargas</span>:</div>
                              </label></th>
                              <td><input name="cantidad_cargas" type="text" id="cantidad_cargas" value="<?php echo $cantidad_cargas ?>" size="3" maxlength="2"/></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">% de Comisi&oacute;n</span>:</div></th>
                              <td><input name="porc_comis" type="text" id="porc_comis" value="<?php echo $porc_comis ?>" size="6" maxlength="5" /></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right"><span class="Emphasize">Afp:</span></div></th>
                              <td><label>
                                <?php
							  		$sqlafp="select * from m05003 order by 2;";
									$resafp=mysql_query($sqlafp,$con) ;				
							  ?>
                                <select name="cmbafp" id="cmbafp" onchange="poneafp()">
								<option value="xxx" selected="selected">Seleccione una AFP</option>
                                  <?php 
									while ($filaafp=mysql_fetch_row($resafp)){
									if ($filaafp[0]==$codafp){
										echo "<option value=$filaafp[0] selected='selected'>$filaafp[1]</option>";
									}else{
										echo "<option value=$filaafp[0]>$filaafp[1]</option>";
										}
									}
								?>
                                        </select>
                                <input name="hdcodafp" type="hidden" id="hdcodafp" value="<?php echo $codafp ?>" />
                              </label></td>
                            </tr>
                            <tr>
                              <th scope="row"><div align="right" class="Emphasize">Isapre:</div></th>
                              <td><?php
							  		$sqlisapre="select * from m05002 order by 2;";
									$resisapre=mysql_query($sqlisapre,$con) ;				
							  ?>
                                <select name="cmbisapre" id="cmbisapre" onchange="poneisapre()">
								<option value="xxx" selected="selected">Seleccione una ISAPRE</option>
                                  <?php 
									while ($filaisapre=mysql_fetch_row($resisapre)){
									if ($filaisapre[0]==$codisapre){
										echo "<option value=$filaisapre[0] selected='selected'>$filaisapre[1]</option>";
									}else{
										echo "<option value=$filaisapre[0]>$filaisapre[1]</option>";
										}
									}
								?>
                                        </select>
                                <input name="hdcodisapre" type="hidden" id="hdcodisapre" value="<?php echo $codisapre ?>" /></td>
                            </tr>
                            <tr>
                              <th scope="row">&nbsp;</th>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <th colspan="2" scope="row"><input name="cmdgra" type="button" id="cmdgra" value="Grabar" onclick="valida()" />
                                <label></label>
                                &nbsp;&nbsp;
                                <label></label>
                                <label></label>                                
                                <label></label>
                                &nbsp;&nbsp;
								<input name="cmdel" type="button" id="cmdel" value="Eliminar" onclick="eliminar()"/>								</th>
                              </tr>
                          </table>
                                </form>						</TD>
                    </TR></TBODY></TABLE></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD width=180 height=8>&nbsp;</TD>
                <TD width=12 height=8>&nbsp;</TD>
                <TD width="461" height=8>&nbsp;</TD>
        <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
<!-- /Footer -->
<script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
</TABLE>
</BODY>
<?php
	mysql_close($con);
?>
</HTML>