// Moves form to new place
function moveForm(form, placeID) {
	var place = document.getElementById(placeID);
	if (!place)
		return;
	var currParent = form.parentNode;
	if (currParent == place)
		return;
	currParent.removeChild(form);
	place.appendChild(form);
	
	// Set commentID
	var val = place.getAttribute('replyCommentID');
	if (val) {
		var controlReplyCommentID = document.getElementById('replyCommentID');
		if (controlReplyCommentID)
			controlReplyCommentID.value = val;
	}
	// Set placeID submitted
	var val = place.getAttribute('notifyPlaceControl');
	if (val) {
		var controlPlaceID = document.getElementById(val);
		if (controlPlaceID)
			controlPlaceID.value = placeID;
	}
}

// Shows form for adding comments at designated place
function flyCommentShow(formID, placeID) {
	try {
		var form = document.getElementById(formID);
		var nowPlaceID = form.getAttribute('placeID');
		if ((!nowPlaceID) || (nowPlaceID != placeID)) {
			moveForm(form, placeID);
			form.style.display = '';
			form.setAttribute('placeID', placeID);
		}
		return false;
	}
	catch(e) {
		return true;
	}
}

// Shows anchor
function commAddAnchor(formID, formControlID) {
	try {
		var form = document.getElementById(formID);
		var nowPlaceID = form.getAttribute('placeID');
		if (!nowPlaceID)
			return true;

		var formControl = document.getElementById(formControlID);
		if (!formControl)
			return true;
			
		// Add anchor
		if (formControl.action.indexOf('#') >= 0)
			return true;
		formControl.action = formControl.action + '#a_' + nowPlaceID;
		return true;
	}
	catch (e) {
		return true;
	}
}