var suffix = '';

function check_contacto(seccion){
	if(seccion == 'pie'){
		suffix = '_pie';
	}
	if($('#nombre_contacto'+suffix).val().trim() == '' || $('#nombre_contacto'+suffix).val().trim() == 'ingresa tu nombre'){
		$('#msg_error_contacto'+suffix).html('Debes ingresar tu nombre');
		$('#error_nombre_contacto'+suffix).show();
	}else if($('#email_contacto'+suffix).val().trim() == '' || $('#email_contacto'+suffix).val().trim() == 'ingresa tu e-mail'){
		$('#msg_error_contacto'+suffix).html('Debes ingresar tu email');
		$('#error_nombre_contacto'+suffix).hide();
		$('#error_email_contacto'+suffix).show();
	}else if(!isEmail($('#email_contacto'+suffix).val())){
		$('#msg_error_contacto'+suffix).html('El email ingresado no es válido');
		$('#error_nombre_contacto'+suffix).hide();
		$('#error_email_contacto'+suffix).show();
	}else if($('#mensaje_contacto'+suffix).val().trim() == '' || $('#mensaje_contacto'+suffix).val().trim() == 'ingresa un comentario o sugerencia'){
		$('#msg_error_contacto'+suffix).html('Debes ingresar tu comentario');
		$('#error_nombre_contacto'+suffix).hide();
		$('#error_email_contacto'+suffix).hide();
		$('#error_mensaje_contacto'+suffix).show();
	}else{
		$('#error_nombre_contacto'+suffix).hide();
		$('#error_email_contacto'+suffix).hide();
		$('#error_mensaje_contacto'+suffix).hide();
		$('#msg_error_contacto'+suffix).html('');
		guardar_contacto();
	}
}

function guardar_contacto()
{
	var datos = 'nombre='+$('#nombre_contacto'+suffix).val().trim()+'&email='+$('#email_contacto'+suffix).val().trim();
	datos += '&msg='+$('#mensaje_contacto'+suffix).val().trim(); 
	
	$('#msg_error_contacto'+suffix).html('Enviando...');
	$('#btn_contacto'+suffix).hide();

	$.ajax({  
		type: "POST",  
		url: RUTA+"ajax/guardar_contacto.php",  
		data: datos,  
		success: function(response) {  
			if(response>0){
				borrar_formulario_contacto();
				$('#btn_contacto'+suffix).show();
				$('#msg_error_contacto'+suffix).html('Tu mensaje ha sido enviado.');
			}else{
				$('#btn_contacto'+suffix).show();
				$('#msg_error_contacto'+suffix).html('Ha ocurrido un error al eviar tu mensaje. Por favor vuelve a intentarlo luego.');
			}
		}  
	});  
	return false;
}

function borrar_formulario_contacto(){
	$('#nombre_contacto'+suffix).val('');
	$('#email_contacto'+suffix).val('');
	$('#mensaje_contacto'+suffix).val('');
}
