function OpenWindow (url, windowname, width, height)
{
	var w = window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=' + width + ',height=' + height + '');
	MoveWindowToCenter (w, width, height);
}

function MoveWindowToCenter (w, width, height)
{
	var Ycor = (screen.height-height) / 2;
	var Xcor = (screen.width-width) / 2;
	w.moveTo (Xcor, Ycor);
}

/* FILTERS */

function ToggleVisiblity (filter_id1, filter_id2, noHide)
{
	if (noHide) ResetFilterSelf ();
	if (!noHide)
	{
		if (filter_id2 == 0)
		{
			if ($("#filter" + filter_id1 + "_contents").css("display") == 'none')
			{
				$("#filter" + filter_id1 + "_contents").css("display", "block");
				$("#filter" + filter_id1 + "_img").attr("src", "images/arrow_right.gif");
			}
			else
			{
				$("#filter" + filter_id1 + "_contents").css("display", "none");
				$("#filter" + filter_id1 + "_img").attr("src", "images/arrow_down.gif");
			}
		}
		else
		{
			if ($("#filter" + filter_id1 + "_" + filter_id2 + "_contents").css("display") == 'none')
			{
				$("#filter" + filter_id1 + "_" + filter_id2 + "_contents").css("display", "block");
				$("#filter" + filter_id1 + "_" + filter_id2 + "_img").attr("src", "images/arrow_right.gif");
			}
			else
			{
				$("#filter" + filter_id1 + "_" + filter_id2 + "_contents").css("display", "none");
				$("#filter" + filter_id1 + "_" + filter_id2 + "_img").attr("src", "images/arrow_down.gif");
			}
		}
	}
}

function ToggleVisibilityMore (filter_id)
{
	if ($("#hidden_filter" + filter_id).css("display") == 'none')
	{
		$("#hidden_filter" + filter_id).css("display", "block");
		$("#filter_more_" + filter_id + "_img").attr("src", "images/arrow_right.gif");
	}
	else
	{
		$("#hidden_filter" + filter_id).css("display", "none");
		$("#filter_more_" + filter_id + "_img").attr("src", "images/arrow_down.gif");
	}
}

function ToggleVisibilityGeneral (element_id)
{
	if ($("#" + element_id).css("display") == 'none')
	{
		$("#" + element_id).css("display", "block");
	}
	else
	{
		$("#" + element_id).css("display", "none");
	}
}

function ImagePreviewDetails (url, windowname)
{
	var width = 900;
	var height = 800;
	var w = window.open ('' + url + '','' + windowname + '','fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=' + width + ',height=' + height);
	MoveWindowToCenter (w, width, height);
}

function TogglePutLT (table_id, content_id, content_source, caller)
{
	var url;
	var new_src;
	var new_value;
	var src = $("#lt_image_" + content_id).attr("src");
	var hidden = parseInt ($("#lt_hidden_" + content_id).attr("value"));
	var lt_block_content = document.getElementById("lt_block_content");
	if (lt_block_content != null) scrollLeft = lt_block_content.scrollLeft;

	if (hidden == 1)
	{
		url = "table_cart_ajax.php?action=lt_remove&caller=" + caller + "&table_id=" + table_id + "&content_id=" + content_id + "&content_source=" + content_source;
		new_src = "images/lt.jpg";
		new_value = 0;
	}
	else
	{
		url = "table_cart_ajax.php?action=lt_add&caller=" + caller + "&table_id=" + table_id + "&content_id=" + content_id + "&content_source=" + content_source;
		new_src = "images/lt_active.jpg";
		new_value = 1;
	}

	$("#lt_image_" + content_id).attr("src", new_src);
	$("#lt_hidden_" + content_id).attr("value", new_value);

	$("#table_cart_block").load (url, function()
	{
		if (lt_block_content != null)
		{
			document.getElementById("lt_block_content").scrollLeft = scrollLeft;
		}
	});
}

function TogglePutCart (content_id, content_source)
{
	var cart_image = document.getElementById ("cart_image_" + content_id);
	var cart_hidden = document.getElementById ("cart_hidden_" + content_id);
	var lt_cart_image = document.getElementById ("lt_cart_image_" + content_id);
	var lt_cart_hidden = document.getElementById ("lt_cart_hidden_" + content_id);
	var url_put = "table_cart_ajax.php?action=cart_add&content_id=" + content_id + "&content_source=" + content_source;
	var url_remove = "table_cart_ajax.php?action=cart_remove&content_id=" + content_id + "&content_source=" + content_source;
	var new_url;
	var new_src;
	var new_value;

	if (cart_image != null)
	{
		var hidden_value = parseInt (cart_hidden.value);

		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.jpg";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.jpg";
			new_value = 1;
		}
		cart_image.src = new_src;
		cart_hidden.value = new_value;
	}
	if (lt_cart_image != null)
	{
		var hidden_value = parseInt (lt_cart_hidden.value);
		if (hidden_value == 1)
		{
			new_url = url_remove;
			new_src = "images/cart.jpg";
			new_value = 0;
		}
		else
		{
			new_url = url_put;
			new_src = "images/cart_active.jpg";
			new_value = 1;
		}
		lt_cart_image.src = new_src;
		lt_cart_hidden.value = new_value;
	}
	$("#cartblock").load (new_url);
}

function ChangeActiveLT (element, caller)
{
	var table_id = element.options[element.selectedIndex].value;
	var new_url = '';

	if (caller == 'search')
		new_url = search_url + "&page=" + page;
	else if (caller == 'table')
		new_url = "table_grid_ajax.php";

	$("#table_cart_block").load ("table_cart_ajax.php?action=current_table&caller=" + caller + "&active_table_id=" + table_id, function()
	{
		$("#gridContent").hide();
		$("#process").show();

		$("#gridContent").load (new_url, function()
		{
			$("#process").hide();
			$("#gridContent").show();
		});
	});
}

function TogglePutLTFromPreview (table_id, content_id, content_source, caller)
{
		var lt_image = opener.document.getElementById ("lt_image_preview_" + content_id);
		var lt_hidden = opener.document.getElementById ("preview_lt_hidden_" + content_id);
		
		if (caller == 'preview')
		{
			var lt_image_parent = opener.opener.document.getElementById ("lt_image_" + content_id);
			var lt_hidden_parent = opener.opener.document.getElementById ("lt_hidden_" + content_id);
		}
		
		var lt_image_preview = document.getElementById ("lt_image_preview_" + content_id);
		var preview_lt_hidden = document.getElementById ("preview_lt_hidden_" + content_id);
		var url_put = "table_cart_ajax.php?action=lt_add&caller=" + caller+ "&table_id=" + table_id + "&content_id=" + content_id + "&content_source=" + content_source;
		var url_remove = "table_cart_ajax.php?action=lt_remove&caller=" + caller + "&table_id=" + table_id + "&content_id=" + content_id + "&content_source=" + content_source;

		if (lt_image != null)
		{
			var hidden_value = parseInt (lt_hidden.value);
			if (hidden_value == 1)
			{
				new_src = "images/lt.jpg";
				new_value = 0;
			}
			else
			{
				new_src = "images/lt_active.jpg";
				new_value = 1;
			}
			lt_image.src = new_src;
			lt_hidden.value = new_value;

			if (caller == 'preview')
			{
				if (lt_image_parent != null && lt_hidden_parent != null)
				{
					lt_image_parent.src = new_src;
					lt_hidden_parent.value = new_value;
				}
			}
		}
		if (parseInt(preview_lt_hidden.value) == 1)
		{
			lt_image_preview.src = "images/lt.jpg";
			preview_lt_hidden.value = 0;
			new_url = url_remove;
		}
		else
		{
			lt_image_preview.src = "images/lt_active.jpg";
			preview_lt_hidden.value = 1;
			new_url = url_put;
		}
		if (caller == 'preview')
			$("#table_cart_block", opener.opener.document).load (new_url);
		else
			$("#table_cart_block", opener.document).load (new_url);
}

function TogglePutCartFromPreview (content_id, content_source, caller)
{
		var cart_image = opener.document.getElementById ("cart_image_preview_" + content_id);
		var cart_hidden = opener.document.getElementById ("preview_cart_hidden_" + content_id);
		var lt_cart_image = opener.document.getElementById ("lt_cart_image_" + content_id);
		var lt_cart_hidden = opener.document.getElementById ("lt_cart_hidden_" + content_id);
		
		if (caller == 'preview')
		{
			var cart_image_parent = opener.opener.document.getElementById ("cart_image_" + content_id);
			var cart_hidden_parent = opener.opener.document.getElementById ("cart_hidden_" + content_id);
		}
		
		var preview_cart_hidden = document.getElementById ("preview_cart_hidden_" + content_id);
		var url_put = "table_cart_ajax.php?action=cart_add&content_id=" + content_id + "&content_source=" + content_source;
		var url_remove = "table_cart_ajax.php?action=cart_remove&content_id=" + content_id + "&content_source=" + content_source;
		var new_url;
		var new_src;
		var new_value;
	
		if (cart_image != null)
		{
			var hidden_value = parseInt (cart_hidden.value);
	
			if (hidden_value == 1)
			{
				new_url = url_remove;
				new_src = "images/cart.jpg";
				new_value = 0;
			}
			else
			{
				new_url = url_put;
				new_src = "images/cart_active.jpg";
				new_value = 1;
			}
			cart_image.src = new_src;
			cart_hidden.value = new_value;
			
			if (caller == 'preview')
			{
				if (cart_image_parent != null && cart_hidden_parent != null)
				{
					cart_image_parent.src = new_src;
					cart_hidden_parent.value = new_value;
				}
			}
		}
		if (lt_cart_image != null)
		{
			var hidden_value = parseInt (lt_cart_hidden.value);
			if (hidden_value == 1)
			{
				new_url = url_remove;
				new_src = "images/cart.jpg";
				new_value = 0;
			}
			else
			{
				new_url = url_put;
				new_src = "images/cart_active.jpg";
				new_value = 1;
			}
			lt_cart_image.src = new_src;
			lt_cart_hidden.value = new_value;
		}
		if (parseInt (preview_cart_hidden.value) == 1)
		{
			$("#cart_image_preview_" + content_id).attr("src", "images/cart.jpg");
			preview_cart_hidden.value = 0;
			new_url = url_remove;
		}
		else
		{
			$("#cart_image_preview_" + content_id).attr("src", "images/cart_active.jpg");
			preview_cart_hidden.value = 1;
			new_url = url_put;
		}
		
		if (caller == 'preview')
			$("#cartblock", opener.opener.document).load (new_url);
		else
			$("#cartblock", opener.document).load (new_url);
}


function RemoveFromLT (table_id, content_id, content_source)
{
	scrollLeft = document.getElementById("lt_block_content").scrollLeft;
	$("#lt_image_" + content_id).attr("src", "images/lt.jpg");
	$("#lt_hidden_" + content_id).attr("value", 0);

	$("#table_cart_block").load("table_cart_ajax.php?action=lt_remove&table_id=" + table_id + "&content_id=" + content_id + "&content_source=" + content_source, function ()
	{
		document.getElementById("lt_block_content").scrollLeft = scrollLeft;
	});
}

function DeleteLT (table_id, caller)
{
	var new_url = '';
	if (caller == 'search')
		new_url = search_url + "&page=" + page;
	else if (caller == 'table')
		new_url = "table_grid_ajax.php";

	$("#table_cart_block").load ("table_cart_ajax.php?action=delete&table_id=" + table_id, function()
	{
		$("#gridContent").hide();
		$("#process").show();

		$("#gridContent").load (new_url, function()
		{
			$("#process").hide();
			$("#gridContent").show();
		});
	});
}

function EmptyLT (table_id, caller)
{
	var new_url = '';
	if (caller == 'search')
		new_url = search_url + "&page=" + page;
	else if (caller == 'table')
		new_url = "table_grid_ajax.php";

	$("#table_cart_block").load ("table_cart_ajax.php?action=empty&table_id=" + table_id, function()
	{
		$("#gridContent").hide();
		$("#process").show();

		$("#gridContent").load (new_url, function()
		{
			$("#process").hide();
			$("#gridContent").show();
		});
	});
}

var menuOn = 0;
function MenuElMouseOver (element)
{
	element.className = 'menu_mouse_over';
}

function MenuElMouseOut (element)
{
	element.className = 'menu_mouse_out';
}

function MenuDivOver()
{
	menuOn = 1;
}

function MenuDivOut()
{
	menuOn = 0;
	setTimeout ("MenuHeaderMouseOutTime()", 300);
}

function MenuHeaderMouseOver()
{
	$("#lt_menu_block").show();
}

function MenuHeaderMouseOut()
{
	setTimeout ("MenuHeaderMouseOutTime()", 300);
}

function MenuHeaderMouseOutTime()
{
	if (!menuOn)
	{
		$("#lt_menu_block").hide();
	}
}

function ResetSearchForm()
{
	form = $('#search_form');
	$(':input', form).each(function()
	{
		var type = this.type;
		var tag = this.tagName.toLowerCase ();
		
		if (type == 'text' || type == 'hidden' || type == 'textarea') this.value = "";
		else if ((type == 'checkbox' || type == 'radio') && this.name != 'presize' && this.name != 'honorar_frei' && this.name != 'search_in_results')
		{
			this.checked = true;
		}
		else if (this.name == 'presize' || this.name == 'honorar_frei' || this.name == 'search_in_results') this.checked = false;	
		else if (tag == 'select') this.selectedIndex = -1;
	});
	$(".linkCategoryActive").toggleClass ('linkCategoryActive');
	//$('#search_form').submit();
}

function ResetFilterSelf ()
{
	$('#online_category_id').val('');
	$(".linkCategoryActive").toggleClass ('linkCategoryActive');
	$('#search_form').submit();
}

function SearchFilterOnclick(form, element)
{
	var h_element = document.getElementById (element.id + '_h');
	if (h_element != null && !element.checked)
	{
		h_element.value = 1;
	}
}

function SubmitSearchForm ()
{
	var search_form = document.forms['search_form'];
	if (search_form.elements['search_in_results'].checked == false)
	{
		search_form.offer_id.value = search_form.search_prev.value = '';
	}
	search_form.submit ();
}

function OpenGateImageOnLoad (image_object, max_size)
{
	var width = image_object.width;
	var height = image_object.height;
	var max = 0;

	if (width >= max_size || height >= max_size)
	{
		if (width > height || width == height) max = width;
		else max = height;

		if (max == width)
		{
			newwidth = max_size;
			newheight = Math.round (newwidth * height / width);
		}	
		else if (max == height)
		{
			newheight = max_size;
			newwidth = Math.round (newheight * width / height);
		}
		else
		{
			newwidth = max_size;
			newheight = max_size;
		}

		image_object.width = newwidth;
		image_object.height = newheight;
	}
}

function FilterOnclick (url, online_category_id, online_category_id_list)
{
	if (online_category_id_list == '') online_category_id_list = ',';
	online_category_id_list += online_category_id + ',';
	document.forms['search_form'].online_category_id.value = online_category_id_list;
	document.forms['search_form'].submit();
	//location.href = url + '&online_category_id=' + online_category_id_list;
}

function FilterDeselectOnclick (url, online_category_id, online_category_id_list)
{
	//online_category_id_list += online_category_id + ',';
    arr = online_category_id_list.split (','); 

    for (i = arr.length - 1; i >= 0; i--)
    {
        if (arr[i] == online_category_id) arr.splice (i, 1);
    }
    str = arr.join (',');
	if (str == ',') str = '';	
	document.forms['search_form'].online_category_id.value = str;
	document.forms['search_form'].submit();
}

function ToggleUSTD (checked)
{
	var field = document.getElementById ('ustidnr');
	
	if (checked)
	{
		field.disabled = false;
		field.className = 'formfield';
	}
	else
	{
		field.disabled = true;
		field.className = 'formfield_disabled';
		field.value = '';
	}
}

function SearchOffer (offer_id)
{
	var search_form = document.forms['search_form'];
	//ResetSearchForm();	
	search_form.search.value = '';
	search_form.offer_id.value = offer_id;
	search_form.submit ();
}

