function serve_ads( url, div_id, use_flash )
{
	var ajax_request = new ajax();

	if ( use_flash == false )
	{
		url = url + "&flash=0";
	}
	
	ajax_request.load_url(url, serve_ads_complete, div_id );
}


/**
 * The search callback function to update the suburb list.
 */
function serve_ads_complete( http_request, div_id )
{
	xmldoc = http_request.responseXML;

	// Check the success.
	success = ajax_success(xmldoc);
	if( true != success )
	{
		alert('There was an error retrieve the ads, please try again later');
		return;
	}
	
	var html_content = ajax_element_value(xmldoc, 'html_content');
	
	if( html_content.length > 0 )
	{
		// Fetch the div where to place the html.
		var div = document.getElementById(div_id);
		if( !div )
		{
			return;
		}
		
		// Add the content onto our list of conditions.
		div.innerHTML = html_content;
	}
}

//
// Function to catch the click paramter and opens the destination url
//

function advert_click_destination(cid, target) 
{
	// Open in new window
	if (20 == target)
	{
		new_window = window.open();
		new_window.location.href = "/_advert/click/" + cid;
	}
	else 
	{
		document.location.href = "/_advert/click/" + cid;	
	}
}
