$(function() {
  $('.errores').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
 $('textarea.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('textarea.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  
   $(".buttonesConsultar").click(function() {
		// validate and process form
		// first hide any error messages
    $('.errores').hide();
		 
	var cedula = $("input#cedula2").val();
		if (cedula == "") {
      $("label#ced2_errores").show();
      $("input#cedula2").focus();
      return false;
    }
	var codigo = $("input#codigo").val();
		if (codigo == "") {
      $("label#cod_errores").show();
      $("input#codigo").focus();
      return false;
    }
				
	var dataString = 'cedula='+cedula +'&codigo=' +codigo;
		//alert (dataString);return false;
	 /*	
	  $.ajax({
      type: "POST",
      url: "controlador/consultarQueja.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Informaci&oacute;n Enviada!</h2>")
        .append("<p>Muchas Gracias.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='imagenes/check.gif' />");
        });
      }
     });
	*/	
	$.ajax({
      type: "POST",
      url: "controlador/consultarQueja.php",
      data: dataString,
	  success: function(dataString) {
		     $('#ampliar').html(dataString);

            }
     });
	 
	return false;
	});
  
  
  
  $(".buttones2").click(function() {
		// validate and process form
		// first hide any error messages
    $('.errores').hide();
		
	 
	var nombre = $("input#nombre").val();
		if (nombre == "") {
      $("label#name_errores").show();
      $("input#nombre").focus();
      return false;
    }
	var cedula = $("input#cedula").val();
		if (cedula == "") {
      $("label#ced_errores").show();
      $("input#cedula").focus();
      return false;
    }
	var dir = $("input#direccion").val();
	var telefono = $("input#telefono").val();
		if (telefono == "") {
      $("label#tel_errores").show();
      $("input#telefono").focus();
      return false;
    }
				
	var correo = $("input#email").val();
		if (correo == "") {
      $("label#email_errores").show();
      $("input#email").focus();
      return false;
    }
	if(!$('input#email').correo()){
		$("input#email").focus();
            return false;
         }
		 
	var tema = $("input#tema").val();
		if (tema == "") {
      $("label#tema_errores").show();
      $("input#tema").focus();
      return false;
    }
	 var dep = $("input#dependencia").val();
		if (dep == "") {
      $("label#dep_errores").show();
      $("input#dependencia").focus();
      return false;
    }
	var mensaje = $("textarea#mensaje").val();
	if (mensaje == "") {
      $("label#msg_errores").show();
      $("textarea#mensaje").focus();
      return false;
    }
	
	var dataString = 'dependencia='+dep +'&tema='+tema +'&mensaje='+mensaje +'&nombre='+nombre +'&direccion=' +dir +'&telefono='+telefono +'&email='+correo +'&cedula='+cedula;
		//alert (dataString);return false;
	 
	  $.ajax({
      type: "POST",
      url: "controlador/enviarQueja.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Informaci&oacute;n Enviada!</h2>")
        .append("<p>Muchas Gracias.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='imagenes/check.gif' />");
        });
      }
     });
	/*		
	$.ajax({
      type: "POST",
      url: "controlador/enviarQueja.php",
      data: dataString,
	  success: function(dataString) {
		     $('#contact_form').html(dataString);

            }
     });
	 */
	 
	 
	 
    return false;
	});
	runOnLoad(function(){
  $("input#nombre").select().focus();
});
	
	
	$(".buttones3").click(function() {
		// validate and process form
		// first hide any error messages
    $('.errores').hide();
		
	  var name = $("input#dependencia").val();
		if (name == "") {
      $("label#name_errores").show();
      $("input#dependencia").focus();
      return false;
    }
		var email = $("input#tema").val();
		if (email == "") {
      $("label#email_errores").show();
      $("input#tema").focus();
      return false;
    }
	
	var comentarios = $("textarea#mensaje").val();
	if (comentarios == "") {
      $("label#phone_errores").show();
      $("textarea#mensaje").focus();
      return false;
    }
	
	var dataString = 'dependencia='+name+'&tema='+email +'&mensaje='+ comentarios;
		//alert (dataString);return false;
		
	  $.ajax({
      type: "POST",
      url: "controlador/enviarEtica.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Informaci&oacute;n Enviada!</h2>")
        .append("<p>Muchas Gracias.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='imagenes/check.gif' />");
        });
      }
     });
    return false;
	});
});
// ..........................

	
jQuery.fn.correo=function()
{
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($(this).val()))
{
return true;

}
else
{
alert('Email Invalido');
$(this).focus();
return false;
}
}
