try {
	if (cvCSSModifier == null) cvCSSModifier = '';
}
catch(er) {
	var cvCSSModifier = '';
}

var gasObj= new Array();
var basObj;
var printed=0;
var whereBAS;

  function google_ad_request_done(google_ads) {
	
   	var randomNu;
	if(whereBAS=='INTESTA') gasObj=basObj.concat(google_ads);
	else if(whereBAS=='INFONDO') gasObj=google_ads.concat(basObj);
	else {
		numeroBAS=basObj.length;
		numeroGAS=google_ads.length;
		numeroTOT=numeroGAS+numeroBAS;
		iGas=0;
		iBas=0;
		for(i=0; i < numeroTOT; ++i) {
			randomNu = (Math.round(Math.random()*1));
			if(randomNu==0){
				if(iGas<numeroGAS){
					gasObj[i]=google_ads[iGas];
					iGas++;
				}else{
					gasObj[i]=basObj[iBas];
					iBas++;
				}
					
			}
			else{
				if(iBas<numeroBAS){
					gasObj[i]=basObj[iBas];
					iBas++;
				}else{
					gasObj[i]=google_ads[iGas];
					iGas++;
				}
				
			}
		}
		
	}
	//gasObj = google_ads;
  }

  function google_ads_view(dal,al,visualizzazione,roll,areaclick) {
	if(gasObj[0]==null) gasObj=basObj;
	var s = '';
    var i;
	 var dalinizio=dal;
	 var alinizio=al;
	dal=printed;
    if (gasObj.length == 0) {
      return;
    }
	if(areaclick==null)areaclick='B';

if (gasObj[0].type == "image") {

    } else {
     if (gasObj.length > dal) {
		 if (gasObj.length < al){ al=gasObj.length;}
		if(!visualizzazione) {s += '<tr><td width="100%" class="dataelencoannunci'+cvCSSModifier+'" '+(visualizzazione?'':'colspan="2"')+'>'+'Link sponsorizzati'+'<br/>'+'</td></tr>';}
		primo=true;
		for(i=dal; i < al; ++i) {
			//alert(gasObj[i].line1);
			var onclickurl=(areaclick=='B'?'onClick="javascript:'+(newTab(currentCity)?'apriTab':'apripop')+'(\''+gasObj[i].url+'\')"':'')
			var stylemouseover=(areaclick=='B'?'cursor:pointer; cursor:hand; ':'');
			if(i>=0){
				if(areaclick!='B')var clickAction='onClick="javascript:'+(newTab(currentCity)?'apriTab':'apripop')+'(\''+gasObj[i].url+'\')"';
				else var clickAction='';
				printed=printed+1;
				ultimo=(i==(al-1));
			 s += '<tr id="ads'+i+'" '+(roll?'onmouseover="this.style.backgroundColor=\''+(cvCSSModifier=='cv'?'#EEFFFF':'#F8F8F8')+'\';" onmouseout="this.style.backgroundColor=\'#FFF\';" ':'')+'  '+onclickurl+' style="'+stylemouseover+'background:'+(visualizzazione?'#FFFFF5':'#FFFFFF')+'; "><td class="rigaelencoannunci'+cvCSSModifier+'" '+(((primo || ultimo) && visualizzazione)?'style="border-'+(primo?'top':'bottom')+':#FFEE99 1px solid;"':'')+' '+((visualizzazione && primo)?'':'colspan="2"')+'>'+
			 	  '<a class="rigatitoloelenco'+cvCSSModifier+'" style="cursor:pointer; cursor:hand;" '+clickAction+'>'+gasObj[i].line1+'</a><br />'+
				  
				  '<p style="color:#4E4E4E;font-size:11px;font-family:Verdana, Arial, Helvetica, sans-serif;padding:0px;margin-top:3px;">'+'<a class="rigaelencoadsense" style="cursor:pointer; cursor:hand;" '+clickAction+'>'+gasObj[i].line2+' '+gasObj[i].line3+
				  '&nbsp;&nbsp;&nbsp;'+gasObj[i].visible_url+'&nbsp;</a>'+'</p>'+
		          '</td>'+((visualizzazione && primo)?'<td style="vertical-align:top;padding-top:4px; padding-right:5px;color:#CC9900; border-top:#FFEE99 1px solid;" align="right" nowrap="nowrap">Link sponsorizzati</td>':'')+'</tr>';
				primo=false;
			}
        }
      }
    }

    document.write(s);
    return;
  }

	google_ad_client = "ca-bakeca"; // inserire l'ID_publisher
	google_ad_type = 'text';
	// google_ad_channel = '1234567890';
	google_ad_output = 'js';
	google_max_num_ads = '6';
	google_feedback = 'on';
	google_language = 'it';
	//google_country = 'IT';
	// google_encoding = 'utf8';
	//google_adtest = 'on'; // assicurati di rimuoverlo dopo il test
	google_ad_section = 'default';
	
var barraok=false;
var newwindow;
function apripop(url){	
	newwindow=window.open(url,'_wingas','height=640,width=800,scrollbars=yes,resizable=yes,menubar=yes,location=yes,toolbar=yes');
	if (window.focus) {newwindow.focus()}
}

function apriTab(url){	
	newwindow=window.open(url,'_blank','');
	if (window.focus) {newwindow.focus()}
}

var catCoInserDiv= new Array();
var valInserz='';

function getElement(id_elemento) {
 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];
 return elemento; 
}

function toggleVisibility(divToShow,valSel){
  var x=document.getElementById(valSel);
 if (catCoInserDiv[x.value]){
		divToShow.disabled=false;;
 }
 if(!catCoInserDiv[x.value] || valInserz==''){
  	divToShow.disabled=true;
 }
}

function newTab(city){
	if(city=='palermo') return true;
	else return false;
	}

//fader
function colorFade(id,element,start,end,steps,speed) {
  var startrgb,endrgb,er,eg,eb,step,rint,gint,bint,step;
  var target = document.getElementById(id);
  steps = steps || 20;
  speed = speed || 20;
  clearInterval(target.timer);
  endrgb = colorConv(end);
  er = endrgb[0];
  eg = endrgb[1];
  eb = endrgb[2];
  if(!target.r) {
    startrgb = colorConv(start);
    r = startrgb[0];
    g = startrgb[1];
    b = startrgb[2];
    target.r = r;
    target.g = g;
    target.b = b;
  }
  rint = Math.round(Math.abs(target.r-er)/steps);
  gint = Math.round(Math.abs(target.g-eg)/steps);
  bint = Math.round(Math.abs(target.b-eb)/steps);
  if(rint == 0) { rint = 1 }
  if(gint == 0) { gint = 1 }
  if(bint == 0) { bint = 1 }
  target.step = 1;
  target.timer = setInterval( function() { animateColor(id,element,steps,er,eg,eb,rint,gint,bint) }, speed);
}
 
// incrementally close the gap between the two colors //
function animateColor(id,element,steps,er,eg,eb,rint,gint,bint) {
  var target = document.getElementById(id);
  var color;
  if(target.step <= steps) {
    var r = target.r;
    var g = target.g;
    var b = target.b;
    if(r >= er) {
      r = r - rint;
    } else {
      r = parseInt(r) + parseInt(rint);
    }
    if(g >= eg) {
      g = g - gint;
    } else {
      g = parseInt(g) + parseInt(gint);
    }
    if(b >= eb) {
      b = b - bint;
    } else {
      b = parseInt(b) + parseInt(bint);
    }
    color = 'rgb(' + r + ',' + g + ',' + b + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
    target.r = r;
    target.g = g;
    target.b = b;
    target.step = target.step + 1;
  } else {
    clearInterval(target.timer);
    color = 'rgb(' + er + ',' + eg + ',' + eb + ')';
    if(element == 'background') {
      target.style.backgroundColor = color;
    } else if(element == 'border') {
      target.style.borderColor = color;
    } else {
      target.style.color = color;
    }
  }
}
 
// convert the color to rgb from hex //
function colorConv(color) {
  var rgb = [parseInt(color.substring(0,2),16), 
    parseInt(color.substring(2,4),16), 
    parseInt(color.substring(4,6),16)];
  return rgb;
}