/****************************************************
function: createMarker
description: utility function that creates a map marker
****************************************************/
function user_create_marker(point, info) {

	var marker = new GMarker(point, iHsp2);

  marker.tooltip = '<div class="tooltip"><nobr>'+info['name']+'</nobr></div>';

	marker.user_id=info['id'];
	marker.token=info['token'];
	marker.name=info['name'];
	GEvent.addListener(marker, "click", function() { user_build_info_window(marker); } );

  GEvent.addListener(marker,"mouseover", function() { showTooltip(marker); });
  GEvent.addListener(marker,"mouseout", function() { tooltip.style.visibility="hidden" });

	return marker;
}


/****************************************************
function: clear_validators
description: destroy any existing validators
****************************************************/
function clear_validators(){
  while (validators.length > 0) {
    var tmp = validators.pop();
    delete tmp;
  }
}

// capture the 'enter' key and submit the form
function CheckForEnter(e)
{
  var key;

  if(window.event)
    key = window.event.keyCode;     //IE
  else
    key = e.which;     //firefox

  if(key == 13) {

    do_login();

  }
}


/****************************************************
function: show_login
description: displays login area - either a form or their info
****************************************************/
function show_login(){

  user_area_reset_styling();
	screen_name = '';
	$('user-area').innerHTML='';

	var myXHR = new XHR({method:'post',onSuccess: function(results){

		var return_obj = Json.evaluate(results);

		if (return_obj["success"] == true){

      screen_name = return_obj["name"];
      show_menu();
      user_area_show_hospots();

		} else {

			show_login_form();
		}

	}}).send('/php/check_login.php','getname=true');
}


/****************************************************
function: show_login_form
description: displays the actual login form
****************************************************/
function show_login_form(){

  user_area_reset_styling();
	var myXHR = new XHR({method:'post',onSuccess:function(results){

		$('menu-area').empty();
		$('user-area').innerHTML=results;

		if(sliderForgotPassword) {

		  delete sliderForgotPassword;
		  sliderForgotPassword = null;
		}

    sliderForgotPassword = new Fx.Slide('forgot_password', {duration: 500});
    sliderForgotPassword.hide(); // hide the div

    RememberMe();

	}}).send('/views/login_form.php', '' );

}

/****************************************************
function: show_menu
description: displays available options
****************************************************/
function show_menu(){

  var ma = $('menu-area');
  ma.empty();

  if (screen_name != '') {

    var tmp = new Element('h3').setText('Welcome ' + screen_name + '!').injectInside(ma);
    tmp = new Element('a', { 'id' : 'accmnu_hotspots', 'href' : 'javascript:user_area_show_hospots()', 'class' : 'sel' }).setText('Hotspots').injectInside(ma);
    tmp = new Element('text').setText('|').injectInside(ma);
    tmp = new Element('a', { 'id' : 'accmnu_tallies', 'href' : 'javascript:user_area_show_tallies()' }).setText('Tallies').injectInside(ma);
    tmp = new Element('text').setText('|').injectInside(ma);
    tmp = new Element('a', { 'id' : 'accmnu_profile', 'href' : 'javascript:user_area_show_profile()' }).setText('Profile').injectInside(ma);

    tmp = new Element('div', { 'id' : 'account_logout'}).injectInside(ma);
    tmp = new Element('a', { 'href' : 'javascript:logout()', 'styles' : { 'color' : '#555' } } ).setText('Logout').injectInside(tmp);

  }
}



/****************************************************
function: do_login
description: logs user in
****************************************************/
function do_login() {

	screen_name = '';
  $('side-bar-content').innerHTML = '';

	var myXHR = new XHR({method:'post',onSuccess:function(results){

		var return_obj = Json.evaluate(results);

		if (return_obj["success"]==true) {

      if($('chkRememberMe').checked) {

// save email and password in a cookie
        createCookie('aviae', $('email').value, 365);
        createCookie('aviap', $('password').value, 365);

      } else {

        eraseCookie('aviae');
        eraseCookie('aviap');
      }

      $('quick-message').innerHTML = "";
      $('quick-message').style.display = "none";

      screen_name = return_obj["name"];
			show_menu();
      user_area_show_hospots();
      $('tn-login').innerHTML = '<a href="#" onclick="logout();">Logout</a>';


		} else {

      $('side-bar-content').innerHTML = return_obj["message"];

		}
	}}).send('/php/controller_user.php?action=login', $('login-form').toQueryString() );
	return false;
}

/****************************************************
function: user_toggle_forgot_password
description: show/hide forgot password div
****************************************************/
function RememberMe()
{
  var username = readCookie('aviae');
  var password = readCookie('aviap');

  if (username && password) {

    document.getElementById('email').value = username;
    document.getElementById('password').value = password;
    document.getElementById('chkRememberMe').checked = true;
  }
}


/****************************************************
function: user_toggle_forgot_password
description: show/hide forgot password div
****************************************************/
function user_show_forgot_password() {

  $('side-bar-content').innerHTML = "";

  if (sliderForgotPassword) {

    sliderForgotPassword.show();
  }
}
/****************************************************
function: user_toggle_forgot_password
description: show/hide forgot password div
****************************************************/
function user_hide_forgot_password() {

  $('side-bar-content').innerHTML = "";

  if (sliderForgotPassword) {

    sliderForgotPassword.hide();
  }
}

/****************************************************
function: logout
description: logs user out
****************************************************/
function logout(){

	screen_name = '';
  $('menu-area').innerHTML = "";
  $('side-bar-content').innerHTML = "";
  $('tn-login').innerHTML = '<a href="#" onclick="set_active_tab($(\'tab-account\'));">Login</a>';

	var post_args='';
	var myXHR = new XHR({method:'post',onSuccess:show_login}).send('/php/logout.php',post_args);
}

/****************************************************
function: show_register_form
description: displays the register form and creates validators
****************************************************/
function show_register_form() {

  user_area_reset_styling();
  set_active_tab($('tab-account'));

	GDownloadUrl("/views/registration_form.html", function(data, responseCode) {
		empty($('side-bar-content'));

		$('user-area').innerHTML=data;

    clear_validators();

    validate = new LiveValidation( 'reg_first_name', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a first name" } );
    validators.push(validate);

    validate = new LiveValidation( 'reg_last_name', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a last name" } );
    validators.push(validate);

		var validate = new LiveValidation( 'reg_email', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a valid email address" } );
    validate.add( Validate.Email, { failureMessage: "Please enter a valid email address" } );
    validators.push(validate);

    validate = new LiveValidation( 'reg_password', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a password" } );
    validators.push(validate);

    validate = new LiveValidation( 'reg_password_confirm', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Confirmation, { match: 'reg_password', failureMessage: "Please confirm your password" } );

    validators.push(validate);

  });
}


/****************************************************
function: show_profile_update_form
description: displays the profile form and creates validators
****************************************************/
function show_profile_update_form(){

  user_area_reset_styling();
	GDownloadUrl("/views/profile_update_form.php", function(data, responseCode) {
		empty($('side-bar-content'));
		empty($('user-area'));

		$('user-area').innerHTML=data;

    clear_validators();

    validate = new LiveValidation( 'pro_first_name', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a first name" } );
    validators.push(validate);

    validate = new LiveValidation( 'pro_last_name', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a last name" } );
    validators.push(validate);

    validate = new LiveValidation( 'pro_screenname', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a screen name" } );
    validators.push(validate);

		var validate = new LiveValidation( 'pro_email', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a valid email address" } );
    validate.add( Validate.Email, { failureMessage: "Please enter a valid email address" } );
    validators.push(validate);

    validate = new LiveValidation( 'pro_password_confirm', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Confirmation, { match: 'pro_password', failureMessage: "Please confirm your password" } );

    validators.push(validate);
	});
}

/****************************************************
function: show_registration_info
description: displays a formatted registration summary
****************************************************/
function show_registration_info(){

  user_area_reset_styling();

	GDownloadUrl("/views/profile_summary.php", function(data, responseCode) {

		$('user-area-wrapper').removeClass('user-hotspots-tallies');

		$('user-area').innerHTML=data;

	});
}


/****************************************************
function: profile_public_show
description: displays a formatted registration summary
****************************************************/
function profile_public_show(lat, lng){

	var myXHR = new XHR({method:'get',onSuccess:function(results){

		$('profile-popup').innerHTML = results;
		$('profile-popup').style.display = "block";


    if (map_mode != MAP_MODE_PEOPLE) {

      set_mode_people();
    }

		center_profile();

    TB_show();

    if (lat && lng) {

  	  map.setCenter(new GLatLng(lat, lng), 12);

    }

	}}).send("/views/profile_public.php","");
}


/****************************************************
function: profile_public_form_show
description: displays a formatted registration summary
****************************************************/
function profile_public_form_show(lat, lng){

  var params="";

  if (lat && lng) {
    params="longitude="+lng+"&latitude="+lat;
  }

  clear_quick_message();

	var myXHR = new XHR({method:'get',onSuccess:function(results){

		$('profile-popup').innerHTML = results;
		$('profile-popup').style.display = "block";

    clear_validators();

    validate = new LiveValidation( 'pro_screenname', { onlyOnSubmit: true, validMessage: " " } );
    validate.add( Validate.Presence, { failureMessage: "Please enter a screen name" } );
    validators.push(validate);

    center_profile();

    TB_show();

	}}).send("/views/profile_public_form.php",params);
}


/* function: center_profile
description: force the profile form to the center of the map
****************************************************/
function center_profile() {

	var width=$('map').offsetWidth - ($('tab-content-wrapper').offsetWidth + $('tab-content-wrapper').style.right);
	var height=$('map').offsetHeight;

  var left = (width / 2) - ($('profile-popup').offsetWidth / 2);
  var top = 38 + ( (height / 2) - ($('profile-popup').offsetHeight / 2) );

  $('profile-popup').style.left = left + 'px';
  $('profile-popup').style.top =  top + 'px';

}


/****************************************************
function: do_registration
description: performs the registration of a new user
****************************************************/
function do_registration(){

    // validate the form...
  if ( LiveValidation.massValidate( validators ) ) {

  	$('side-bar-content').innerHTML='<img src="/images/progress.gif">';

  	var myXHR = new XHR({method:'post',onSuccess:function(results){
  		var return_obj = Json.evaluate(results);

  		if (return_obj["success"]){

  			show_login();

  			alert(return_obj["message"]);

        $('side-bar-content').innerHTML = return_obj["message"];

  		}else{

        $('side-bar-content').innerHTML = return_obj["message"];

  		}

  	}}).send('/php/controller_user.php?action=register', $('registration-form').toQueryString() );

  }
}

/****************************************************
function: profile_save
description: save changes to a user's public profile
****************************************************/
function profile_save(){


    // validate the form...
  if ( LiveValidation.massValidate( validators ) ) {

    var params = "pro_screenname=" + encodeURIComponent($('pro_screenname').value);
    params += "&latitude=" + $('latitude').value;
    params += "&longitude=" + $('longitude').value;
    params += "&altitude=" + $('altitude').value;
    params += "&longitude=" + $('longitude').value;
    params += "&city=" + $('city').value;
    params += "&state=" + $('state').value;
    params += "&zip=" + $('zip').value;
    params += "&country=" + $('country').value;
    params += "&pro_favorite_quote=" + encodeURIComponent($('pro_favorite_quote').value);
    params += "&pro_contact_info=" + encodeURIComponent($('pro_contact_info').value);
    params += "&pro_birthday=" + encodeURIComponent($('pro_birthday').value);
    params += "&pro_education=" + encodeURIComponent($('pro_education').value);
    params += "&pro_birding_since=" + encodeURIComponent($('pro_birding_since').value);
    params += "&pro_favorite_bird=" + encodeURIComponent($('pro_favorite_bird').value);
    params += "&pro_favorite_place=" + encodeURIComponent($('pro_favorite_place').value);
    params += "&pro_affiliations=" + encodeURIComponent($('pro_affiliations').value);

  	var myXHR = new XHR({method:'post',onSuccess:function(results){
  		var return_obj = eval("("+results+")");
  		if (return_obj["success"]==true){

    // update the map marker

        if (undefined_profile) {

      		var info=Array();

      		info["id"] = $('user_id').value;
      		info["name"] = $('pro_screenname').value;

    		  var marker = user_create_marker(undefined_profile.getPoint(),info);
    		  map.addOverlay(marker);
    		  gmarkers.push(marker);

      	  map.removeOverlay(undefined_profile);
      	  undefined_profile=null;
        }

        profile_public_show();
        show_registration_info();

  		}else{

        $('side-bar-content').innerHTML = return_obj["message"];

  		}
  	}}).send('/php/controller_user.php?action=update_public', params );

  }
}



/****************************************************
function: do_profile_update
description: performs the registration of a new user
****************************************************/
function do_profile_update(){


    // validate the form...
  if ( LiveValidation.massValidate( validators ) ) {

  	var myXHR = new XHR({method:'post',onSuccess:function(results){
  		var return_obj = eval("("+results+")");
  		if (return_obj["success"]==true){

        show_registration_info();

  		}else{

        $('side-bar-content').innerHTML = document.createTextNode(return_obj["message"]);

  		}
  	}}).send('/php/controller_user.php?action=update', $('registration-form').toQueryString() );

  }
}



/****************************************************
function: profile_public_delete
description: remove this user's public profile
****************************************************/
function profile_public_delete(user_id) {

  if (confirm("Are you sure you want to delete your public profile?")) {

  	var myXHR = new XHR({method:'post',onSuccess:function(results){
  		var return_obj = eval("("+results+")");
  		if (return_obj["success"]==true){
  			for (var i=0;i<gmarkers.length;i++){
  				if (parseInt(gmarkers[i].user_id)==parseInt(user_id)){
  						map.removeOverlay(gmarkers[i]);
  				}
  			}
    		$('profile-popup').style.display = "none";

      	TB_remove();

        show_registration_info();

  		}else{
  			alert(return_obj["message"]);
  		}
  	}}).send('/php/controller_user.php?action=delete_public','user_id='+user_id);
  }
}


/****************************************************
function: user_build_info_window
description: gets user window content
****************************************************/
function user_build_info_window(marker){

	var myXHR = new XHR({method:'get',onSuccess:function(results){

		$('profile-popup').innerHTML = results;
		$('profile-popup').style.display = "block";

    center_profile();

    TB_show();

	}}).send("/views/profile_public.php","user_id="+marker.user_id);

}

function profile_close() {

	$('profile-popup').style.display = "none";
	$('profile-popup').innerHTML="";
	if (undefined_profile) {
	  map.removeOverlay(undefined_profile);
	  undefined_profile="";
	}

	$('quick-message').innerHTML = "";
	$('quick-message').style.display = "none";

	TB_remove();
}


/****************************************************
function: hotspot_enable_move_mode
description: enables onclick hotspot-moving event for map
****************************************************/
function profile_enable_move_mode(user_id){

  profile_close();

	if (undefined_profile) map.removeOverlay(undefined_profile);

  map_tool_mode = MAP_TOOL_MOVE_PROFILE;

	eventListenerClick = GEvent.addListener(map, "click", function(marker, point) {

  	if (!marker) {

  	  if (map.getZoom() >= ADD_HOTSPOT_THRESHOLD) {

  			if (undefined_profile)
  			  map.removeOverlay(undefined_profile);

  			var icon = new GIcon();
  			icon.image = "/images/mm_20_blue.png";
  			icon.shadow = "/images/mm_20_shadow.png";
  			icon.iconSize = new GSize(12, 20);
  			icon.shadowSize = new GSize(22, 20);
  			icon.iconAnchor = new GPoint(6, 20);
  			icon.infoWindowAnchor = new GPoint(5, 1);
  			undefined_profile = new GMarker(point, { icon:icon, draggable:true } );
  			undefined_profile.enableDragging();
  			map.addOverlay(undefined_profile);

        msg = "<p>Please confirm you've located yourself correctly.</p>";
        msg += "<p><a href=\"javascript: profile_update_location(" + user_id + ");\">OK</a>";
        msg += "<a href=\"javascript: reset_map_mode();\">Cancel</a></p>";

      	$('quick-message').innerHTML = msg;
      	$('quick-message').style.display = "block";
  		}
    }
	});

  validate_tool_mode(map.getZoom());
}

/****************************************************
function: profile_update_location
description: move the user's profile
****************************************************/
function profile_update_location(user_id) {

	var myXHR = new XHR({method:'post',onSuccess: function(results){

		var return_obj = eval("("+results+")");

		if (return_obj["success"]==true){

// clean up
		  $('quick-message').style.display = "none";

// move the marker

			for (var i=0;i<gmarkers.length;i++){
				if (parseInt(gmarkers[i].user_id)==parseInt(user_id)){
					gmarkers[i].setPoint( undefined_profile.getPoint() );
				}
			}

//      set_mode_hotspot();
      reset_map_mode();

		} else {

		  alert(return_obj["message"]);

		}
	}}).send('/php/controller_user.php',"action=move&id="+user_id+"&lat="+undefined_profile.getPoint().lat()+"&lng="+undefined_profile.getPoint().lng());
}
/****************************************************
function: profile_enable_add_mode
description: enables onclick profile-adding event for map
****************************************************/
function profile_enable_add_mode(){

  if (map_mode != MAP_MODE_PEOPLE) {

    set_mode_people();
  }

  map_tool_mode = MAP_TOOL_ADD_PROFILE;

	eventListenerClick = GEvent.addListener(map, "click", function(marker, point) {

  	if (!marker) {

  	  if (map.getZoom() >= ADD_HOTSPOT_THRESHOLD) {

  	    if (!undefined_profile) {

          msg = "<p>Please confirm you've located yourself correctly.</p>";
          msg += "<p><a href=\"javascript: profile_public_form_show(undefined_profile.getPoint().lat(),undefined_profile.getPoint().lng());\">OK</a>";
          msg += "<a href=\"javascript: reset_map_mode();\">Cancel</a></p>";

        	$('quick-message').innerHTML = msg;
        	$('quick-message').style.display = "block";

  	    }

  			if (undefined_profile)
  			  map.removeOverlay(undefined_profile);

  			var icon = new GIcon();
  			icon.image = "/images/mm_20_yellow.png";
  			icon.shadow = "/images/mm_20_shadow.png";
  			icon.iconSize = new GSize(12, 20);
  			icon.shadowSize = new GSize(22, 20);
  			icon.iconAnchor = new GPoint(6, 20);
  			icon.infoWindowAnchor = new GPoint(5, 1);
  			undefined_profile = new GMarker(point, { icon:icon, draggable:true } );
  			undefined_profile.enableDragging();
  			map.addOverlay(undefined_profile);
  		}
    }

  });

// check the zoom level

  validate_tool_mode(map.getZoom());

}


function set_profile_photo_img_fullsize(filename, name, uploaded) {

  $('photo_img_fullsize').src = '/uploads/' + filename;
  $('photo_title').innerHTML = name;
  $('photo_date').innerHTML = 'Uploaded at: ' + uploaded;
}



function user_start_photo_upload() {

	$('photo_upload_progress').style.display = 'inline';
}



function user_completed_photo_upload(response) {

	$('photo_upload_progress').style.display = 'none';

	GDownloadUrl("/php/controller_user.php?action=get_photos&user_id=" + $('user_id').value, function(data, responseCode) {

		$('pp-tc-photo').innerHTML=data;

// if this id the 1st photo for this hotspot, replace the thumbnail

		if ($('profile-icon').src == home + 'images/Geese59x59.jpg' || $('profile-icon').src == home + 'images/Geese 330x330.jpg') {

		  $('profile-icon').src = $('photo_img_fullsize').src;
		}

	});
}



function user_photo_delete(el, file_id) {

  if (confirm("Are you sure you want to delete this photo?")) {

  	var myXHR = new XHR({method:'post',onSuccess:function(results){
  		var return_obj = eval("("+results+")");

  		if (return_obj["success"]==true){

  		  var img_id = 'thumb' + file_id;

        var old_photo = $(img_id).src;

        if ( $('profile-icon').src == old_photo) {
    		  $('profile-icon').src = '/images/Geese59x59.jpg';
        }


      	GDownloadUrl("/php/controller_user.php?action=get_photos&user_id=" + $('user_id').value, function(data, responseCode) {

      		$('pp-tc-photo').innerHTML=data;

      // if this id the 1st photo for this hotspot, replace the thumbnail

      		if ($('profile-icon').src == home + 'images/Geese59x59.jpg' ) {

      		  $('profile-icon').src = $('photo_img_fullsize').src;
      		}

      	});

  		} else {

  			alert(return_obj["message"]);
  		}
  	}}).send('/php/delete_photo.php', 'file_id=' + file_id);
  }
}




/****************************************************
function: user_send_password
description: try to send the user their password
****************************************************/
function user_send_password() {

  if ( $('email') && $('email').value ) {

  	var myXHR = new XHR({method:'post',onSuccess:function(results){

  		var return_obj = Json.evaluate(results);

  		if (return_obj["success"]==true){

        user_hide_forgot_password();

  		} else {

        $('side-bar-content').innerHTML = return_obj["message"];
  		}

  	}}).send('/php/controller_user.php', 'action=forgotpassword&email=' + $('email').value);

  } else {

    $('side-bar-content').innerHTML = "Please enter your email address";
  }
}

/****************************************************
function: hotspot_show
description: show the hotspot info window
****************************************************/
function user_show(user_id){

  hotspot_close();

  if (map_mode != MAP_MODE_PEOPLE) {

    set_mode_people(user_show, user_id);

  } else {

  	for (var i=0;i<gmarkers.length;i++){

  		if (parseInt(gmarkers[i].user_id)==parseInt(user_id)){

    	  map.setCenter(gmarkers[i].getPoint(), 12);
    	  user_build_info_window(gmarkers[i]);
  		  break;
  		}
  	}
  }
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = '; expires='+date.toGMTString();
	}
	else var expires = '';
	document.cookie = name+'='+value+expires+'; path=/';
}

function readCookie(name) {
	var nameEQ = name + '=';
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,'',-1);
}


function ShowLoginPrompt(prompt)
{
  msg = "<p>" + prompt + "</p><p><a href=\"javascript: clear_quick_message()\">OK</a></p>";
  $('quick-message').innerHTML = msg;
  $('quick-message').style.display = "block";

  // not logged in, show the login form

  $('side-bar-content').innerHTML = prompt;
  set_active_tab($('tab-account'));

 	screen_name = '';
  $('menu-area').innerHTML = "";
  $('side-bar-content').innerHTML = "";
  $('tn-login').innerHTML = '<a href="#" onclick="set_active_tab($(\'tab-account\'));">Login</a>';

  show_login_form();
}


function user_send_activation(userid) {

	var myXHR = new XHR({method:'post',onSuccess:function(results){

		var return_obj = Json.evaluate(results);

    $('side-bar-content').innerHTML = return_obj["message"];

	}}).send('/php/controller_user.php?action=sendactivate', 'userid=' + userid);
}

/* load user's hotspots into the user area
------------------------------------------------------------*/
function user_area_show_hospots() {

  $('user-area-wrapper').style.padding = '5px 2px 16px 2px';
  $('user-area-wrapper').style.width = '308px';

  var ua = $('user-area');
  ua.empty();

  $('accmnu_hotspots').className='sel';
  $('accmnu_tallies').className='';
  $('accmnu_profile').className='';

  var div = new Element('div', { 'id' : 'user-area-hotspots-header' } ).injectInside(ua);

  var tmp = new Element('h3').setText('My Hotspots').injectInside(div);
  div = new Element('div', { 'styles' : { 'text-align' : 'right' } }).setText(' ').injectInside(div);
  tmp = new Element('a', { 'href' : 'javascript:hotspot_enable_add_mode()', 'class' : 'btngrn spcrht', 'id' : 'user-area-new-sighting' } ).setText('Create New Hotspot').injectInside(div);

  tmp = new Element('hr').injectInside(ua);
  var ul = new Element('ul', { 'id' : 'user-area-list' }).injectInside(ua);

	var myXHR = new XHR({method:'post',onSuccess:function(resp){

		var ro = Json.evaluate(resp);

		var hots = ro['hotspots'];

    for(var i = 0; i < hots.length; ++i) {

      var li = new Element('li').injectInside(ul);
      var div = new Element('div', { 'class' : 'hotspot-list-left' } ).injectInside(li);
      tmp = new Element('a', { 'class' : 'name', 'href' : 'javascript:hotspot_show('+hots[i].id+')' } ).setHTML(hots[i].name).injectInside(div);
      tmp = new Element('p', { 'class' : 'date' }).setHTML(hots[i].date).injectInside(div);
      div = new Element('div', { 'class' : 'hotspot-list-right' } ).injectInside(li);

      var params = hots[i].id + ',"' + hots[i].name + '",' + hots[i].lat + ',' + hots[i].lng + ',true';

      tmp = new Element('a', { 'class' : 'add_sighting', 'href' : 'javascript:sighting_add('+params+')'}).setHTML('Add sightings').injectInside(div);

    }

	}}).send('/php/controller_user.php?action=gethotspots');
}

/* revert to default styling
------------------------------------------------------------*/
function user_area_reset_styling() {

  $('user-area-wrapper').style.padding = '';
  $('user-area-wrapper').style.width = '';
}

/* load user's profile into the user area
------------------------------------------------------------*/
function user_area_show_profile() {

  user_area_reset_styling();

  var ua = $('user-area');
  ua.empty();

  $('accmnu_hotspots').className='';
  $('accmnu_tallies').className='';
  $('accmnu_profile').className='sel';

  show_registration_info();
}


/* load user's profile into the user area
------------------------------------------------------------*/
function user_area_show_tallies() {

  $('user-area-wrapper').style.padding = '5px 2px 16px 2px';
  $('user-area-wrapper').style.width = '308px';

  var ua = $('user-area');
  ua.empty();

  $('accmnu_hotspots').className='';
  $('accmnu_tallies').className='sel';
  $('accmnu_profile').className='';

  var div = new Element('div', { 'id' : 'user-area-tallies-header' } ).injectInside(ua);

  var tmp = new Element('a', { 'id' : 'mnutallies-sightings', 'href' : 'javascript:user_area_show_tallies()', 'class' : 'mnubrn sel'} ).setText('Sightings Records').injectInside(div);
  tmp = new Element('span').setText('|').injectInside(div);
  tmp = new Element('a', { 'id' : 'mnutallies-lifelist', 'href' : 'javascript:user_area_show_lifelist()', 'class' : 'mnubrn'} ).setText('Life List').injectInside(div);

  tmp = new Element('div', { 'style' : 'text-align:right;' } ).injectInside(ua);
  tmp = new Element('a', { 'href' : 'javascript:sighting_enable_add_mode()', 'class' : 'btngrn', 'id' : 'user-area-new-sighting'} ).setText('Create New Sightings Record').injectInside(tmp);

  tmp = new Element('ul', { 'class' : 'popup-nav'} ).injectInside(div);

  var li = new Element('li', { 'events' : { 'mouseover' : function() { tallies_sighting_menu_show(); }, 'mouseout' : function() { tallies_sighting_menu_hide(); } } } ).injectInside(tmp);
  tmp = new Element('a', { 'href' : '#'} ).setText('Options').injectInside(li);
  var ul = new Element('ul', { 'id' : 'tallies_sighting-submenu', 'class' : 'submenu_hide'} ).injectInside(li);
  tmp = new Element('li').injectInside(ul);
  tmp = new Element('a', { 'href' : 'javascript:sightings_delete()' }).setText('Delete').injectInside(tmp);

  tmp = new Element('hr').injectInside(ua);
  var ul = new Element('ul', { 'id' : 'user-area-list' }).injectInside(ua);

	var myXHR = new XHR({method:'post',onSuccess:function(resp){

		var ro = Json.evaluate(resp);

		var sights = ro['sightings'];

    for(var i = 0; i < sights.length; ++i) {

      var li = new Element('li', { 'id' : 'asid'+sights[i].id } ).injectInside(ul);
      var div = new Element('div', { 'class' : 'sighting-list-left' } ).injectInside(li);

      tmp = new Element('input', { 'type' : 'checkbox', 'name' : 'usersightingchecked' }).injectInside(div);

      var div = new Element('div', { 'class' : 'sighting-list-right' } ).injectInside(li);

      tmp = new Element('a', { 'class' : 'name', 'href' : 'javascript:sighting_view('+ sights[i].id +','+ sights[i].hid +')' } ).setText(sights[i].name).injectInside(div);
      tmp = new Element('p', { 'class' : 'date' } ).setText(sights[i].date).injectInside(div);
      tmp = new Element('p', { 'class' : 'count' } ).setText(sights[i].num + ' species reported').injectInside(div);

    }

	}}).send('/php/controller_user.php?action=getsightings');
}



/* load user's profile into the user area
------------------------------------------------------------*/
function user_area_show_lifelist() {

  $('user-area-wrapper').style.padding = '5px 2px 16px 2px';
  $('user-area-wrapper').style.width = '308px';

  var ua = $('user-area');
  ua.empty();

  var div = new Element('div', { 'id' : 'user-area-tallies-header' } ).injectInside(ua);

  var tmp = new Element('a', { 'id' : 'mnutallies-sightings', 'href' : 'javascript:user_area_show_tallies()', 'class' : 'mnubrn'} ).setText('Sightings Records').injectInside(div);
  tmp = new Element('span').setText('|').injectInside(div);
  tmp = new Element('a', { 'id' : 'mnutallies-lifelist', 'href' : 'javascript:user_area_show_lifelist()', 'class' : 'mnubrn sel'} ).setText('Life List').injectInside(div);

  tmp = new Element('p', { 'id':'user-life-species-count' }).injectInside(div);


  tmp = new Element('hr').injectInside(ua);
  var ul = new Element('ul', { 'id' : 'user-life-list' }).injectInside(ua);

  var total = 0;

	var myXHR = new XHR({method:'post',onSuccess:function(resp){

		var ro = Json.evaluate(resp);

		var familyspecies = Json.evaluate(resp)['species'];

    for(var family in familyspecies) {

      var species = familyspecies[family];
      var li = new Element('li' ).setText(family).injectInside(ul);

      var subul = new Element('ul').injectInside(li);

      for(var j = 0; j < species.length; ++j) {

        var subli = new Element('li').setText(species[j]).injectInside(subul);

        total += 1;
      }
    }

    $('user-life-species-count').setText(total + ' Species');

	}}).send('/php/controller_user.php?action=getlifelist');
}

function tallies_sighting_menu_show() {  $('tallies_sighting-submenu').className='submenu_show';  }
function tallies_sighting_menu_hide() {  $('tallies_sighting-submenu').className='submenu_hide';  }


