$(document).ready( function() 
{
	$('a.enviar').click( function() 
	{
		
		if (!_validar_str('ContactoNombre', 'Debe escribir su nombre.')) return false;
		if (!_validar_str('ContactoEmail', 'Debe escribir una dirección de email.')) return false;	
		if (!_validar_str('ContactoTelefono', 'Debe escribir un teléfono de contacto.')) return false;	
		if (!_validar_str('ContactoComentario', 'Debe escribir un comentario o consulta.')) return false;
	
		$.ajax( 
		{
			// url: APP_URL_BASE+'/contacto/enviar',
			url: $('#ContactoForm').attr('action'),
			type: 'POST',
			dataType: 'html',
			data: $('#ContactoForm').serializeArray(),
			async: false,
			success: function(mensaje, estado) {
				alert(mensaje);
				
				if (estado=='success')
				{
					$('#ContactoNombre').val('');
					$('#ContactoDireccion').val('');
					$('#ContactoCp').val('');
					$('#ContactoEmail').val('');
					$('#ContactoTelefono').val('');
					$('#ContactoComentario').val('');
				}
			}
		});
	
		// $('ContactoForm').submit();
		return false;
	});	
});



// funcion de validacion de no_vacio
function _validar_str( id, mensaje )
{
	if( document.getElementById(id).value.length==0 ) 
	{
		alert( mensaje);
		document.getElementById(id).focus();
		return false;
	}
	else
	{
		return true;
	}
}


// funcion de validacion de no_vacio
function _validar_num( id, mensaje )
{
	if( parseFloat( document.getElementById(id).value )==0 )
	{
		alert( mensaje );
		document.getElementById(id).focus();
		return false;
	}
	else
	{
		return true;
	}
}

// toma un valor desde html, verificar que sea un numero y convertirlo 
function _getParseFloat(id)
{
	var i = $(id).value;
	if( i.length>0 )
	{	
		return parseFloat(i);
	}
	else
	{
		return 0;
	} 
}
