function popWindow(url,name,w,h) {
	newwindow=window.open(url,name,'height=' + h + ',width=' + w + ',resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}

function popWindow2(url,name,w,h, trackerurl) {
	var mediaplex='http://altfarm.mediaplex.com/ad/bk/';
	newwindow=window.open(url,name,'height=' + h + ',width=' + w + ',resizable=yes,scrollbars=yes,toolbar=yes,status=yes,menubar=yes,location=yes');
	if (window.focus) {newwindow.focus()}
	if (isdefined(trackerurl) && trackerurl!="undefined")  
		(new Image).src=mediaplex+trackerurl;
	return false;
}

function popImage(trackerurl) {
	var mediaplex='http://altfarm.mediaplex.com/ad/bk/';
	if (isdefined(trackerurl) && trackerurl!="undefined") 
		(new Image).src=mediaplex+trackerurl;
	return true;
}

function adSenseStackWideDisplay(google_ads) {
	return _adSenseStackWideDisplay(google_ads,0,100,"adsense-div","stack-adsense-title","adsense-item");
}

function _adSenseStackWideDisplay(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;
    var popwin='popWindow';

    if (google_ads.length == 0) {
      return null;
    }
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
		
	if (isdefined(mplxurl)) 
		popwin='popWindow2';
	var img = '';
	var topMargin = '';
	var bottompadding = '';
	if((window.imgPlaceHolderIconUrl != undefined) && (imgPlaceHolderIconUrl.length>0)){
	    img = '<img class="thumbnail-placeholderIcon" style="margin-top: 5px;margin-right: 16px; margin-left:49px" src="'+imgPlaceHolderIconUrl+'">';
	    topMargin = 'style="margin-top:5px"';
	      bottompadding = 'style="padding-bottom:22px"';
	}

  	s += '<div class="' + divclass + '"><div width="100%" class="' + titleclass + '">' + adSenseTitle + '</div>';
	for(i=start; i < end; ++i) {
		var a = '<a href="' + google_ads[i].url + '" target="_blank" onclick="return popImage(\'' + mplxurl + '\'); return true;"' + 
			' onmouseout="window.status=\'\'" ' + 'onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" ' + 'style="text-decoration:none">'; 
		s += '<div class="' + itemclass + '">' + 
				 img + '<div class="adsenseContentOpt"' + topMargin + '>' + 
				 a+'<span class="adsenseLine1">' + google_ads[i].line1 + '</span></a><br/>'+
				 a+google_ads[i].line2 + ' ' + google_ads[i].line3 + '</a></div>'+
				'<div class="adsenseUrlOpt"' + bottompadding + '>' + a + google_ads[i].visible_url + '</a></div></div>';
    }
	s+= '</div>';
    return s;
}


function _adSenseStackWideSearchDisplayNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;

    if (google_ads.length == 0) {
      return null;
    }
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
	
	var img = '';
	var topMargin = '';
	var bottompadding = '';
	if((window.imgPlaceHolderIconUrl != undefined) && (imgPlaceHolderIconUrl.length>0)){
	    img = '<img class="thumbnail-placeholderIcon" style="margin-top:5px; margin-right:16px; margin-left:49px" src="'+imgPlaceHolderIconUrl+'">';
	    topMargin = 'style="margin-top:5px"';
	    bottompadding = 'style="padding-bottom:5px"';
	}	
		
  	s += '<div class="' + divclass + '"><div width="100%" class="' + titleclass + '" id="'+itemclass+'">' + adSenseTitle + '</div>';
	for(i=start; i < end; ++i) {
		var a = '<a href="' + google_ads[i].url + '" id="adsenseLink" target="_blank" onclick="return popImage(\'' + mplxurl +  '\'); return true;" >';
		//var b = '<a href="' + google_ads[i].url + '" id="adsenseLink2">';
	
		s += a + '<div><span id="' + [i] + '" onmouseover="AdNav(this,\''+start+'\',\''+itemclass+'\');window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" class="' + itemclass + '" onmouseout="AdNavOut(this,\''+itemclass+'\')">'+
				 img + '<div class="adsenseContentOpt"' + topMargin + '>' + 
				 '<span class="adsenseLine1">' + google_ads[i].line1 + '</span><br/>'+
				 google_ads[i].line2 + ' ' + google_ads[i].line3 + '</div>'+
				 '<div class="adsenseUrlOpt"' + bottompadding + '>' + google_ads[i].visible_url + '</div></span></div></a>';
    }
	s+= '</div>';
	if((window.displaySearchAdsenseBottomBar != undefined) && (displaySearchAdsenseBottomBar == 'true')){
		s+= '<div class="adsense-bottom-bar">&nbsp;</div>';
	}
	
    return s;
}

function _adSenseStackWideSearchDisplayNoImageNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;

    if (google_ads.length == 0) {
      return null;
    }
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
	
	
		
  	s += '<div class="' + divclass + '"><div width="100%" class="' + titleclass + '" id="'+itemclass+'">' + adSenseTitle + '</div>';
	for(i=start; i < end; ++i) {
		var a = '<a href="' + google_ads[i].url + '" id="adsenseLink" target="_blank" onclick="return popImage(\'' + mplxurl +  '\'); return true;" >';
		//var b = '<a href="' + google_ads[i].url + '" id="adsenseLink2">';
	
		s += a + '<div><span id="' + [i] + '" onmouseover="AdNav(this,\''+start+'\',\''+itemclass+'\');window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" class="' + itemclass + '" onmouseout="AdNavOut(this,\''+itemclass+'\')">'+
				 '<span class="adsenseLine1">' + google_ads[i].line1 + '</span>'+
				 '<br/><div class="adsenseContentOpt">' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</div>'+
				 '<div class="adsenseUrlOpt">' + google_ads[i].visible_url + '</div></span></div></a>';
    }
	s+= '</div>';
	if((window.displaySearchAdsenseBottomBar != undefined) && (displaySearchAdsenseBottomBar == 'true')){
		s+= '<div class="adsense-bottom-bar">&nbsp;</div>';
	}
	
    return s;
}

function _adSenseStackHorizontalSearchDisplayNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var htmlString = '';

    if (google_ads.length == 0) {
      return null;
    }
    
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
	
	
	htmlString += '<div width="100%" class="' + titleclass + '">' + adSenseTitle + '</div>';
	htmlString += '<ul class="adsense-horizontal">';
	for(var i=start; i < end; ++i) {
		htmlString += '<li>';
		htmlString += '<h4><a href="' + google_ads[i].url + '"  target="_blank" onclick="return popImage(\'' + mplxurl +  '\'); return true;"> ' + google_ads[i].line1 + ' </a></h4>';
		htmlString += '<p>' + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</p>';
		htmlString += '<a href="' + google_ads[i].url + '"  target="_blank" onclick="return popImage(\'' + mplxurl +  '\'); return true;">' + google_ads[i].visible_url + '</a>';
		htmlString += '</li>';
	}
	htmlString += '</ul>';	
	
	
	if((window.displaySearchAdsenseBottomBar != undefined) && (displaySearchAdsenseBottomBar == 'true')){
		htmlString += '<div class="adsense-bottom-bar">&nbsp;</div>';
	}
	
    return htmlString;
}

function _adSenseStackWideDisplayPOA(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;
    var popwin='popWindow';

    if (google_ads.length == 0) {
      return null;
    }
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
		
	if (isdefined(mplxurl)) 
		popwin='popWindow2';	
	var img = '';
	var topMargin = '';
	var bottompadding = '';
	if((window.imgPlaceHolderIconUrl != undefined) && (imgPlaceHolderIconUrl.length>0)){
	    img = '<img class="thumbnail-placeholderIcon" style="margin-top: 5px;margin-right: 8px;" src="'+imgPlaceHolderIconUrl+'">';
	    topMargin = 'style="margin-top:5px"';
	    bottompadding = 'style="padding-bottom:22px"';
	}

  	s += '<div class="' + divclass + '"><div width="100%" class="' + titleclass + '">' + adSenseTitle + '</div>';
	for(i=start; i < end; ++i) {
		var a = '<a href="' + google_ads[i].url + '" target="_blank" onclick="return popImage(\'' + mplxurl + '\'); return true;"' + 
				' onmouseout="window.status=\'\'" ' + 'onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" ' + 'style="text-decoration:none">'; 
				
		s += '<div class="' + itemclass + '">' + img +
                    '<div class="adsenseContentOpt"' + topMargin + '>' + 
                    '<div>' + a + '<span  class="adsenseLine1">' + google_ads[i].line1 + '</span></a></div>' +
                    a + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</a></div>' +
                     '<div class="adsenseUrlOpt"' + bottompadding + '>' + a + google_ads[i].visible_url + '</a></div></div>';
    }
	s+= '</div>';
    return s;
}
function _adSenseStackWideDisplayViewAd(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;
    var popwin='popWindow';

    if (google_ads.length == 0) {
      return null;
    }
	if ( end > google_ads.length )
		end = google_ads.length;
	if ( start >= end )
		return;
		
	if (isdefined(mplxurl)) 
		popwin='popWindow2';
	var img = '';
	var topMargin = '';
	var bottompadding = '';
	if((window.imgPlaceHolderIconUrl != undefined) && (imgPlaceHolderIconUrl.length>0)){
	    img = '<img class="thumbnail-placeholderIcon" style="margin-top: 5px;margin-right: 8px;" src="'+imgPlaceHolderIconUrl+'">';
	    topMargin = 'style="margin-top:5px"';
	      bottompadding = 'style="padding-bottom:22px"';
	}

  	s += '<div class="' + divclass + '"><div width="100%" class="' + titleclass + '">' + adSenseTitle + '</div>';
	for(i=start; i < end; ++i) {
		var a = '<a href="' + google_ads[i].url + '" target="_blank" onclick="return popImage(\'' + mplxurl + '\'); return true;"' + 
			' onmouseout="window.status=\'\'" ' + 'onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" ' + 'style="text-decoration:none">'; 
		s += '<div class="' + itemclass + '">' + 
                    '<div>' + a + '<span class="adsenseLine1">' + google_ads[i].line1 + '</span></a></div>' +
                    img + 
                    '<div class="adsenseContentOpt"' + topMargin + '>' + a + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</a></div>' +
                    '<div class="adsenseUrlOpt"' + bottompadding + '>' + a + google_ads[i].visible_url + '</a></div></div>';
    }
	s+= '</div>';
    return s;
}

function AdNavOut(adDivId1,iclass){
    adDivId1.parentNode.className = "";
	window.status="";
	return true;
}

function AdNav(adDivId,s,iclass){
    adDivId.parentNode.className = "adsenseMO"
	return true;
}

function _adSenseStackWideDisplayTable(google_ads,start,end,divclass,titleclass,itemclass,mplxurl) {
    var s = '';
    var i;
    var popwin='popWindow';

    if (google_ads.length == 0) {
    	return null;
    }
	if ( end > google_ads.length )
  		end = google_ads.length;
  	if ( start >= end )
		return;
		
	if (isdefined(mplxurl)) 
		popwin='popWindow2';		

    s += '<div class="' + divclass + '">';
    s += '<table cellpadding="4">';  
    for(i=start; i < end; ++i) {
        if (i % 2 == 0) {
        	if (i > 0) 
        		s+= '</tr><tr>';
        	else
	            s+= '<tr>';
        }
            	
	    s += '<td>';    
		var a = '<a href="' + google_ads[i].url + '" target="_blank" onclick="return popImage(\'' + mplxurl + '\'); return true;"' + 
				' onmouseout="window.status=\'\'" ' + 'onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'; return true;" ' + 'style="text-decoration:none">'; 
		s += '<div class="' + itemclass + '">' + 
                    '<div>' + a + '<span class="adsenseLine1">' + google_ads[i].line1 + '</span></a></div>' +
                    '<div class="adsenseContent">' + a + google_ads[i].line2 + ' ' + google_ads[i].line3 + '</a></div>' +
                    '<span class="adsenseUrl">' + a + google_ads[i].visible_url + '</a></span><br></div>';
		s += '</td>'; 
 
    }
    
    s += '</tr></table>';    
    s+= '<div width="100%" class="' + titleclass + '">' + adSenseTitle + '</div>';    
	s+= '</div>';
	

    return s;
}

function _adSenseStackWideDisplayWithID(google_ads,id,start,end,divclass,titleclass,itemclass,mplxurl) {
	var s = _adSenseStackWideDisplay(google_ads,start,end,divclass,titleclass,itemclass,mplxurl);
	if ( s != null ) {
		var element = document.getElementById(id);
		if ( element != null ) {
			element.innerHTML = s;
		}
	}
}

function _adSenseStackWideDisplayWithIDNewStyle(google_ads,id,start,end,divclass,titleclass,itemclass,mplxurl) {
	var s = _adSenseStackWideSearchDisplayNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl);
	if ( s != null ) {
		var element = document.getElementById(id);
		if ( element != null ) {
			element.innerHTML = s;
		}
	}
}

function _adSenseStackWideDisplayNoImageWithIDNewStyle(google_ads,id,start,end,divclass,titleclass,itemclass,mplxurl) {
	var s = _adSenseStackWideSearchDisplayNoImageNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl);
	if ( s != null ) {
		var element = document.getElementById(id);
		if ( element != null ) {
			element.innerHTML = s;
		}
	}
}

function _adSenseStackHorizontalDisplayWithIDNewStyle(google_ads,id,start,end,divclass,titleclass,itemclass,mplxurl) {
	var s = _adSenseStackHorizontalSearchDisplayNewStyle(google_ads,start,end,divclass,titleclass,itemclass,mplxurl);
	if ( s != null ) {
		var element = document.getElementById(id);
		if ( element != null ) {
			element.innerHTML = s;
		}
	}
}

function adSenseStackWide(google_ads) {
	searchResultBottomAdsenseOriginal(google_ads);
    return;
}

function searchResultBottomAdsenseOriginal(google_ads) {
	_adSenseStackWideDisplayWithID(google_ads,"bottomAdSense",0,100,"adsense-div","stack-adsense-title","adsense-item");
}

function searchResultBottomAdsenseStyleA(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,"bottomAdSense",start,end,"adsense-div-border","left-adsense-titleOpt","adsense-item",mplx);
}

function searchResultBottomAdsenseStyleB(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,"bottomAdSense",start,end,"adsense-div","left-adsense-titleOpt","bottom-adsense-itemB",mplx);
}

function searchResultBottomAdsenseStyleC(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,"bottomAdSense",start,end,"bottom-adsense-divB","left-adsense-titleOpt","bottom-adsense-itemB",mplx);
}

// new styles for adsense 
function searchResultBottomAdsenseStyleD(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithIDNewStyle(google_ads,'bottomAdSense',start,end,"bottom-adsense-divB","left-adsense-titleOpt","adsense-item",mplx);
}
function searchResultBottomAdsenseStyleE(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithIDNewStyle(google_ads,"bottomAdSense",start,end,"bottom-adsense-divBOpt","left-adsense-titleOpt","bottom-adsense-itemBOpt",mplx);
}
function searchResultBottomAdsenseStyleF(google_ads,start,end,mplx) {
        _adSenseStackWideDisplayWithIDNewStyle(google_ads,"bottomAdSense",start,end,"bottom-adsense-divCOpt","left-adsense-titleOpt","bottom-adsense-itemBOpt",mplx);
}

function searchResultBottomAdsenseStyleG(google_ads,start,end,mplx) {
        _adSenseStackWideDisplayWithIDNewStyle(google_ads,"bottomAdSense",start,end,"bottom-adsense-divCOpt","left-adsense-titleOpt","bottom-adsense-itemBOpt",mplx);
}

function searchResultBottomAdsenseStyleH(google_ads,start,end,mplx) {
        _adSenseStackWideDisplayWithIDNewStyle(google_ads,"bottomAdSense",start,end,"bottom-adsense-divCOpt","left-adsense-titleOpt","bottom-adsense-itemBOpt",mplx);
}

function searchResultTopAdsenseStyleA(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,'head1AdSense',start,end,"head-adsense-div","left-adsense-titleOpt","top-adsense-item",mplx);
}
function searchResultTopAdsenseStyleB(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,'head2AdSense',start,end,"head-adsense-div","left-adsense-titleOpt","top-adsense-item",mplx);
}

function searchResultTopAdsenseStyleC(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,'topAdSense',start,end,"top-adsense-divA","left-adsense-titleOpt","top-adsense-item",mplx);
}
function searchResultTopAdsenseStyleD(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithID(google_ads,'topAdSense',start,end,"top-adsense-divB","left-adsense-titleOpt","top-adsense-item",mplx);
}
// new styles for google adsense ph2 
function searchResultTopAdsenseStyleE(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithIDNewStyle(google_ads,'topAdSense',start,end,"top-adsense-divCOpt","left-adsense-titleOpt","top-adsense-itemOpt",mplx);
}
function searchResultTopAdsenseStyleF(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayWithIDNewStyle(google_ads,'topAdSense',start,end,"top-adsense-divDOpt","left-adsense-titleOpt","top-adsense-itemOpt",mplx);
}

function searchResultTopAdsenseStyleG(google_ads,start,end,mplx) {
	_adSenseStackHorizontalDisplayWithIDNewStyle(google_ads,'topAdSense',start,end,"top-adsense-divDOpt","left-adsense-titleOpt","top-adsense-itemOpt",mplx);
}

function searchResultTopAdsenseStyleH(google_ads,start,end,mplx) {
	_adSenseStackWideDisplayNoImageWithIDNewStyle(google_ads,'topAdSense',start,end,"top-adsense-divDOpt","left-adsense-titleOpt","top-adsense-itemOpt",mplx);
}

function googsenseContent(sHtml) {
	if ( sHtml != null ) {
		var gs_top = document.getElementById("googsense");				
		if (gs_top)	gs_top.innerHTML = sHtml;
	}
}

var isGum = false;
function setupAdSenseWithClientId(afcClientId,channel,n,hints,locale,adTest,isAdult) {
    google_max_num_ads = n;
	if ( hints )
		google_hints = hints;
    _setupAdSense(afcClientId,channel,locale,adTest,isAdult);
}
function setupAdSense(channel,locale,adTest,isAdult) {
	var country = locale.substring(3).toLowerCase();
	if (country == "hk" || country == "nz" || country == "sg" || country == "au" || country == "za" || country == "pl"){
		afcClientId = 'ca-gumtree-' + country + '_js';
		isGum = true;
	}
	else
		afcClientId = 'ca-kijiji-' + country + '_js';
    _setupAdSense(afcClientId,channel,locale,adTest,isAdult);
}

function _setupAdSense(afcClientId,channel,locale,adTest,isAdult) {
	if ( channel )
		google_ad_channel = channel; 
    google_ad_output = 'js';
	google_encoding = "utf8";
	if ( adTest )
		google_adtest = 'on';
	google_safe = isAdult == 'true'? 'medium':'high';
	google_language = locale.substring(0,2);

	google_ad_client = afcClientId;
	document.writeln('<script language="JavaScript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');

}

var kijiji_afs_adsafe;
function setupAfsAdsenseWithClientId(afsClientId,afcClientId,afschannel,afcchannel,locale,adTest,isAdult,q,page,n) {
    _setupAfsAdsense(afsClientId,afcClientId,afschannel,afcchannel,locale,adTest,isAdult,q,page,n);
}
function setupAfsAdsense(afsClientId,afschannel,afcchannel,locale,adTest,isAdult,q,page,n) {
    afcClientId = null;
    if ( isAdult != 'adultonly' ) {
	    var country = locale.substring(3).toLowerCase();
	    if (country == "hk" || country == "nz" || country == "sg"){
	    	afcClientId = 'ca-gumtree-' + country + '_js';
			isGum = true;
		}
	    else
	    	afcClientId = 'ca-kijiji-' + country + '_js';
    }
    _setupAfsAdsense(afsClientId,afcClientId,afschannel,afcchannel,locale,adTest,isAdult,q,page,n);
}
function _setupAfsAdsense(afsClientId,afcClientId,afschannel,afcchannel,locale,adTest,isAdult,q,page,n) {
    if ( n < 1 ) return;
	google_afs_ad = 'n' + n;
	google_afs_adpage = page;
	google_afs_query = q;
	if ( afschannel ) {
		google_afs_channel = afschannel;
	} 
	google_afs_ie = "utf8";
	google_afs_oe = "utf8";
	if ( adTest )
		google_afs_adtest = 'on';
    kijiji_afs_adsafe = google_afs_adsafe = isAdult == 'true'? 'medium':(isAdult == 'false' ? 'high': isAdult);
	google_afs_hl = locale.substring(0,2);
	google_afs_gl = locale.substring(3);
    google_afs_client = afsClientId;

	//preset the afc variable incase we need to go to afc
    if ( isAdult != 'adultonly' ) {
	    if ( afcchannel )
		    google_ad_channel = afcchannel; 
    	    google_ad_output = 'js';
	    google_encoding = "utf8";
	    if ( adTest )
		    google_adtest = 'on';
	    google_safe = isAdult == 'true'? 'medium':'high';
	    google_language = locale.substring(0,2);
	   /* var country = locale.substring(3).toLowerCase();
	    if (country == "hk" || country == "nz" || country == "sg"){
	    	google_ad_client = 'ca-gumtree-' + country + '_js';
			isGum = true;
		}
	    else
	    	google_ad_client = 'ca-kijiji-' + country + '_js';*/
	    google_ad_client = afcClientId;
	    google_max_num_ads = n;
	}
	document.writeln('<script language="JavaScript" src="http://www.google.com/afsonline/show_afs_ads.js"></script>');
}

function google_afs_request_done(google_ads) {
	if ( google_ads.length <= 0 ) {
      if ( kijiji_afs_adsafe != 'adultonly' && google_ad_client != "") {
		   document.writeln('<script language="JavaScript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
			}
	} else {
		if ( google_ad_request_done )
			google_ad_request_done(google_ads);
	}
}

/*function searchBrowseAdsense(google_ads) {
	searchResultBottomAdsenseStyleC(google_ads,0,2);
	searchResultTopAdsenseStyleA(google_ads,2,10);
}
*/
//locale-country temporarily tested here until configuration part completed
/*function searchResultBottomAdSense(locale,n,channel,adTest,isAdult) {
    if ( n < 1 ) return;

	//google_ad_request_done = adSenseStackWide;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div-border","stack-adsense-title","adsense-item");
		if ( s != null )
    		document.write(s);
	};
    google_max_num_ads = n;
	setupAdSense(channel,locale,adTest,isAdult);

}
*/

/*function viewAdBottomAdSense(locale,n,channel,adTest,isAdult,hints,id) {
    if ( n < 1 ) return;
	//google_ad_request_done = adSenseStackWide;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div","stack-adsense-title","adsense-item");
		if ( s != null ) {
			if ( id != null ) {
				var element = document.getElementById(id);
				if ( element != null ) {
					element.innerHTML = s;
				}
			} else {
    			document.write(s);
			}
		}
	};
    google_max_num_ads = n;
	if ( hints )
		google_hints = hints;
	setupAdSense(channel,locale,adTest,isAdult);

}

function bottomAdSense(yahooPartnerId,locale,n,channel,adTest,isAdult,hints) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div","stack-adsense-title","adsense-item");
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
		      if (gs_top)	gs_top.innerHTML = s;
		}
	};
				
	google_max_num_ads = n;
	if (yahooPartnerId != "" ) { 
		setupYahooAdSense(yahooPartnerId,channel,google_max_num_ads ,hints,isAdult);
	} else {
		if ( hints )
			google_hints = hints;
		setupAdSense(channel,locale,adTest,isAdult);
	}
}
*/
/*
 * View large image style b adsense - to be remove after switching to new struncture
 */
function bottomAdSense2(yahooPartnerId,locale,n,channel,adTest,isAdult,catpath,hints,mplxurl) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplxurl);
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
		      if (gs_top)	gs_top.innerHTML = s;
		}
	};
				
	google_max_num_ads = n;
	if (yahooPartnerId != "" ) { 
		setupYahooAdSense2(yahooPartnerId,channel,google_max_num_ads ,catpath,hints,isAdult);
	} else {
		if ( hints )
			google_hints = catpath + hints;
		else if ( catpath )
		    google_hints = catpath;
		setupAdSense(channel,locale,adTest,isAdult);
	}
}

/*
  * View ad adsense
  */
function bottomAdSenseViewAdStyleA(google_ads,mplxurl) {
	var sHtml = _adSenseStackWideDisplayViewAd(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplxurl);
    googsenseContent(sHtml);
}
//for backward compatibility - should be removed after switching to new structure 
function bottomAdSenseViewAd(yahooPartnerId,locale,n,channel,adTest,isAdult,catpath,hints,mplxurl) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplayViewAd(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplxurl);
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
			if (gs_top)	gs_top.innerHTML = s;
		}
    	};
				
	google_max_num_ads = n;
	if (yahooPartnerId != "" ) { 
		setupYahooAdSense2(yahooPartnerId,channel,google_max_num_ads ,catpath,hints,isAdult);
	} else {
		if ( hints )
			google_hints = catpath + hints;
		else if ( catpath )
		    google_hints = catpath;
		setupAdSense(channel,locale,adTest,isAdult);
	}
}

/*
 * POA adsense - currently A & B are the same.
 */
function bottomAdsensePOAStyleA(google_ads,mplx) {
	var sHtml = _adSenseStackWideDisplayPOA(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplx);
    googsenseContent(sHtml);
}
function bottomAdsensePOAStyleB(google_ads,mplx) {
	var sHtml = _adSenseStackWideDisplayPOA(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplx);
    googsenseContent(sHtml);
}
//for backward compatibility - remove after switching to new structure
function bottomAdSensePOA(yahooPartnerId,locale,n,channel,adTest,isAdult,catpath,hints,mplx) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplayPOA(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplx);
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
		      if (gs_top)	gs_top.innerHTML = s;
		}
	};
				
	google_max_num_ads = n;
	if (yahooPartnerId != "" ) { 
		setupYahooAdSense2(yahooPartnerId,channel,google_max_num_ads ,catpath,hints,isAdult);
	} else {
		if ( hints )
			google_hints = catpath + hints;
		else if ( catpath )
		    google_hints = catpath;			
		setupAdSense(channel,locale,adTest,isAdult);
	}
}


function bottomAdSenseStyleB(yahooPartnerId,locale,n,channel,adTest,isAdult,catpath,hints,mplx) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div-view","stack-adsense-titlenobg","adsense-item",mplx);

		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
		      if (gs_top)	gs_top.innerHTML = s;
		}
	};
				
	google_max_num_ads = n;
	if (yahooPartnerId != "" ) { 
		setupYahooAdSense2(yahooPartnerId,channel,google_max_num_ads ,catpath,hints,isAdult);
	} else {
		if ( hints )
			google_hints = catpath + hints;
		else if ( catpath )
		    google_hints = catpath;			
		setupAdSense(channel,locale,adTest,isAdult);
	}
}

/*
 * View large image adsense
 */
//For ad count = 1 StyleA
function viewAdLargeImageBottomAdSenseStyleA1(google_ads,mplx) {
	var sHtml = _adSenseStackWideDisplayTable(google_ads,0,100,"adsense-div-border2","stack-adsense-title2mid","adsense-item",mplx);
    googsenseContent(sHtml);
}
//For ad count >1 Style A
function viewAdLargeImageBottomAdSenseStyleAN(google_ads,mplx) {
	var sHtml = _adSenseStackWideDisplayTable(google_ads,0,100,"adsense-div-border2","stack-adsense-title2","adsense-item",mplx);
    googsenseContent(sHtml);
}
// Style B
function viewAdLargeImageBottomAdSenseStyleB(mplxurl) {
	var sHtml = _adSenseStackWideDisplay(google_ads,0,100,"adsense-div-view","stack-adsense-title","adsense-item",mplxurl);
    googsenseContent(sHtml);
}

//for backward compatibility - remove after switching to new structure
function viewAdLargeImageBottomAdSense(clientId,locale,n,channel,adTest,isAdult,catpath,hints,mplx) {
    _viewAdLargeImageBottomAdSense((clientId != "" ? "yahoo" : "google"),clientId,locale,n,channel,adTest,isAdult,catpath,hints,mplx);
}
function _viewAdLargeImageBottomAdSense(adsenseType,clientId,locale,n,channel,adTest,isAdult,catpath,hints,mplx) {
    if ( n < 1 ) return;
	google_ad_request_done = function(google_ads) {
		var s;
		if (n == 1)
			s = _adSenseStackWideDisplayTable(google_ads,0,100,"adsense-div-border2","stack-adsense-title2mid","adsense-item",mplx);
		else
			s = _adSenseStackWideDisplayTable(google_ads,0,100,"adsense-div-border2","stack-adsense-title2","adsense-item",mplx);
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
			if (gs_top)	gs_top.innerHTML = s;
		}
	};
	google_max_num_ads = n;
	if (adsenseType == "yahoo" ) { 
		setupYahooAdSense2(clientId,channel,google_max_num_ads ,catpath,hints,isAdult);
	} else {
		if ( hints )
			google_hints = catpath + hints;
		else if ( catpath )
		    google_hints = catpath;			
		setupAdSenseWithClientId(clientId,channel,locale,adTest,isAdult);
	}
}
	
	/*	
function browseAdSense(locale,n,channel,adTest,isAdult,hints) {
    if ( n < 1 ) return;
    google_max_num_ads = n;
	if ( hints )
		google_hints = hints;
	setupAdSense(channel,locale,adTest,isAdult);

}*/

function setupYahooAdSense(partnerId,channelId,maxAdCount,categoryPath,isAdult) {
	if(isAdult){
		ysm_Adult = 'any';
	}else{
		ysm_Adult = 'clean';
	}
	
	ysm_Partner = partnerId;
	
	ysm_Path = categoryPath;
	ysm_Maxcount = maxAdCount;
	ysm_Page = '';
	ysm_Keywords = '';
	ysm_Type = channelId;
	document.writeln('<script language="JavaScript" src="http://tw.yimg.com/i/tw/ysm/kijiji/kijijitw2ysm.js"></script>');

}

function isdefined( variable)
{
    return (typeof(variable) == "undefined")?  false: true;
}




function setupYahooAdSense2(partnerId,channelId,maxAdCount,categoryPath,keywords,isAdult,page) {
	if(isAdult){
		ysm_Adult = 'any';
	}else{
		ysm_Adult = 'clean';
	}
	
	ysm_Partner = partnerId;
	
	ysm_Path = categoryPath;
	ysm_Maxcount = maxAdCount;
	ysm_Page = page ? page : '';
	ysm_Keywords = '';
	if (isdefined(keywords))
		ysm_Keywords = keywords;
	ysm_Type = channelId;
	document.writeln('<script language="JavaScript" src="http://tw.yimg.com/i/tw/ysm/kijiji/kijijitw2ysm.js"></script>');

}


function yahoo_ad_request_done(){
	var google_ads = new Array();
	var google_ad;
	var j=0;
	var i=0;
	var firstAdSkipped = false;
	while(i < zSr.length){
		google_ad = new Object();
		google_ad.n = j+1;
		google_ad.line2 = zSr[i++]; //Listing description
		i++; //for unused1
		google_ad.url = zSr[i++]; //Click url
		google_ad.line1 = zSr[i++]; //title
		google_ad.visible_url = zSr[i++]; // advertiser's domain
		i++ ;// unused2
		if(firstAdSkipped == false){
			//skip the first ad as it is alwasy about overure
			firstAdSkipped = true;
		}else{
			google_ads[j++] = google_ad;
		}
		google_ad_type="";
		google_ad.bidtype="";
		google_ad.line3="";

	}
	google_ad_request_done(google_ads);


}

function getURLParameter(paramName)
{
	var sURL = window.document.URL.toString();
	var i = 0;
	if (sURL.indexOf("?") > 0){
		var arrParams = sURL.split("?");
		var arrURLParams = arrParams[1].split("&");

		for (i=0;i<arrURLParams.length;i++){
			var sParam = arrURLParams[i].split("=");
			if (sParam[0].toLowerCase() == paramName.toLowerCase()) {
				return (sParam[1] != "") ? unescape(sParam[1]) : "";
			}
		}
	}
	else  return ("");	
}

/*first page, link unit on browse page*/
/*only display 5 ad links generated by google*/
function displayAdLinkOnly(unitTitle, selCatId, selLocId, layout, id, divclass, titleclass, itemclass){	
	var txt="";
	google_ad_request_done = function(google_ads) {	}
	google_radlink_request_done=function (radlinks) {		
		if (radlinks.length < 1) return;
		txt += "<div class=\"" + divclass + "\"><span class=\"" + titleclass + "\">" + unitTitle + "</span>";
		txt += "<ul class=\"" + itemclass + "\">";

		for(i=0; i < radlinks.length; ++i) {
			txt += "<li>";
			var termExist = radlinks[i].term != getURLParameter("term");
			if (termExist)
				txt += '<a target="_top" href="AdLinkUnit?term='+ escape(radlinks[i].term) + '&google_kw=' + radlinks[i].url_escaped_term + '&google_page_url=' + window.location + '&CatId='+ selCatId+ '&LocId='+ selLocId + '&Layout=' + layout + '">';
			txt += radlinks[i].term;
			if (termExist)
				txt += "</a>";
			txt += "<br>\n</li>";
	    	}	    
		txt+="</ul></div>";
		if ( txt != null ) {
			
			var element = document.getElementById(id);
			if ( element != null ) {
				element.innerHTML = txt;
			}
		}		
	}	
}

/*2nd page, google ad sense page*/
/*display 10 ads generated by google*/
function displayAdSenseInAdLinkUnit() {
	google_ad_request_done = function(google_ads) {
		var s = _adSenseStackWideDisplay(google_ads,0,100,"linkunit-adsense-div","linkunit-adsense-title","linkunit-adsense-item");
		if ( s != null ) {
			var gs_top = document.getElementById("googsense");				
			if (gs_top)	gs_top.innerHTML = s;
		}
	};
	
}


/*set up first page, link unit on browse page*/
function setupAdLinkOnly(client, channel,language,adTest,isAdult, kw) {	
	if ( channel )
		google_ad_channel = channel; 
	google_ad_output = 'js';
	google_encoding = "utf8";
	if ( adTest )
		google_adtest = 'on';
	google_safe = isAdult == 'true'? 'medium':'high';
	google_language = language;	

	google_max_num_ads = 0;

	google_num_radlinks = 5;
	google_max_radlink_len = 30;
	
	google_rl_filtering = 'medium';
	google_rl_mode = 'default';

	google_ad_client = client;
}


/*set up 2nd page, google ad sense page*/
function setupAdLinkUnit( prevLink, client, channel,language,adTest,isAdult, kw) {
	google_page_url = prevLink;	
	google_prev_ad_formats_by_region = {"":"adlinks"};   //requested by google
	google_max_num_ads = 10;
	
	
	if ( channel )
		google_ad_channel = channel; 
	google_ad_output = 'js';
	google_encoding = "utf8";
	if ( adTest )
		google_adtest = 'on';
	google_safe = isAdult == 'true'? 'medium':'high';
	google_language = language;	

	google_max_num_ads = 0;	
	google_kw = kw;
	google_kw_type = 'broad';	
	google_ad_client = client;
}

