function startLoading() { infoWin.showLoading(); }
function endLoading() { infoWin.hideLoading(); }

var gml = new GoogleMapLoader(startLoading, endLoading);

function showMap(lat, lng, zoom) {
	infoWin.showAW(); 
	gml.setRunFunction('doJob('+lat+','+lng+','+zoom+')');	
	gml.loadGoogleMap();		
}

var map = new SimpleGoogleMap('map');
function doJob(lat, lng, zoom) {
	map.load();
	map.showStillMarker(lat, lng, zoom);
}

var gDbCommentId = null;
var gDbId = null;

function showDeleteComment(dbCommentId, dbId) {
	gDbCommentId = dbCommentId;
	gDbId = dbId;
	
	deleteCommentWin.showAW(); 
}

function deleteCommentAction() {
	deleteCommentWin.showLoading();
	getElem('deleteCommentButtonId').disabled = true;
	getElem('cancelCommentButtonId').disabled = true;
	
	oConnector.SendPOSTCommand('deleteComment', '', 'id='+gDbCommentId+'&type=EVENT', onDeleteCommentActionCallBack);		
}

function onDeleteCommentActionCallBack(oXml) {
	deleteCommentWin.hideLoading();
	getElem('deleteCommentButtonId').disabled = false;
	getElem('cancelCommentButtonId').disabled = false;
	
	var status = oXml.SelectSingleNode('connector/status');
	if (status == null) {
		deleteCommentWin.showError();
		return;
	}
	
 	var type = status.attributes.getNamedItem('type').value;
 	deleteCommentWin.hideAW();
 	if (type == "ok") {
		var commentsCount = status.attributes.getNamedItem('value').value;
		getElem('commentsCountId').innerHTML = commentsCount;
		
		linkElem = getElem('postACommentStatus');
		linkElem.style.background = 'url(/g/status/successSmall.gif) no-repeat';
		linkElem.style.padding = '3px 0 3px 23px';
		linkElem.innerHTML = '<span class="green" >' + 'Komentarz został usunięty.' + '</span>';
		
		getCommentsPage('EVENT', gDbId, 1, commentsCount);
	}
}

var gDbEventId = null;

function showSendMessageAction(dbEventId) {
	gDbEventId = dbEventId;
	
	smWin.showAW(); 
	smWin.setContent('');
	smWin.showLoading();
	getElem('sendButtonId').disabled = true;
	getElem('cancelButtonId').disabled = true;
	
	oConnector.SendPOSTCommand('sendMessage', '', 'id='+gDbEventId, onShowSendMessageActionCallBack);		
}

function onShowSendMessageActionCallBack(oXml) {	
	smWin.hideLoading();
	getElem('sendButtonId').disabled = false;
	getElem('cancelButtonId').disabled = false;
	
	var oNode = oXml.SelectSingleNode('connector/html');
	if (oNode == null) {
		smWin.showError();
		getElem('sendButtonId').disabled = true;	
		return;
	}
	
	var textTemp = oNode.firstChild.nodeValue;		
	smWin.setContent(textTemp);	
}
	
function sendMessageAction() {	   
	smWin.showLoading();
	getElem('sendButtonId').disabled = true;
	getElem('cancelButtonId').disabled = true;
	
	postParameters = getFieldAsFormParameter(document.sendMessageForm, 'msg_subject');
	postParameters += '&' + getFieldAsFormParameter(document.sendMessageForm, 'msg_message');
	postParameters += '&' + prepareParameter('sendButton', 'true');

	oConnector.SendPOSTCommand('sendMessage', null, 'id='+gDbEventId+'&'+postParameters, onSendMessageActionCallBack);		
}

function onSendMessageActionCallBack(oXml) {
	smWin.hideLoading();
	getElem('sendButtonId').disabled = false;
	getElem('cancelButtonId').disabled = false;
	
	var oNode = oXml.SelectSingleNode('connector/status');
	if (oNode == null) {
		smWin.showError();
		return;
	}
	
	var statusValue = oNode.attributes.getNamedItem('type').value;
	if (statusValue == 'ok') {
		smWin.hideAW();	
	}
	else if (statusValue == 'dbNotFound') {
		smWin.showError();
		getElem('sendButtonId').disabled = true;
	}
	else {
		oNode = oXml.SelectSingleNode('connector/html');
		if (oNode == null) {
			smWin.showError();
			return;
		}
		
		var textTemp = oNode.firstChild.nodeValue;		
		smWin.setContent(textTemp);	
	}
}

