var req = new http_request();

function refresh_page() {
	location = location;
}

function detail($id)
{
	open_window('popup_detail.php?id='+$id,'detail_'+$id,600,480,false);
}

function order($by)
{
	location = '?action=order&by='+$by;
}

function check_refresh()
{
	if ($kat_refresh) window.opener.refresh_page();
}

function toggle_list(on)
{
	setCookie('list',on ? 'true' : 'false',365);
	refresh_page();
}

/* -------------------------------------------------------------------------- */

function login_toggle()
{
	var div = document.getElementById('login_box');
	div.style.display = (div.style.display == 'block') ? 'none' : 'block';
}

function login_result($data)
{
	if ($data[0]) {
		refresh_page();
	} else {
		alert('Zadali jste nesprávné heslo!')
	}
	
	$challenge = $data[1];
}

function login()
{
	var $password = document.getElementById('password').value;
	
	var data = new post_data();
	data.add('challenge',$challenge);
	data.add('hmac',hex_hmac_md5(hex_md5($password),$challenge));

	req.go('?action=login',data,login_result);
}

function logout()
{
	location = '?action=logout';
}

/* -------------------------------------------------------------------------- */

function katalog_new(kat)
{
	open_window('popup_editor.php?k='+kat,'editor',620,505,false);
}

function katalog_edit($id)
{
	open_window('popup_editor.php?id='+$id,'editor',620,505,false);
}

function katalog_del($id)
{
	if (confirm('Opravdu chcete smazat tuhle položku?')) {
		location = '?action=kat_del&id='+$id;
	}
}

function katalog_prefer($id,$refresh)
{
	var $url = '?action=kat_prefer&id='+$id;
	if ($refresh) location = $url; else req.go($url,null,null);
}

