$(document).ready(function(){

	$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
	

/*$('.login').click(function(){
		$('.titu').text('Ingresar Administrador');
		$('#link').hide();
	});

*/

$('#btn').click(function(){
			$('#dialog2').dialog('open'); 
							 });
$('#dialog').dialog({ 
					draggable: true, 
					modal:true, 
					show:'highlight', 
					autoOpen: false, 
					position:'center', 
					width: 350, 
					height: 'auto', 
					title: 'Mensaje',
					resizable: false
					
					}); 
$('#dialog1').dialog({ 
					draggable: true, 
					modal:true, 
					show:'highlight', 
					autoOpen: false, 
					position:'center', 
					width: 350, 
					height: 'auto', 
					title: 'Mensaje',
					resizable: false
					
					}); 

$('#dialog2').dialog({ 
					draggable: true, 
					modal:true, 
					show:'fold', 
					autoOpen: false, 
					position:'center', 
					width: 850, 
					height: 'auto', 
					title: 'Mantenimiento',
					resizable: false,
					buttons: {"Ok":function(){
						 $(this).dialog("close");
						}},
					hide:"scale"
					}); 



	$('.error').hide();
	$('.sub').click(function(){
		$('.error').hide();
			
			var nombre =$('input#nombre').val();
			if(nombre=="")
			{
			  $('label#nombre_error').show();
			  $('input#nombre').focus();
              
			  return false;
			}
			
			var email=$('input#email').val();
			if(email=="")
			{
			$('label#email_error').show();
			$('input#email').focus();
			return false;
			}
			
			var sug=$('textarea#sugerencia').val();
			if(sug=="")
			{
			 $('label#sug_error').show();
			 $('textarea#sugerencia').focus();
			 return false;
			}
					
			$('#dialog').dialog('open');
			
	});
	
	$('.botong').click(function(){
		//$('.error').hide();
			
			var nombre =$('#nomb').val();
			if(nombre=="")
			{
			  $('#nomb_error').show();
			  $('#nomb').focus();
              
			  return false;
			}
			var ape=$('#ape').val();
			if(ape=="")
			{
			 $('#ape_error').show();
			 $('#ape').focus();
			 return false;
			}
			var dni=$('#dni').val();
			if(dni=="")
			{
			$('#dni_error').show();
			$('#dni').focus();
			return false;
			}
			var email=$('#email').val();
			if(email=="")
			{
			$('#email_error').show();
			$('#email').focus();
			return false;
			}
			existe=$('#grilla tbody tr').length;
			if(existe<=0)
			{
				$('#service_error').show();
				$('#service').focus();
				return false;
			}
			
	});
/* function blur */	
	$('.inpt').blur(function(){
      if($(this).val()!=""){$('.error').hide();}							 
							 })
	
/* ----------------------------------- */

$('.clic').click(function(){
						  
	$('#formulario').css('display','block');
						  });

/*$(".check").bind("change",function(){
					if($(this).val()=="on"){
					$(".check").addClass("bc");
					alert("check");
								}
								  });


*/
/* guardar datos */

function guardar_sug()
{	
	var str=$("#sug").serialize();	
	$.ajax({
			url: 'guardar.php',
			type: 'POST',
			async: true,
			data: str,
			success: mostrar_confirm
		});	

}

function guardar_user()
{
	var str=$('#registro').serialize();
	$.ajax({
		   url:'save/user.php',
		   type:'POST',
		   async:true,
		   data:str,
		   success:mostrar_confirm
		   });
} 

function guardar_generado()
{
	var str=$('#consult').serialize();
	$.ajax({
		   url:'save/generado.php',
		   type:'POST',
		   async:true,
		   data:str,
		   success:mostrar_confirm
		   });
} 

});

/* ---------------- */

function agregar(obj){
	//agregar();
	tr="<tr>"+$(obj).parents("tr").html()+"</tr>";
	mio=$("#grilla tbody").html();

	$("#grilla tbody").html(mio+tr);
	$("#grilla tbody .agregar").replaceWith("<img src='images/delete.png' class='quitar' onclick='quitar(this)'/>");
	$(obj).parents("tr").remove();
	
}
function quitar(obj){

	tr="<tr>"+$(obj).parents("tr").html()+"</tr>";
	mio=$("#tbody").html();	

	$("#tbody").html(tr+mio);
	$("#tbody .quitar").replaceWith("<input class='agregar' type='button'  onclick='agregar(this)'>");
	$(obj).parents("#grilla tbody tr").remove();
}
