While the lead in “40 Days and 40 Nights” eventually went to heartthrob Josh Hartnett, director Michael Lehmann initially had another choice in mind — “That 70’s Show” star Ashton Kutcher.

The choice is a telling one, as Lehmann’s film shares one common trait with sitcoms in general. The plot and the jokes are substantial enough to fill up a solid, hilarious 22 minutes. Unfortunately, “40 Days and 40 Nights” attempts to be a real movie, complete with a silver-screen hunk, lots of unnecessary raunchiness, and an extra 70 or so unfunny minutes.

Lehmann can’t be faulted for trying, however. He pumps the abstinence jokes until they’re completely spent. Avoiding excessive preachiness or romantic comedy mock-misfortunes, “40 Days and 40 Nights” at least has fun with itself and its likable cast.

Hartnett takes the lead as Matt Sullivan, a down-on-his-luck schlub whose girlfriend Nicole (Vinessa Shaw) leaves him for “the youngest executive vice president at Morgan Stanley.” After six months he still can’t sleep with another girl without imagining a giant black hole forming above the bed.

He sees the light after a talk with his brother, a rather anxious, sex-starved priest in training. Despite his brother’s skepticism, Matt decides to forsake “sex and all things sex-like” for Lent. For a while, he’s in guy heaven. After disposing of his treasure trove of porn, Matt takes up building model cars. But his cheerfulness quickly degenerates into what can only be described as twitchiness — suddenly, everything around him reminds him of sex, including fruits and power outlets and bagels (you figure it out).

The ensuing plot sequence is entirely predictable. Matt finds the girl of his dreams, Erica (Shannyn Sossamon), at the mecca of meeting places for urban singles — the Laundromat. They date cautiously and sexlessly as Matt’s office starts an Internet betting pool to guess when the poor boy will finally break the vow. It’s Silicon Valley before the bust, and the gambling money starts rolling in the thousands, especially when Matt’s ex gets involved.

After an engaging set-up, Lehmann lets his film coast on the same regurgitated jokes. Matt confronts a number of temptations as gorgeous women try to seduce him so they can cash in on the pool. When he’s not crossing his legs to avoid getting sprung, Matt spends his time imagining women everywhere stark naked and ready to — um — pounce. So, in fact, he’s always trying not to get sprung. That’s it. That’s the joke.

In other words, “40 Days and 40 Nights” is the converse of any other sex movie, in which the characters are trying desperately to get laid. In both cases, the erection (or lack of erection) jokes get old fast. By making sex a taboo, Lehmann forces sex constantly into the spotlight, much more than do films that actually purport to be about sex. When Matt’s 40 days are up, the audience is so sick of sex that they’re ready for another round of abstinence.

Or perhaps that only applies for women. The film certainly targets men, who probably find the plot a little more amusing — if only out of the deepest sympathy for a guy who can’t even jack off. And if all else fails the men in the audience can stare at the endless parade of nude women to amuse themselves, not to mention Matt’s dream in which he’s floating over billowy clouds of — breasts.

Without the sex jokes, there isn’t a lot left of Lehmann’s film. The romantic comedy portion gets only second billing to the raunchy humor. Hartnett and Sossamon have decent chemistry, but there isn’t enough time for sparks to fly. Or maybe there isn’t enough sex for sparks to fly.

Indeed, screenwriter Rob Perez can’t seem to tell the difference between real and sexual relationships, nor does he understand that the former can exist without the latter. While Matt constantly espouses his theory of “connecting on a whole new level” with Erica, the connection is virtually undetectable. It seems that a sex-free world is in fact a world that precludes interaction between men and women, a rather depressing conclusion.

In spite of its flaws, and its rather insulting depiction of both men and women, “40 Days and 40 Nights” has enough ups to make it enjoyable. Hartnett is always a pleasure to watch (“Pearl Harbor” aside), and his bumbling, nervous portrayal provides a good contrast to the deadpan sarcasm of his costars, who eerily resemble rescued extras from “Friends.”

Lehmann has fallen a long way from the biting dark comedy of his 1989 film “Heathers,” but he’s still good for a few laughs. His latest film’s humor is less effective and more repetitive, stretched taut over a long running time. But hey, if “Friends” is a repeat, “40 Days and 40 Nights” may be a satisfying substitute.