var theTitle = "";
var cmdString = document.location.search;

var webParams = cmdString;
var reloadTimer=0;
var browser = navigator.appName;
var moreStuff = 'onresize="reloadApp()"';
var addNS = 0;
if (browser=="Netscape") {
  addNS = 3;
}

var formURL = "jsForm.htm";
var connectorType = "Servlet";

function getParameterValue(pars, parName) {
  var parValue = "";
  var iS = pars.indexOf(parName);
  if (iS >= 0) {
	  iS = pars.indexOf("=", iS) + 1;
  	  if (iS >= 0) {
		  var iE = pars.indexOf("&", iS);
		  if (iE < 0) {
		  	iE = pars.length;
		  }
		  parValue = pars.substring(iS, iE);
	  }
  }
  return parValue;
}

function doIt() {
  /* Imposta parametri per Start Query */
  var selType = getParameterValue(window.location.search, "SelType");
  var idItem = getParameterValue(window.location.search, "IdItem");
  var geoSel = getParameterValue(window.location.search, "GeoSel");
  if ((idItem.length > 0) && (geoSel.length > 0)) {
	  /* Controllo dei parametri */
  	  idItem = idItem.replace(/%20/g, ' ');
  	  geoSel = geoSel.replace(/%20/g, ' ');
  	  
  	  var idVisual = SystemCore.getIdVisual(idItem);
	  if (idVisual == -1) {
		  alert('Non sono stati trovati elementi sulla cartografia!');
	  } else {
		  MapFrame.ActiveLayerIndex = idVisual;
		  MapFrame.selectCount = 1;
		  var q = SystemCore.getGeoPosQuery(selType, geoSel);
		  MapFrame.highlightedOne = q;
		  MapFrame.setQueryString = MapFrame.highlightedOne;
	  }
  }

  MapFrame.useJava=false;
  MapFrame.checkParams();
}

function replacePlus(inText) {
  var re = /\+/g;
  inText = inText.replace(re," ");
  return inText;
}

function reloadApp() {
	window.clearTimeout(reloadTimer);
	reloadTimer = window.setTimeout("reMap()", 1000);
}

function windowResize() {
  if (window.name == 'GisMasterWebSystem') { /* No prima apertura della finestra */
    reloadApp();
  }
}

function reMap()	{
	var mf = MapFrame;
	var e;
		
	mf.mWidth = mf.getMapWidth();
	mf.mHeight = mf.getMapHeight();
	mf.iWidth = mf.mWidth;
	mf.iHeight = mf.mHeight;
	mf.sWidth = mf.screen.width;
	mf.sHeight = mf.screen.height;

	mf.ovRatio = mf.mWidth / mf.mHeight;
	mf.locHeight = parseInt(mf.mHeight/5);
	mf.locWidth = parseInt(mf.locHeight*mf.ovRatio);
	mf.loadBannerLeft = parseInt((mf.mWidth - 104)/2);
	mf.loadBannerTop = parseInt((mf.mHeight - 104)/2);

	/* Sposta LoadData */
	e = mf.document.getElementById("LoadData");
	e.style.left = mf.loadBannerLeft;
	e.style.top = mf.loadBannerTop;
	
	/* Sposta LoadMap */
	e = mf.document.getElementById("LoadMap");
	e.style.left = mf.loadBannerLeft;
	e.style.top = mf.loadBannerTop;
	
	e = mf.document.getElementById('theImage');
	e.width = mf.mWidth;
	e.height = mf.mHeight;

	/* Per evitare il problema della zona grigia in caso di ridimensionamento dopo un pan */
	mf.clipLayer2("theMap", 0, 0, mf.mWidth, mf.mHeight);

	e = mf.document.getElementById('ovImage');
	e.width = mf.locWidth;
	e.height = mf.locHeight;

	e = mf.document.getElementById('pixel');
	e.width = mf.sWidth;
	e.height = mf.sHeight;

	e = mf.document.getElementById('ovShadow');
	e.style.width = mf.locWidth+8;
	e.style.height = mf.locHeight+8;
	e = mf.document.getElementById('ovLayer');
	e.style.width = mf.locWidth+4;
	e.style.height = mf.locHeight+4;

	e = mf.document.getElementById('zoomOVBoxTop');
	e.style.visibility = 'hidden';
	e = mf.document.getElementById('zoomOVBoxLeft');
	e.style.visibility = 'hidden';
	e = mf.document.getElementById('zoomOVBoxRight');
	e.style.visibility = 'hidden';
	e = mf.document.getElementById('zoomOVBoxBottom');
	e.style.visibility = 'hidden';

	e = mf.document.getElementById('zoomOVBoxTop');
	e.style.width = mf.locWidth+4;
	e.style.height = mf.locHeight+4;
	e = mf.document.getElementById('zoomOVBoxLeft');
	e.style.width = mf.locWidth+4;
	e.style.height = mf.locHeight+4;
	e = mf.document.getElementById('zoomOVBoxRight');
	e.style.width = mf.locWidth+4;
	e.style.height = mf.locHeight+4;
	e = mf.document.getElementById('zoomOVBoxBottom');
	e.style.width = mf.locWidth+4;
	e.style.height = mf.locHeight+4;

	mf.i2Width = mf.locWidth;
	mf.i2Height = mf.locHeight;

	mf.forceNewOVMap = true;
	mf.sendMapXML();
}

