<?php
session_start();
if($_SESSION["sistema"]!= "1"){ header("location: ../../index.php"); exit();}
require_once ("../../config/Cado.php");

require_once ("../contenido/contenido.php");
$oContenido = new cContenido();

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Mesas</title>
<link href="../../css/Estilo/miestilo.css" rel="stylesheet" type="text/css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="../../css/Estilo/menu_estilo.css" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="../../js/jquery-ui/development-bundle/themes/start/jquery.ui.all.css">
<script src="../../js/jquery-ui/development-bundle/jquery-1.6.2.js"></script>
<script src="../../js/jquery-ui/development-bundle/external/jquery.bgiframe-2.1.2.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.core.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.widget.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.mouse.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.button.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.draggable.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.position.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.resizable.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.ui.dialog.js"></script>
<script src="../../js/jquery-ui/development-bundle/ui/jquery.effects.core.js"></script>

<script src="../../js/jquery-validation/jquery.validate.js" type="text/javascript"></script>
<script src="../../js/jquery-validation/additional-methods.js" type="text/javascript"></script>
<script src="../../js/jquery-validation/localization/messages_es.js" type="text/javascript"></script>

<link rel="stylesheet" href="../../js/tablesorter/themes/blue/style.css" type="text/css" media="print, projection, screen" />
<script type="text/javascript" src="../../js/tablesorter/jquery.tablesorter.js"></script>

<script type="text/javascript">

function mesa_filtro()
{
	$.ajax({
		type: "POST",
		url: "mesa_filtro.php",
		async:true,
		dataType: "html",
		beforeSend: function() {
			$('#div_mesa_filtro').html('Cargando <img src="../../images/loadingf11.gif" align="absmiddle"/>');
        },
		success: function(html){
			$('#div_mesa_filtro').html(html);
		},
		complete: function(){ 
		}
	});
}

function mesa_tabla()
{	
	$.ajax({
		type: "POST",
		url: "mesa_tabla.php",
		async:true,
		dataType: "html", 
		data: $("#for_fil_mesa").serialize(),
		beforeSend: function() {
			$('#div_mesa_tabla').addClass("ui-state-disabled");
        },
		success: function(html){
			$('#div_mesa_tabla').html(html);
		},
		complete: function(){			
			$('#div_mesa_tabla').removeClass("ui-state-disabled");
		}
	});     
}

function mesa_form(act,idf)
{
	$.ajax({
		type: "POST",
		url: "mesa_form.php",
		async:true,
		dataType: "html",                      
		data: ({
			action: act,
			mesa_id:	idf,
			vista:	'mesa_tabla'
		}),
		beforeSend: function() {
			$('#msj_mesa').hide();
			$('#div_mesa_form').dialog("open");
			$('#div_mesa_form').html('Cargando <img src="../../images/loadingf11.gif" align="absmiddle"/>');
        },
		success: function(html){
			$('#div_mesa_form').html(html);				
		}
	});
}

function eliminar_mesa(id)
{   
	$('#msj_mesa').hide();   
	if(confirm("Realmente desea eliminar?")){
		$.ajax({
			type: "POST",
			url: "mesa_reg.php",
			async:true,
			dataType: "html",
			data: ({
				action: "eliminar",
				mesa_id:id
			}),
			beforeSend: function() {
				$('#msj_mesa').html("Cargando...");
				$('#msj_mesa').show(100);
			},
			success: function(html){
				$('#msj_mesa').html(html);
			},
			complete: function(){
				mesa_tabla();
			}
		});
	}
}


//
$(function() {
	
	$('#btn_actualizar').button({
		icons: {primary: "ui-icon-arrowrefresh-1-e"},
		text: true
		}).click(function() {
		location.reload();
	});
	
	$('#btn_agregar').button({
		icons: {primary: "ui-icon-plus"},
		text: true
	});

	mesa_filtro();
	
	$( "#div_mesa_form" ).dialog({
		title:'Información de la Mesa',
		autoOpen: false,
		resizable: false,
		height: 'auto',
		width: 500,
		position:'top',
		modal: true,
		buttons: [
			{
				text: 'Guardar',
				id: 'btn_for_mesa_guardar',
				click: function(){
					$("#for_mesa").submit();
				}
			},
			{
				text: 'Cancelar',
				id: 'btn_for_mesa_cancelar',
				click: function(){
					$('#for_mesa').each (function(){this.reset();});
					$( this ).dialog( "close" );
				}
			},
		],
	});
	
});

</script>
</head>

<body>
<div class="container">
	<header>
    	<?php echo $oContenido->print_header()?>
	</header>
    <article class="content">
    	<div class="contenido">
            <div class="contenido_des">
            <table align="center" class="tabla_cont">
                  <tr>
                    <td class="caption_cont">MESAS</td>
                  </tr>
                  <tr>
                    <td align="right" class="cont_emp"><?php echo $_SESSION['empresa_nombre']?></td>
                  </tr>
                  <tr>
                    <td>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="25" align="left" valign="middle"><a id="btn_agregar" href="#" onClick="mesa_form('insertar')">Agregar</a></td>
                      <td width="25" align="left" valign="middle"><a id="btn_actualizar" href="#">Actualizar</a></td>
                      <td align="left" valign="middle">&nbsp;</td>
                      <td align="right"><div id="msj_mesa" class="ui-state-highlight ui-corner-all" style="width:auto; float:right; padding:2px; display:none"></div></td>
                    </tr>
                  </table>
                    </td>
                  </tr>
                  <tr>
                    <td>
                    </td>
                  </tr>
              </table>
			</div>
			<div id="div_mesa_filtro"> </div>
        	<div id="div_mesa_form"> </div>
        	<div id="div_mesa_tabla" class="contenido_tabla">
      		</div>
      	</div>
    </article>
</div>
<footer>
    <?php echo $oContenido->print_footer()?>
</footer>
</body>
</html>