$(function(){
	$("a.confirm").click(function(){
		return confirm('Oletko varma?');
	});

	if($(".sort").sortable)
	{
		$(".sort").sortable({
			axis : 'y',
			items : 'tr'
		});
	}

	if($(".sortul").sortable)
	{
		$(".sortul").sortable({
			placeholder : 'sortul-hilight'
		});
		$(".sortul").disableSelection();
	}

	$(".hilight:not(.valittu)").hover(
		function(){
			$(this).css("background-position", "0 -" + "64px");
		},
		function(){
			$(this).css("background-position", "0 0");
		}
		);
});

function productOrder(order, cid)
{
	$("#dialog").dialog({
		bgiframe: true,
		modal: true
	});
	xajax_productOrder(order, cid);
	return false;
}

function checkRequired()
{
	var valid;
	valid = false;

	$(".required").each(function(){
		if(this.value == undefined || this.value == ''){
			valid = false;
			alert("Arvo puuttuu: " + $(this).attr('rel'));
			return false;
		}
		
		valid = true;
		return true;
	});

	return valid;
}

function popitup(url,width,height)
{
	newwindow=window.open(url,'editwindow','height=' + height + ',width=' + width +',scrollbars=1,resizable=1');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function showEditor(name)
{
	$('.editor_div').hide();
	$('.text_content').show();
	$('#editor_' + name).show();
	if (!tinyMCE.get(name))
		tinyMCE.execCommand('mceAddControl', false, name);
}

function hideEditor(name)
{
	$('.editor_div').hide();
	if (tinyMCE.get(name))
		tinyMCE.execCommand('mceRemoveControl', false, name);
}

function lltiny(id)
{
	if (!tinyMCE.get(id))
		tinyMCE.execCommand('mceAddControl', false, id);
	else
		tinyMCE.execCommand('mceRemoveControl', false, id);
}
