$(document).ready(function(){
  $(".contact_edit a.show_form").click(function(){
    $(".contact_edit div").hide();
    $(".contact_edit p").show();
    
    $(this).parent().parent().children("a.submit").hide();
    $(this).parent().parent().children("div").show();
    $(this).parent().parent().children("p").hide();
    
    
    
    return false;
  });
  
  $(".contact_edit a.cancel").click(function(){
    $(".contact_edit div").hide();
    $(".contact_edit p").show();
    
    $(this).parent().parent().children("a.submit").hide();
    $(this).parent().parent().children("div").hide();
    $(this).parent().parent().children("p").show();
    
    //alert('storno');
    
    
    
    return false;
  });
  
  $(".contact_edit a.submit").click(function(){
    $(this).parent().submit();
    return false;
  });
});



function open_window($url,$name,$w,$h,$scroll)
{
  var $l = (screen.width - $w) / 2;
  var $t = (screen.height - $h) / 2;
	var $scr = $scroll ? 'yes' : 'no';

  window.open($url,$name,'copyhistory=no,scrollbars='+$scr+',width='+$w+',height='+$h+',left='+$l+',top='+$t);
}

function min(a,b) {return a < b ? a : b}
function max(a,b) {return a > b ? a : b}

function switch_image(offset)
{
	var img = imgs.split(',');
	current = offset > 0 ? min(img.length - 1,current + offset) : max(0,current + offset);
	
	document.getElementById('arraws_text').innerHTML = (current+1)+' / '+img.length;
	document.getElementById('thumb').src = 'img/db/'+img[current]+'.jpg';
}

timestamp = new Date();

function switch_thumb(id)
{
	src = id == '' ? 'img/nothing.png' : 'img/db/'+id+'.jpg?'+timestamp.getTime()+'';
	document.getElementById('thumb').src = src;
}

function show_big()
{
	var img = document.getElementById('thumb');
	var m = img.src.match('img/db/(.*)\.jpg');
	if (!m) return;
	
	var n = new Number(m[1]);
	open_window('image.php?id='+(n+1)+'&rnd='+timestamp.getTime(),'image',810,610,false);
}

function image_del(page,id)
{
	if (!confirm('Opravdu chcete smazat aktuální obrázek?')) return;
	
	var img = document.getElementById('thumb');
	var m = img.src.match('img/db/(.*)\.jpg');
	if (!m) return;
	
	var n = new Number(m[1]);
	location = '?action=image_del&page='+page+'&id='+id+'&id_image='+n;
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate)
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
		{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
			{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			return unescape(document.cookie.substring(c_start,c_end))
			} 
		}
	return null
}

function switch_lang()
{
	var lang = getCookie('lang');
	setCookie('lang',(lang == 'en') ? 'cz' : 'en',365);
	location = location;
}

function submit(id)
{
	document.getElementById(id).submit();
}

function projekt_del(id)
{
	if (confirm('Opravdu chcete smazat aktuální projekt?')) {
		location = '?action=projekt_del&id='+id;
	}
}

function soutez_del(id)
{
	if (confirm('Opravdu chcete smazat aktuální soutěž?')) {
		location = '?action=soutez_del&id='+id;
	}
}

function move(page,id,how)
{
	location = '?action=move&page='+page+'&id='+id+'&how='+how;
}

function move_image(page,id,how)
{
	var img = document.getElementById('thumb');
	var m = img.src.match('img/db/(.*)\.jpg');
	if (!m) return;
	
	var n = new Number(m[1]);
	window.location = '?action=image_move&page='+page+'&id='+id+'&id_image='+n+'&how='+how;
}
