var UOLAF = window.UOLAF || {};

UOLAF.init = function () {
	if(!UOLAF.runOnce) {
		UOLAF.runOnce=true;
		/*
		UOLAF.atual=1;
		ss = document.getElementsByTagName('script');
		UOLAF.afs=0;
		console.debug(ss.length);
		for(i=0;i<ss.length;i++) { var now = ss[i];
			if(now.src.match(/uolaf.js$/)) {
				UOLAF.afs++;
			}
		}
		*/
		try {
			UOLAF.pg = Number((/UOLAFpg=([^|;]+)/).exec(document.cookie)[1]);
			//console.debug('leu '+UOLAF.pg)
		} catch(e) {
			UOLAF.pg = -1;
		}
        
	} else {
		//UOLAF.pg++;
	}
	UOLAF.ads();
}

UOLAF.ads = function () {
    adBlockCountLp = (typeof adBlockCountLp != "undefined")? adBlockCountLp + 1 : 0;
    UOLAF.pg++;
	UOLAF.pg = (UOLAF.pg>9)?0:UOLAF.pg;
	urlAdvertiseUol  = 'http://adclient-af.lp.uol.com.br/';
	try{urlAdvertiseUol += 'format'+formatId+'.html?&amp;';}catch(e){void(null)}
    try{urlAdvertiseUol += 'adBlockCount='+adBlockCountLp+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'page='+UOLAF.pg+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'urlReferer='+encodeURIComponent(document.location.href)+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'formatId='+formatId+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'numads='+numads+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'borderColor='+borderColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'bgColor='+bgColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'titleColor='+titleColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'descrColor='+descrColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'urlColor='+urlColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'altColor='+altColor+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'hasFrames='+hasFrames+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'deslabel='+deslabel+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'coddisplaysupplier='+coddisplaysupplier+'&amp;';}catch(e){void(null)}
	try{urlAdvertiseUol += 'blank='+blank;}catch(e){void(null)}
	document.cookie = 'UOLAFpg='+UOLAF.pg;
	htmlUol = '<iframe src="'+urlAdvertiseUol+'" ';
	htmlUol += 'marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" scrolling="no"';
	tipos = ['zeroIndex', [728,90], [468,60], [125,125], [234,60], [120,600], [160,600], [180,150], [120,240], [300,250], [250,250], [336,280] ];
	tipos[100] = [160, numads * 93.5];
	tipos[101] = [160, numads * 93.5];
	height = tipos[Number(formatId)][1];
	width  = tipos[Number(formatId)][0];
	htmlUol += 'height="'+height+'" width="'+width+'"></iframe>';
	document.write(htmlUol);
    if(typeof blank != "undefined" && blank == 1) blank = 0;
}


UOLAF.init();