<?
session_start();
if ($_SESSION['estado'] != "ON")
		{
		?>
		<script>
			parent.location.href = '../index.php';
		</script>
		<? 
		exit();
		}
$id_empresa = $_SESSION['ss_empresa'];
$id_user = $_SESSION['ss_user'];
?>
<?
include("../conex.php");
$get_cod_producto = $_GET["cp"];
$sql_bpro = "SELECT * FROM nombres WHERE codigo = $get_cod_producto";
$res_bpro = mysql_query($sql_bpro,$enlace);
if (mysql_fetch_object ($res_bpro))
	{
	$sql_rut = mysql_result($res_bpro, 0, "rut");
	$sql_rsoc = mysql_result($res_bpro, 0, "razon_social");	
	}

	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Productos por bodegas</title>
<style type="text/css">
<!--
body {
	background-color: #CCCCCC;
	margin-left: 0px;
	margin-top: 3px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.Estilo13 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9px;
	color: #000099;
	text-decoration: underline;
}
.titulos2 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 13px;
	color: #003366;
	background-color: #CCCCCC;
	font-style: normal;
	font-weight: bold;
}
.botones {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	height:26px;
}
.Estilo16 {color: #FFFFFF}
-->
</style>

</head>
<body vlink="#2293ff" alink="#2293ff" link="#2293ff">
<form name="form1" method="post" action="guardae_producto.php">
<div align="left" class="titulos2" style="font-size:12px">
<table width="90%" border="0" align="center">
	<tr>
		<td><div align="center">Sucursales de <?=$sql_rsoc;?></div></td>
	</tr>
</table>

<br>
<table width="500px" border="1" align="center">
	<tr bgcolor="#00CCFF" class="detalle_tablas_II_negrita">
		<td width="70%" bgcolor="#0033CC"><div align="center" class="Estilo16">Sucursal</div></td>
		<td width="15%" bgcolor="#0033CC"><div align="center" class="Estilo16">Editar</div></td>
        <td width="15%" bgcolor="#0033CC"><div align="center" class="Estilo16">Borrar</div></td>
	</tr>
<?
$sql_bbod = "SELECT * FROM sucursales WHERE rut='$sql_rut'";
$res_bbod = mysql_query($sql_bbod,$enlace);
$row_bbod=0;
while (mysql_fetch_object ($res_bbod))
	{
	$sql_suc = mysql_result($res_bbod, $row_bbod, "sucursal");	

?>

	<tr bgcolor="#CBFEC2">
		<td bgcolor="#0099FF"><div align="left"><?=$sql_suc;?></div></td>
   		<td bgcolor="#0099FF"><div align="center">
        <span align="center" class="Estilo13" onClick="javascript:enviar('editar_sucursales.php?cp=<?=mysql_result($res_bbod, $row_bbod, "id");?>')" style="cursor:pointer" title="Click aqui para modificar datos del nombre">
		<img src="img/edit.gif"></span>	</td>
		<td bgcolor="#0099FF"><div align="center">
        <span align="center" class="Estilo13" onClick="javascript:if(confirm('¿Desea eliminar esta sucursal?')) { borrar('borrar_sucursales.php?cp=<?=mysql_result($res_bbod, $row_bbod, "id");?>&&crp=<?=$get_cod_producto;?>','<?=$sql_suc;?>') }" style="cursor:pointer" title="Click aqui para modificar datos del nombre">
		<img src="img/delete.gif"></span>	</td>                
	</tr>	
<?
	$row_bbod+=1;
	}
?>
</table>
  <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center">
        <label>
        <input type="button" name="nuevo" value="Nueva Sucursal" onClick="javascript:enviar('nueva_sucursal.php?cp=<?=$sql_rut;?>');">
        <input type="button" name="Submit" value="Salir" onClick="window.top.open('','_parent','');window.top.close();">
        </label>
      </div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
</div>
</form>
<div align="center">
  <script language="javascript">
function enviar(aux)
	{
	document.form1.action = aux;
	document.form1.submit();
	}
function borrar(aux, suc)
	{
	if (suc=='PRINCIPAL'){
		alert("La sucursal principal no se puede eliminar\nPara eliminar esta sucursal debe eliminar el cliente");
		}
	else
		{
		document.form1.action = aux;
		document.form1.submit();
		}
	}	
</script>
</div>
