function upload_images(images)
{
	var id = document.getElementById('id').value;
	images = latin2_convert(images);
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=upload_images&images="+images+"&id="+id,
		success: function(msg){
			msg = ajax_retrieve_messages(msg);
			document.getElementById('gallery_images').innerHTML = msg[0];
		}
	});
	
}

function delete_image(id)
{
	$("#ajax-icon-"+id).show();
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=delete_image&id="+id,
		success: function(msg){
			msg = ajax_retrieve_messages(msg);
			$("#ajax-icon-"+id).hide();
			$("#image-div-"+id).fadeOut('slow');
		}
	});
}

function update_image(id)
{
	//var title = document.getElementById('title-'+id).value;
	//var description = document.getElementById('description-'+id).value;
	var products = document.getElementById('products').value;
	products = products.split(",");
	var prices = "";
	for(var i = 0; i < products.length; i++)
		prices += products[i] + ":" + document.getElementById('price-'+id+'-'+products[i]).value + "|";
	//var price = document.getElementById('price-'+id).value;
	
	$("#ajax-icon-"+id).show();
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=update_image&id="+id+"&prices="+prices,
		success: function(msg){
			$("#ajax-icon-"+id).hide();
		}
	});
}

function change_position(order)
{
	var p = order.replace(/\[\]/g, '');
	p = p.split("&");
	var str = "";
	for(var i = 1; i <= p.length; i++)
	{
		var t = p[i-1].split("=");
		str += "&order-"+i+"="+t[1];
	}
	var id = document.getElementById('id').value;
	document.getElementById('gallery-fieldset').style.backgroundColor = "#ffb414";
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=change_position"+str,
		success: function(msg){
			$("#gallery-fieldset").animate({ backgroundColor: "#d5e1fa" }, 'slow');
		}
	});
}

function gallery_browser(gallery_id, direction)
{
	$("#gallery_slider_icon").show();
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=ajax_gallery_browser&module=galleries&gallery_id="+gallery_id+"&direction="+direction,
		success: function(msg){
			msg = ajax_retrieve_messages(msg);
			document.getElementById('gallery_dep_container').innerHTML = msg[0];
			gallery_slider();
		}
	});	
}

function gallery_slider()
{
	$('#slider_bar').slider({
		handle: '#slider_handle'
	});
	$('#slider_bar').slider('option', 'min', 0);
	$('#slider_bar').slider('option', 'max', 100);
	$('#slider_bar').slider('option', 'animate', true);
	$('#slider_bar').bind('slide', function(event, ui) {
		mypos = (($('#slider_handle').position().left + 0) * (-1)) / 196;  //grab position of slider dot + 2
		mypos = $('#gallery-dep-holder').width() * mypos + 0;
		$('#gallery-dep-holder').css('left', mypos);
	});
}

function change_values()
{
	var product = 1;
	var dir = 1;
	var val = 1;
	
	var products = document.getElementById('products').value;
	products = products.split(",");
	
	for(var i = 0; i < products.length; i++)
	{
		if(document.getElementById('product-'+products[i]).checked)
		{
			product = products[i];
			break;
		}
	}
	
	if(document.getElementById('sign-plus').checked)
		dir = 1;
	else
		dir = -1;
		
	val = parseFloat(document.getElementById('product-price').value);
	
	var images = document.getElementById('images').value;
	images = images.split(",");
	
	for(var i = 0; i < images.length; i++)
	{
		var p = document.getElementById('price-'+images[i]+'-'+product);
		var d = parseFloat(p.value) + dir * val;
		p.value = d.toFixed(2);
	}
	
	var id = document.getElementById('id').value;
	$.ajax({
		type: "POST",
		url: "index.php",
		data: "action_type=ajax&action=change_values&dir="+dir+"&id="+id+"&val="+val+"&product="+product,
		success: function(msg){
			$("#gallery-fieldset").animate({ backgroundColor: "#d5e1fa" }, 'slow');
		}
	});
}

function check_price(input, id)
{
	var min_value = parseFloat(document.getElementById('product-min-val-'+id).value);
	var curr_value = parseFloat(input.value);
	
	if(curr_value < min_value)
		input.value = min_value;
}

