/* group.php - get city list corresponding to country */
function generate_city_list(country_obj) {
  var country = country_obj.value;
  if ( country ) {
    $('#city_drop_down').html('<font color = "red">loading..</font>');
    $.get(
      base_url + "/ajax/generate_city_list.php",
      {
        'country' : country,
        'random': (new Date().getTime())
      },
      function(response) {
        $('#city_drop_down').html(response);
      }
    );
  } else {
    $('#city_drop_down').html('<select class="category" name = "group_city"><option>Select City</option></select>');
  }
}
/* group_home.php - load group details corresponding to category and selected tab */
function load_group_details(category_id) {
  var selected_tab = '';
  $('a[@id^="sort_by_"]').each(function() {
    if ( $(this).attr('class') == 'active' ) {
      var split_id = $(this).attr('id').split('_')
      selected_tab = split_id[2];
    }
  });
  $('#group_details_inner').html('<img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." />');
  $.get(
    base_url + "/ajax/load_group_details.php",
    {
      'category_id' : category_id,
      'selected_tab' : selected_tab,
      'page_type' : page_type
    },
    function(response) {
      $('#group_details_inner').html(response);
    }
  );
}
function group_sort_by(obj) {
  $('a[@id^="sort_by_"]').each(function() {
    $(this).attr('class', '');
  });
  $(obj).attr('class', 'active');
  var category_id = $('#group_details_category').val();
  load_group_details(category_id);
}
function update_invite_list(act) {
  document.group_list.link_name.value = act;
  document.group_list.submit();
}
function get_group_moderated_user(gid) {
  $('#create_topic').css('display', 'block');
  $('#group_request_data').html('<span><strong><img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." /></strong></span>');
  $('#create_topic').html($('#group_request_moderate').html());
  $('#group_request_moderate').html('');
  $.get(
    base_url + "/ajax/group_moderated_user.php",
    {
      'gid' : gid,
      'random': (new Date().getTime())
    },
    function(response) {
      $('#group_request_data').html(response);
    }
  );
}
function get_group_moderated_image(gid, type, album_id) {
  if ( typeof(album_id) == 'undefined' ) {
    album_id = 0;
  }
  $('#create_topic').css('display', 'block');
  $('#group_request_data').html('<span><strong><img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." /></strong></span>');
  $('#create_topic').html($('#group_request_moderate').html());
  $('#group_request_moderate').html('');
  $.get(
     base_url + "/ajax/get_group_moderation.php",
    {
      'gid' : gid,
      'type' : type,
      'album_id' : album_id,
      'random': (new Date().getTime())
    },
    function(response) {
      $('#group_request_data').html(response);
    }
  );
}

function get_group_updates(tab) {
  $('#group_updates_data').html('<font color = "red">loading..</font>');
  if ( tab == 'invites' ) { 
    document.getElementById('invites_tab').style.fontWeight= 'bold';
    document.getElementById('requests_tab').style.fontWeight= 'normal';
  } else if ( tab == 'requests' ) {
    document.getElementById('invites_tab').style.fontWeight= 'normal';
    document.getElementById('requests_tab').style.fontWeight= 'bold';
  }
  $.get(
    base_url + "/ajax/group_updates.php",
    {
      'selected_tab': tab,
      'random': (new Date().getTime())
    },
    function(response) {
      $('#group_updates_data').html(response);
    }
  );
}
function send_message_to_member (member_name, gid) {
  url = base_url+'/send_group_message_all.php?gid='+gid+'&member_name='+member_name;
  group_bubble(url);
}
function validate_request(form_name, field) {
  count = document.forms[form_name].elements.length;
  var check_flag = false;
  for ( var i = 0; i < count; i++ ) {
    if ( document.forms[form_name].elements[i].type == 'checkbox' ) {
      if ( document.forms[form_name].elements[i].checked == 1 ) {
        chk_cnt++;
        check_flag = true;
      }
    }
  }
  if ( !check_flag ) {
    alert(__("Please select atleast one"));
    return false;
  }
  return true;
}
function view_all_group_details() {
  var selected_tab = '';
  $('a[@id^="sort_by_"]').each(function() {
    if ( $(this).attr('class') == 'active' ) {
      var split_id = $(this).attr('id').split('_')
      selected_tab = split_id[2];
    }
  });
  if ( selected_tab ) {
    selected_tab = '?tab='+selected_tab;
  }
  redirect(base_url+'/browse-groups'+selected_tab);
}
function close_pop_request() {
  $('#create_topic').css('display', 'none');
  $('#create_topic').html('');
  $('#group_request_moderate').html('<tt><img src="'+base_url+'/images_new/create_topic_top.gif" alt="" /></tt><div class="pending_requsts_community" id = "group_request_data"></div><tt><img src="'+base_url+'/images_new/create_topic_bottom.gif" alt="" /></tt>');
}
function change_action(act, id, text) {
  var href_val = $('#'+id).attr('href');
  if ( act == 'check' ) {
    $('#'+id).attr('href', "javascript:checkall_fields('group_list', 'check');change_action('uncheck', 'group_invites_select_all', 'Deselect all');");
    $('#'+id).html(text);
  } else {
    $('#'+id).attr('href', "javascript:checkall_fields('group_list', 'uncheck');change_action('check', 'group_invites_select_all', 'Select all');");
    $('#'+id).html(text);
  }
}