// JavaScript Document
var img = "<img src='../imagenes/buzon/ajax-loader.gif'> ";

$(document).ready(function() 
	{
		
	$(window).keydown(function(e){  
	    if(e.keyCode == 27){  
			$("#mensaje1").hide();
			$("#fondo").hide();
	    }  
	});
		
	$("#mensaje1").hide();
	$("#fondo").hide();
	
	$("#nuevo").click(function()
		{
		$("#fondo").fadeTo(0,0.5);
		$("#fondo").height($(window).height());
//		$("#titulo").html("AGREGAR USUARIO");
		$("#mensaje1").show(); 
		
		//agrego validacion
		$("#form0 [name=nombre]").focus();
      	$("#form0").submit(function(e) 
		{
		
		e.preventDefault();
		var inp = $('#form0 :input');

		var error = false;
		for(var i = 0; i < inp.length-3; i++) 
		{
			if(inp.eq(i).val() == "" || inp.eq(i).val() == 0) {
				error = true;
			}
			
		}

		if(error) {
			$("#load").html("<b>Rellene los campos en blanco y seleccione una Opcion</b>");
			return false;	
		}
		$("#load").html(img + " guardando datos...");
		$.post("../buzon/Mysql/buzon.php", 
			{
				nom: $("#form0 [name='nombre']").val(),
				ape: $("#form0 [name='apellido']").val(),
				cat: $("#form0 [name='categoria']").val(),
				tip: $("#form0 [name='tipo']").val(),
				sug: $("#form0 [name='sugerencia']").val(),
				cor: $("#form0 [name='correo']").val()
				
				
			},
			function(data) {
					//$("#load").html("<b>Se envio Correctamente</b>");
					$("#mensaje1").hide();
					$("#fondo").hide();
					
					$('#form0').each (function(){
  						this.reset();
					});
					location.href="/portal/";
					
					
			})


			
		})
	
	$(".close").click(function()
		{
			$("#mensaje1").hide();
			$("#fondo").hide();
			$("#load").html("");
			$('#form0 :input').each(function() 
				{
				var type = this.type;
				var tag = this.tagName.toLowerCase();
				if (type == 'text')
					this.value = "";
				if (tag == 'select')
					this.selectedIndex = 0;
				})
		});	


	})
	})
