function GetParam(name) {
	var match = new RegExp(name + "=(.+)[&]","i").exec(location.search);
	if (match==null)
	  match = new RegExp(name + "=(.+)","i").exec(location.search);
	if (match==null)
	  return null;
	match = match + "";
	result = match.split(",");
	return result[1];
}
  
var whereBAS;
var gasObj= new Array();
var gasObj;
var printed=0;
var basObj;

  function google_afs_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++;
				}
				
			}
		}
		
	}
  }
   
  function google_ads_view(dal,al,visualizzazione,roll,areaclick) { 
   	if(gasObj[0]==null) gasObj=basObj;
   	var s = '';
    var i;
	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) {
			 var onclickurl=(areaclick=='B'?'onClick="javascript:'+(newTab(currentCity)?'apriTab':'apripop')+'(\''+gasObj[i].url+'\')"':'')
			 var stylemouseover=(areaclick=='B'?'cursor:pointer; cursor:hand; ':'');
			//alert(gasObj[i].line1);
			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':'#FFFFDD')+'\';" 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?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;
				//console.log(gasObj[i]);
			}
        }
      }
    }

    document.write(s);
    return;
  } 

google_afs_query ='';
google_afs_ad = 'w4'; // specify the number of ads you are requesting
google_afs_client = 'bakeca'; // substitute your client ID
google_afs_channel = ''; // enter your comma-separated channel IDs
google_afs_ie = 'utf8'; // select input encoding scheme
google_afs_oe = 'utf8'; // select output encoding scheme
google_afs_adsafe = 'high'; // specify level for filtering non-family-safe ads
//google_afs_adtest = 'on'; // ** set parameter to off before launch to production
google_afs_adpage = '';
google_afs_hl = 'it'; // enter your interface language if not English
//google_afs_gl = 'it';
var barraok=false;
//funzione per aprire url in popup con focus
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 newTab(city){
	if(city=='palermo') return true;
	else return false;
	}
	
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;
 }
}