var WowheadObject =
{ 
_url:null,
_post:null,
_callback:null,
handleSuccess:function(o)
{ 
    if(this._callback) {
        this._callback(o.responseXML);
    }
}, 
handleFailure:function(o)
{ 
},
startRequest:function()
{
    YAHOO.util.Connect.initHeader('Chat-Request', this._post);
    YAHOO.util.Connect.asyncRequest('POST', this._url, wowheadCallback, this._post);
}
};
var wowheadCallback = 
{ 
success:WowheadObject.handleSuccess, 
failure:WowheadObject.handleFailure, 
scope:WowheadObject 
};

function whr(u, f, p)
{
    var r = false;
    if (!u) { return false; }

    if (window.XMLHttpRequest) {
        r = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            r = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                r = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            }
        }
    }

    if (!r) { return false; }

    r.onreadystatechange = function() {
        if(r.readyState == 4) {
            f(r, u, p);
        }
    }
    r.open('GET', u, true);
    r.send(null);
}

var whic = 0;
var whicf = 0;
var whi = new Array();
var wht = new Array();

function whg()
{
    var o = document.getElementById('whi');
    var s = encodeURIComponent(o.innerHTML);
    o.id = 'whi-'+whic;
    whi[whic] = s;
    wht[whic] = 0;
    whic++;
}

function whgi()
{
    var o = document.getElementById('whi');
    var s = encodeURIComponent(o.innerHTML);
    o.id = 'whi-'+whic;
    whi[whic] = s;
    wht[whic] = 1;
    whic++;
}

function whge()
{
    var o = document.getElementById('whi');
    var s = encodeURIComponent(o.innerHTML);
    o.id = 'whi-'+whic;
    whi[whic] = s;
    wht[whic] = 2;
    whic++;
}

function whf()
{
    var q = '';
    var i;
    var c;
    for(c=0, i=whicf; i<whi.length; whicf=++i)
    {
        q += ( q != '' ? '&'+i+'='+whi[i] : i+'='+whi[i] );
        if(c++ > 4) { break; }
    }
    if(q != '')
    {
        WowheadObject._url = 'http://'+document.domain+'/forum/wowhead.php?'+q;
        WowheadObject._callback = whcb;
        WowheadObject.startRequest();
    }
}

function whcb(x)
{
    try {
        whp(x);
    } catch(e) {
    }
    whf();
}

function whp(x)
{
    var y = x.getElementsByTagName('root').item(0).getElementsByTagName('wh-item');
    var i;
    for(i=0; i<y.length; i++)
    {
        var o = ge('whi-'+y[i].getAttribute('id'));
        if(y[i].getElementsByTagName('not-found').item(0))
        {
            o.innerHTML='['+y[i].getElementsByTagName('not-found').item(0).firstChild.nodeValue+']';o.className='q0';o.style.fontWeight='bold';
            continue;
        }
        var w = y[i].getElementsByTagName('wowhead').item(0).getElementsByTagName('item').item(0);
        o.innerHTML = '';
        o.className = '';

        var a=ce('a');
        a.className='q'+w.getElementsByTagName('quality').item(0).getAttribute('id');
        a.style.fontWeight='bold';
        a.href='http://www.wowhead.com/?item='+w.getAttribute('id');a.target='_blank';
        ae(a,ct('['+w.getElementsByTagName('name').item(0).firstChild.nodeValue+']'));
        ae(o, a);
    }
}

