function validMail(string){var mail=/^.+@.+\..{2,4}$/; return mail.test(string);}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function sendComment(pubid){	$('#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/send-comment/', {name:name, surname:surname, comment:comment, pubid:pubid}, sendCommentCallback, 'json');
}
function sendCommentCallback(data){
	switch (data.status){
		case 'ALL_OK':
			$('#komentar').val('');
			var ret = '<div class="koment-top"></div><div class="koment-text">'+data.comment+'</div><div class="koment-bottom">'+data.name+' | '+data.date+'</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 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;">Změnit</button> <button onclick="cancelComment('+id+'); return false;">Storno</button>');}
function cancelComment(id){$("#koment_"+id).html($("#ta_"+id).val());}
function saveComment(id){var c = $("#ta_"+id).val();$.post('/smallapp/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/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');}}

/******** COOKIE METHODS FROM AGE-CHECK *********************/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
function flash (file,width,height,flashvars,winmode,id,classs,alternative,will_be_age_check_shown) {
	if (will_be_age_check_shown==1) {
		return;
	}

	var shockmode = false;
	if(id!=''){
		id=" id=\""+id+"\"";
	}
	if(classs!=''){
		classs=' class="'+classs+'"';
	}
	var mimetype = 'application/x-shockwave-flash';

	if (navigator.mimeTypes) {
		if (navigator.mimeTypes[mimetype] != null) {
			if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
				shockmode = true;
		      }
		}
	}
	if (!shockmode && navigator.appVersion.indexOf('MSIE') !=-1) {
		shockmode = true;
	}
	if (shockmode) {
		document.write("<object"+id+" type=\"application/x-shockwave-flash\" data=\""+file+"\""+classs+" width=\""+width+"\" height=\""+height+"\">");
		document.write("<param name=\"movie\" value=\""+file+"\" />");
		document.write("<param name=\"menu\" value=\"false\" />");
		document.write("<param name=\"wmode\" value=\""+winmode+"\" />");
		if(flashvars!=''){
			document.write("<param name=\"flashvars\" value=\""+flashvars+"\" />");
		}
		document.write(alternative);
		document.write("</object>");
	}
	else {
		document.write(alternative);
	}
}