A major theme of John McCain’s campaign is that he has far more experience in foreign affairs than does Barack Obama. McCain has now escalated his attacks by targeting Obama’s judgment as well — especially the latter’s pessimism about the effectiveness of the surge in Iraq.

There is little doubt about McCain’s lengthier foreign policy experience. But it is not at all apparent that his judgment is superior to Obama’s. Indeed, the record indicates that McCain’s own judgment is alarmingly bad.

Even if one concedes that Obama was excessively negative about the surge’s prospects for success (and the jury may be out on that point for months or even years to come), McCain’s own prognostications on Iraq have repeatedly been off the mark. He was not prescient about the course of the war: As senior member of the Senate Armed Services Committee prior to the invasion, McCain predicted Iraq would be a quick and easy victory, and even told MSNBC he had “no doubt” U.S. troops “will be welcomed as liberators.”

There have been recent episodes in which McCain has missed even the most basic facts about foreign policy. During a recent CNN interview, McCain said the surge of U.S. forces, which began in the spring of 2007, led to the Sunni Awakening — which started in early autumn of 2006, months before the surge was even announced.

Despite McCain’s multiple trips to Iraq, he still manages to mangle facts on the ground. As a member of a senatorial delegation visiting Iraq this year, he erroneously accused Iran of aiding al Qaeda and suffered the embarrassment of an on-camera correction by his friend and fellow hawk, Sen. Joe Lieberman, that Tehran was aiding “Shiite extremists,” not the Sunni zealots of al Qaeda. Yet, during a Senate hearing a few weeks later, McCain committed a similar gaffe. He asked Gen. David Petraeus to confirm that al Qaeda was far more than “an obscure sect of the Shiites,” and then, apparently catching himself, added, “or Sunnis or anybody else.”

McCain apparently is not even certain about Iraq’s geographic location. He recently referred to a nonexistent “Iraq-Pakistan border.” (The two countries are separated by more than 800 miles of Iranian territory.)

Far worse than such embarrassing factual errors, though, have been his shockingly careless — and at times tasteless and insensitive — off-the-cuff comments on various topics. His flip statement about keeping U.S. troops in Iraq for a hundred years is probably the least serious verbal blunder in an ever-mounting total. Leaving aside the key point that fractious Iraq is nothing like stable South Korea (McCain’s model for an extended troop presence), his comment was still damaging because it ignored the probable reaction in the Muslim world. Al Qaeda and other radical Islamic groups repeatedly charge that the U.S. is determined to undermine their civilization and act as an imperial hegemon in their region. McCain’s “100 years in Iraq” banner gives those allegations credibility and puts moderate Muslims on the defensive.

But that comment was well-thought-out compared to some others. McCain’s “joke” at an April 2007 campaign stop, in which he sang “bomb bomb bomb, bomb bomb Iran” to the tune of a Beach Boys song, was beyond tasteless. This month, he again offended basic sensibilities when he joked that despite the imposition of economic sanctions, America’s unimpeded sale of cigarettes to Iran might be a good thing because “maybe that’s a way of killing ‘em.”

At best, the senator has a warped sense of humor. But such gaffes also betray a disturbing lack of judgment.

Foreign policy is serious business, and America needs a president who carefully considers his comments rather than shoots from the hip. The world is always watching and listening, and such thoughtless remarks can do tremendous damage to America’s already tattered reputation.

McCain’s record shows clearly that he is a verbal loose cannon, and would be a clear and present danger in the Oval Office.