function share_photo(val, keyId, keyType) {
  switch (val) {
    case '0':
    break;
    case '1':
      redirect(base_url+'/send_invites_friends.php?keyid='+keyId+'&keytype='+keyType+'&invite_using=by_friend_list');
    break;
    case '2':
      redirect(base_url+'/send_invites_friends.php?keyid='+keyId+'&keytype='+keyType+'&invite_using=by_email');
    break;
  }
}
function follow_content(val, content_id, author, type, html_id) {
  if ( val ) {
    $('#follow_photo_div_msg').show();
    $('#follow_photo_div').hide();
    $.get(
      base_url + "/ajax/follow_content.php",
      {
        'type_val':val,
        'content_id':content_id,
        'author_id':author,
        'content_type':type,
        'random': (new Date().getTime())
      },
      function(htmlData) {
        var msg_arr = htmlData.split('#@$%!&');
        if ( !msg_arr[1] ) {
          set_error_massage(htmlData);
        } else {
          set_error_massage(msg_arr[1]);
        }
        //$('#follow_photo_div').html(htmlData);
        $('#follow_photo_div_msg').hide('slow');
        $('#follow_photo_div').show('slow');
      }
    );
  }
}
function submit_to_mg(obj) {
  if ( obj.checked ) {
    if ( $('#album_privacy').val() != 1 ) {
      alert(__('All albums set to itimes Nites will be searchable. Once submitted, you can not revert the privacy settings'));
    }
    document.getElementById('album_privacy').selectedIndex = 3;
    document.getElementById('album_privacy').disabled = true;
    $('#category_main').show();
    $('#mobile_main').show();
    $('#mobile_main_msg').show();
    $('#code_main').show();
    $('#mobile_no').removeAttr('readonly');
    $('#mg_form_outer').show();
    $('div.mgSuggstMsgLarge').attr('class', 'mgSuggstMsg');
    //$('#subcategory_main').show();
  } else {
    document.getElementById('album_privacy').disabled = false;
    $('#mg_form_outer').hide();
    $('div.mgSuggstMsg').attr('class', 'mgSuggstMsgLarge');
    $('#category_main').hide();
    $('#mobile_main').hide();
    $('#mobile_main_msg').hide();
    $('#mobile_no').val('');
    //$('#country_code').val('');
    $('#verification_code').val('');
    document.getElementById('mg_category').selectedIndex = 0;
    $('#code_main').hide();
    //$('#hosted_by_div').hide();
    //$('#subcategory_main').hide();
  }
}
function mg_change_tab(obj) {
  $('a[@id^="mg_tab_"]').each(function() {
    $(this).attr('class', '');
  });
  $(obj).attr('class', 'active');
  mg_sort_by($('#sort_by_recency'));
}
function mg_sort_by(obj) {
  var selected_tab = '';
  var sort_by = '';
  $('a[@id^="mg_tab_"]').each(function() {
    if ( $(this).attr('class') == 'active' ) {
      var split_id = $(this).attr('id').split('_')
      selected_tab = split_id[2];
    }
  });
  $('a[@id^="sort_by_"]').each(function() {
    $(this).attr('class', '');
  });
  $(obj).attr('class', 'active');
  $('a[@id^="sort_by_"]').each(function() {
    if ( $(this).attr('class') == 'active' ) {
      var split_id = $(this).attr('id').split('_')
      sort_by = split_id[2];
    }
  });
  $('#mg_listing_inner').html('<img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." />');
  $.get(
    base_url + "/ajax/load_mg_listing.php",
    {
      'sort_by' : sort_by,
      'selected_tab' : selected_tab,
      'page_type' : page_type
    },
    function(response) {
      $('#mg_listing_inner').html(response);
    }
  );
}
function find_media_gallery(obj, type) {
  if ( type == 'category' ) {
    var mg_category = obj.mg_category.value;
    if ( mg_category ) {
      redirect(base_url+'/nites/category/'+mg_category);
    } else {
      alert("Please select a category");
    }
  } else if ( type == 'city' ) {
    var mg_city = obj.mg_city.value;
    if ( mg_city ) {
      redirect(base_url+'/nites/city/'+mg_city);
    } else {
      alert("Please select a city");
    }
  }
}
function mg_permalink_sort_by(obj, sort_by, mg_type, mg_name) {
  var selected_tab = '';
  var sort_by = '';
  $('a[@id^="sort_by_"]').each(function() {
    $(this).attr('class', '');
  });
  $(obj).attr('class', 'active');
  $('a[@id^="sort_by_"]').each(function() {
    if ( $(this).attr('class') == 'active' ) {
      var split_id = $(this).attr('id').split('_')
      sort_by = split_id[2];
    }
  });
  $('#mg_listing_inner').html('<img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." />');
  $.get(
    base_url + "/ajax/load_mg_by_category.php",
    {
      'sort_by' : sort_by,
      'type' : mg_type,
      'name': mg_name
    },
    function(response) {
      $('#mg_listing_inner').html(response);
    }
  );
}
function addUploadElement() {
  var ni = document.getElementById('mydiv');
  var obj = document.createElement('DIV');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 4;
  numi.value =eval(num);
  var inc=eval(num);
  var inc1=inc-1;
  var inc2=inc1-1;
  var inc3=inc2-1; 
  var field="<dfn><input  name=SourceFile_"+inc3+" type='file' /></dfn><dfn><input  name=SourceFile_"+inc2+" type='file' /></dfn><dfn><input  name=SourceFile_"+inc1+" type='file' /></dfn>";
  obj.innerHTML = field;
  document.getElementById('mydiv').appendChild(obj);
  if ( num == '12' ) {
    document.getElementById('more').innerHTML="";
  }
}
function send_verification_code() {
  var country_code = $('#country_code').val();
  var mobile_no = $('#mobile_no').val();
  if ( !country_code ) {
    set_error_massage(__('Country code can not be left blank'));
    //alert('Country code can not be left blank');
    return false;
  } else if ( !mobile_no ) {
    set_error_massage(__('Mobile no can not be left blank'));
    //alert('Mobile no can not be left blank');
    return false;
  } else if ( isNaN(mobile_no) ) {
    set_error_massage(__('Invalid mobile number'));
    //alert('Invalid mobile number');
    return false;
  } else if ( mobile_no.length != 10 ) {
    set_error_massage(__('Invalid mobile number'));
    //alert('Invalid mobile number');
    return false;
  }
  $.get(
    base_url + "/ajax/send_verification_code.php",
    {
      'country_code' : country_code,
      'mobile_no' : mobile_no
    },
    function(response) {
      var data = response.split('ERROR@#$%^&&');
      if ( data[1] ) {
        set_error_massage(data[1]);
        //alert(data[1])
      } else {
        $('#code_main_msg').show();
        $('#code_main_msg_txt').html('The code has been sent to your mobile no: '+mobile_no);
        $('#country_code').attr('readonly', 'readonly');
        $('#mobile_no').attr('readonly', 'readonly');
        //$('#code_main_msg').hide(10000);
      }
    }
  );
}
function toggle_host_name(cat_obj, host_div_id) {
  $('#'+host_div_id).val('');
  //var cat_txt = cat_obj.options[cat_obj.options.selectedIndex].text.toLowerCase();
  //if ( cat_txt == 'parties' || cat_txt == 'social events' || cat_txt == 'weddings' ) {
  if ( cat_obj.value != 0 ) {
    $('#'+host_div_id+'_div').show();
    $('#'+host_div_id).focus();
    //pageScroll(host_div_id);
  } else {
    $('#'+host_div_id+'_div').hide();
  }
}
function mg_album_save(obj) {
  if ( !$('#album_title').val() ) {
    set_error_massage(__('Title cannot be left blank'));
    return false;
  } else if ( document.getElementById('MG-submit').checked == true ) {
    if ( $('#mg_category').val() == 0 ) {
      set_error_massage(__('Please select itimes Nites category'));
      return false;
    } else if ( $('#hosted_by').val() == '' || $('#hosted_by').val() == __('Event host') ) {
      set_error_massage(__('Event host can not be left blank'));
      return false;
    } else if ( document.getElementById('accept-terms').checked == false ) {
      set_error_massage(__('Please accept Terms & Conditions'));
      return false;
    }
  }
  return true;
}