//wow-card-popup.js (c) 2006 http://warcraftcardgame.com


// Removes leading whitespaces
function LTrim( value ) {

var re = /\s*((\S+\s*)*)/;
return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim( value ) {

var re = /((\s*\S+)*)\s*/;
return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim( value ) {

return LTrim(RTrim(value));

}


function doCardReplace() {
//for reg ex, why is the \x5b in []?  working around stupid browser.  all of them.
//why does \x5d need the same workaround?  who knows!
// matches something of the form [[My Card name ]]
// the \? has to come before the \- for some uknown reason
var regEx = new RegExp ('[\x5b][\x5b]([a-zA-Z0-9_ :,!\x27\.\?\-]*)\x5d\x5d', 'gi') ; //x5b=[ x5d=] \x27='
document.body.innerHTML = document.body.innerHTML.replace(regEx,
function(thematch){ //this function is inside the repalce
    //alert(thematch);
    var namelink = thematch.substring(2,thematch.length-2);
    namelink = trim(namelink);
    var prettyName = namelink;  // at this point we have name how we want to display it
    namelink = namelink.replace(/-/g, "--");
    namelink = namelink.replace(/ /g, "-");
    namelink = namelink.replace(/\?/g, "%3F");
    var namelinkapostrope = namelink.replace(/\x27/g, "\\'"); //make a var that has the ' replaced by \\' for the mouseover
    var newHTML = "<a onmouseover=\"return overlib('<iframe src=http://warcraftcardgame.com/image-cards/" + namelinkapostrope + "/ HEIGHT=420 WIDTH=260></iframe>', STICKY, MOUSEOFF, CAPTION, ' ', HAUTO, VAUTO);\" onmouseout=\"return nd();\" href=\"http://warcraftcardgame.com/cards/" + namelink + "/\">" + prettyName + "</a>";
    return newHTML;
}
);
//"open $1 close" + urlName);

}

