var http = createRequestObject();

// Creamos conexion
function createRequestObject() {
    var xmlhttp;
    try { 
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
    } catch(e) {
        try { 
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        } catch(f) { 
            xmlhttp = null;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

// Envia TEXTO por POST
function sendRequestTextPost(web) {
    var rnd = Math.random();
    try{
        web = escape(web);

        http.open('POST', '/trades.php', true);
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.onreadystatechange = handleResponseText;
        http.send('web='+web+'&rnd='+rnd);
    } catch(e) {
//        alert("error send: "+e);
    } finally {}
}

// Recoge respuesta del servidor como TEXTO
function handleResponseText() {
    try {
        if (http.readyState == 4 && http.status == 200) {
            var response = http.responseText;
        }
    } catch(e) {
//        alert("error rcv: "+e);
    } finally {}
}

window.onload = function () {
    var i = 0;
    var j = 0;
    var obj = document.getElementsByTagName('a');

    for (i = 0; i < obj.length; i++) {
        /*if (!obj[i].getAttribute('trade')) {
            continue;
        }*/
        obj[i].onclick = function () {
            updateTrade(this);
        }
    }
}

function updateTrade(web) {
    sendRequestTextPost(web);
}