function nextPage(num,userId) {
	var root = document.getElementById('comments');
	root.innerHTML = '';
	document.getElementById('please-wait').style.display = '';
	var xmlhttp = new XMLHttpRequest()
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			document.getElementById('please-wait').style.display = 'none';
			if (xmlhttp.status == 200) {
				var output = xmlhttp.responseText;
				root.innerHTML = output;
			}
		}
	};
	xmlhttp.open('get', '/comments.php?xml=1&page='+num+'&id='+userId, true);
	xmlhttp.send("");
}

function removeComment(id,userId) {
	var row = document.getElementById('comment-1-'+id);
	row.parentNode.removeChild(row);
	row = document.getElementById('comment-2-'+id);
	row.parentNode.removeChild(row);
	document.getElementById('please-wait').style.display = '';
	var xmlhttp = new XMLHttpRequest()
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			document.getElementById('please-wait').style.display = 'none';
			if (xmlhttp.status == 200) {
				var output = xmlhttp.responseText;
			}
		}
	};
	xmlhttp.open('post', '/comments.php', true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send('xml=1&comment='+id+'&user='+userId+'&remove=1');
}

function smilieBtnClick(e) {
	var type = 0;
	if (!e) {
		e = event;
		type = e.srcElement.getAttribute('title');
	} else {
		type = e.currentTarget.getAttribute('title');
	}
	var txtarea = document.getElementById('comment-txt');
	type = ' ' + type + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + type + ' ' : caretPos.text + type;
		txtarea.focus();
	} else {
		txtarea.value  += type;
		txtarea.focus();
	}
	
	var oldOne = document.getElementById('smilie-popup');
	if (oldOne) oldOne.parentNode.removeChild(oldOne);
	
	return false;
}

function checkCommentEmail(id) {
	var txt = document.getElementById(id);
	if (txt) {
		if (txt.value.indexOf('@') >= 0) {
			document.getElementById(id+'-error').style.display = '';
			return false;
		} else {
			// check if comment longer than 200 chars
			if (txt.value.length > 200) {
				document.getElementById(id+'-toolong-error').style.display = '';
				return false;
			}				
			document.getElementById(id+'-error').style.display = 'none';
		}
	}
	return true;
}

function goBack() {
	history.back();
	return false;
}

function rejectPhoto(userID) {
	var win = window.open('/reject_photo.php?user='+userID,'RejectPhoto','status=1,toolbar=0,location=0,menubar=0,directories=0,location=0,width=795,height=500');
	win.moveTo(50,50);
}