var dtype = 'gpxfile';
exportWaypoints = true;
exportRoutes = true;
exportTracks = true;

control = null;
xmlToGarmin = '';

function toggleExportWaypoints() {
	exportWaypoints = !exportWaypoints;
}

function toggleExportRoutes() {
	exportRoutes = !exportRoutes;
}

function toggleExportTracks() {
	exportTracks = !exportTracks;
}

function getContentParameters() {
	url = 'mid=' + GF.edit.MAP_ID + '&';
	
	if (exportWaypoints) {
		url += 'exportWaypoints=true&';
	} 
	
	if (exportRoutes) {
		url += 'exportRoutes=true&';
	} 
	
	if (exportTracks) {
		url += 'exportTracks=true&';
	} 
	
	return url;
}

function getElement(id) {
	if (document.getElementById || document.all) {
    	return document.getElementById? document.getElementById(id): document.all[id];
    }
}

function hideAll() {
	getElement('tomtomfile').style.display = "none";
	getElement('tomtomdevice').style.display = "none";
	getElement('garmindevice').style.display = "none";
	getElement('gpxfile').style.display = "none";
	getElement('garminfile').style.display = "none";
}
  	
function setSelectedType(selectedType) {
	dtype = selectedType;
	hideAll();	
	getElement(selectedType).style.display = "block";
}

function getDownloadUrl(xmlurl) {
	url = '';
	
	if (dtype == 'tomtomfile') {
		url = '../../app/export?type=tomtom&';
		url += getContentParameters();
	} else if (dtype == 'gpxfile') {
		url = '../../app/export?type=gpx&';
		url += getContentParameters();
	} else if (dtype == 'garminfile') {
		url = '../../app/export?type=garmin&';
		url += getContentParameters();
	} else if (dtype == 'tomtomdevice' && (exportWaypoints || exportRoutes)) {
		url = 'http://addto.tomtom.com/api/home/v2/content?action=install&apikey=29c2db84-d8a7-4112-82b2-cd0d56f66896&' + 
			'uri=http%3A//' + xmlurl + '/tomtom/' + GF.edit.MAP_ID + '/addtotomtomxml.xml&source=http%3A//' + xmlurl + '/mapdetail.html';
	}
	return url;
}