function validMail(string){var mail=/^.+@.+\..{2,4}$/; return mail.test(string);}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function sendComment(uuid){	$('#odeslat-btn').attr("disabled","disabled");var name = $('#jmeno').val();var surname = $('#prijmeni').val();var comment = $('#komentar').val();	if (jQuery.trim(comment) == ''){$('#comment-empty').show();$('#odeslat-btn').attr("disabled","");return false;}	$.post('/smallapp/140let/send-comment/', {name:name, surname:surname, comment:comment, uuid:uuid}, sendCommentCallback, 'json');}
function sendCommentCallback(data){switch (data.status){case 'ALL_OK':$('#komentar').val('');	
var ret = '<div class="koment"><div class="koment-top"></div><div class="koment-text">'+data.comment+'</div><div class="koment-bottom">'+data.name+' | '+data.date+'</div></div>';
var html = $('#komentare').html() + ret;$('#komentare').html(html);
$('#odeslat-btn').attr("disabled","");break;case 'ERROR_EMPTY':$('#comment-empty').show();	$('#odeslat-btn').attr("disabled","");break;case 'ERROR_DB':	$('#comment-dberror').show();$('#odeslat-btn').attr("disabled","");break;}}
function setDefault(pid, uuid){$.post('/smallapp/140let/set-default/', {pid:pid, uuid:uuid}, setDefaultCallback, 'json');}
function setDefaultCallback(data){if (data.status == 'ALL_OK'){$('#user_photo_'+data.old).removeClass("default");$('#user_photo_'+data.current).addClass("default");}}
function emailProfile(uuid){
$('#mail-btn').attr("disabled","disabled");
var from = $('#from').val();var fromemail = $('#fromemail').val();var to = $('#to').val();var body = $('#body').val();var errors = new Array();
var recipients = to.split(",");
if(recipients.length>1){for(var key in recipients){if(!validMail(recipients[key])){errors.push("Jedna nebo více adres příjemce má nesprávný formát");break;}}
}else{if(!validMail((trim(to)))){errors.push("Zadaný e-mail příjemce má nesprávný formát");}}
if(trim(from) == ""){errors.push("Musíte uvést své jméno");}
if(trim(fromemail) == ""){errors.push("Musíte uvést svůj e-mail");}
else if(!validMail((trim(fromemail)))){errors.push("Zadaný e-mail má nesprávný formát");}
if(trim(body) == ""){errors.push("Musíte napsat text vzkazu");}
if(errors.length == 0){$.post('/smallapp/140let/send-photo/', {from:from, fromemail:fromemail, to:to, body:body, uuid:uuid}, sendProfileCallback, 'json');} 	else {$('#messages').html(errors.join("<br />"));$('#mail-btn').attr("disabled","");}}
function sendProfileCallback(data){switch(data.status){	
case 'EMPTY_FROM':$('#messages').html('Musíte uvést své jméno');break;
case 'EMPTY_FROMEMAIL':	$('#messages').html('Musíte uvést svůj e-mail');break;
case 'EMPTY_TO':$('#messages').html('Jedna nebo více adres příjemce má nesprávný formát');break;
case 'EMPTY_BODY':$('#messages').html('Musíte napsat text vzkazu');	break;
case 'NO_PROFILE':$('#messages').html('Fotka neexistuje');	break;
case 'ERROR_SEND':$('#messages').html('Chyba při odesílání');break;
case 'ALL_OK':$('#messages').html('');$('#mail-btn').attr("disabled","");$.modal.close();break;}}
//function showNext(uuid){$.get('/smallapp/140let/get-next/', {uuid:uuid}, showNextCallback)}
//function showNextCallback(data){$('#karta').html(data)}
function editComment(id){var comment = $("#koment_"+id).html();$("#koment_"+id).html('<textarea id="ta_'+id+'" cols="" rows="" style="width:100%">'+comment+'</textarea><br /><button onclick="saveComment('+id+'); return false;">Save</button> <button onclick="cancelComment('+id+'); return false;">Cancel</button>');}
function cancelComment(id){$("#koment_"+id).html($("#ta_"+id).val());}
function saveComment(id){var c = $("#ta_"+id).val();$.post('/smallapp/140let/save-comment/', {id:id, c:c}, saveCommentCallback, 'json')}
function saveCommentCallback(data){if (data.status == 'ALL_OK'){$("#koment_"+data.id).html(data.c);} else {alert('Error while saving comment');}}
function deleteComment(id){$.post('/smallapp/140let/delete-comment/', {id:id}, deleteCommentCallback, 'json');}
function deleteCommentCallback(data){if (data.status == 'ALL_OK'){$("#koment_"+data.id).remove();$("#koment_t"+data.id).remove();$("#koment_b"+data.id).remove();} else {alert('Error while deleting comment');}}
function deletePhoto(id){$.post('/smallapp/140let/delete-photo/', {id:id}, deletePhotoCallback, 'json');}
function deletePhotoCallback(data){if (data.status == "ALL_OK"){$("#user_photo_"+data.id).remove();} else {alert('Při odstranění fotky došlo ke chybě');}}
//function adminDeletePhoto(id, puid){$.post('/smallapp/140let/admin-delete-photo/', {id:id, uuid:puid}, adminDeletePhotoCallback, 'json');}
//function adminDeletePhotoCallback(data){if (data.status == "ALL_OK"){/*$("#user_photo_"+data.id).remove();*/ alert('Foto bylo odstraněno.');} else {alert('Při odstranění fotky došlo ke chybě');}}
//function adminDeleteProfile(uuid){$.post('/smallapp/140let/admin-delete-profile/', {uuid:uuid}, adminDeleteProfileCallback, 'json');}
//function adminDeleteProfileCallback(data){if (data.status == "ALL_OK"){/*$("#user_photo_"+data.id).remove();*/ alert('Profil byl smazan.');} else {alert('Při odstranění profilu došlo ke chybě');}}
function adminDeletePhoto(puid){var email = $('#ato').val(); var body = $('#abody').val();$.post('/smallapp/140let/admin-delete-photo/', {puid:puid, email:email, body:body}, adminDeletePhotoCallback, 'json');}
function adminDeletePhotoCallback(data){if (data.status == "ALL_OK"){alert('Foto bylo odstraněno.');} else {alert('Při odstranění fotky došlo ke chybě');}}
function getImageText(id){$.post('/smallapp/140let/get-image-text/', {imgid:id}, getImageTextCallback, 'json');}
function getImageTextCallback(data){$('#content').html(data.text);}
function adminDisableVote(puid){$.post('/smallapp/140let/admin-disable-vote/', {puid:puid}, adminDisableVoteCallback, 'json');}
function adminDisableVoteCallback(data){if (data.status == "ALL_OK"){alert('Hlasovani bylo zakazano.');} else {alert('Chyba na serveru');}}
function adminEnableVote(puid){$.post('/smallapp/140let/admin-enable-vote/', {puid:puid}, adminEnableVoteCallback, 'json');}
function adminEnableVoteCallback(data){if (data.status == "ALL_OK"){alert('Hlasovani bylo povoleno.');} else {alert('Chyba na serveru');}}


function VideoPopup(path){

  var popup = document.getElementById("popup");
  var width = 560;
  var height = 448;

	var html = '<div id="age_check"></div><div id="video_tab"><div class="container" style="width:'+width+'px;">';
	html+= '<embed src="http://www.gambrinus.cz/_swf/flvplayer.swf" width="'+width+'" height="'+height+'" allowfullscreen="true" flashvars="&displayheight='+height+'&file='+path+'&width='+width+'&location=http://www.gambrinus.cz/_swf/flvplayer.swf" />';
	html+='<a href="" onclick="closeVideoPopup(); return false;">[x] zavřít</a></div></div>';

	popup.innerHTML = html;

    self.scrollTo(0, 0);

	window.onresize=resizeLayer;
	resizeLayer();


}
function closeVideoPopup(){

  var popup = document.getElementById("popup");
	popup.innerHTML = "";

}

