var SITE_URL = 'http://www.gymbudd.com/';

function relocate(url) {
  window.location = url;
}

function preloading() {
	for ( i = 0; i < preloading.arguments.length; i++ ) {
		my_images[i] = new Image();
		my_images[i].src = preloading.arguments[i];
	}
}

function checkEmail(email) {
  var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if ( !filter.test(email) ) {
    return false;
  } else {
    return true;
  }
}

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 trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function delete_user(id) {
  var r = confirm('Are you sure you want to delete this user?');

  if ( r == true ) {
    window.location = 'admin_users.php?action=delete&id=' + id;
  }
}

function change_option(value, action, to_content) {
  if ( action == 1 ) {
    $('#'+ value + 'on').attr('src', 'images/checked.jpg');
    $('#'+ value + 'off').attr('src', 'images/not_checked.jpg');

    $('#' + to_content).val(action);
  } else {
    $('#'+ value + 'off').attr('src', 'images/checked.jpg');
    $('#'+ value + 'on').attr('src', 'images/not_checked.jpg');
    
    $('#' + to_content).val(action);
  }
}

function focus_day() {
  var day = $('#day').val();
  if ( day == 'day' ) {
    $('#day').val('');
  }
}

function focus_year() {
  var year = $('#year').val();
  if ( year == 'year' ) {
    $('#year').val('');
  }
}

function interval_birthday(interval) {
  setInterval("show_index_birthdays(" + interval + ")", 5000);
  //show_index_birthdays(interval);
}

var num = 1;
function show_index_birthdays(interval) {
  //alert(interval);
  $('#birthday_div').fadeOut(200);
  interval = parseInt(interval);

  if ( interval > 0 ) {
    num++;
    
    if ( num > interval ) {
      num = 1;
    }
    
    $.ajax({
      type: "POST",
      url: SITE_URL + "get_birthday",
      data: "interval=" + num,
      success: function(msg){
        $('#birthday_div').html(msg);
        $('#birthday_div').fadeIn(200);
      }
    });
  }
}

var chat_friends = '';
var chat_messages = '';
function start_chat() {
  $('#chat_window').fadeIn(500);

  eraseCookie('chat_cookie');

  load_friends();
  chat_friends = setInterval("load_friends()", 5000);
}

function end_chat() {
  $('#chat_window').fadeOut(500);

  createCookie('chat_cookie', 'close_chat', 1);

  clearInterval(chat_friends);
  clearInterval(chat_messages);
}

function load_friends() {
  $.ajax({
      type: "POST",
      url: SITE_URL + "chat_load_friends",
      success: function(msg){
        $('#chat_friends').html(msg);
      }
    });
}

function load_chat(chat_id) {
  var chat = chat_id;
  clearInterval(chat_messages);

  load_messages(chat_id);
  chat_messages = setInterval("load_messages(" + chat_id + ")", 3000);
}

var q_im = true;
function load_messages(chat_id) {
  $('#conversation').val(chat_id);
  $('#chat_button').focus();
  
  $.ajax({
      type: "POST",
      url: SITE_URL + "chat_load_messages",
      data: "to_id=" + chat_id,
      success: function(msg){
        $('#chat_area').html(msg);
        
        if ( q_im == true ) {
          animate_down();
        }
      }
    });
}

function animate_down() {
  $('#chat_message').animate({scrollTop: $('#chat_message > #chat_area').outerHeight()}, -2000);
}


function insert_message() {
  var message = $('#chat_button').val();
  var chat_id = $('#conversation').val();
  
  if ( message != '' ) {
    $('#chat_button').val('');
    $.ajax({
        type: "POST",
        url: SITE_URL + "chat_insert_messages",
        data: "to_id=" + chat_id + "&message=" + message,
        success: function(msg){
        }
      });
  }
}

function check_chat_requests() {
  if ( readCookie('chat_cookie') != 'close_chat' ) {
    $.ajax({
      type: "POST",
      url: SITE_URL + "chat_check_requests",
      success: function(msg){
        if ( msg == 1 ) {
          start_chat();
        }
      }
    });
  }
}

function action_message(chat_id, action) {
  $.ajax({
    type: "POST",
    url: SITE_URL + "chat_load_messages",
    data: "to_id=" + chat_id + "&action=" + action,
    success: function(msg){
      
    }
  });
}

$(document).ready(function() {
  check_chat_requests();
  setInterval("check_chat_requests()", 30000);
});

function load_user(avatar, username) {
  $('#sel_username').html(username);
  $('#sel_avatar').attr('src', avatar);

  if ( $('#user_talk').css('display') == 'none' ) {
    $('#user_talk').fadeIn(500);
  }
}

function checkLimits(box){
  var prison_left   = document.getElementById("prison").offsetLeft;
  var prison_right  = prison_left + document.getElementById("prison").offsetWidth;
  var prison_top    = document.getElementById("prison").offsetTop;
  var prison_bottom = prison_top + document.getElementById("prison").offsetHeight;

  var box_left   = parseInt(box.css("left"));
  var box_right  = box_left + parseInt(box.css("width"));
  var box_top    = parseInt(box.css("top"));
  var box_bottom = box_top + parseInt(box.css("height"));

  if(box_left < prison_left){
    box.css("left", prison_left);
  }

  if(box_top < prison_top){
    box.css("top", prison_top);
  }

  if(box_right > prison_right){
    box.css("left", prison_right - parseInt(box.css("width")));
  }

  if(box_bottom > prison_bottom){
    box.css("top", prison_bottom - parseInt(box.css("height")));
  }
}

function show_user_menu(action) {
  if ( $('#mmenu').css('display') == 'none' ) {
    $('#mmenu').fadeIn(500);
  } else {
    $('#mmenu').fadeOut(500);
  }
}

function wall_status(action) {
  var status = $('#status').val();
  if ( action == 1 && status == 'Add new status' ) {
    $('#status').val('');
    $('#status').css('color', 'black');
  }

  if ( action == 0 && status == '' ) {
    $('#status').val('Add new status');
    $('#status').css('color', '#CCCCCC');
  }
}

function comment_status(action) {
  var status = $('#status').val();
  if ( action == 1 && status == 'Add new comment' ) {
    $('#status').val('');
    $('#status').css('color', 'black');
  }

  if ( action == 0 && status == '' ) {
    $('#status').val('Add new comment');
    $('#status').css('color', '#CCCCCC');
  }
}

function star_choose(nr) {
  var i;
  
  for ( i = 1; i <= 5; i++ ) {
    $('#img_' + i).attr('src', SITE_URL + 'images/star_empty.jpg');
  }

  for ( i = 1; i <= nr; i++ ) {
    $('#img_' + i).attr('src', SITE_URL + 'images/star_full.jpg');
  }
}

function star_restore(nr) {
  var i;
  for ( i = 0; i < nr; i++ ) {
    $('#img_' + i).attr('src', SITE_URL + 'images/star_full.jpg');
  }

  for ( i = nr; i < 5; i++ ) {
    $('#img_' + i).attr('src', SITE_URL + 'images/star_empty.jpg');
  }
}

function star_vote(type, id, value) {
  $.ajax({
    type: "POST",
    url: SITE_URL + "vote_things",
    data: "type=" + type + "&id=" + id + "&value=" + value,
    success: function(msg){
      alert(msg);
    }
  });
}

function checkAll() {
	var all_entries = $('#all_email').val();

	for ( i = 0; i < all_entries; i++ ) {
		$('#checkbox_' + i).attr('checked', true);
	}
}

function uncheckAll() {
	var all_entries = $('#all_email').val();

	for ( i = 0; i < all_entries; i++ ) {
		$('#checkbox_' + i).attr('checked', false);
	}
}

function check_deletes() {
	var all_entries = $('#all_email').val();
	var a = false;

	for ( i = 0; i < all_entries; i++ ) {
		if ( $('#checkbox_' + i).attr('checked') == true ) {
			a = true;
			break;
		}
	}

	if ( a ) {
		var r = confirm('Are you sure you want to delete?');

		if ( r == true ) {
			$('#selected_mails').submit();
		}
	}
	else {
		alert('Please choose a message');
	}
}

function mark_read() {
	var all_entries = $('#all_email').val();
	var a = false;

	for ( i = 0; i < all_entries; i++ ) {
		if ( $('#checkbox_' + i).attr('checked') == true ) {
			a = true;
			break;
		}
	}

	if ( a ) {
		var r = confirm('Are you sure you want to mark as read?');

		if ( r == true ) {
			$('#hidden_it').val('thats true');
			$('#type_it').val(0);
			$('#selected_mails').submit();
		}
	}
	else {
		alert('Va rugam alegeti un mesaj');
	}
}

function mark_unread() {
	var all_entries = $('#all_email').val();
	var a = false;

	for ( i = 0; i < all_entries; i++ ) {
		if ( $('#checkbox_' + i).attr('checked') == true ) {
			a = true;
			break;
		}
	}

	if ( a ) {
		var r = confirm('Are you sure you want to mark as unread?');

		if ( r == true ) {
			$('#hidden_it').val('thats true');
			$('#type_it').val(1);
			$('#selected_mails').submit();
		}
	}
	else {
		alert('Please choose a message');
	}
}

/* search friend popup start functions */
function lookup(inputString) {
  if(inputString.length == 0) {
    // Hide the suggestion box.
    $('#suggestions').hide();
  } else {
    $.post("search_friends", {queryString: ""+inputString+""}, function(data){
      if(data.length >0) {
        $('#suggestions').show();
        $('#autoSuggestionsList').html(data);
      }
    });
  }
} // lookup

function fill(thisValue) {
  $('#inputString').val(thisValue);

  setTimeout("$('#suggestions').hide();", 200);
}
/* end */

function add_new_album() {
  if ($('#new_album').css('display') == 'none') {
    //$('#new_album').css('display', 'block');
    $('#new_album').slideDown(1000);
  } else {
    //$('#new_album').css('display', 'none');
    $('#new_album').slideUp(1000);
  }
}

function delete_picture() {
  var r = confirm('Are you sure you want to delete this image?');

  if ( r == true ) {
    window.location = window.location + '&action=delete'
  }
}

function delete_video() {
  var r = confirm('Are you sure you want to delete this video?');

  if ( r == true ) {
    window.location = window.location + '&action=delete'
  }
}

function delete_video_album(id) {
  var r = confirm('Are you sure you want to delete this album? All the videos from this album will be erased!');

  if ( r == true ) {
    window.location = window.location + '?action=delete&aid=' + id;
  }
}

function delete_picture_album(id) {
  var r = confirm('Are you sure you want to delete this album? All the pictures from this album will be erased!');

  if ( r == true ) {
    window.location = window.location + '?action=delete&aid=' + id;
  }
}

function upload_file() {
  $('#loader_ad').css('display', 'block');
  
  $.ajaxFileUpload (
    {
      url: SITE_URL + 'upload_ad_banner',
      secureuri: false,
      fileElementId: 'fileToUpload',
      dataType: 'json',
      success: function (data, status) {
        /*
        if(typeof(data.error) != 'undefined') {
          if(data.error != '') {
            alert(data.error);
          }else {
            alert(data.msg);
          }
        }
        */
        $('#ad_href').attr('src', SITE_URL + 'ads_images/' + data.msg);

        $('#loader_ad').css('display', 'none');
      },
      error: function (data, status, e) {
        alert(e);
      }
    }
  );

  return false;
}

function get_ad_image() {
  $.ajax({
    type: "POST",
    url: SITE_URL + "get_ad_image",
    success: function(msg){
      alert(msg);
    }
  });
}

function change_ad_title() {
  $('#ad_title').html($('#title').val());
}

function change_ad_body() {
  var textarea = $('#body').val();
  if ( textarea.length > 100 ) {
    $('#ad_body').html(textarea.substring(0, 100));
    $('#body').val(textarea.substring(0, 100));
  } else {
    $('#ad_body').html(textarea);

    var a = 100 - textarea.length;
    a = a + '';
    $('#body_limit').html(a);
  }
}

function change_ad_link() {
  $('#ad_title').attr('href', 'http://' + $('#url').val());
}

function ad_step1() {
  if ( $('#url').val() == '' ) {
    alert('Please add link');
  } else {
    if ( $('#title').val() == '' ) {
      alert('Please add title');
    } else {
      if ( $('#body').attr('value') == '' ) {
        alert('Please add text');
      } else {
        //$('#step_1').fadeIn(500);
        $('#step_1').css('display', 'none');
       // $('#step_2').fadeOut(1000);
        $('#step_2').css('display', 'block');
      }
    }
  }
}

function show_step1() {
  $('#step_1').css('display', 'block');
  $('#step_2').css('display', 'none');
}

function ad_step2() {
  $('#step_3').css('display', 'block');
  $('#step_2').css('display', 'none');
}

function show_step2() {
  $('#step_2').css('display', 'block');
  $('#step_3').css('display', 'none');
}

function ad_step3() {
  $('#step_4').css('display', 'block');
  $('#step_3').css('display', 'none');
}

function add_locations() {
  var current_locations = $('#current_locations').html();

  var add = $('#countries option:selected').text();

  if ( current_locations.indexOf('Please add location') != -1 ) {
    $('#current_locations').html('');
    current_locations = '';
  }

  if ( current_locations.indexOf(add) == -1 ) {
    $('#current_locations').html(current_locations + add + ' <a class="simple_link" href="javascript: void(0);" onclick="javascript: del_locations(\'' + add + '\');">del</a>;');

    $('#locationss').val(current_locations + add + ' <a class="simple_link" href="javascript: void(0);" onclick="javascript: del_locations(\'' + add + '\');">del</a>;');
  } else {
    alert('Already added ' + add);
  }
}

function del_locations(location_name) {
  var current_locations = $('#current_locations').html();
  
  if ( current_locations.indexOf(location_name) != -1 ) {
    var a = location_name + ' <a class="simple_link" href="javascript: void(0);" onclick="javascript: del_locations(\'' + location_name + '\');">del</a>;';
    var new_current_locations = current_locations.replace(a, '');

    if ( new_current_locations == '' ) {
      $('#current_locations').html('Please add location');
    } else {
      $('#current_locations').html(new_current_locations);
      $('#locationss').val(new_current_locations);
    }
  }
}

function show_attendees(div) {
  var total_events = $('#total_events').val();
  
  for ( i = 0; i < total_events; i++ ) {
    if ( i != div ) {
      $('#dan_' + i).css('display', 'none');
    }
  }

  if ( $('#dan_' + div).css('display') == 'block' ) {
    $('#dan_' + div).css('display', 'none');
  } else {
    $('#dan_' + div).css('display', 'block');
  }
}

function relationship_picker(user_id) {
  if ( user_id > 0 ) {
    $('#pick_relationship').html('');
    $.ajax({
      type: "POST",
      url: SITE_URL + "specify_relationship",
      data: "user_id=" + user_id,
      success: function(msg){
        $('#pick_relationship').html(msg);
        $('#pick_relationship').fadeIn(200);
        //$('#pick_relationship').css('display', 'block');
      }
    });
  }
}

function end_relationship_picker() {
  $('#pick_relationship').fadeOut(300);
  $('#pick_relationship').html('');
}

function gym_vote(type, id, value) {
  $.ajax({
    type: "POST",
    url: SITE_URL + "vote_gym",
    data: "type=" + type + "&id=" + id + "&value=" + value,
    success: function(msg){
      alert(msg);
    }
  });
}

var page_review = 0;
function browse_gyms_reviews(action) {
  if ( action == 0 ) {
    page_review--;
  } else {
    page_review++;
  }

  if ( page_review < 0 ) {
    page_review++;
    $('#review_back').removeClass('user');
    $('#review_back').addClass('user_disabled');
  } else {
    $('#review_back').removeClass('user_disabled');
    $('#review_back').addClass('user');
  }

  var max_r = reviews.length;
  
  if ( page_review >= max_r ) {
    page_review--;
    $('#review_next').removeClass('user');
    $('#review_next').addClass('user_disabled');
  } else {
    $('#review_next').removeClass('user_disabled');
    $('#review_next').addClass('user');
  }
  
  $('#review_id').html(reviews[page_review][3]);
  $('#spent_id').html(reviews[page_review][2] + '&nbsp;');
  $('#added_by').attr('href', SITE_URL + reviews[page_review][1]);
  $('#review_u_image').attr('href', SITE_URL + reviews[page_review][1]);
  $('#review_u_image').html(reviews[page_review][0]);

  //alert(page_review);
  if ( page_review == 0 ) {
    $('#review_back').removeClass('user');
    $('#review_back').addClass('user_disabled');
  }

  if ( page_review == max_r - 1 ) {
    $('#review_next').removeClass('user');
    $('#review_next').addClass('user_disabled');
  }
}

function clear_menu() {
  for ( i = 0; i < 5; i++ ) {
    $('#menu_' + i).css('display', 'none');
    $('#up_menu_' + i).removeClass('menu_top_selected');
    $('#up_menu_' + i).addClass('menu_top');

    var alt = $('#menu_at').val();

    $('#up_menu_' + alt).removeClass('menu_top');
    $('#up_menu_' + alt).addClass('menu_top_selected');
  }
}

function clear_menu_special(skip) {
  for ( i = 0; i < 5; i++ ) {
    if ( i != skip ) {
      $('#menu_' + i).css('display', 'none');
      $('#up_menu_' + i).removeClass('menu_top_selected');
      $('#up_menu_' + i).addClass('menu_top');
    }
    var alt = $('#menu_at').val();

    $('#up_menu_' + alt).removeClass('menu_top');
    $('#up_menu_' + alt).addClass('menu_top_selected');
  }
}

function show_menu(id, action, alerrt) {
  if ( action == 1 ) {
    $('#menu_' + id).css('display', 'block');
    
    $('#up_menu_' + id).removeClass('menu_top');
    $('#up_menu_' + id).addClass('menu_top_selected');
  }

  if ( action == 0 ) {
    $('#menu_' + id).css('display', 'none');

    $('#up_menu_' + id).removeClass('menu_top_selected');
    $('#up_menu_' + id).addClass('menu_top');
  }

  if ( alerrt == 1 ) {
    $('#up_menu_' + id).removeClass('menu_top');
    $('#up_menu_' + id).addClass('menu_top_selected');

    $('#menu_at').val(id);
  }
}

function delete_event(id) {
  var r = confirm('Are you sure you want to delete this event?');

  if ( r == true ) {
    window.location = SITE_URL + 'my_account/events&action=delete&id=' + id;
  }
}

function advanced_search() {
  if ( $('#advanced').css('display') == 'none' ) {
    $('#advanced').css('display', 'block');
  } else {
    $('#advanced').css('display', 'none');
  }
}

function go_over(action, obj) {
  if ( action == 0 ) {
    obj.style.background = 'white';
  }

  if ( action == 1 ) {
    obj.style.background = '#E9F3F5';
  }
}

function share_stuff(action) {
  var this_share = $('#all_share').val();
  
  if ( action == 1 ) {
    for ( i = 0; i <= this_share; i++ ) {
      $('#share_' + i).attr('checked', true);
    }
  }

  if ( action == 0 ) {
    for ( i = 0; i <= this_share; i++ ) {
      $('#share_' + i).attr('checked', false);
    }
  }
}

function validate_share() {
  var this_share = $('#all_share').val();
  var j = 0;
  
  for ( i = 0; i <= this_share; i++ ) {
    if ( $('#share_' + i).attr('checked') ==  true ) {
      j++;
    }
  }

  if ( j > 0 ) {
    $('#share_a').submit();
  } else {
    alert('Please select at least one user!');
  }
}

function share_share() {
  if ( $('#share_share').css('display') == 'none' ) {
    $('#share_share').fadeIn(500);
  } else {
    $('#share_share').fadeOut(500);
  }
}

function gym_effect(action) {
  if ( $('#block_' + action).css('display') == 'block') {
    $('#block_' + action).css('display', 'none');
  } else {
    $('#block_' + action).css('display', 'block');
  }
}

function delete_gym_section(id, sign) {
  var r = confirm('Are you sure you want to delete item?');

  if ( r == true ) {
    window.location = window.location + sign + "action=delete&id_delete=" + id;
  }
}

function mark_spam() {
  var r = confirm('Are you sure you want to mark as spam this message?');

  if ( r == true ) {
    window.location = window.location + '&action=report';
  }
}

function mark_report() {
  var r = confirm('Are you sure you want to report this?');

  if ( r == true ) {
    window.location = window.location + '&action=report';
  }
}

function friend_picker(user_id) {
  if ( user_id > 0 ) {
    $('#pick_friends').html('');
    $.ajax({
      type: "POST",
      url: SITE_URL + "specify_friends",
      data: "user_id=" + user_id,
      success: function(msg){
        $('#pick_friends').html(msg);
        $('#pick_friends').fadeIn(200);
        //$('#pick_relationship').css('display', 'block');
      }
    });
  }
}

function end_friend_picker() {
  $('#pick_friends').fadeOut(300);
  $('#pick_friends').html('');
}

function show_tag(div_id, action) {
  if ( action == 1 ) {
    $('#' + div_id).css('border-left', '2px solid red');
    $('#' + div_id).css('border-right', '2px solid blue');
    $('#' + div_id).css('border-top', '2px solid green');
    $('#' + div_id).css('border-bottom', '2px solid yellow');
  } else {
    $('#' + div_id).css('border', 'none');
  }
}

function remove_tags(id) {
  window.location = window.location + '&act=tag&tag_id=' + id;
}

var run = 1;
function tag_this_photo() {
  if ( run == 1 ) {
    $('.test').css('display', 'none');
    run = 0;
    $('#tag_this').html('Finished editing');
    $('#tag_photo').css('cursor', 'crosshair');

    $('#tag_photo').click(function () {
      tag_it();
    });
  } else {
    if ( run == 0 ) {
      $('.test').css('display', 'block');
      run = 1;
      $('#tag_this').html('Tag photo');
      $('#tag_photo').css('cursor', 'default');
      $('#tag_photo').unbind("click");
      document.getElementById('tag_photo').onclick = '';
      $('#add_tag').css('display', 'none');
    }
  }
}

function tag_it() {
  $("#tag_photo").click(function(e){
      var relativeX = e.pageX - document.getElementById('elem_id').offsetLeft;
      var relativeY = e.pageY - document.getElementById('elem_id').offsetTop;

      $('#coord_x_value').val(relativeX);
      $('#coord_y_value').val(relativeY);

      $('#add_tag').css('top', relativeY);
      $('#add_tag').css('left', relativeX);

      $('#add_tag').css('display', 'block');
   });
}

function addit_tag(username) {
  $('#tag_value').val(username);

  $('#add_tag').css('display', 'none');

  $('#form_tag').submit();
}

function new_group() {
  if ( $('#new_group').css('display') == 'none' ) {
    $('#new_group').css('display', 'block');
  } else {
    $('#new_group').css('display', 'none');
  }
}

function smoking() {
  var price_pack = parseFloat($('#price_pack').val());
  var cigarettes = parseInt($('#cigarettes').val());
  var cigarettes_smoked = parseInt($('#cigarettes_smoked').val());

  if ( cigarettes_smoked == 0 ) {
    alert('Please add the cigarettes number you smoke');
  } else {
    if ( cigarettes == 0 ) {
      alert('Please add the cigarettes number in a pack');
    } else {
      if ( price_pack == 0 ) {
        alert('Please add the price for a pack');
      } else {
        $('#smoked').html(cigarettes_smoked);
        $('#money').html('$' + price_pack);
        $('#pack').html(cigarettes);

        
        var cigarettes_per_year = 365 * cigarettes_smoked;
        var result1 = (cigarettes_per_year / cigarettes) * price_pack;
        
        $('#result1').html(result1);
        $('#result1_1').html(cigarettes_per_year);
        $('#result2').html(result1 * 3);
        $('#result2_2').html(cigarettes_per_year * 3);
        $('#result3').html(result1 * 5);
        $('#result3_3').html(cigarettes_per_year * 5);

        $('#smocking_quit').effect("highlight", {}, 3000);
      }
    }
  }
}

function change_log_div() {
  if ( $('#logo_div').css('display') == 'none' ) {
    $('#logo_div').fadeIn(500);
  } else {
    $('#logo_div').fadeOut(500);
  }
}

function disband_group() {
  var r = confirm('Are you sure you want to disband this group?');

  if ( r == true ) {
    window.location = window.location + '&action=disband';
  }
}

function invite_user() {
  if ( $('#inv_member').css('display') == 'none' ) {
    $('#inv_member').css('display', 'block');
  } else {
    $('#inv_member').css('display', 'none');
  }
}

function close_group_members() {
  window.location = window.location;
}

function delete_post(id) {
  var r = confirm('Are you sure you want to delete?');

  if ( r == true ) {
    window.location = SITE_URL + 'my_blog/blog_view?action=delete&id=' + id;
  }
}

function delete_category(id) {
  var r = confirm('Are you sure you want to delete?');

  if ( r == true ) {
    window.location = SITE_URL + 'my_blog/categories?action=delete&id=' + id;
  }
}

function delete_comment(id, user_id) {
  var r = confirm('Are you sure you want to delete?');

  if ( r == true ) {
    window.location = SITE_URL + 'my_blog/comments?action=delete&id=' + id + '&user_id=' + user_id;
  }
}

function calculate_weight() {
  // Lorentz formula
  var height1 = parseFloat($('#height_1').val());
  var height2 = parseFloat($('#height_2').val());
  var height = height1 + 0.1 * height2;
  var age = parseInt($('#age').val());
  var sex = parseInt($('#sex').val());
  var transformation = 0.032808399;

  if ( height > 0 ) {
    if ( age > 13 && age < 110 ) {
      if ( sex == 1 || sex == 0 ) {
        var sex2 = sex == 0 ? 4 : 6;
        sex = sex == 0 ? 4 : 2.5;
        
        var centimeteres = result = Math.round((height / transformation), 2);
        var result = ( centimeteres - 100 - ( (centimeteres - 150) / sex ) ) + ( age - 20) / sex2;

        result = parseFloat(result);

        result = result * 2.2;

        result = Math.round(result);

        $('#weight_calculate').html('Your ideal weight should be of ' + result + ' lbs');
        $('#weight_calculate').effect("highlight", {}, 3000);
      } else {
        alert('Please add gender');
      }
    } else {
      alert('Please add age');
    }
  } else {
    alert('Please add weight');
  }
}

function calculate_heart_rate() {
  var age = parseInt($('#age').val());

  if ( age > 13 && age < 110 ) {
    var my_rate = 220 - age;

    var my_rate1 = 50 / 100 * my_rate;
    var my_rate2 = 85 / 100 * my_rate;

    var per_seconds = (my_rate * 10) / 60;

    $('#rate1').html(Math.round(my_rate1));
    $('#rate2').html(Math.round(my_rate2));
    $('#max_rate').html(Math.round(my_rate));
    $('#per_seconds').html(Math.round(per_seconds));

    $('#target_heart').effect("highlight", {}, 3000);
  } else {
    alert('Please add age');
  }
}

function show_event(div, action) {
  if ( action == 1 ) {
    $('#' + div).css('display', 'block');
  }

  if ( action == 0 ) {
    $('#' + div).css('display', 'none');
  }
}

function leave_gym(gym_id) {
  var r = confirm('Are you sure you want to leave this gym?');

  if ( r == true ) {
    window.location = SITE_URL + 'my_gym?action=leave&gym_id=' + gym_id;
  }
}

function add_gym() {
  var r = confirm('Are you sure you want to add this gym?');

  if ( r == true ) {
    window.location = window.location + '&action=add_gym';
  }
}

function new_schedule_event() {
  if ( $('#scheduler').css('display') == 'none' ) {
    $('#scheduler').css('display', 'block');
  } else {
    $('#scheduler').css('display', 'none');
  }
}

function edit_album(album_name, album_description, album_id) {
  //alert(album_name + ', ' + album_id);
  if ($('#edit_album').css('display') == 'none') {
    //$('#new_album').css('display', 'block');
    $('#album_name').val(album_name);
    $('#description').val(album_description);
    $('#edit_album_id').val(album_id);
    
    $('#edit_album').slideDown(1000);
  } else {
    //$('#new_album').css('display', 'none');
    $('#album_name').val('');
    $('#description').val('');
    $('#edit_album_id').val('');
    
    $('#edit_album').slideUp(1000);
  }
}

function delete_ad(id, page_nr) {
  var r = confirm('Are you sure you want to remove this ad?');

  if ( r == true ) {
    window.location = SITE_URL + 'manage_ads/' + page_nr + '&action=delete&id=' + id;
  }
}

function remove_group_stuff(type, group_name, id) {
  var r = confirm('Are you sure you want to delete?');

  if ( r == true ) {
    window.location = SITE_URL + 'view/groups/' + group_name + '&action=delete&type=' + type + "&item_id=" + id;
  }
}

function invite_friend(user_id, event_id) {
  if ( user_id > 0 ) {
    $('#invite_friends').html('');
    $.ajax({
      type: "POST",
      url: SITE_URL + "invite_friends",
      data: "user_id=" + user_id,
      success: function(msg){
        $('#invite_friends').html(msg);
        $('#invite_friends').fadeIn(200);
        //$('#pick_relationship').css('display', 'block');
        $('#uid').val(event_id);
      }
    });
  }
}

function end_invite_friend() {
  $('#invite_friends').fadeOut(300);
  $('#invite_friends').html('');
}

function inv_my_friends() {
  if ( $('#inv_u').css('display') == 'none' ) {
    $('#inv_u').css('display', 'block');
  } else {
    $('#inv_u').css('display', 'none');
  }
}

function delete_post_my_account(post_id) {
  var r = confirm('Are you sure you want to remove this post?');

  if ( r == true ) {
		var loc = window.location.toString();
		var res = loc.indexOf("wall");
		if ( res == -1 ) {
	    window.location = window.location + '?action=delete_wall&post_id=' + post_id;
		} else {
			window.location = window.location + '&action=delete_wall&post_id=' + post_id;
		}
  }
}

function delete_post_user_profile(post_id) {
  var r = confirm('Are you sure you want to remove this post?');
  
  if ( r == true ) {
    window.location = window.location + '&action=delete_wall&post_id=' + post_id;
  }
}

function display_info(number) {
  for ( var i = 1; i <= 3; i++ ) {
    $('#info_' + i).css('display', 'none');
  }

  $('#info_' + number).css('display', 'block');
}

function ask_delete(story_id) {
  var r = confirm('Are you sure you want to delete your story?');

  if ( r == true ) {
    window.location = SITE_URL + 'success_stories?action=delete&id=' + story_id;
  }
}

function show_comment(comm_id) {
  var a_comm = $('#all_comments').val();
  
  for ( var i = 1; i <= a_comm; i++ ) {
    $('#remove_div_' + i).css('display', 'block');
  $('#comment_div_' + i).css('display', 'none');
  }
  
  $('#remove_div_' + comm_id).css('display', 'none');
  $('#comment_div_' + comm_id).css('display', 'block');
  $('#comment_id_' + comm_id).focus();
}

function post_comment(comm_id) {
  if ( $('#comment_id_' + comm_id).val() == '' ) {
    $('#remove_div_' + comm_id).css('display', 'block');
    $('#comment_div_' + comm_id).css('display', 'none');
  } else {
    $('#account_div_' + comm_id).submit();
  }
}

function show_disturbed_coments(comm_id) {
  $('#big_' + comm_id).css('display', 'none');
  var max_ccc = $('#all_max_' + comm_id).val();
  for ( var i = 4; i <= max_ccc; i++ ) {
    $('#abc_' + comm_id + '_' + i).css('display', 'block');
  }
}

function load_video_trainer(video_id) {
  $.ajax({
    type: "POST",
    url: SITE_URL + "load_video_trainer",
    data: "video_id=" + video_id,
    success: function(msg){
      $('#video_load').html(msg);
    }
  });
}

function cancel_video_preview() {
  $('#video_load').html('');
}

function ask_delete_tip(tip_id) {
  var r = confirm('Are you sure you want to delete your tip?');

  if ( r == true ) {
    window.location = SITE_URL + 'tips4fits?action=delete&id=' + tip_id;
  }
}

function close_corner_all() {
  $('#select_event').css('display', 'none');
  $('#select_link').css('display', 'none');
  $('#select_video').css('display', 'none');
  $('#select_image').css('display', 'none');

  $('#selection_corner').css('display', 'block');

  var status = $('#status').val();
  if ( status == '' ) {
    $('#status').val('Add new status');
  }
}

function choose_corner(val) {
  $('#selection_corner').css('display', 'none');
  switch (val) {
    case 0:
      $('#select_image').css('display', 'block');
      break;
    case 1:
      $('#select_video').css('display', 'block');
      break;
    case 2:
      $('#select_link').css('display', 'block');
    break;
    case 3:
      $('#select_event').css('display', 'block');
      break;
  }

  $('#upload_type').val(val);

  var status = $('#status').val();
  if ( status == 'Add new status' ) {
    $('#status').val('');
		$('#status').focus();
  }
}

function load_corner_video( video_location, video_div ) {
  $.ajax({
    type: "POST",
    url: SITE_URL + "load_corner_vid",
    data: "video_location=" + video_location,
    success: function(msg){
      $('#' + video_div).html(msg);
    }
  });
}