//Yahoo Content Match
var cb = Math.floor(Math.random() * 100000);
function yahoo_ad_rand() {
	var cat = [1,"idg_1",1,"idg_2",1,"idg_3"];
	var pesocategorias = new Array();
	for (i=0;i<cat.length;i = i+2){
		for (x=0;x<cat[i];x++) {
			pesocategorias[pesocategorias.length] = cat[i+1];
		}
	}
	return pesocategorias[Math.floor(Math.random()*pesocategorias.length)];
}

function lim(s){
          var max=95, w=s.split(' '), f=[], c=0, word;
          for (var i=0,length=w.length; i<length; i++){
                   word=w[i];
                   c = c+ word.length;
                   if (c<max){
                             f.push(word);
                   } else {
                             f[f.length-1] = f[f.length-1].replace(lim.re,'');
                             f = f.join(' ')+'...';
                             break;
                   }
          }
          if (typeof f=='object'){
                   f = f.join(' ');
          }
          return f;
}
lim.re = /\,$|\.$|\;$|\:$|\!$|\?$/i;

function getAdsArray(){
    //remove anchors ("#nome") to prevent errors in IE
    var urlLocation = encodeURIComponent(document.URL);
    urlLocation = urlLocation.split("#", 1);
    var a = 'http://cm.br.idg.overture.com/js_flat_1_0/?config=9229440103&source=idg_br_cm_js&ctxtUrl=' +urlLocation+ '&keywordCharEnc=utf8&outputCharEnc=utf8&maxCount=2&type='+yahootype+'&ctxtId=' + yahoo_ad_rand() + '&cb=';
    var url = a + cb;
    document.write('<SCRIPT LANGUAGE=JavaScript1.1 SRC="' + url + '"></SCRIPT>');
    document.write('<SCRIPT LANGUAGE=JavaScript>var linksCount = 1;</SCRIPT>');
}

//only one call to ContentMatch
try {
    half_zSr = linksCount;
} catch (e) {
    getAdsArray();
}

function YAHOO_2C2L_Show(){
	p_content = '\n<table class="tabela-links-patrocinados">';
        i = linksCount;
	while(i < (linksCount+1)){
            if (zSr[(i*6)+3] != undefined){
		p_content += '<tr><td><div id="yahoo_cm_ad">';
		p_content += '<a href="'+ zSr[(i*6)+2]+'" target="_blank" id="yahoo_cm_ad_link">' + zSr[(i*6)+3] + '</a>';
		p_content += '<div id="yahoo_cm_ad_text">' + lim(zSr[(i*6)]) + '</div>';
		p_content += '<div id="yahoo_cm_ad_url"><a href="'+ zSr[(i*6)+2]+'" target="_blank">'+ zSr[(i*6)+4]+ '</a></div>';
		p_content += '</div></td></tr>';
            }
            i = i+1;
	}
        linksCount = linksCount+1;
	p_content += '</table>';

	document.write(p_content);
}
