// JavaScript Documento lamardivina.com
var lib_vis=0;
function libro_visitas(id)
{
  URLStr = "respuesta.php"+"?id="+id;
  if(lib_vis)
  {
    if(!lib_vis.closed) lib_vis.close();
  }
  lib_vis = open(URLStr, 'lib_vis', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+600+',height='+400+',left='+10+', top='+10+',screenX='+10+',screenY='+10+'');
}


/*******************************************/
// Funciones de jquery para usar el boletin
/*******************************************/

var $j = jQuery.noConflict();
$j(document).ready(function(){

	$j(".abrirfirmar").click(function(){
      //lo que se hace al abrir el formulario de visitas
	  $j("#capamensajeForm").css("display", "block"); 
	  $j(this).css("display", "none");
	  $j(".cerrarfirmar").css("display", "block");
	  $j("#resultado").html("");
	  
   });


	$j(".cerrarfirmar").click(function(){
      //lo que se hace al cerrar el formulario de visitas
	  $j("#imgcaptcha").load("./php/imgcaptcha.php");
	  $j("#capamensajeForm").css("display", "none");
	  $j(this).css("display", "none");
	  $j(".abrirfirmar").css("display", "block");
	  $j("#captchaverif").attr("value", "");
   });

   $j("#recargarcaptcha").click(function(){
      //lo que se desee hacer al recibir un clic el checkbox
	  $j("#imgcaptcha").load("./php/imgcaptcha.php");
   });



	var options = { 
				target: '#resultado',   // target element(s) to be updated with server response 
 
        // other available options: 
				url: './php/guardar.php'       // override for form's 'action' attribute 
		//	type:     'POST'      // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
			};	

	// validando el formulario mientras se teclea y cuando se envía
	$j("#mensajeForm").validate({
		rules: {
			nombre: {
				required: true,
				minlength: 3
			},
			email: {
				email: true
			},
			mensaje: {
				required: true,
				minlength: 4
			},
			captchaverif: {
				required: true,
				rangelength: [5, 5]

			}
		},
		messages: {
			nombre: {
				required: "Por favor, ingresa tu nombre",
				minlength: "El nombre debe tener al menos 3 caracteres"
			},
			email: {
				email: "Por favor, ingrese un email válido"
			},
			mensaje: {
				required: "Deja un mensaje",
				minlength: "El mensaje debe tener al menos 4 caracteres"
			},
			captchaverif: {
				required: "Por favor, ingresa el código de la imagen",
				rangelength: "El código se compone de 5 caracteres"
			}
		},
		submitHandler: function(form) {
					$j("#capamensajeForm").hide();
					$j(".abrirfirmar").css("display", "block");
					$j(".cerrarfirmar").css("display", "none");
					
					$j("#mensajeForm").ajaxSubmit(options);
					
					$j("#captchaverif").attr("value", "");
					$j("#mensaje").attr("value", "");
					return false;
			}
	});

});