function initEventFeature() {
	if (document.getElementById('eventFeatureSpecies').style.display != 'none') {
		jQuery('#species').jcarousel({
        scroll: 4
    });
	}
		
	var ctrlat = $('#latitude').val();
	var ctrlng = $('#longitude').val();
	$('#eventFeatureMap').jmap('init',{ 
                'mapType':'hybrid',
								'mapCenter':[ctrlat,ctrlng], 
								'mapZoom':10, 
                'mapEnableType':true, 
                'mapShowjMapsIcon': false
                }, 
								function(map,element,options) {
									mapObj = map;
	}); // end init function 
	//$('#eventFeatureMap').jmap('CreateMarkerManager', {'markerManager':'MarkerManager'});
	
	initEventSightingMarkers();
}

function initEventSightingMarkers(speciesId, speciesName) {
	if (speciesId) {
		$('#species_filter').html(speciesName).addClass('unchecked').show();
	}
	else {
		speciesId = '';
	}
	
	$.ajax({
		type: 'GET',
		url: base_url + 'event/sighting_markers/',
		data: '&event_id=' + event_id + '&species_id=' + speciesId,
		dataType: "json",
		success: function(data){
			createEventSightingMarkers(data.markers);
		}
	});
}

function removeEventSightingMarkers() {
	$('#species_filter').empty().hide();
	
	initEventSightingMarkers();
}

function createEventSightingMarkers(list) {
	markerArr = new Array();
	var item, point, html, marker;
	for (var i = 0; i < list.length; i++) {
		item = list[i];
		species_dir = getSpeciesDir(item.species_name);
		
		point = new GLatLng(item.latitude, item.longitude);

		html = '';
		html += '<div id="hotspot_sighting_box">';
		html += '  <div id="hotspot_sighting_list" class="clearAfter">';
		html += '    <div class="clearAfter">';
		html += '      <div class="species_picture floatLeft">';
		html += '        <a href="' + base_url + 'species/view/' + species_dir + '" target="_blank"><img width="50" height="50" src="' + static_url + 'statics/images/species/' + item.folder + '/st.jpg" /></a>';
		html += '      </div>';
		html += '      <div class="species_desc floatRight">';
		html += '        <div class="species_title">SPECIES NAME:</div>';
		html += '        <div class="species_name"><a href="' + base_url + 'species/view/' + species_dir + '" target="_blank">' + item.species_name + '</a></div>';
		html += '      </div>';
		html += '    </div>';
		html += '    <div class="sighting_desc clearAfter">';
		html += '      <p>Quantity: ' + item.number_sighted + '</p>';
		if (item.username != '') {
			html += '      <p>User: ' + item.username + '</p>';
		}
		html += '      <p>Time Sighted: ' + item.sighting_time + '</p>';
		html += '    </div>';
		html += '  </div>';
		html += '</div>'; 
		
		marker = createSightingMarker(point, html);
		markerArr.push(marker);
	}
	
	if (markerClusterer != null) {
		markerClusterer.clearMarkers();
	}
	markerClusterer = new MarkerClusterer(mapObj, markerArr);
}

function createSightingMarker(point, html) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html);});
	return marker;
}





function initEventView() {
	var ctrlat = $('#latitude').val();
	var ctrlng = $('#longitude').val();
	$('#eventViewMap').jmap('init',{ 
                'mapType':'hybrid',
								'mapCenter':[ctrlat,ctrlng], 
								'mapZoom':10, 
                'mapEnableType':true, 
                'mapShowjMapsIcon': false
                }, 
								function(map,element,options) {
									mapObj = map;
									GEvent.addListener(map, 'click', addHotspot);
	}); // end init function 
	//$('#eventFeatureMap').jmap('CreateMarkerManager', {'markerManager':'MarkerManager'});
		
	initEventMarkers();

	var pars = '&event_id=' + event_id;
	$.ajax({
		type: 'GET',
		url: base_url + 'event/sighting_lists/',
		data: pars,
		success: function(data){
			$('#sighting_list').html(data);

			$('#data_list table').tablesorter({
				headers: {0: {sorter: false}, 5: {sorter: false}}
			});
			//}).tablesorterPager({container: $('#tablepager')});

			$('#data_list table').columnManager({listTargetID:'targetColumn', onClass: 'simpleon', offClass: 'simpleoff', saveState: false, hideInList: [1,2], colsHidden: [4,5,6,7,8]});
		}
	});
	
	//$('select#participant_id,select#deviceid,select#species_id').sSelect();
	//$('#participant_dropdown ul,#deviceid_dropdown ul,#species_dropdown ul').css('height', 'auto');
}

function initEventMarkers() {
	if (mapObj != null) {
		mapObj.clearOverlays();
	}
	
	$.ajax({
		type: 'GET',
		url: base_url + 'event/hotspot_markers/',
		data: '&event_id=' + event_id,
		dataType: "json",
		success: function(data){
			createEventMarker(data.markers);
		}
	});
}

function changeEventViewMarkers() {
	$.ajax({
		type: 'GET',
		url: base_url + 'event/hotspot_markers/',
		data: '&event_id=' + event_id + '&user_id=' + $('#participant_id').val() + '&deviceid=' + $('#deviceid').val() + '&species_id=' + $('#species_id').val(),
		dataType: "json",
		success: function(data){
			createEventMarker(data.markers);
		}
	});
}

function createEventMarker(list) {
	if (mapObj != null) {
		mapObj.clearOverlays();
	}
	
	var item,lat,lng,hotspot_id,html;

	for (var i = 0; i < list.length; i++) {
		item = list[i];
		lat = item.latitude;
		lng = item.longitude;
		hotspot_id = item.hotspot_id;
		
		$('#eventViewMap').jmap('AddMarker',{ 
								'pointLatLng':[lat,lng], 
                //'pointIsRemovable':true, 
                //'pointIsDraggable':true,
								'hotspot_id':hotspot_id
                },
								function(marker, options) {
									GEvent.addListener(marker, 'click', function(){
										$.ajax({
											type: 'GET',
											url: base_url + 'hotspot/sighting/', 
											data: '&hotspot_id=' + options.hotspot_id,
											success: function(data){
												markerObj = marker;
												marker.openInfoWindowHtml(data);
											}
										});
				          });
								}); 
	}
}

function pageHostspotSighting(hotspot_id, p) {
	$.ajax({
		type: 'GET',
		url: base_url + 'hotspot/sighting/', 
		data: '&hotspot_id=' + hotspot_id + '&p=' + p,
		success: function(data){
			markerObj.openInfoWindowHtml(data);
		}
	});
}

function showHotspotSighting(hotspot_id, sighting_id, latitude, longitude) {
	$.ajax({
		type: 'GET',
		url: base_url + 'hotspot/sighting/', 
		data: '&hotspot_id=' + hotspot_id + '&sighting_id=' + sighting_id,
		success: function(data){
			mapObj.openInfoWindowHtml(new GLatLng(latitude, longitude), data);
		}
	});
}

function getHotspotFormHtml(data) {
	var str = '<div id="hotspotForm">' 
	+ '<h4>Add Hotspot</h4>'
	+ '<form name="hotspot_form" id="hotspot_form" method="post" action="' + base_url + 'hotspot/edit" target="hidden_iframe">' 
	+ '<input type="hidden" name="rt" id="rt" value="iframe">' 
	+ '<input type="hidden" name="event_id" id="event_id" value="' + event_id + '">' 
	+ '<input type="hidden" name="hotsopt_id" id="hotsopt_id" value="' + data.hotspot_id + '">' 
	+ '<input type="hidden" name="point_id" id="point_id" value="' + data.point_id + '">' 
	+ '<table border="0" class="google_map_table" cellspacing="0" cellpadding="0">' 
	+ '<tbody><tr> <td width="40%"><p class="boldText">Location: </p> </td> <td width="60%"> <input id="location" name="location" value="' + data.location + '" type="text" style="width: 250px;"> <span class="grayText">* LatLng: [' + data.latitude + ',' + data.longitude + ']</span><input type="hidden" name="latitude" id="latitude" value="' + data.latitude + '"> <input type="hidden" name="longitude" id="longitude" value="' + data.longitude + '"> </td> </tr> <tr> <td width="40%"><p class="boldText">City :</p></td> <td width="60%"> <input id="city" name="city" value="' + data.city + '" type="text"> <span class="grayText">*</span> </td> </tr> <tr> <td width="40%"><p class="boldText">State :</p></td> <td width="60%"> <input id="state" name="state" value="' + data.state + '" type="text"> <span class="grayText">*</span> </td> </tr> <tr> <td><p class="boldText">Postcode :</p></td> <td> <input id="postcode" name="postcode" value="' + data.postcode + '" type="text"> <span class="grayText">*</span> </td> </tr> <tr> <td><p class="boldText">Country :</p></td> <td>	 <input id="country" name="country" value="' + data.country + '" type="text"> <span class="grayText">*</span> </td> </tr> <tr> <td><p class="boldText">Note: <span class="grayText">*</span></p></td> <td><textarea cols="30" rows="3" id="note" name="note"></textarea></td> </tr>' 
	+ '<tr> <td>&nbsp;</td> <td> <input type="image" name="createsightingBtn" id="createsightingBtn" src="' + static_url + 'statics/images/en/save_btn.jpg"> </td> </tr> </tbody></table>	 </form> </div>';
	return str;
}

function addHotspot(overlay,latlng) {
	//mapObj.clearOverlays(); 
	if (!latlng) return;
	var lat = latlng.lat().toFixed(8); 
  var lng = latlng.lng().toFixed(8); 
	var data = {
		'location':'', 
		'street':'',
		'city':'',
		'state':'',
		'postcode':'',
		'country':'',
		'latitude':'',
		'longitude':''
	};
	//window.opener.triggerLatLonField(lat,lng);

	$('#eventViewMap').jmap('SearchAddress', {
				'query': new GLatLng(lat, lng),
				'returnType': 'getLocations'
		}, function(result, options) {
				var valid = Mapifies.SearchCode(result.Status.code);
				if (valid.success && result.Placemark.length > 0) {
					//alert(result.Placemark.length);
			  	var point = result.Placemark[0];
					
					var data = getGeocodingData(point);
					data.latitude = lat; 
					data.longitude = lng;
					
					var str = getHotspotFormHtml(data);
					mapObj.openInfoWindowHtml(new GLatLng(lat, lng), str);
				}
				else {
					return;
				}
		});
	return false;
}

function completeSaveHotspot() {
	initEventMarkers();
}

function completeAddHotspot(data) {
	alert(data.status);
}

function deleteHotspot(hotspot_id) {
	if (tabId != 'tab1') return;
	
	if (!hotspot_id) return;

	$.ajax({
		type: 'POST',
		url: base_url + 'hotspot/del/',
		data: '&hotspot_id=' + hotspot_id,
		dataType: "json",
		success: function(data){
			completeSaveHotspot();
		}
	});
}

function addSighting(hotspot_id) {
	$('#sightingBox').empty();
	
	var pars = 'event_id=' + event_id + '&hotspot_id=' + hotspot_id;
	Boxy.load(base_url + 'sighting/edit_popup/?' + pars, {modal:true, title:'Add Sighting', 
		afterShow: function() {
			sightingValidate();			
			speciesAutocomplete();
		}
	});
}

function editSighting(sighting_id) {
	$('#sightingBox').empty();
	
	var pars = 'sighting_id=' + sighting_id;
	Boxy.load(base_url + 'sighting/edit_popup/?' + pars, {modal:true, title:'Edit Sighting', 
		afterShow: function() {
			sightingValidate();			
			speciesAutocomplete();
			editSightingFindInGoogleMap();
		}
	});
}

function editSightingFindInGoogleMap() {
	$('#location_submit').click(function() {
		var geocoder = new GClientGeocoder();
		geocoder.getLocations($('#location').val(), changeSightingFindInGoogleMap);
	});
}

function changeSightingFindInGoogleMap(response) {
	if (!response || response.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address");
	} else {
		point = response.Placemark[0];
		var data = getGeocodingData(point);
		$('#street').val(data.street);
		$('#city').val(data.city);
		$('#state').val(data.state);
		$('#postcode').val(data.postcode);
		$('#country').val(data.country);
		$('#latitude').val(data.latitude);
		$('#longitude').val(data.longitude);
	}
}

function deleteSighting(sighting_id) {
	$.ajax({
		type: 'POST',
		url: base_url + 'sighting/delete',
		data: '&sighting_id=' + sighting_id,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function sightingValidate() {
	var validator = $('#sighting_form').validate({
		rules: {
			species_id_popup: "required"
		},
		messages: {
			species_id_popup: "Please select some species."
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			sightingSubmit();
		}
	});
}

function sightingSubmit() {
	$.ajax({
		type: 'POST',
		url: base_url + 'sighting/edit_popup/',
		data: $('#sighting_form').serialize(),
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				showMessage(data.message, '#sightingBox');
				wait('refreshUrl()', 0.5);
				//new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
			else {
				showError(data.message, '#sightingBox');
			}
		}
	});
}



function initEventEdit() {
	var ctrlat = 40.747009;
	var ctrlng = -73.989944;
	$('#eventEditMap').jmap('init',{ 
                'mapType':'hybrid',
								'mapCenter':[ctrlat,ctrlng], 
								'mapZoom':12, 
                'mapEnableType':true, 
                'mapShowjMapsIcon': false
                }, 
								function(map,element,options) {
									mapObj = map;
	}); // end init function 
	
	findInGoogleMap();
	
	if ($('event_checklist').val() == 1) {
		if ($('#species_ids').val() != '') {
			speciesIdArr = $('#species_ids').val().split(',');	
			if (speciesIdArr.length > 0) {
				$('#eventChecklist').css('height', 'auto');
			}
		}
	}
	try {
		if ($('#event_id').val() == '')	{
			var d = new Date();
			/*
			$("#StartMonth")[0].options(d.getMonth()).selected = true; 
			$("#StartDay")[0].options(d.getDate()-1).selected = true; 
			$("#StartHour")[0].options(d.getHours()%12==0?11:d.getHours()%12-1).selected = true; 
			$("#StartMinute")[0].options(d.getMinutes()).selected = true; 

			$("#EndMonth")[0].options(d.getMonth()).selected = true; 
			$("#EndDay")[0].options(d.getDate()-1).selected = true; 
			$("#EndHour")[0].options((d.getHours()+3)%12==0?11:(d.getHours()+3)%12-1).selected = true; 
			$("#EndMinute")[0].options(d.getMinutes()).selected = true; 
			*/
			document.getElementById("StartMonth").options(d.getMonth()).selected = true; 
			document.getElementById("StartDay").options(d.getDate()-1).selected = true; 
			document.getElementById("StartHour").options(d.getHours()%12==0?11:d.getHours()%12-1).selected = true; 
			document.getElementById("StartMinute").options(d.getMinutes()).selected = true; 

			document.getElementById("EndMonth").options(d.getMonth()).selected = true; 
			document.getElementById("EndDay").options(d.getDate()-1).selected = true; 
			document.getElementById("EndHour").options((d.getHours()+3)%12==0?11:(d.getHours()+3)%12-1).selected = true; 
			document.getElementById("EndMinute").options(d.getMinutes()).selected = true; 
		}
	}
	catch (e) {}
}

function findInGoogleMap() {
	$('#location_submit').click(function(){
		if ($('#location').val() == '') {
			alert('Please enter a valid location!');
			return false;
		}

		if (mapObj != null) {
			mapObj.clearOverlays(); 
		}
		
		$('#eventEditMap').jmap('SearchAddress', {
				'query': $('#location').val(),
				'returnType': 'getLocations'
		}, function(result, options) {
				var valid = Mapifies.SearchCode(result.Status.code);
				if (valid.success) {
					//alert(result.Placemark.length);
					if (result.Placemark.length > 0) {
				  	var point = result.Placemark[0];
				  	//debug(point.Point.coordinates[1] + '/' + point.Point.coordinates[0]);

						var lat = point.Point.coordinates[1].toFixed(8);
						var lng = point.Point.coordinates[0].toFixed(8);
						
				  	$('#eventEditMap').jmap('AddMarker', {
				  		'pointLatLng': [lat, lng],
				  		'pointHTML': point.address
				  	});
				  	Mapifies.MoveTo($('#eventEditMap'), {'mapCenter':[lat, lng], 'mapZoom': 12});

						var data = getGeocodingData(point);
						$('#street').val(data.street);
						$('#city').val(data.city);
						$('#state').val(data.state);
						$('#postcode').val(data.postcode);
						$('#country').val(data.country);
						$('#latitude').val(data.latitude);
						$('#longitude').val(data.longitude);
						loadWeather(data.latitude, data.longitude);
				  }
				} else {
						//$('#location').val(valid.message);
						alert('Please enter a valid location!');
				}
		});
		
		return false;	
	});
}

function editChecklist() {
	$('#checklistBox').remove();
	
	Boxy.load(base_url + 'checklist/popup/', {modal:true, title:'Event Checklist', 
		afterShow: function() {
			speciesAutocompleteChecklist();
			$('#species_search').focus();
			
			var id = '';
			var name = '';
			var liArr = $('#eventChecklist ul li');
			
			$('#eventChecklist ul li').each(function(i){
				id = speciesIdArr[i];
				name = $(this).find('span:first').text();
				$('<li id="species_' + id + '"><span class="floatLeft">' + name + '</span><span class="floatRight"><a href="javascript:void(0);" onclick="removeSpecies(' + id + ')">' + '</a></span></li>').addClass(i%2 == 0 ? 'ac_even' : 'ac_odd').appendTo('#species_selected ul');	
			});

		}, 
		afterHide: function() {
			speciesAutofill();
		}
	});
}

function speciesAutocomplete() {
	$('#species_search').autocomplete(base_url + 'species/search/', {
		minChars: 1,
		width: 180,
		max: 10,
		scrollHeight: 220,
		selectFirst: true
	});
	
	$('#species_search').result(function(event, data, formatted) {
		if (data) {
			var id = data[1];
			var name = data[0];

			$('#species_id_popup').val(id);
		}
	});
}

function speciesAutocompleteChecklist() {
	$('#species_search').autocomplete(base_url + 'species/search/', {
		minChars: 1,
		width: 180,
		max: 10,
		scrollHeight: 220,
		selectFirst: true
	});
	
	$('#species_search').result(function(event, data, formatted) {
		if (data) {
			$('#species_search').val('');
			var id = data[1];
			var name = data[0];

			if (!speciesIdArr.contains(id)) {
				speciesIdArr.push(id);
				$('<li id="species_' + id + '"><span class="floatLeft">' + name + '</span><span class="floatRight"><a href="javascript:void(0);" onclick="removeSpecies(' + id + ')">' + '</a></span></li>').addClass(speciesIdArr.length%2 == 0 ? 'ac_even' : 'ac_odd').appendTo('#species_selected ul');	
			}
		}
	});
}

function speciesAutofill() {
	$('#eventChecklist ul').empty();
	var cnt = 0;
	$('#species_selected ul li').each(function(i){
		$('<li><span>' + $(this).find('span:first').text() + '</span></li>').appendTo('#eventChecklist ul');
		cnt++;
	});
	
	if (cnt > 0) {
		$('#eventChecklist').css('height', 'auto');
	}
	$('#species_ids').val(speciesIdArr.join(','));
}

function removeSpecies(id) {
	$('li#species_'+id).remove();
	speciesIdArr.remove(id);
	
	$('#species_selected ul li:nth-child(even)').each(function(){ 
		$(this).removeClass('ac_odd').addClass('ac_even'); 
	});
	
	$('#species_selected ul li:nth-child(odd)').each(function(){ 
		$(this).removeClass('ac_even').addClass('ac_odd'); 
	});
}

function rsvpEvent(eventId) {
	$('#rsvpBox').empty();
	
	Boxy.load(base_url + 'event/rsvp_popup', {modal:true, title:'Sign up for the event', 
		afterShow: function() {
			$('#rsvp_event_id').val(eventId);
			rsvpValidate();
		}
	});
}

function rsvpValidate() {
	$('#rsvp_message').focus();
	var validator = $('#rsvp_form').validate({
		rules: {
			rsvp_message: "required"
		},
		messages: {
			rsvp_message: "Please enter your message."
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			rsvpSubmit();
		}
	});
}

function rsvpSubmit() {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/rsvp_popup',
		data: '&rsvp_event_id=' + $('#rsvp_event_id').val() + '&rsvp_message=' + $('#rsvp_message').val(),
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function editEvent(eventId) {
	locateUrl(base_url + 'event/edit/' + eventId);
}

function joinEvent(eventId) {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/join',
		data: '&event_id=' + eventId,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function deleteEvent(eventId) {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/delete',
		data: '&event_id=' + eventId,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function leaveEvent(eventId) {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/leave',
		data: '&event_id=' + eventId,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function approveEventRsvp(uid) {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/rsvp_approve',
		data: '&uid=' + uid,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}

function disapproveEventRsvp() {
	$.ajax({
		type: 'POST',
		url: base_url + 'event/rsvp_disapprove',
		data: '&uid=' + uid,
		dataType: "json",
		success: function(data){
			if (data.status == 'success') {
				new Boxy('<div id="popupBox">' + data.message + '</div>', {modal: true, title:'Message', afterHide: function(){refreshUrl();}});
			}
		}
	});
}


function loadWeather(lat, lng) {
	var days = 0;
	
	try {
		var now = new Date();
		var now_s = now.format('yyyy-m-d');
		var event_date_s = document.getElementById('StartYear').value + '-' + document.getElementById('StartMonth').value + '-' + document.getElementById('StartDay').value;
		
		days = dateDiff('D', now_s, event_date_s);
		if (days == -1) days = 0;
	}
	catch (e) {}
	
	if (Number(days) < 0 || Number(days) > 3) days = 0;
	$.ajax({
		type: 'GET',
		url: base_url + 'weather/index/?latlng=' + Math.round(lat*1000000) + ',' + Math.round(lng*1000000) + '&days=' + days + '&r=' + Math.random(),
		data: '',
		dataType: 'json',
		success: function(data) {
			var s = data.condition + ' ' + data.low + '-' + data.high;
			document.getElementById('weather').value = s;
		}
	});
}

function loadUserDeviceid(userId) {
	var html = '<select id="deviceid" name="deviceid" onchange="changeEventViewMarkers();"><option value="">Select Device</option>';
	
	if (userId == '') {
		html += '</select>&nbsp;';
		document.getElementById('deviceid_select').innerHTML = html;
		changeEventViewMarkers();
	}
	else {
		$.ajax({
			type: 'GET',
			url: base_url + 'account/user_deviceid_json/' + userId,
			data: '',
			dataType: 'json',
			success: function(data){
				html += '<option value="-1">Web entry</option>';
				
				var list = data.deviceid_array;
				var device = null;
				for (var i = 0; i < list.length; i++) {
					device = list[i];
					html += '<option value="' + device.deviceid + '">' + device.device_name + '</option>';
				}
				html += '</select>&nbsp;';
				document.getElementById('deviceid_select').innerHTML = html;
				changeEventViewMarkers();
			}
		});
	}
}


function callFBPublish() {
	var event_name = document.getElementById('event_name').value;
	var event_note = document.getElementById('note').value;
  FB.ensureInit(function () {
		var message = ''; 
		var attachment = { 
		'name': event_name, 
		'href': base_url + 'event/view/' + event_id, 
		'description': event_note
		};
		var action_link = null; 
    FB.Connect.streamPublish(message, attachment, action_link, null, null, callFBPublish_callback);
  });
}

function callFBPublish_callback(post_id, exception) {
  if (post_id) {
    //post_to_my_server(post_id);
		//alert(post_id);
		//location.href = location.href;
  }
	else {
		//alert(exception);
	}
}

function toggleColumn() {
	toogleObj('targetColumn');
}