// ==========================================
// FUNKCJE UŻYWANE WE WSZYSTKICH FORMULARZACH
// ==========================================

// -------------------------------------
// ŁADOWANIE TREŚCI Z BAZY DO PÓL SELECT
// -------------------------------------

var ajax_loadOptions=function(input_id,add_get,successFn)
{ 	
	$("#loader_"+input_id).fadeIn(200);

	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action=pobierz_"+input_id+add_get+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			var exp_data=data.split("|");

			// WYJĄTKI

			if (exp_data.length!=1)
			{
				// WYJĄTEK DLA POLA > PAPIER FOTO < W FORMULARZU DO FOTOALBUMÓW

				if (input_id=="papier_foto") 
				{
					var for_single="";
					var for_multi="";

					for (var i=0; i<exp_data.length; i++)
					{
						for_single+=exp_data[i];
						if (i<(exp_data.length-1)) for_multi+=exp_data[i];
					}

					$("#"+input_id).html(for_single);

					for (var i=1; i<=50; i++)
					{
						$("#"+input_id+"_"+i).html(for_multi);
					}
				}

				// WYJĄTEK DLA POLA > ILOŚĆ ETUI W ZESTAWIE < W FORMULARZU DO ETUI

				if (input_id=="parent_amount")
				{
					$("#"+input_id).html(exp_data[0]);

					if (exp_data[1]==1)
					{
						$("#pl_formats_list").slideDown(300);
					}
					else
					{
						$("#pl_formats_list").slideUp(300);
					}
				}
			}
			else
			{
				$("#"+input_id).html(data);
			}

			if ($("#loader_"+input_id).length) $("#loader_"+input_id).fadeOut(200);

			successFn();
		}
	});
}





var ajax_loadOptionsToValue=function(input_id,add_get,successFn)
{
	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action=pobierz_"+input_id+add_get+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			$("#"+input_id).attr("value",data);					

			successFn();
		}
	});
}





var ajax_checkDisplay=function(input_id,input_display)
{
	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action="+input_id+"&input_display="+input_display+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			if (data=="show")
			{
				$("#"+input_display).slideDown(300);
			}
			else
			{
				$("#"+input_display).slideUp(300);
			}
		}
	});
}





var ajax_checkDisplay2=function(input_id,input_display)
{
	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action="+input_id+"&input_display="+input_display+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			if (data=="show")
			{
				$("#"+input_display).show();
			}
			else
			{
				$("#"+input_display).hide();
			}
		}
	});
}





var ajax_loadContent=function(input_id)
{
	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action="+input_id+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			$("#"+input_id).html(data);
			$(".no_visible").animate({"opacity":0.1},500);

			$("#s-m-t-tooltip").remove();			

			$("#"+input_id+" .tooltip").style_my_tooltips(
			{
				tip_follows_cursor:"on",
				tip_delay_time:200
			});
		}
	});
}





var ajax_showPreview=function(input_id)
{
	var get_id=$("#get_id").attr("value");

	$.ajax(
	{
		type:"POST",
		url:"include/sitemap/"+get_id+"/ajax.actions.php?action="+input_id+"&get_id="+get_id,
		data:$("#ajax_form").serialize(),
		success:function(data)
		{
			$("#"+input_id).html(data);

			// ---------------------------------------------------------------
			// WZNOWIENIE GALERII - LIGHTBOX - DLA OBIEKTÓW WSTAWIONYCH AJAXEM
			// ---------------------------------------------------------------

			$('#podglad_wzor a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt1 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt2 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt3 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt4 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt5 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
			$('.gt6 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});

			// --------------------------------------------------
			// WZNOWIENIE TOOLTIP DLA OBIEKTÓW WSTAWIONYCH AJAXEM
			// --------------------------------------------------

			$("#s-m-t-tooltip").remove();

			$("#"+input_id+" .tooltip").style_my_tooltips(
			{
				tip_follows_cursor:"on",
				tip_delay_time:200
			});
			
			
		}
	});
}





var ajax_showInfo=function(input_id)
{
	var get_id=$("#get_id").attr("value");

	if ($("#"+input_id).length)
	{
		$.ajax(
		{
			type:"POST",
			url:"include/sitemap/"+get_id+"/ajax.actions.php?action="+input_id,
			data:$("#ajax_form").serialize(),
			success:function(data)
			{
				if (input_id=="available_info")
				{
					if (data==0)
					{
						$("#"+input_id).attr("title","").fadeOut(500);
						$("#color_no_available").attr("value","0");
					}
					else
					{
						$("#"+input_id).attr("title",data).fadeIn(500);
						$("#color_no_available").attr("value","1");
					}
				}
				else
				{
					if (data=="show" || data=="hide")
					{
						if (data=="show") $("#"+input_id).fadeIn(500); else $("#"+input_id).hide();
					}
					else
					{
						$("#"+input_id).hide().attr("title",data).fadeIn(500);
					}
				}
			}
		});
	}
}

















$(document).ready(function()
{	
	// WCZYTANIE DODATKOWYCH TEKSTÓW AJAXA Z POLA AJAX_TXT
	
	var exp=$("#ajax_txt").attr("value");
	var ajax_txt=exp.split("|");







	$(".validate_inputs").live("change",function()
	{
		$(this).removeClass("validate_inputs");
	});





	$(".bt_up,.bt_down").css("opacity",0.5).hover(function(){$(this).css("opacity",1);},function(){$(this).css("opacity",0.5);});
	$(".disabled_on_start").attr("disabled","disabled").css("color","#ddd");





	$(".only_numeric").change(function(){if (($(this).attr("value")==0)||($(this).attr("value")=="")||(!isNumeric($(this).attr("value")))) $(this).attr("value","1");});
	$(".only_numeric2").change(function(){if (!isNumeric($(this).attr("value"))) $(this).attr("value","");});





	$(".bt_up,.bt_down").click(function()
	{
		if ($("#minimum").length)
		{
			var minimum=$("#minimum").attr("value");
		}
		else
		{
			var minimum=1;
		}

		var c_id=$(this).attr("id");
		var c_alt=$(this).attr("alt");
		var ilosc=$(this).parent(".line").children("input").attr("value");

		if ($(this).attr("title")=="+")
		{
			$(this).parent(".line").children("input").attr("value",eval(ilosc)+1);

			if (c_alt!="n") countPrice();
		}
		else
		{
			if (ilosc>minimum)
			{
				$(this).parent(".line").children("input").attr("value",eval(ilosc)-1);
				if (c_alt!="n") countPrice();
			}
		}
	});





	$("#ilosc").keyup(function()
	{
		countPrice();
	});





	// ----------------------------------------------------
	// AKTYWACJA GALERII W PODGLĄDACH PARAMETRÓW FORMULARZY
	// ----------------------------------------------------

	$('#podglad_wzor a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt1 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt2 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt3 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt4 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt5 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt6 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
});





























// OGÓLNE FUNKCJE UŻYWANE NA CAŁEJ STRONIE ==============================================================================================================================================================================================





function convertPL(input_id)
{
	var polskie=new Array('±','¶','Ľ','ć','ń','ó','ł','ę','ż','ˇ','¦','¬','Ć','Ń','Ó','Ł','Ę','Ż','&');
	var zakodowane=new Array('a_','s_','x_','c_','n_','o_','l_','e_','z_','A_','S_','X_','C_','N_','O_','L_','E_','Z_','_and_');

	if ($("#"+input_id).length)
	{
		var str=$("#"+input_id).attr("value");
	
		for(var i=0; i<polskie.length; i++)
		{
			str=str.replace(new RegExp(polskie[i],'gm'),zakodowane[i]);
		}

		$("#"+input_id).css("color","#fff").attr("value",str);
	}
}





function convertISO(input_id)
{
	var polskie=new Array('±','¶','Ľ','ć','ń','ó','ł','ę','ż','ˇ','¦','¬','Ć','Ń','Ó','Ł','Ę','Ż','&');
	var zakodowane=new Array('a_','s_','x_','c_','n_','o_','l_','e_','z_','A_','S_','X_','C_','N_','O_','L_','E_','Z_','_and_');

	if ($("#"+input_id).length)
	{
		var str=$("#"+input_id).attr("value");

		for(var i=0; i<polskie.length; i++)
		{
			str=str.replace(new RegExp(zakodowane[i],'gm'),polskie[i]);
		}

		$("#"+input_id).css("color","#000").attr("value",str);
	}
}









function isNumeric(src) 
{
	var regex=/^[\-]{0,1}[0-9]{1,8}$/;
	return regex.test(src);
}

