
108 Cal.Rptr.2d 282 (2001)
90 Cal.App.4th 149
CONSTRUCTION PROTECTIVE SERVICES, INC., Plaintiff and Appellant,
v.
TIG SPECIALTY INSURANCE COMPANY, Defendant and Respondent.
No. B142811.
Court of Appeal, Second District, Division Three.
June 27, 2001.
Review Granted October 24, 2001.
*283 Devirian & Shinmoto and Donald B. Devirian, Los Angeles, for Plaintiff and Appellant.
Selman-Breitman, Alan B. Yuter, Los Angeles, and Rachel E. Hobbs, for Defendant and Respondent.
KLEIN, P.J.
Plaintiff and appellant Construction Protective Services, Inc. (CPS) appeals an order of dismissal in favor of defendant and respondent TIG Specialty Insurance Company (TIG, or the insurer) following the sustaining without leave to amend of a demurrer interposed by TIG to CPS's original complaint.[1]
The essential issue presented is whether a cause of action is stated against the insurer for a failure to defend.
*284 In the underlying action, CPS sued SHC/Mark Diversified (SHC), the general contractor, for payment for security services it rendered at a construction site.[2] In its answer, SHC pled as an offset that CPS's failure to perform the contract had resulted in property damage to the project. CPS tendered the defense of the affirmative defense to TIG, which declined the matter.
CPS then brought this action against TIG. We conclude the instant complaint adequately pleads a breach of TIG's duty to defend a suit for damages against its insured. In the underlying action, CPS and SHC were parties to a suit in that they were "involved in actual court proceedings initiated by the filing of a complaint. (Black's Law Diet. (6th ed.1990) p. 1434, col. 1....)" (Foster-Gardner, Inc. v. National Union Fire Ins. Co. (1998) 18 Cal.4th 857, 878-879, 77 Cal.Rptr.2d 107, 959 P.2d 265.) Further, SHC's affirmative defense of an offset had the potential to negate any recovery by CPS and to lead to a damage award in favor of SHC, the defendant in the underlying action. The mere fact SHC elected to assert its claim against CPS by way of an offset pled in the answer, in accordance with section 431.70, rather than by way of a crosscomplaint, did not absolve TIG of the duty to defend its insured.

FACTUAL AND PROCEDURAL BACKGROUND

1. The underlying litigation.

SHC was the general contractor on an Oakland high school construction project. SHC hired CPS to provide security services at the job site. On October 19,1996, the property was damaged by fire.
On May 20, 1998, CPS filed suit against SHC, alleging it was owed $26,790 for construction site guard services on the project.
SHC answered, generally denying the allegations and pleading numerous affirmative defenses, including its entitlement to "an offset pursuant to common law and/or Code of Civil Procedure section 431.70 as a result of [CPS's] conduct, including, but not limited to, numerous deficiencies in performance and its failure to perform its contract relating to security services, which resulted in damage to the construction project...."

2. The instant complaint.

On February 10, 2000, CPS, TIG's insured, filed suit against TIG for breach of contract and breach of the implied covenant of good faith and fair dealing. CPS alleged:
TIG issued CPS a comprehensive general liability (CGL) insurance policy. "Under the terms of the insurance policy, [TIG] agreed to indemnify [CPS], up to the amount of $1,000,000.00, for claims against [CPS] by third parties based upon bodily injury or property damage, and to defend plaintiff in any civil action or suit seeking such damages.'" (Italics added.)[3] On May 20, 1998, CPS filed an action against *285 SHC to recover $26,790 for security services rendered at the school construction site. In answering the complaint, SHC asserted the damages arising out of the school fire to offset the sum due and owing to CPS for services rendered. CPS tendered the defense of said affirmative defense to TIG. TIG refused the tender. Consequently, CPS was required to employ its own counsel to defend against the affirmative defense. On April 29, 1999, CPS "settled the obligation owing to it by [SHC] for the sum of $20,000.00, thereby forgiving the principal sum of $6,790.00, together with interest in the sum of $5,804.00 and attorney's fees and costs in the sum of $13,955.00, for a total of $26,589.00." In addition, CPS's complaint prayed for punitive damages.

3. Demurrer and opposition thereto.

TIG demurred, arguing SHC's affirmative defense did not constitute a "suit" as defined in the policy and in case law, and therefore there was no suit triggering a defense duty on TIG's part. TIG further contended in its points and authorities in support of the demurrer that in invoking the defense of an offset, SHC merely sought to mitigate its own damages, but did not seek any "damages" against CPS, as required for coverage. TIG also asserted it had contributed to a global settlement agreement, wherein SHC expressly agreed not to pursue any claims against CPS arising out of the fire loss, and therefore SHC's claim had no potential to result in a judgment holding CPS liable for damages.
CPS argued the demurrer should be overruled because SHC's affirmative defense was a "suit" sufficient to trigger the insurer's duty to defend. Further, merely because SHC had asserted its claim against TIG by way of an affirmative defense rather than by way of a cross-complaint should not enable TIG to avoid its obligation under the policy.

4. Trial court's ruling.

On May 2, 2000, the matter came on for hearing. The trial court sustained the demurrer without leave to amend, ruling that "under California law, an insurer does not have a duty to defend against affirmative defenses raised in response to an insured's complaint against another party."
CPS filed a timely notice of appeal from the order of dismissal.

CONTENTIONS
CPS contends an insurance carrier may have a duty to defend an affirmative defense, and an offset can constitute damages under an insurance policy.

DISCUSSION

1. Standard of appellate review.

A demurrer serves to test the sufficiency of a pleading by raising questions of law. (Buford v. State of California (1980) 104 Cal.App.3d 811, 818, 164 Cal.Rptr. 264.) When a demurrer is sustained, we determine whether the complaint states facts sufficient to constitute a *286 cause of action. (Blank v. Kirwan (1985) 39 Cal.3d 311, 318, 216 Cal.Rptr. 718, 703 P.2d 58.) The allegations are regarded as true and are liberally construed with a view to attaining substantial justice. (Shaeffer v. State of California (1970) 3 Cal.App.3d 348, 354, 83 Cal.Rptr. 347; King v. Central Bank (1977) 18 Cal.3d 840, 843,135 Cal.Rptr. 771, 558 P.2d 857.)
In addition, other relevant matters which are properly the subject of judicial notice (Evid.Code, § 452), such as CPS's underlying complaint against SHC and SHC's answer thereto, may be treated as having been pled. (Marina Tenants Assn. v. Deauville Marina Development Co. (1986) 181 Cal.App.3d 122, 128, 226 Cal.Rptr. 321.)
Generally, when a demurrer is sustained without leave to amend, we decide whether there is a reasonable possibility the defect can be cured by amendment. If it can, the trial court abused its discretion and we reverse; if not, there was no abuse of discretion and we affirm. (Blank v. Kirwan, supra, 39 Cal.3d at p. 318, 216 Cal.Rptr. 718, 703 P.2d 58.)
"However, where, as here, a demurrer is sustained to the original complaint, denial of leave to amend constitutes an abuse of discretion if the pleading does not show on its face that it is incapable of amendment. (King v. Mortimer (1948) 83 Cal.App.2d 153, 158 [188 P.2d 502].)" (California Federal Bank v. Matreyek (1992) 8 Cal.App.4th 125, 130-131, 10 Cal. Rptr.2d 58.)

2. Trial court should have overruled TIG's demurrer because CPS alleged a "suit" seeking "damages".

The key allegations are: "Under the terms of the insurance policy, [TIG] agreed to indemnify [CPS], up to the amount of $1,000,000.00, for claims against [CPS] by third parties based upon bodily injury or property damage, and to defend plaintiff in any civil action or suit seeking such damages." (Italics added.) In the underlying action by CPS, SHC's answer pled as an affirmative defense an offset for property damage arising out of the fire, implicating TIG's duty to provide CPS with a defense thereto.
Thus, under the policy as alleged, TIG was required to defend CPS in a "suit seeking ... damages." Nonetheless, TIG asserts SHC's affirmative defense seeking an offset was merely a claim, and not a "suit" that could render CPS legally obligated to pay "damages."
As explained, CPS adequately alleged a suit seeking damages so as to give rise to the duty to defend.

a. SHC's affirmative defense comes within the literal definition of "suit" as adopted in Foster-Gardner.

In Foster-Gardner, Inc., supra, 18 Cal.4th at page 860, 77 Cal.Rptr.2d 107, 959 P.2d 265, the Supreme Court was called upon to determine whether environmental agency activity prior to the filing of a complaint, such as an order notifying the insured that it is a responsible party for pollution and requiring remediation, is a "suit" triggering the insurer's duty to defend under a CGL policy.
Foster-Gardner held the word "suit" in the policies meant a civil action commenced by the filing of a complaint; anything short of this was a "claim." (Foster-Gardner, Inc., supra, 18 Cal.4th at p. 878, 77 Cal.Rptr.2d 107, 959 P.2d 265.) Because the environmental agency's order was initiated prior to the filing of a complaint and did not initiate a suit within the meaning of the policies, it did not give rise to a duty to defend. (Id. at pp. 878-879, 77 Cal.Rptr.2d 107, 959 P.2d 265.)
*287 In arriving at a definition of "suit," Foster-Gardner considered both a "literal meaning" approach and "functional" and "hybrid" approaches. (Foster-Gardner, Inc., supra, 18 Cal.4th at pp. 869-874, 77 Cal.Rptr.2d 107, 959 P.2d 265.) The court settled on the most restrictive definition, the "literal meaning" approach, so as to create a "bright-line rule." (Id. at p. 887, 77 Cal.Rptr.2d 107, 959 P.2d 265.) In so doing, the court stated: "The primary attribute of a `suit,' as that term is commonly understood, is that parties to an action are involved in actual court proceedings initiated by the filing of a complaint. (Black's Law Diet. (6th ed.1990) p. 1434, col. 1 [`Suit' is `[a] generic term, of comprehensive signification, referring to any proceeding by one person or persons against another or others in a court of law in which the plaintiff pursues, in such court, the remedy which the law affords him ... Term "suit" has generally been replaced by term "action"; which includes both actions at law and in equity.']; Webster's New Collegiate Diet. (9th ed.1987) p. 1180 [`suit' is `an action or process in a court for the recovery of a right or claim'].) As the Court of Appeal in Fireman's Fund [v. Superior Court (1997), 65 Cal.App.4th 1205, 78 Cal.Rptr.2d 418] stated, `A "claim" can be any number of things, none of which rise to the formal level of a suitit may be a demand for payment communicated in a letter, or a document filed to protect an injured party's right to sue a governmental entity, or the document used to initiate a wide variety of administrative proceedings.... While a claim may ultimately ripen into a suit, "claim" and "suit" are not synonymous.' (Fireman's Fund supra, 65 Cal. App.4th at p. 1216 [78 Cal.Rptr.2d 418]; ... Safeco Surplus Lines Co. v. Employer's Reinsurance Corp. (1992) 11 Cal. App.4th 1403, 1408 [15 Cal.Rptr.2d 58] [`"[T]here is an inherent difference between the "making" of a claim and the "bringing" of a lawsuit. The former, by its very nature, involves some kind of notice. The latter only requires the filing of a complaint."'])" (Foster-Gardner, Inc., supra, 18 Cal.4th at pp. 878-879, 77 Cal. Rptr.2d 107, 959 P.2d 265, italics added; accord Certain Underwriters at Lloyd's of London v. Superior Court (hereafter, Certain Underwriters) (2001) 24 Cal.4th 945, 959-960, 103 Cal.Rptr.2d 672, 16 P.3d 94.)
The instant fact situation falls within the Foster-Gardner definition of "suit," under the most restrictive definition. CPS and SHC were "involved in actual court proceedings initiated by the filing of a complaint. (Black's Law Diet. (6th ed.1990) p. 1434, col. 1....)" (Foster-Gardner, Inc., supra, 18 Cal.4th at pp. 878-879, 77 Cal.Rptr.2d 107, 959 P.2d 265.) In response to CPS's lawsuit, SHC pled as an affirmative defense its right to an offset for property damage (covered by the CGL policy) caused by CPS's failure to perform its contract for security services. Because a "`suit' is `an action or process in a court for the recovery of a right or claim'" (id. at p. 879, 77 Cal.Rptr.2d 107, 959 P.2d 265), SHC's pleading of an offset was more than a "claim" against CPSit rose to the level of a suit.

b. SHC's assertion of an offset for property damages sought, and had the potential to result in, an award of "damages" against CPS.

The instant policy obligated TIG to defend a "suit seeking ... damages." (Italics added.) It is "in a `suit' that `damages' are fixed in their amount through the court's order. [Fn. omitted.]" (Certain Underwriters, supra, 24 Cal.4th at p. 962, 103 Cal.Rptr.2d 672, 16 P.3d 94.) Damages are "money ordered by a court." (Ibid.) An offset comes within this definition of damages.
*288 Section 431.70, relating to the pleading of an offset, states in relevant part: "Where cross-demands for money have existed between persons at any point in time when neither demand was barred by the statute of limitations, and an action is thereafter commenced by one such person, the other person may assert in the answer the defense of payment in that the two demands are compensated so far as they equal each other, notwithstanding that an independent action asserting the person's claim would at the time of filing the answer be barred by the statute of limitations. If the cross-demand would otherwise be barred by the statute of limitations, the relief accorded under this section shall not exceed the value of the relief granted to the other party." (Italics added.) Thus, where the cross-demand is not otherwise time-barred, the relief accorded pursuant to an offset may exceed the value of the relief granted to the plaintiff. (5 Witkin, Cal. Procedure (4th ed. 1997) Pleading, § 1091(2), p. 548.)
Here, there was a written contract between SHC and CPS for security services. The agreement was dated March 25, 1996, with various written amendments after that date. The statute of limitations for breach of a written contract is four years. (§ 337, subd. 1.) Thus, at the time SHC filed its answer asserting the offset, on September 2, 1998, SHC's cause of action against CPS was not time-barred. Accordingly, SHC's offset against CPS could have negated the value of the relief awarded to CPS and could have resulted in a net award of damages in favor of SHC.
Consequently, there is no merit to TIG's contention that by invoking the defense of an offset, SHC was not seeking any damages for harm suffered. SHC elected to assert its claim against CPS by way of an offset pled in the answer, in accordance with section 431.70, rather than by way of a cross-complaint. SHC's election of that form of pleading does not alter the fact that in this "suit" between CPS and SHC, the latter's pleading of an offset had the potential to negate any recovery by CPS and to lead to a damage award in favor of SHC, the defendant.
Accordingly, CPS pled sufficient facts to state a cause of action against TIG for breach of its duty to defend.

3. Pertinent case law decided before Foster-Gardner.

Although we conclude this matter is controlled by Foster-Gardner's definition of "suit" and Certain Underwriters' definition of "damages," we look to earlier case law for additional guidance.
American Home Assur. Co. v. Miller (9th Cir.1983) 717 F.2d 1310, is consistent with our analysis. There, a client brought a legal malpractice action. (Id. at p. 1311.) The attorney's carrier handled the defense and obtained a dismissal on statute of limitations grounds. (Ibid.) The attorney then sued the client for unpaid fees in unrelated matters, and the client's answer prayed for a monetary offset for damages suffered from the malpractice alleged in the first suit. (Ibid.) When the attorney's malpractice carrier declined his request that it represent him on the offset claim, a declaratory relief action ensued in the federal district court in Arizona. (Ibid.) The Ninth Circuit reversed the summary judgment obtained by the insurer, ruling the offset claim was in substance and effect a suit against the insured seeking damages for legal malpractice. (Id. at pp. 1311-1312.)
In 3250 Wilshire Boulevard Bldg. v. Employers Ins. of Wausau (hereafter 3250 Wilshire) (1995) 39 Cal.App.4th 1277, 46 Cal.Rptr.2d 399, plaintiff/lessor sued a tenant for breaches of the lease, including failure to pay rent. (Id at p. 1279, 46 *289 Cal.Rptr.2d 399.) The tenant counterclaimed for damages for breach of the lease, and his answer contained similar allegations as defenses. (Ibid.) Lessor tendered the defense of the counterclaim to its business liability insurer, which accepted the tender and eventually settled the counterclaim by paying the tenant $50,000. (Ibid.) Lessor then demanded that the insurer provide it with "`a defense to' [the tenant's] defenses." (Ibid.) The insurer refused. Lessor then prosecuted its claims against the tenant to a successful conclusion, incurring legal fees in the process. (Ibid.)
Lessor then sued the insurer, alleging its "refusal to `defend it' against [the tenant's] defenses was a breach of the insurance contract and of the implied covenant of good faith and fair dealing." (3250 Wilshire, supra, 39 Cal.App.4th at p. 1279, 46 Cal.Rptr.2d 399.) The insurer demurred, contending the liability policy did not obligate it to furnish legal services for lessor's prosecution of its action against the tenant, "because [the tenant's] defenses pleaded in that action had no potential to result in a judgment holding [lessor] liable to pay damages to [the tenant]." (Id. at p. 1280, 46 Cal.Rptr.2d 399, italics added.) The trial court agreed, sustained the demurrer without leave to amend, and dismissed lessor's action. (Ibid.)
The reviewing court found the trial court's ruling was correct and affirmed. (3250 Wilshire, supra, 39 Cal.App.4th at p. 1280, 46 Cal.Rptr.2d 399.) Under the policy, the insurer had the duty to defend any suit seeking damages because of bodily injury, property damage, personal injury or advertising injury. (Ibid.) "This provision did not obligate [the insurer] to prosecute [lessor's] claims against [the tenant], because neither the prosecution of [lessor's] prima facie case nor the defeat of [the tenant's] defenses thereto could be considered the defense of a suit seeking damages." (Ibid.)[4]
3250 Wilshire is clearly distinguishable from the instant case. In 3250 Wilshire, the offset claim was extinguished by settlement, so that "[the tenant's] defenses pleaded in that action had no potential to result in a judgment holding [lessor] liable to pay damages to [the tenant]." (3250 Wilshire, supra, 39 Cal.App.4th at p. 1280, 46 Cal.Rptr.2d 399, italics added.) Here, in contrast, as explained above, SHC's defense of an offset could have negated any recovery by CPS and had the potential to result in a judgment holding CPS liable to pay damages to SHC. Under these circumstances a cause of action is stated for a failure to defend.

4. The effect of the alleged TIG/SHC settlement.

Separately, TIG contends it contributed to a global settlement agreement, wherein SHC expressly agreed not to pursue any claims against CPS arising out of the fire loss. Therefore, according to TIG, SHC's allegation of an offset was not a viable affirmative defense and had no potential to result in a judgment holding CPS liable for damages and hence, TIG had no duty to defend. This contention on appeal is improper as it is not based on the allegations *290 of the complaint or any materials before the court by way of judicial notice. (Blank v. Kirwan, supra, 39 Cal.3d at p. 318, 216 Cal.Rptr. 718, 703 P.2d 58; Marina Tenants Assn., supra, 181 Cal.App.3d at pp. 127-128, 226 Cal.Rptr. 321.)
Further, TIG's contention conflicts with the allegations of the complaint, which are regarded as true for purposes of demurrer. (Shaeffer v. State of California, supra, 3 Cal.App.3d at p. 354, 83 Cal.Rptr. 347.) The complaint alleges that TIG compromised and settled SHC's claim "without obtaining a release of [SHC's] claims against [CPS] arising out of the fire...." The question of whether SHC's assertion of an offset was barred by a settlement or remained a viable affirmative defense cannot be resolved at the pleading stage.
However, assuming arguendo the insurer had settled with SHC and obtained release of its insured so that SHC's claims against CPS were extinguished, once SHC pled an offset against CPS, the insurer would have been obligated to defend, if only to come into court to establish that SHC already had relinquished any rights it may have had to pursue CPS for damages. As stated in Horace Mann Ins. Co. v. Barbara B. (1993) 4 Cal.4th 1076, 1086, 17 Cal.Rptr.2d 210, 846 P.2d 792, an insured buys liability insurance in large part to secure a defense against all suits potentially within policy coverage, "even frivolous [ones] unjustly brought."

DISPOSITION
The order is reversed. CPS to recover costs on appeal.
CROSKEY, J., and ALDRICH, J., concur.
NOTES
[1]  An order of dismissal signed by a trial court and filed in the action constitutes a judgment and is effective for all purposes. (Code Civ. Proc. § 58Id.) All further statutory references are to the Code of Civil Procedure, unless otherwise indicated.
[2]  The pleadings in the underlying action are before this court pursuant to a grant of TIG's request for judicial notice.
[3]  CPS did not append a copy of the policy to the complaint as an exhibit. Where a written instrument is the foundation of a cause of action, it may be pleaded by setting it forth in haec verba in the body of the complaint or as a copy attached and incorporated by reference. (Wise v. Southern Pacific Co. (1963) 223 Cal.App.2d 50, 59, 35 Cal.Rptr. 652, disapproved on other grounds in Applied Equipment Corp. v. Litton Saudi Arabia Ltd. (1994) 7 Cal.4th 503, 521, fn. 10, 28 Cal.Rptr.2d 475, 869 P.2d 454; see generally, 4 Witkin, Cal. Procedure (4th ed. 1997) Pleading, §§ 388, 389, 479.) "The other method of pleading a written contract is according to its legal effect, by alleging the making, and then proceeding to allege the substance of its relevant terms. This is more difficult, for it requires a careful analysis of the instrument, comprehensiveness in statement, and avoidance of legal conclusions, and it involves the danger of variance where the instrument proved differs from that alleged; it is not frequently employed. Nevertheless, it is an established method. [Citations.]" (4 Witkin, Pleading, supra, § 480, p. 573.)
[4]  3250 Wilshire also ruled that Miller, supra, 717 F.2d 1310, was nonbinding because it was decided under Arizona law, and that it was distinguishable because the transactions which formed the basis of the client's offset claim against the attorney were unrelated to the transactions on which the attorney was suing. 3250 Wilshire also observed that although the offset claims in Miller could not be the subject of affirmative relief because barred by the statute of limitations, they remained legally viable defenses, whereas the tenant's offset claims in 3250 Wilshire were liquidated, paid, and extinguished by the settlement. (3250 Wilshire, supra, 39 Cal. App.4th at p. 1280, 46 Cal.Rptr.2d 399.)
