var komm_lapoz;
function getpicture_comments(picture_id,l) {
	new Ajax.Request('/xhr_hozzaszolas_list.inc.php', {
			method:'get',
			parameters: { picture_id: picture_id, l: l},
			onSuccess: function(transport) {			
				$('commentholder').innerHTML = transport.responseText;
				if (komm_lapoz) document.location = '#comments';
				komm_lapoz = true;
			}
		}
	);
}

function save_picture_comment(form) {
	var komm = trim(form.comment.value);
	if(komm == ''){
		alert('Nem adtál meg kommentet!');
	}else{
		new Ajax.Request('/xhr_ajaxhelper.inc.php', {
				method:'get',
				parameters: { save_picture_comment: form.picture_id.value, comment: form.comment.value },
				onSuccess: function(transport) {
					//alert('Hozzászólás elmentve!');
					//getpicture_comments(form.picture_id.value,0);
					document.location.reload();
				}
			}
		);
	}
}

function kep_kedvencekhez(id) {
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: { addtofavorites_picture: id },
			onSuccess: function(transport) {
				alert('A receptet hozzáadtuk a kedvencekhez.');
				document.location.reload();
			}
		}
	);
}

function kep_nem_kedvenc(id) {
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: { removefromfavorites_picture: id },
			onSuccess: function(transport) {
				alert('A receptet eltávolítottuk a kedvencek közül.');
				document.location.reload();
			}
		}
	);
}

function recept_torol(id) {
	if (!confirm('Biztos törli a receptet?')) return false;

	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: { delete_recept: id },
			onSuccess: function(transport) {
				alert('A receptet eltávolítottuk.');
				document.location.reload();
			}
		}
	);
}

function komment_torlese(id) {
	if (!confirm('Biztos törli a hozzászólást?')) return false;

	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: { delete_comment: id },
			onSuccess: function(transport) {
				//alert('A hozzászólást eltávolítottuk.');
				getpicture_comments($('recept_hozzaszol').value,$('lap_hozzaszol').value);
			}
		}
	);
}

function picture_vote(picture_id,rating) {
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: {vote_picture_id: picture_id, rating: rating},
			onSuccess: function(transport) {
				$('picture_rating_div').innerHTML = transport.responseText;
			}
		}
	);
}

function recept_aktiv(id,aktiv) {
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: {recept_aktiv: id, aktiv: aktiv},
			onSuccess: function(transport) {
				document.location.reload();
			}
		}
	);
}

function suggest_hozzavalok(input) {
	if (input.value.length<2) {$('suggest').style.display='none';$('suggest').innerHTML=''; return false;}
	
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: {suggest_hozzavalok: input.value},
			onSuccess: function(transport) {
				if (transport.responseText=='') {
					$('suggest').style.display='none';
				} else {
					$('suggest').innerHTML = transport.responseText;
					
					with($('suggest').style) {
						display = 'block';
						position = 'absolute';
						padding = '10px 0';
						top = input.offsetTop+input.offsetHeight+'px';
						left = input.offsetLeft+'px';
					}
				}
			}
		}
	);
}

function suggest_ok(a) {
	$('hozzavalo').value = a.innerHTML;
	$('suggest').innerHTML='';
	$('suggest').style.display = 'none';
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function setTapeta(aId){
	set_background(aId);
	if(aId==6){
		document.body.style.backgroundImage = "url(http://static.pink.hu/style/pink/i/bg_t5.jpg)";
		document.body.className = "karacsonyi";
		var div = document.createElement("div");
		div.id = "karacsonyi_hatter";
		document.body.appendChild(div);
		 Effect.BlindDown("extra_div");
	}else{
		document.body.style.backgroundImage = "url(http://static.pink.hu/style/pink/i/bg_t" + aId + ".jpg)";
		document.body.className = "";
		document.body.removeChild($("karacsonyi_hatter"));		
		 Effect.BlindUp("extra_div");
	}
}


function set_background(id) {
	new Ajax.Request('/xhr_ajaxhelper.inc.php', {
			method:'get',
			parameters: {background_session: id},
			onSuccess: function(transport) {
			}
		}
	);
}