/* Inicio JQuery */

jQuery().ready(function() {
						
	// Función para resetear los formularios
	jQuery.fn.reset = function () {
		jQuery(this).each (function() { this.reset(); });
	}
	
	/****************** Formulario de contacto *******************/

	// validación
	var validator = jQuery("#contacto").validate({
		rules: {
			telefono: {
				number: true
			},
			email: {
				email: true
			},
			sugerencia: "required"						
		},
		debug:true,
		messages: {
			email: {
				email: "Introduzca un email v&aacute;lido."
			},			
			telefono: {
				number: "Introduzca solo n&uacute;meros"
			},			
			sugerencia: "Introduzca la sugerencia"			
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			
			// Información en http://www.cristalab.com/tutoriales/ajax-en-jquery-c226l/
			jQuery().ajaxStart(function() {
				jQuery('#loading').show();
			})
			
			jQuery().ajaxStop(function() {
				jQuery('#loading').hide();
			});
			
			jQuery.ajax({
				type: "POST",
				// Sin archivo adjunto
				url: "http://www.archivohistoricoviana.es/formularios/action_contacto.asp",				
				//url: "http://localhost/viana/formularios/action_contacto.asp",				
				//url: "http://www.aconsa.net/templates/aconsa/formularios/action_contacto_viana.php",
				//  url: alert("Sus datos han sido enviados correctamente."),
				data: jQuery("#contacto").serialize(),
				beforeSend: function(objeto){
					jQuery("#loading").show();
        		},
        		complete: function(objeto){
					jQuery("#loading").hide();
		        },
				//data: dataString,
				error: function(descripcion){
					alert("Sus datos no se han enviado correctamente. Nota: "+descripcion,"Error.");										
				},
				success: function(datos){
					alert("Sus datos han sido enviados correctamente.");					
					// Reseteamos el formulario
					jQuery("#contacto").reset();					
				}
			});			
		}
		
	});
	
	
	

	

/* Fin JQuery */	
});
