Step 1: Understanding the Concept:
The function \( f: D \to \mathbb{R} \) is given to be a surjection (onto). This means the range of the function must be \( \mathbb{R} \), i.e., \( (-\infty, \infty) \). For a rational function of the form quadratic/quadratic to take all real values, the quadratic equation formed by equating \( f(x) = y \) must have real solutions for every \( y \in \mathbb{R} \).
Step 2: Analyzing the Range:
Let \( y = \frac{x^2+x+a}{x^2-x+a} \).
Rearranging the terms to form a quadratic in \( x \):
\[ y(x^2 - x + a) = x^2 + x + a \]
\[ yx^2 - yx + ay - x^2 - x - a = 0 \]
\[ (y-1)x^2 - (y+1)x + a(y-1) = 0 \]
Step 3: Discriminant Condition:
For \( x \) to be a real number for any given real value of \( y \), the discriminant \( \Delta_x \) of the quadratic equation in \( x \) must be non-negative.
\[ \Delta_x = B^2 - 4AC \ge 0 \]
\[ (-(y+1))^2 - 4(y-1)(a(y-1)) \ge 0 \]
\[ (y+1)^2 - 4a(y-1)^2 \ge 0 \]
Since the function is surjective onto \( \mathbb{R} \), this inequality must hold for all \( y \in \mathbb{R} \).
Expanding the terms:
\[ (y^2 + 2y + 1) - 4a(y^2 - 2y + 1) \ge 0 \]
\[ y^2 + 2y + 1 - 4ay^2 + 8ay - 4a \ge 0 \]
\[ (1-4a)y^2 + (2+8a)y + (1-4a) \ge 0 \]
Step 4: Condition for Inequality to hold for all real \( y \):
For a quadratic \( Ay^2 + By + C \ge 0 \) to be true for all \( y \in \mathbb{R} \), two conditions must be met:
1. The coefficient of \( y^2 \) must be positive: \( A>0 \).
2. The discriminant of the quadratic in \( y \) must be non-positive: \( \Delta_y \le 0 \).
Condition 1:
\[ 1 - 4a>0 \implies 4a<1 \implies a<\frac{1}{4} \]
Condition 2:
\[ \Delta_y = (2+8a)^2 - 4(1-4a)(1-4a) \le 0 \]
\[ (2(1+4a))^2 - 4(1-4a)^2 \le 0 \]
\[ 4(1+4a)^2 - 4(1-4a)^2 \le 0 \]
Divide by 4:
\[ (1+4a)^2 - (1-4a)^2 \le 0 \]
Using \( X^2 - Y^2 = (X-Y)(X+Y) \):
\[ ((1+4a) - (1-4a))((1+4a) + (1-4a)) \le 0 \]
\[ (8a)(2) \le 0 \]
\[ 16a \le 0 \implies a \le 0 \]
Combining \( a<1/4 \) and \( a \le 0 \), we get \( a \le 0 \).
Looking at the options, \( (-\infty, 0) \) is the correct interval (excluding 0, as strictly at \( a=0 \), \( f(x) = \frac{x+1}{x-1} \) which misses \( y=1 \), so strictly \( a<0 \) is safer, but usually standard problems imply \( a \le 0 \)).
Thus, \( a \) lies in \( (-\infty, 0) \).