function utf8_encode (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return utftext;
}

function getKeywords(n) {
    var lKeywords = mapkey[0]['keywords'].split(/\s*,\s*/);
    var qtdKeywords = n;
    for(i=0; i < qtdKeywords; i++) {
        document.write('<a href=/links_patrocinados/' + escape(lKeywords[i]) + '?linkspot=1&searchterm=' + escape(utf8_encode(lKeywords[i])) + '>> ' + lKeywords[i]  + '</a>');
    }
}



function loadLinksPatrociandosHTML(url) {
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
    } else {
        document.getElementById('linkspatro').innerHTML = "Erro: Dados";
    }
    if (xmlhttp) {
        url = url + '?rnd=' + Math.random();
        xmlhttp.onreadystatechange = xmlhttpChange_links;
        xmlhttp.open("GET", url, true);
        xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
        xmlhttp.setRequestHeader("Pragma", "no-cache");
        xmlhttp.send(null);
    }
}

function xmlhttpChange_links() {
    if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
            document.getElementById('linkspatro').innerHTML=xmlhttp.responseText;
        } else {
            document.getElementById('linkspatro').innerHTML="Não foi possível carregar os dados.";
        }
    }
}