/**
 * collected tags
 */
var tags = $A();


function handleTag(id,obj) {
	if ($('seealltag_'+id)){
		$('seealltag_'+id).toggleClassName('taken');
	}
	if ($('leftnavtag_'+id)){
		$('leftnavtag_'+id).toggleClassName('taken');
	}
	
	if (tags.indexOf(id)>=0) {
		tags = tags.without(id);
	} else {
		tags = tags.uniq();
		tags[tags.size()] = id;
	}
	$('tag_container').value = tags.join(',');
}

/**
 * Clicking on tags in leftnav
 * 
 * @param {Integer} id 
 * @param {DOM element} obj - Anchor tag
 */
function toggleTag(id,obj) {
	if (obj) {
		obj.parentNode.toggleClassName('taken');
	}
	handleTag(id);
}

/**
 * Clicking on tags in See all
 * 
 * @param {Integer} id 
 * @param {DOM element} obj - Anchor tag
 */
function toggleTagSeeAll(id,obj) {
	if (obj) {
		obj.toggleClassName('taken');
	}
	handleTag(id);
}

/**
 * Google Map initialization for search
 *
 **/
var geocoder = new GClientGeocoder();
function getCoord(searchfor,postGlue) {
	if (searchfor.length>0) {
		//alert(searchfor + ', ' + (postGlue?postGlue:'UK'));
		geocoder.reset();
		geocoder.getLatLng(
			searchfor + ', ' + (postGlue?postGlue:'UK'),
			function(point) {
				if (point) {
					document.getElementById("coords").value =  point.x + ',' + point.y;
					//document.getElementById("postcodesearchform").submit();
				} else {
					//alert('Sorry, postcode not found!');
				}
			}
		);
	}
}

/**
 * Flashmap click JS callback
 */
function map_click(id) {
	//window.location = '<?=$html->url('/venues/search/location/'); ?>'+id;
	$('location').value = id;
}