

var comment_parent;


$(function()
{
	searchform_initialize();
	$('a.lightbox').lightBox();
});


function searchform_initialize()
{
	$(".search_region_id").change(function() { fillSelect(".search_place_id",places[this.value],0); } );
	fillSelect(".search_region_id",regions,region_id);
	fillSelect(".search_place_id",places[region_id],place_id);
	fillSelect(".search_type_id",types,type_id,types_sort);
	fillSelect(".search_price_id",prices,price_id);
}


function fillSelect(target,ar,s,sort)
{
	$(target).each(function()
	{
		var self = this;

		$(self).empty();

		if (typeof sort == "object")
		{
			for (var i in sort)
			{
				$(self).append("<option value='" + sort[i] + "'" + (sort[i]==s?" selected='selected'":"") + ">" + ar[sort[i]] + "</option>");
			}
		}
		else
		{
			for (var i in ar)
			{
				$(self).append("<option value='" + i + "'" + (i==s?" selected='selected'":"") + ">" + ar[i] + "</option>");
			}
		}
	});
}


function blueForm_switch()
{
	if ($(".blueForm").css("display") == "block") 
		$(".blueForm").animate({height:"hide"},500);
	else 
		$(".blueForm").animate({height:"show"},500,function() { $(this).css("display","block"); });
	return false;
}


function switch_children_checkboxes(parent)
{
	var i = $("#parent_checkbox_"+parent).attr("checked")?1:0;
	if (i > 0)
		$(".children_checkbox_"+parent).attr("checked","checked");
	else
		$(".children_checkbox_"+parent).removeAttr("checked");
}


function inquiry_send(options)
{
	$("#statusInquiry").load({url:"/inquiry.php",datasource:"#inquiry",callback:inquiry_setstatus});
	return false;
}

	
function editoffer_send(options)
{
	$("#statusInquiry").load({url:"/partners_edit.php",datasource:"#inquiry",callback:inquiry_setstatus});
	return false;
}


function inquiry_setstatus(options)
{
	$("#inquiry #divHide").animate({height:"hide"},500,function() { $(this).css("display","none"); });
	return false;
}


function antirobot_refresh()
{
	var img = new Image();
	img.src = "/antirobot.gif?rand="+Math.random(1000);

	img.onload = function() { $("#antirobot_place").empty().append(img); };
}


function switchCommentForm(new_comment_parent)
{
	if (comment_parent != null)
	{
		$("#commentForm_place_"+comment_parent).animate({height:"hide"},500,function() { $(this).empty(); });
	}

	if (new_comment_parent != comment_parent)
	{
		if (new_comment_parent != null)
			$("#commentForm_place_"+new_comment_parent).css("display","none").append($("#commentForm_tmpl").html()).animate({height:"show"},500);
		comment_parent = new_comment_parent;
		antirobot_refresh();
	}
	else
		comment_parent = null;

	$("#commentForm_parent").attr("value",comment_parent);
	return false;
}


function addComment()
{
	$("#statusComment").load({url:"/comment.php",datasource:"#commentForm",callback:addComment_done});
	return false;
}


function addComment_done()
{
	location.reload(true);
	return false;
}


function check_length(ar)
{
	var i = 0;
	for (ii in ar)
		i++;
	return i;
}


