var upload_running = 0;
var current_target = '';
var account_form_open = 0;
var gallery_form_open = 0;
var gallery_images_options = 0;
var update_image_timeout = new Array();
var images_update_timeout = new Array();
var texts_update_timeout = 0;
var seo_update_timeout = new Array();
var update_gallery_timeout = 0;
var text_string = '';
var uploadify_count = 0;
var cmanager_clients_update_timeout = new Array();

$(document).ready
( function()
  {
				corners();
		}
);


function login()
{
  $("#forgot_password_form").hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'login',
				  account_id: account_id,
						user_id: user_id,
						login_email: $("#login_email").val(),
						login_password: $("#login_password").val()
				},
				function(data)
				{
						clear_input();
						eval(data);
      align_gallery_boxes();
						corners();
			 }
		);
  adjust_footer();
}
function logout()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'logout',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
				  eval(data);
						clear_input();
						corners();
      adjust_footer();
				}
		);
}
function account()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'account',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('account');
						if(account_form_open == 1)
						{
        $("#account_form").toggle();
								account_form_open = 0;
						}
      adjust_footer();
						corners();
      $("#global_loading").hide();
				}
		);
}
function accounts_update()
{
  $("#account_form_feedback").hide();
  $("#accounts_update_updating").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'accounts_update',
				  account_id: account_id,
						user_id: user_id,
						account_email: $("#account_email").val(),
						account_password: $("#account_password").val(),
						account_name: $("#account_name").val(),
						account_first_name: $("#account_first_name").val(),
						account_last_name: $("#account_last_name").val(),
						account_address: $("#account_address").val(),
						account_city: $("#account_city").val(),
						account_province: $("#account_province").val(),
						account_zip: $("#account_zip").val(),
						account_country: $("#account_country").val(),
						account_phone: $("#account_phone").val()
				},
				function(data)
				{
				  eval(data);
						corners();
      adjust_footer();
      $("#accounts_update_updating").hide();
				}
		);
}
function gallery_one_images(gallery_id)
{
  $("#global_loading").show();
		$("#get_galleries_scope").val('gal_' + gallery_id);
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'gallery',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id,
						gallery_purpose: $.trim($("#gallery_purpose").html())
				},
				function(data)
				{
				  $("#content").html(data);
      align_image_boxes();
				  $("#content").show();
      //manage_buttons('galleries');
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
						corners();
      $("#global_loading").hide();
				}
		);
}
//
function gallery_one_settings_SA(gallery_id)
{
		$("#get_galleries_scope").val('gal_' + gallery_id);
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'gallery_settings',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id
				},
				function(data)
				{
				  $("#content").html(data);
				  $("#content").show();
						if(gallery_form_open == 1)
						{
        $("#gallery_form").show();
								gallery_form_open = 0;
						}
      adjust_footer();
				  $("#content_left").show();
						corners();
				}
		);
}
function gallery_insert()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'gallery_insert',
				  account_id: account_id,
						user_id: user_id,
						gallery_display_name: $("#gallery_display_name_create").val(),
						gallery_purpose: $.trim($("#gallery_purpose").html())
				},
				function(data)
				{
						clear_input();
				  eval(data);
      align_gallery_boxes();
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
function manage_buttons(target)
{
  $(".button").removeClass("button_selected");
		if(target == "gallery_one")
		{
		  $("#gallery_one_button").addClass("button_selected");
		}
		else
		{
		  $("#gallery_one_button").hide();
		  $("#" + target + "_button").addClass("button_selected");
		}
		current_target = target != 'support' ? target : current_target;
}
function clear_input()
{
  $("input").val('');
		$("#login_feedback").hide();
}
function create_account_reset()
{
  clear_input();
  $("#create_account_feedback").hide();
}
function galleries_positions()
{
  $("#global_loading").show();
  var galleries = '';
		var i = 1;
		var id = 0;
		var category_current = '';
  $(".gallery").each(
		function()
		{
		  id = $(this).attr("id").slice(3);
				var category = $.trim($("#category_" + id).html());
				if(category != category_current)
				{
				  category_current = category;
						i = 1;
				}
		  galleries += id + '|';
				$("#gallery_position_" + id).html(i);
				++i;
		});
		galleries = galleries.slice(0,galleries.length - 1);
		if($.trim(galleries) == '')
		{
		  return;
		}
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'galleries_positions',
				  account_id: account_id,
						user_id: user_id,
						galleries: galleries
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
						  alert(data);
						}
      $("#global_loading").hide();
				}
		);
}
function images_positions(gallery_id)
{
  $("#upload_feedback").hide();
  $("#global_loading").show();
  var images = '';
		var i = 1;
		var id = 0;
  $(".image").each(
		function()
		{
		  id = $(this).attr("id").slice(12);
		  images += id + '|';
				$("#image_position_" + id).html(i);
				++i;
		});
		images = images.slice(0,images.length - 1);
		if($.trim(images) == '')
		{
    $("#global_loading").hide();
		  return;
		}
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'images_positions',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id,
						images: images
				},
				function(data)
				{    
      $("#global_loading").hide();
				  if($.trim(data) != '')
						{
						  alert(data);
						}
				}
		);
}
function image_uploader(account_id, gallery_id, target, image_is_fore, image_is_client)
{
		$('#gallery_form_feedback').html('').hide();
		$("#clients_insert_feedback").hide();
  var target_extension = image_is_client == 'no' ?  '' : '_' + image_is_client;
		new AjaxUpload
		( target + target_extension,
		  { action: 'private_galleries_ajax.php',
				  name: 'file',
						data: { account_id: account_id,
						        user_id: user_id,
						        gallery_id: gallery_id,
              task: 'upload_file',
														image_is_fore: image_is_fore,
														image_is_client: image_is_client
						      },
						onSubmit: function(file, extension)
						{
						  if(upload_running == 1)
								{
								  alert('A file is already uloading. A quick solution is to logout, refresh the page and log back in.');
										return false;
								}
						  upload_running = 1;
						  $("#" + target + target_extension).hide();
						  $("#" + target + "_upload_feedback" + target_extension).html('').hide();
						  $("#" + target + "_image_feedback" + target_extension).html('').hide();
						  $("#" + target + "_uploading_button" + target_extension).show();
						},
						onComplete: function(file, response)
						{
  		    $('#gallery_no_image').hide();
						  upload_running = 0;
						  $("#" + target + target_extension).show();
						  $("#" + target + "_upload_feedback" + target_extension).html('').show();
						  $("#" + target + "_image_feedback" + target_extension).html('').show();
						  $("#" + target + "_uploading_button" + target_extension).hide();
								response = $.trim(response);
								if(image_is_client != 'no')
								{
								  eval(response);
										return;
								}
								else
								{
								  if($.trim(response) != '')
								  {
									  	if(response.slice(0,2) == 'no')
										  {
											  	eval(response.slice(2));
												  return;
										  }
								  }
								  get_galleries();
          adjust_footer();
								}
						}
				}
		);
}
function update_image(image_id)
{
		$('#image_saving_' + image_id).css('color','red');
  clearTimeout(update_image_timeout[image_id]);
		update_image_timeout[image_id] = setTimeout("update_image_(" + image_id + ");", 2000);
}
function update_image_(image_id)
{
  var image_positioning = '';
		if($("#image_positioning_" + image_id).length != 0)
		{
		  image_positioning = $("#image_positioning_" + image_id).val();
		}
		else
		{
		  image_positioning += $("#image_is_above_" + image_id).attr("checked") ? "above" : "";
		  image_positioning += $("#image_is_below_" + image_id).attr("checked") ? "below" : "";
		  image_positioning += "|";
		  image_positioning += $("#image_is_large_" + image_id).attr("checked") ? "large" : "";
		  image_positioning += $("#image_is_small_" + image_id).attr("checked") ? "small" : "";
  }
		$("#upload_feedback").hide();
		var image_subname = $("#image_subname_" + image_id).length == 0 ?
		                    "" :
                      $("#image_subname_" + image_id).val();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'update_image',
				  account_id: account_id,
						user_id: user_id,
						image_id: image_id,
						image_is_visible: $("#image_is_visible_yes_" + image_id).attr("checked") ? 'yes' : 'no',
						image_is_fore: $("#image_is_fore_yes_" + image_id).attr("checked") ? 'yes' : 'no',
						image_title: $("#image_title_" + image_id).val(),
						image_comment: $("#image_comment_" + image_id).val(),
						image_positioning: image_positioning,
						image_alt: $("#image_alt_" + image_id).val(),
						image_subname: image_subname
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
						  eval(data);
						  corners();
						}
		    $('#image_saving_' + image_id).css('color','white');
				}
		);
}
function images_update_field(image_id, field)
{
		$('#image_saving_' + image_id).css('color','red');
  var key = field + "_" + image_id;
  clearTimeout(images_update_timeout[key]);
		images_update_timeout[key] = setTimeout("images_update_field_(" + image_id + ",'" + field + "');", 2000);
}
function images_update_field_(image_id, field)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'images_update_field',
				  account_id: account_id,
						user_id: user_id,
						image_id: image_id,
						field: field,
						value: $("#" + field + "_" + image_id).val()
				},
				function(data)
				{
				  eval(data);
		    $('#image_saving_' + image_id).css('color','white');
				}
		);
}
function update_fore(image_id)
{
  $("#upload_feedback").hide();
  if($("#image_is_fore_yes_" + image_id).attr("checked"))
		{
				$(".fore_yes").each( function()
				{
		    var id = $(this).attr("id").slice(18);
      if( id != image_id && $("#image_is_fore_yes_" + id).attr("checked"))
						{
						  $("#image_is_fore_yes_" + id).attr("checked",false);
						  $("#image_is_fore_no_" + id).attr("checked",true);
						}
						return;
				});
		}
}
function image_delete(image_id)
{
  if(!confirm("Do you really want to delete this image? The image will be lost."))
		{
		  return;
		}
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'images_delete',
				  account_id: account_id,
						user_id: user_id,
						image_id: image_id
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
								eval(data);
						}
      adjust_footer();
				}
		);
}
function image_gallery_move(image_id)
{
  if(!confirm("Confirm that you want to move this image to another collection"))
		{
		  return;
		}
		$("#image_gallery_move_" + image_id).hide().next().show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'image_gallery_move',
				  account_id: account_id,
						user_id: user_id,
						image_id: image_id,
						gallery_id_target: $("#image_gallery_move_" + image_id).val()
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
								eval(data);
						}
      adjust_footer();
				}
		);
}
function galleries_delete(gallery_id)
{
  if(!confirm("Do you really want to delete this gallery? The gallery and its images will be lost."))
		{
		  return;
		}
		$('#delete_gallery_button_' + gallery_id).hide();
		$('#deleting_gallery_button_' + gallery_id).show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'galleries_delete',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
								eval(data);
						}
      adjust_footer();
				}
		);
}
function corners()
{
		$('.rc').corner('5px');
		$('.rcb').corner(' bottom 10px');
};
function gallery_options_update_submit_show(gallery_id)
{
  $("#upload_feedback").hide();
		$('#gallery_form_feedback').html('').hide();
		$('#gallery_updating').show();
  clearTimeout(update_gallery_timeout);
		update_gallery_timeout = setTimeout("galleries_update(" + gallery_id + ");", 2000);
}
function galleries_update(gallery_id)
{ 
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'galleries_update',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id,
						gallery_is_online: $("#gallery_is_online_yes").attr("checked") ? 'yes' : 'no',
						gallery_description: $("#gallery_description").val(),
						gallery_category: $("input:radio[name=gallery_category]:checked").val(),
						gallery_is_superpassword: $("#gallery_is_superpassword_yes").attr("checked") ? 'yes' : 'no',
						gallery_interface: $("#gallery_interface_dropdown").val()
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
						  eval(data);
		      $('#gallery_updating').hide();
						  corners();
						}
				}
		);
}
function galleries_update_gallery_display_name(gallery_id)
{ 
		$('#gallery_form_feedback_display_name').html('').hide();
		$('#galleries_display_name_change_button').hide();
		$('#galleries_display_name_changing_button').show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'galleries_update_gallery_display_name',
				  account_id: account_id,
						user_id: user_id,
						gallery_id: gallery_id,
						gallery_display_name: $("#gallery_display_name").val()
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
						  eval(data);
		      $('#galleries_display_name_change_button').show();
		      $('#galleries_display_name_changing_button').hide();
						  corners();
						}
				}
		);
}
function accounts_create()
{
		$('#artstrollers_area').hide();
  $('#artstrollers_splash_account_creation').show();
  $("#account_form_feedback").hide();
		$("#create_account_feedback").hide();
		$("#account_form_area").hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'accounts_insert',
				  account_id: account_id,
						user_id: user_id,
						account_email: $("#account_email").val(),
						account_password: $("#account_password").val(),
						account_password_bis: $("#account_password_bis").val(),
						account_name: $("#account_name").val(),
						account_first_name: $("#account_first_name").val(),
						account_last_name: $("#account_last_name").val(),
						account_address: $("#account_address").val(),
						account_city: $("#account_city").val(),
						account_province: $("#account_province").val(),
						account_zip: $("#account_zip").val(),
						account_country: $("#account_country").val(),
						account_phone: $("#account_phone").val(),
						account_terms: $("#account_terms").attr('checked') ? 'yes' : 'no'
				},
				function(data)
				{
				  eval(data);
						corners();
      $('#artstrollers_splash_account_creation').hide();
				}
		);
}
function forgot_password()
{ 
  $('#login_feedback').html('').hide();
  $("#account_form_feedback").hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'forgot_password',
				  account_id: account_id,
						user_id: user_id,
						forgot_password_email: $("#forgot_password_email").val()
				},
				function(data)
				{
				  eval(data);
						corners();
				}
		);
}
function change_password()
{
  $("#change_password_feedback").hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'change_password',
				  account_id: account_id,
						user_id: user_id,
						change_password_current: $("#change_password_current").val(),
						change_password_new_1: $("#change_password_new_1").val(),
						change_password_new_2: $("#change_password_new_2").val()
				},
				function(data)
				{
				  eval(data);
						corners();
				}
		);
}
function texts()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'texts',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('texts');
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
      $("#global_loading").hide();
				}
		);
}
function options()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'options',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('options');
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
				}
		);
}
function show_text()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'show_text',
				  account_id: account_id,
						user_id: user_id,
						target: $('#select_text_id').val()
				},
				function(data)
				{
						clear_input();
						eval(data);
      manage_buttons('texts');
						corners();
      adjust_footer();
				}
		);
}
function texts_update()
{
		$('#texts_saving').show();
  clearTimeout(texts_update_timeout);
		texts_update_timeout = setTimeout("texts_update_();", 2000);
}
function texts_update_()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'texts_update',
				  account_id: account_id,
						user_id: user_id,
						target: target_id_current,
						text_production: $('#text_production').val()
				},
				function(data)
				{
				  data = $.trim(data);
				  if(data != '' && data != "nothing was done" )
						{
						  eval(data);
						  corners();
						}
		    $('#texts_saving').hide();
				}
		);
}
function push_changes_to_production(gallery_id)
{
  if(!confirm("Please, confirm that you want the changes be pushed to production."))
		{
		  return;
		}

  $(".buttons_push_to_production").toggle();

  $.post
		( "/private_galleries_ajax.php",
		  { task: 'push_changes_to_production',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						//eval(data);
						if($.trim(data) != '')
						{
						  $("#compile_feedback_text").html(data).show();
						  $("#compile_feedback").show();
						}		
      $(".buttons_push_to_production").toggle();
						corners();
				}
		);
}
function get_galleries()
{
  var target = $.trim($("#get_galleries_scope").val());
		if(target == 0)
		{
		  return;
		}
  $("#global_loading").show();
		switch(target.substr(0,3))
		{
		  case 'cat':
		  case 'all':
      $.post
	    	( "/private_galleries_ajax.php",
		      { task: 'get_galleries',
		 	      account_id: account_id,
		 			    user_id: user_id,
		 			    scope: target.substr(4),
						    gallery_purpose: $.trim($("#gallery_purpose").html())
		 	    },
			     function(data)
		 	    {
		 	      if($.trim(data) != '')
					    	{
            $("#boxes_toggle_img").attr('src','./private_galleries_elements/hide_details.png');
            $("#boxes_toggle_img_mouseover").attr('src','./private_galleries_elements/hide_details_mouseover.png');
						      eval(data);
            adjust_footer();
						    }
						    $('#support_navigation').remove();
				      $("#content_left").show();
		        $('.gallery_actions').hide();
						    corners();
          align_gallery_boxes();
          $("#global_loading").hide();
			    	}
		    );
				  break;
				case 'gal':
		    gallery_one_images(target.substr(4));
      align_image_boxes();
				  break;
		}

}
function galleries()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'galleries',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
				  eval(data);
						corners();
      adjust_footer();
      align_gallery_boxes();
      manage_buttons('galleries');
						clear_input();
      $("#boxes_toggle_img").attr('src','./private_galleries_elements/hide_details.png');
      $("#boxes_toggle_img_mouseover").attr('src','./private_galleries_elements/hide_details_mouseover.png');
						$('#support_navigation').remove();
				  $("#content_left").show();
		    $('.gallery_actions').hide();
      $("#global_loading").hide();
				}
		);
}
function galleries_toggle_details(action)
{
  action = action == 0 ? 'hide' : 'show';
		if(action == 'hide')
		{
		  $('.gallery_toggle').hide()
		}
		else
		{
		  $('.gallery_toggle').show()
		}
}
function images_toggle_details(action, larger_width)
{
  $(".image").each
		( function()
		  {
				  var image_id = $(this).attr('id').slice(12);
						image_toggle_details(image_id, action, larger_width);
				}
		);
}
function image_toggle_details(image_id, action, larger_width)
{
  action = action == 0 ? 'hide' : 'show';
		var w = action == 'hide' ? 120 : larger_width;
		var r = action == 'hide' ? 20 : 0;
		$("#image_block_" + image_id).width(w).css('margin-right',r);
		if(action == 'hide')
		{
		  $("#box_toggle_image_" + image_id).hide();
		  $("#button_image_details_show_" + image_id).show();
		  $("#button_image_details_hide_" + image_id).hide();
		}
		else
		{
		  $("#box_toggle_image_" + image_id).show();
		  $("#button_image_details_show_" + image_id).hide();
		  $("#button_image_details_hide_" + image_id).show();
		}
}
function adjust_footer()
{
  return;
  //if($("#content_left").height() > $("#content").height())
  //{
		//  $("#footer").css("margin-top", 200);
		//}
}
function share()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'share',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						clear_input();
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('share');
      adjust_footer();
						corners();
				}
		);
}
function share_url()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'share_url',
				  account_id: account_id,
						user_id: user_id,
      share_to_email: $("#share_to_email").val(),
						share_from_name: $("#share_from_name").val(),
						share_from_email: $("#share_from_email").val(),
						share_message: $("#share_message").val(),
						share_subject: $("#share_subject").val()
				},
				function(data)
				{
				  eval(data);
      adjust_footer();
						corners();
				}
		);
}
function support()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'support',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('support');
						clear_input();
      adjust_footer();
						corners();
      $("#global_loading").hide();
				}
		);
}
function support_show_section(section)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'support_show_section',
				  account_id: account_id,
						user_id: user_id,
						section: section
				},
				function(data)
				{
				  if(section.substr(0,8) != 'details_')
						{
						  $('.support_selected :first-child').show();
						  $('.support_selected :last-child').hide();
						  $('.support_selected').removeClass('support_selected');
						  $('#nav_' + section).addClass('support_selected');
						  $('#nav_' + section).children().hide();
						  $('#nav_' + section + ' :last-child').show();
      }
				  $("#content_support").html(data);
						corners();
				}
		);
}
function tickets_insert()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'tickets_insert',
				  account_id: account_id,
						user_id: user_id,
						ticket_summary: $("#ticket_summary").val(),
						ticket_message: $("#ticket_message").val()
				},
				function(data)
				{
				  eval(data);
						corners();
				}
		);
}
function tickets_update(ticket_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'tickets_update',
				  account_id: account_id,
						user_id: user_id,
						ticket_id: ticket_id,
						update_message: $("#update_message").val()
				},
				function(data)
				{
				  eval(data);
						corners();
				}
		);
}
function image_rotate(image_id, direction)
{
  $("#image_rotating_" + direction + "_" + image_id).show();
  $("#image_rotate_" + direction + "_" + image_id).hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'image_rotate',
				  account_id: account_id,
						user_id: user_id,
						direction: direction,
						image_id: image_id
				},
				function(data)
				{
						eval(data);
      adjust_footer();
      $("#image_rotating_" + direction + "_" + image_id).hide();
      $("#image_rotate_" + direction + "_" + image_id).show();
				}
		);
}
function image_gamma(image_id, gamma)
{
  if(gamma < 0)
		{
    $("#image_darkening_" + image_id).show();
    $("#image_darken_" + image_id).hide();
  }
		else
		{
    $("#image_lightening_" + image_id).show();
    $("#image_lighten_" + image_id).hide();
  }
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'image_gamma',
				  account_id: account_id,
						user_id: user_id,
						image_id: image_id,
						gamma: gamma
				},
				function(data)
				{
						eval(data);
      adjust_footer();
      $("#image_darkening_" + image_id).hide();
      $("#image_lightening_" + image_id).hide();
      $("#image_darken_" + image_id).show();
      $("#image_lighten_" + image_id).show();
				}
		);
}
function reload_content_actions()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'reload_content_actions',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
				  $("#content_actions").remove();
						$("#content_actions").html(data);
		    $('.content_left_gallery').hide();
      adjust_footer();
				}
		);
}
function seo()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'seo',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
      $("#global_loading").hide();
						clear_input();
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('seo');
      adjust_footer();
						corners();
				}
		);
}
function repping()
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'repping',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
						clear_input();
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('repping');
      adjust_footer();
						corners();
				}
		);
}
function align_gallery_boxes()
{
  var i = 1;
  $(".gallery_box").each
		( function()
		  {
		    if(i == 3)
				  {
				    $(this).css('margin-right','-10px');
				  		i = 1;
				  }
				  else
				  {
				    $(this).css('margin-right','45px');
				    ++i;
				  }
    }
		);
}
function align_image_boxes()
{
  var i = 1;
  $(".image_box").each
		( function()
		  {
		    if(i == 7)
				  {
				    $(this).css('margin-right','0px');
				  		i = 1;
				  }
				  else
				  {
						  if(i == 2 || i == 4)
								{
				      $(this).css('margin-right','18px');
        }
				    ++i;
				  }
    }
		);
}
function show_images_details(larger_width)
{
		images_toggle_details(1, larger_width);
		$(".show_images_button").hide();
		$(".hide_images_button").show();
		$("#images").sortable("disable");
}
function hide_images_details(larger_width)
{
		images_toggle_details(0, larger_width);
		$(".show_images_button").show();
		$(".hide_images_button").hide();
		$("#images").sortable("enable");
}
function image_details()
{
  if($("#show_images_button").css('display') == 'none')
		{
		  hide_images_details(1000);
		}
  else
		{
		  show_images_details(1000);
  }
}
function blogs(blog_purpose, blog_button)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blogs',
				  account_id: account_id,
						user_id: user_id,
						blog_purpose: blog_purpose
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons(blog_button);
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
      $("#global_loading").hide();
				}
		);
}
function select_blog(blog_purpose)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blogs',
				  account_id: account_id,
						user_id: user_id,
						blog_id: $("#select_blog").val(),
						blog_purpose: blog_purpose
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
      $("#global_loading").hide();
				}
		);
}
function blogs_insert(blog_purpose)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blogs_insert',
				  account_id: account_id,
						user_id: user_id,
						blog_purpose: blog_purpose
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
function blogs_delete()
{
		$("#blogs_delete_button").hide();
		$("#blogs_deleting_button").show();
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blogs_delete',
				  account_id: account_id,
						user_id: user_id,
						blog_id: $("#select_blog").val()
				},
				function(data)
				{
						clear_input();
						eval(data);
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
function blog()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blog',
				  account_id: account_id,
						user_id: user_id,
						blog_id: $("#get_blog").val()
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
var update_blog_timeout = 0;
function blogs_update(blog_id)
{
		$('#blog_updating').show();
  clearTimeout(update_blog_timeout);
		update_blog_timeout = setTimeout("blogs_update_(" + blog_id + ");", 2000);
}
function blogs_update_(blog_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'blogs_update',
				  account_id: account_id,
						user_id: user_id,
						blog_id: blog_id,
						blog_title: $("#blog_title").val(),
						blog_is_online: $("#blog_is_online_yes").attr("checked") ? 'yes' : 'no',
						blog_text: $("#blog_text").val()
				},
				function(data)
				{
		    $('#blog_updating').hide();
						$("#select_" + blog_id).html($("#blog_title").val());
				}
		);
}
var update_rss_channel_timeout = 0;
function rss_channels_update(rss_channel_id)
{
		$('#rss_channels_updating').show();
  clearTimeout(update_rss_channel_timeout);
		update_rss_channel_timeout = setTimeout("rss_channels_update_(" + rss_channel_id + ");", 2000);
}
function rss_channels_update_(rss_channel_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'rss_channels_update',
				  account_id: account_id,
						user_id: user_id,
						rss_channel_id: rss_channel_id,
						rss_channel_title: $("#rss_channel_title").val(),
						rss_channel_link: $("#rss_channel_link").val(),
						rss_channel_description: $("#rss_channel_description").val()
				},
				function(data)
				{
		    $('#rss_channels_updating').hide();
				}
		);
}
function button_to_upload()
{
		$('#button_to_upload').hide();
		$("#button_uploading").show();
		$("#uploadifypoint").uploadifyUpload(); 
}
function blog_button_to_upload()
{
		$('#button_to_upload').hide();
		$("#button_uploading").show();
		$("#uploadify_blog").uploadifyUpload(); 
}
function blog_upload(blog_id)
{
  try
		{
				var i = 0;
  		$('#uploadify_blog').uploadify
  		({ 'uploader': '/example/scripts/uploadify.swf',
       'cancelImg': '/example/cancel.png',
  					'script': '/private_galleries_ajax.php',
  					'displayData': 'speed',
  					'fileDataName': 'file',
  					'multi': true,
							'fileDesc': 'upload images (jpg, png), audios (mp3), and videos (flv)',
							'fileExt': '*.jpg;*.jpeg;*.mp3;*.flv',
							'buttonImg': '/private_galleries_elements/upload_browse_media.png',
							'width': 394,
							'height': 20,
							'rollover': true,
  					'scriptData': { 'user_id': user_id,
  																	    'account_id': account_id,
  																					'task': 'blog_upload',
																							'blog_id': blog_id
  																				},
								onSelectOnce: function(event, data)
								{
										$('#button_uploading').hide();
										$('#button_to_upload').show();
								},
  						onComplete: function(event, queueID, fileObj, response, data)
  						{
										response = $.trim(response);
										if(response.slice(0,2) == 'no')
										{
												eval(response.slice(2));
										}
										else
										{
												++i;
										}
  						},
  						onAllComplete: function(event, data)
  						{
										select_blog();
										$('#button_uploading').hide();
										$('#button_to_upload').hide();
  						}
  				}
  		);
		}
		catch(err)
		{
		  alert(err);
				$('#image_interface_one_at_a_time').show();
				$('#image_interface').hide();
		}
}
function events(event_purpose, event_button)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'events',
				  account_id: account_id,
						user_id: user_id,
						events_purpose: event_purpose
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons(event_button);
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
      $("#global_loading").hide();
				}
		);
}
function events_by_type(event_purpose)
{
		if($.trim($("#events_type_id_select").val()) == '')
		{
		  return;
		}
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'events',
				  account_id: account_id,
						user_id: user_id,
						events_purpose: event_purpose,
						events_future: $("#events_future").attr("checked") ? 'yes' : 'no',
						events_past: $("#events_past").attr("checked") ? 'yes' : 'no',
						events_type_id: $("#events_type_id_select").val()
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
function events_insert(event_purpose, event_type_id)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'events_insert',
				  account_id: account_id,
						user_id: user_id,
						event_purpose: event_purpose,
						event_type_id: event_type_id
				},
				function(data)
				{
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
function event_details(event_id)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'event',
				  account_id: account_id,
						user_id: user_id,
						event_id: event_id
				},
				function(data)
				{
						clear_input();
						$("#event_detail").remove();
						$("#block_" + event_id).after(data);
						corners();
      adjust_footer();
      $("#global_loading").hide();
				}
		);
}
var update_events_timeout;
function events_update(event_id)
{
  $(".event_saving").show();
  clearTimeout(update_events_timeout);
		update_events_timeout = setTimeout("events_update_(" + event_id + ");", 2000);
}
function events_update_(event_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'events_update',
				  account_id: account_id,
						user_id: user_id,
						event_id: event_id,
						event_display_name: $("#event_display_name").val(),
						event_date: $("#event_date").val(),
						event_time: $("#event_time").val(),
						event_is_online: $("#event_is_online_yes").attr("checked") ? 'yes' : 'no',
						event_description_long: $("#event_description_long").val(),
						event_description_short: $("#event_description_short").val()
				},
				function(data)
				{
				  eval(data);
      $(".event_saving").hide();
				}
		);
}
function seo_update(seo_id)
{
		$('.seo_saving_' + seo_id).css('color','red');
  clearTimeout(seo_update_timeout[seo_id]);
		seo_update_timeout[seo_id] = setTimeout("seo_update_(" + seo_id + ");", 2000);
}
function seo_update_(seo_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'seo_update',
				  account_id: account_id,
						user_id: user_id,
						seo_id: seo_id,
      seo_value: $("#seo_" + seo_id).val()
				},
				function(data)
				{
				  if($.trim(data) != '')
						{
						  eval(data);
						  corners();
						}
		    $('.seo_saving_' + seo_id).css('color','white');
				}
		);
}
function private_galleries_versions_change()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'versions_change',
				  account_id: account_id,
						user_id: user_id,
						version_id: $("#version_select").val()
				},
				function(data)
				{
      $("#global_loading").hide();
				  if($.trim(data) != '')
						{
						  eval(data);
						  corners();
						}
				}
		);
}
function repopulate()
{
  $("#global_loading").show();
		$("#compile_feedback").hide();
		$('.buttons_repopulate').toggle();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'repopulate',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
      $("#global_loading").hide();
		    $('.buttons_repopulate').toggle();
						if($.trim(data) != '')
						{
						  $("#compile_feedback_text").html(data).show();
						  $("#compile_feedback").show();
						}		
				}
		);
}
var cmanager_client_id = 0;
var orderby = '';
var offset = '';
var limit = '';
var constraint = '';
var selection_id = 0;
var cmanager_message_parameters = '';
var cmanager_template_id = 0;
var cmanager_keywords_area_show = 0;

function cmanager()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'private_galleries_cmanager',
				  account_id: account_id,
						user_id: user_id,
						orderby: orderby,
						offset: offset,
						selection_id: selection_id,
						constraint: constraint,
						limit: limit
				},
				function(data)
				{
      ckeditor_clean('email_body');
						clear_input();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('cmanager');
						corners();
      adjust_footer();
						$('#support_navigation').remove();
				  $("#content_left").show();
      $("#global_loading").hide();
      if(cmanager_keywords_area_show == 1)
						{
						  $("#cmanager_keywords_area").show();
						}
				}
		);
}
function cmanager_keywords_area_toggle()
{
  cmanager_keywords_area_show = cmanager_keywords_area_show == 1 ? 0 : 1;
		$("#cmanager_keywords_area").toggle();
}
function ckeditor_clean(id)
{
		$('.ckeditor_stuff').each
		( function()
		  {
				  var id = $(this).attr('id');
      var o=CKEDITOR.instances[id];
		    if (o) o.destroy();
				}
		);
}
function loadEditor(id)
{
  var instance = CKEDITOR.instances[id];
		if(instance)
		{
		  CKEDITOR.remove(instance);
		}
		CKEDITOR.replace(id);
		$("#" + id).ckeditor();
}
function cmanager_clients_table()
{
  cmanager_message_shoot_emails_list_clean();
  
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'private_galleries_cmanager_clients_table',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						orderby: orderby,
						offset: offset,
						limit: limit,
						constraint: constraint
				},
				function(data)
				{
      $("#global_loading").hide();
				  $("#clients_table").html(data);
				}
		);
}
function cmanager_details_show(client_id)
{
  cmanager_message_shoot_emails_list_clean();
  if(client_id == 0)
		{
		  client_id = cmanager_client_id;
		  if($(".client_details").size() == 0)
		  {
		    return;
		  }
		}
		else
		{
		  cmanager_client_id = client_id;
		}
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_client_details',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id
				},
				function(data)
				{
      $("#global_loading").hide();
						$(".client_details").remove();
      $("#client_" + client_id).after("<tr class='client_details'><td colspan='6'>" + data + "</td></tr>");
				}
		);
}
function cmanager_create_client()
{
  cmanager_message_shoot_emails_list_clean();
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_add_client',
				  account_id: account_id,
						orderby: orderby,
						limit: limit,
						offset: offset,
						constraint: constraint,
						selection_id: selection_id,
						user_id: user_id
				},
				function(data)
				{
      $("#global_loading").hide();
				  $("#clients_table").html(data);
				}
		);
}
function cmanager_client_delete(client_id)
{
  cmanager_message_shoot_emails_list_clean();
  if(!confirm('Please confirm you want to delete this client from the system'))
		{
		  return;
		}
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_delete',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id,
						selection_id: selection_id,
						orderby: orderby,
						offset: offset,
						limit: limit
				},
				function(data)
				{
      $("#global_loading").hide();
				  $("#clients_table").html(data);
				}
		);
}
function cmanager_message(section)
{
  cmanager_message_shoot_emails_list_clean();
  $(".message_tab_area").hide();
  $("#message_area_" + section).show();

  $('.message_tab_selected').addClass('message_tab_normal');
  $('.message_tab_selected').removeClass('message_tab_selected');
		$("#message_tab_" + section).addClass('message_tab_selected');
}
function cmanager_message_get_customization(template_id)
{
  cmanager_message_shoot_emails_list_clean();
		$('#cmanager_preview').html('');
		cmanager_template_id = template_id;
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_message_get_customization',
				  account_id: account_id,
						user_id: user_id,
						template_id: template_id
				},
				function(data)
				{
      ckeditor_clean('email_body');
      $("#global_loading").hide();
		    $('#message_area_parameters').html(data);
						$('#message_area_shoot').show();
		    cmanager_message("customize_template");
				}
		);
}
function cmanager_clients_update(client_id, field)
{
  cmanager_message_shoot_emails_list_clean();
  var key = field + "_" + client_id;
		$("#clients_table_saving").show();
		$('#button_client_close').hide();
  clearTimeout(cmanager_clients_update_timeout[key]);
		cmanager_clients_update_timeout[key] = setTimeout("cmanager_clients_update_(" + client_id + ",'" + field + "');", 2000);
}
function cmanager_clients_update_(client_id, field)
{
  cmanager_message_shoot_emails_list_clean();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_update',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id,
						field: field,
						value: $("#" + field + "_" + client_id).val()
				},
				function(data)
				{
				  eval(data);
		    $("#clients_table_saving").hide();
		    $('#button_client_close').show();
				}
		);
}
function cmanager_add_keyword()
{
  cmanager_message_shoot_emails_list_clean();
		$(".adding_keyword").toggle();
  $('#keyword_name_feedback').html('');
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_add_keyword',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						orderby: orderby,
						limit: limit,
						offset: offset,
						keyword_name: $("#keyword_name_new").val()
				},
				function(data)
				{
				  cmanager();
		    $("#cmanager_keywords_area").show();
				}
		);
}
function cmanager_clients_keywords_update(client_id, keyword_id)
{
  cmanager_message_shoot_emails_list_clean();
		$("#clients_table_saving").show();
		$('#button_client_close').hide();
		var	value = $("#keyword_" + keyword_id + "_" + client_id).attr("checked") ? 'yes' : 'no';
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_keywords_update',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id,
						orderby: orderby,
						limit: limit,
						offset: offset,
						keyword_id: keyword_id,
						selection_id: selection_id,
						value: value
				},
				function(data)
				{
						if(value == 'yes' && $("#selection_keyword_" + keyword_id).attr("checked") )
						{
						   $("#client_checkbox_" + client_id).attr('checked',true);
						}
						else
						{
						  $("#client_checkbox_" + client_id).removeAttr("checked");
      }
		    $("#clients_table_saving").hide();
		    $('#button_client_close').show();
						var count = parseInt($.trim($("#keyword_count_id_" + keyword_id).html()));
						if(value == 'yes')
						{
        ++count;
						}
						else
						{
						  --count;
						}
						$(".keyword_count_" + keyword_id).html(count);
				}
		);
}
function cmanager_clients_table_select_all(operation)
{
  cmanager_message_shoot_emails_list_clean();
  if(operation == 'select_all')
		{
		  $(".client_selected").attr('checked','checked');
  }
		else
		{
		  $(".client_selected").removeAttr("checked");
				$(".keyword_checkbox").removeAttr("checked");
  }
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_table_select_all',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						operation: operation
				},
				function(data)
				{
				}
		);
}
function cmanager_clients_table_select_one(client_id)
{
  cmanager_message_shoot_emails_list_clean();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_table_select_one',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						client_id: client_id,
						value: $("#client_checkbox_" + client_id).attr("checked") ? 'checked' : ''
				},
				function(data)
				{
				}
		);
}
function cmanager_clients_table_select_keyword(keyword_id)
{
  cmanager_message_shoot_emails_list_clean();
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_clients_table_select_keyword',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						orderby: orderby,
						offset: offset,
						limit: limit,
						constraint: constraint,
						keyword_id: keyword_id,
						value: $("#selection_keyword_" + keyword_id).attr("checked") ? 'checked' : ''
				},
				function(data)
				{
      $("#global_loading").hide();
				  $("#clients_table").html(data);
				}
		);
}
var search_by_field_client_id = 0;
function cmanager_get_details_by_field()
{
  cmanager_message_shoot_emails_list_clean();
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'private_galleries_cmanager_clients_table',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						orderby: orderby,
						offset: 0,
						limit: limit,
						constraint: 'search_by_field_' + search_by_field_client_id
				},
				function(data)
				{
		    $("#search_by_name").val('enter string to search');
      $("#global_loading").hide();
				  $("#clients_table").html(data);
						search_by_field_client_id = 0;
				}
		);
}
function cmanager_message_shoot_list_emails()
{
  cmanager_message_shoot_emails_list_clean();
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_message_shoot_emails',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						template_id: cmanager_template_id
				},
				function(data)
				{
      $("#global_loading").hide();
		    $("#cmanager_message_shoot_emails_list").html($.trim(data));
				}
		);
}
function cmanager_message_shoot_emails_list_clean()
{
		$("#cmanager_message_shoot_emails_list").html('');
}
function cmanager_message_shoot()
{
  $('.cmanager_shoot_buttons').toggle();
  $('#cmanager_shoot_feedback').html('').hide();
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_message_shoot',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						template_id: cmanager_template_id,
						parameters: cmanager_message_get_parameters()
				},
				function(data)
				{
      $('.cmanager_shoot_buttons').toggle();
      $("#global_loading").hide();
      $('#cmanager_shoot_feedback').html(data).show();
				}
		);
}
function cmanager_message_preview()
{
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_message_preview',
				  account_id: account_id,
						user_id: user_id,
						selection_id: selection_id,
						template_id: cmanager_template_id,
						parameters: cmanager_message_get_parameters()
				},
				function(data)
				{
      $("#global_loading").hide();
						$("#cmanager_preview").html(data);
				}
		);
}
function cmanager_client_end(client_id)
{
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_client_end',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id
				},
				function(data)
				{
      $("#global_loading").hide();
						$('#mass_mailing_' + client_id).html(data);
				}
		);
}
function cmanager_client_restart(client_id)
{
  $("#global_loading").show();
		$.post
		( "/private_galleries_ajax.php",
		  { task: 'cmanager_client_restart',
				  account_id: account_id,
						user_id: user_id,
						client_id: client_id
				},
				function(data)
				{
      $("#global_loading").hide();
						$('#mass_mailing_' + client_id).html(data);
				}
		);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function email()
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'email',
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
      $("#global_loading").hide();
						clear_input();
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons('email');
      adjust_footer();
						corners();
				}
		);
}
function em_create()
{
		$('#create_email_feedback').html('');
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'email_create',
				  account_id: account_id,
						user_id: user_id,
						username: $("#username_new").val(),
						password: $("#password_new").val()
				},
				function(data)
				{
      $("#global_loading").hide();
						corners();
						eval(data);
				}
		);
}
function em_update_password(id)
{
		$('#create_email_feedback').html('');
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'email_update_password',
				  account_id: account_id,
						user_id: user_id,
						address: $("#email_" + id).html(),
						password_new: $("#password_" + id).val()
				},
				function(data)
				{
      $("#global_loading").hide();
						corners();
						eval(data);
				}
		);
}
function em_delete(id)
{
  var str = "Please confirm you want to delete address " + $.trim($("#email_" + id).html());
		if(!confirm(str))
		{
		  return;
		}
		$('#create_email_feedback').html('');
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'email_delete',
				  account_id: account_id,
						user_id: user_id,
						address: $("#email_" + id).html()
				},
				function(data)
				{
      $("#global_loading").hide();
						corners();
						eval(data);
				}
		);
}
//2109
  //I could just copy those codes into my system
		//is there a way to ahve them belong to the module?:e#
		//create a module js file for those and add it dynamically to the real js 

function toff_products(section)
{
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: section,
				  account_id: account_id,
						user_id: user_id
				},
				function(data)
				{
      $("#global_loading").hide();
						clear_input();
				  $("#content_top").html('').hide();
				  $("#content_left").hide();
				  $("#content").html(data);
				  $("#content").show();
      manage_buttons(section);
      adjust_footer();
						corners();
				}
		);
}
function products_groups_def_insert(group_type_id)
{
		$("#group_feedback_create_" + group_type_id).html('').hide();
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_groups_def_insert',
				  account_id: account_id,
						user_id: user_id,
						group_display_name: $("#group_display_name_create_" + group_type_id).val(),
						group_type_id: group_type_id
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|');
				  if(arr[0] == 'no')
						{
						  $("#group_feedback_create_" + group_type_id).html(arr[1]).show();
						}
						else
						{ 
						  $("#group_display_name_create_" + group_type_id).val('');
						  $("#group_block_" + group_type_id).html(data);
						}
      $("#global_loading").hide();
				}
		);
}
function products_groups_def_update(group_id, group_type_id)
{
		$("#group_feedback_" + group_id).html('').hide();
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_groups_def_update',
				  account_id: account_id,
						user_id: user_id,
						group_display_name: $("#group_display_name_" + group_id).val(),
						group_is_online: $("#group_is_online_" + group_id).attr("checked") ? 'yes' : 'no',
						group_id: group_id
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|');
				  if(arr[0] == 'no')
						{
						  $("#group_feedback_" + group_id).html(arr[1]).show();
								if(arr.length >= 3)
								{
						    $("#group_display_name_" + group_id).val(arr[2]);
								}
						}
						else
						{
						  $("#group_block_" + group_type_id).html(data);
						}
      $("#global_loading").hide();
				}
		);
}
function products_groups_def_delete(group_id, group_type_id)
{
  if(!confirm("Do you really want to delete this group?"))
		{
		  return;
		}
		$('.group_delete_button_' + group_id).toggle();
		$("#groupy_feedback_" + group_id).html('').hide();
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_groups_def_delete',
				  account_id: account_id,
						user_id: user_id,
						group_id: group_id
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|');
				  if(arr[0] == 'no')
						{
						  $("#group_feedback_" + group_id).html(arr[1]).show();
						}
						else
						{
						  $("#group_block_" + group_type_id).html(data);
						}
      $("#global_loading").hide();
		    $('.group_delete_button_' + group_id).toggle();
				}
		);
}
function toff_products_get(group_type_id)
{
  $("#product_details").html('').hide();
  $(".products_search").each
		( function()
		  {
				  var gti = $(this).attr("id").substring(16);
						if(gti != group_type_id)
						{
						  $("#products_search_" + gti).val('');
						}
				}
		);
		$("#products").html('');
		if($("#products_search_" + group_type_id).val() == '')
		{
		  return;
		}
  $("#global_loading").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_get',
				  account_id: account_id,
						user_id: user_id,
						group_type_id: group_type_id,
						group_id: $("#products_search_" + group_type_id).val()
				},
				function(data)
				{
						data = $.trim(data);
				  $("#products").html(data).show();
      align_gallery_boxes();
						corners();
      $("#global_loading").hide();
				}
		);
}
function toff_product_details(product_id)
{
  $("#global_loading").show();
		$("#products").hide();
		$("#product_details").html('').hide();
		$("#product_details_splash").show();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_product_details',
				  account_id: account_id,
						user_id: user_id,
						product_id: product_id
				},
				function(data)
				{
		    $("#product_details_splash").hide();
				  $("#product_details").html(data).show();
      $("#global_loading").hide();
						corners();
				}
		);
}
function toff_products_get_details()
{
  $(".products_search").each
		( function()
		  {
				  var id = $(this).attr("id");
						if(id != 'products_search_product_id')
      {
						  $(this).val('');
						}
				}
		);
  var product_id = $("#products_search_product_id").val();
  toff_product_details(product_id);
}

var products_update_timeout = 0;
function toff_products_update(product_id)
{
		$('.products_saving').show();
  clearTimeout(products_update_timeout);
		products_update_timeout = setTimeout("toff_products_update_(" + product_id + ");", 2000);
}
function toff_products_update_(product_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_update',
				  account_id: account_id,
						user_id: user_id,
						product_id: product_id,
						product_is_online: $("input:radio[name='product_is_online']:checked").val()
				},
				function(data)
				{
		    $('.products_saving').hide();
				}
		);
}
function toff_products_update_name(product_id)
{
		$('.products_saving').show();
		$("#product_update_name_feedback").html('').hide();
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_update_name',
				  account_id: account_id,
						user_id: user_id,
						product_id: product_id,
						product_display_name: $("#product_display_name").val()
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|');
				  if(arr[0] == 'no')
						{
						  $("#product_update_name_feedback").html(arr[1]).show();
						}
						else
						{
        $("#products_search_bar").html(data);
						}
		    $('.products_saving').hide();
				}
		);
}
function toff_product_details_close()
{
  $(".products_search").val('');
  $("#product_details").html('').hide();
  $("#products").show();
}
function toff_products_insert()
{
  $("#global_loading").show();
  $(".products_search").val('');
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_insert',
				  account_id: account_id,
						user_id: user_id,
						product_display_name: $("#product_display_name_create").val()
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|||||');
				  if(arr[0] == 'no')
						{
						  $("#product_feedback_insert").html(arr[1]).show();
						}
						else
						{
						  $("#product_insert_form").hide();
        $("#product_display_name_create").val('');
				    $("#products").html('').hide();
								$("#product_details").html(arr[0]).show();
        $("#products_search_bar").html(arr[1]);
						}
				  corners();
      $("#global_loading").hide();
				}
		);
}
function toff_products_delete(product_id)
{
  if(!confirm("Do you really want to delete this product (no check on whether that product was sold or not in the past)?"))
		{
		  return;
		}
  $("#global_loading").show();
  $(".products_search").val('');
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_delete',
				  account_id: account_id,
						user_id: user_id,
						product_id: product_id
				},
				function(data)
				{
						data = $.trim(data);
						var arr = data.split('|');
				  if(arr[0] == 'no')
						{
						  $("#product_feedback_delete").html(arr[1]).show();
						}
						else
						{
						  $("#id_" + product_id).remove();
        align_gallery_boxes();
				    $("#products").show();
								$("#product_details").html('').hide();
        $("#products_search_bar").html(data);
						}
				  corners();
      $("#global_loading").hide();
				}
		);
}
var products_groups_update_timeout = 0;
function toff_products_groups_update(product_id, group_id)
{
		$('.products_groups_saving').show();
  clearTimeout(products_groups_update_timeout);
		products_groups_update_timeout = setTimeout("toff_products_groups_update_(" + product_id + "," + group_id + ");", 2000);
}
function toff_products_groups_update_(product_id, group_id)
{
  $.post
		( "/private_galleries_ajax.php",
		  { task: 'toff_products_groups_update',
				  account_id: account_id,
						user_id: user_id,
						product_id: product_id,
						group_id: group_id,
						product_group_value: $("#product_group_" + product_id + "_" + group_id).attr("checked") ? 'yes' : 'no'
				},
				function(data)
				{
		    $('.products_groups_saving').hide();
				}
		);
}

