/**
 * Funzioni richiamate dalle finestre di Info ma appartenenti alla main,
 * sono la versione "residente" di info.js 
 * 20080923 DC
 */

function verificaConsistenzaVista(nomevista)
{
  if (getAIMSServiceName() != nomevista) {
		alert("Impossibile procedere perche' la vista e' cambiata.");
    return false;
  } else {
    return true;
  }
}

function highlightEntity(nomevista, _layerid, _id, _colname) {
  if (verificaConsistenzaVista(nomevista)) {
  	doHighlight(_layerid, _colname + " = "+_id);
	}
}

function zoomToEntity(nomevista, _layerid, _id, _colname) {
  if (verificaConsistenzaVista(nomevista)) {
  	doInfoZoom(_layerid, _colname + " = "+_id);
	}
}

/**
 * Zoom su tutte le entita' del layer
 * @param _layer L'id del layer a cui appartengono le entità.
 * @return
 */
function zoomToEntities(nomevista, _layerid, where) {
  if (where==undefined || where.length==0) alert("zoomToEntities deve specificare where");
  if (verificaConsistenzaVista(nomevista)) {
  	doInfoZoom(_layerid, where);
	}
}

function zoomToAndHighlightEntities(nomevista, _layerid, where) {
  if (where==undefined || where.length==0) alert("zoomToAndHighlightEntities deve specificare where");
  if (verificaConsistenzaVista(nomevista)) doInfoZoomAndHighlight(_layerid, where);
}

function selectEntities(nomevista, _layerid, where) {
  if (where==undefined || where.length==0) alert("zoomToEntities deve specificare where");
  if (verificaConsistenzaVista(nomevista)) doSelection(_layerid, where);
}

/**
 * Chiamata zoom sul template
 * @param _layername 		l' ID del layer.
 * @param where     	l'espressione SQL di selezione
 * @return
 */
function doInfoZoomAndHighlight(_layerid, _where)
{
	document.processa.HighlightLayerIds.value   = _layerid;
	document.processa.HighlightWhereClauses.value = _where;
	doInfoZoom(_layerid, _where);
}

function doInfoZoom(_layerid, _where)
{
  //alert("TBVerified: doInfoZoom");
  var statoform = form_getStato();
  form_setAction("infozoom");
  document.processa.ZoomLayerId.value   = _layerid;
  document.processa.ZoomWhereClause.value = _where;
  toolLoad();
  form_restoreStato(statoform);
}

function doEntityDetails(nomevista, _layerid, _idcolname, _id)
{
	if (verificaConsistenzaVista(nomevista)) {
		var statoform = form_getStato();
  	document.processa.identifylayerid.value   = _layerid;
  	document.processa.identifywhereclause.value = (_idcolname + " = "+_id);
    toolDoOp("identify");
	}
}

/**
 * Setta la selection sul template
 * @param _layername il nome del layer.
 * @param where     l'espressione SQL di selezione
 * @return
 */
function doSelection(_layerid, _where)
{
  //alert("TBVerified: doSelection");
  var statoform = form_getStato();
  form_setAction("refresh");
  document.processa.SelectionLayerIds.value   = _layerid;
  document.processa.SelectionWhereClauses.value = _where;
  toolLoad();
  form_restoreStato(statoform);
}

/**
 * Setta la highlight sul template
 * @param _layername il nome del layer.
 * @param where     l'espressione SQL di selezione
 * @return
 */
function doHighlight(_layerid, _where)
{
  //alert("TBVerified: doHighlight");
  var statoform = form_getStato();
  form_setAction("refresh");
  document.processa.HighlightLayerIds.value   = _layerid;
  document.processa.HighlightWhereClauses.value = _where;
  toolLoad();
  form_restoreStato(statoform);
}

