function setMousePointer(Control, mousePointer)
{
    var panel = getObject(Control);
    
    if (panel != null)
	    panel.style.cursor = mousePointer;
}


///////////////////////////////////////////////////////////////////////////////
// MENU DE SEPARADORES                                                       //
///////////////////////////////////////////////////////////////////////////////

var Status = "0";  // Ligado = '1'; Desligado = '0';

function getObject(id)
{
	if(document.all)
		{return(document.all(id))}
	else if (document.getElementById)
		{return(document.getElementById(id))}
}

function hideDetails()
{

	getObject('submenu1').className = 'Off';
	getObject('Tab1').className = 'Tab';
	getObject('submenu2').className = 'Off';
	getObject('Tab2').className = 'Tab';
	getObject('submenu3').className = 'Off';
	getObject('Tab3').className = 'Tab';
	/*getObject('submenu4').className = 'Off';
	getObject('Tab4').className = 'Tab';*/
}

function showDetails(id)
{	
	var IDSeparador = "Tab" + id
	var IDContent = "submenu" + id
	
	var obj = getObject(IDContent);
	var Tabobj = getObject(IDSeparador);
	var Separador = getObject('txtHiddenSelectedTab');
	var StatusClass = obj.className + Status ;
			
	switch (StatusClass)
		{
		case 'MenuContent1':
			hideDetails()
			Separador.value = id;
			/*getObject('Map').className='Big';*/
			break
		default:
			hideDetails()
			obj.className = 'MenuContent';	
			Separador.value = id;	
			if (Tabobj != Tab3){Tabobj.className = 'TabOn';} else {Tabobj.className = 'TabOnEnd';}
		}
}

///////////////////////////////////////////////////////////////////////////////
// BROWSER TYPE AND VERSION                                                  //
///////////////////////////////////////////////////////////////////////////////

var isNav  = (navigator.appName.indexOf("Netscape")>=0);
var isMoz  = (navigator.appName.indexOf("Mozzila")==0);
var is5up  = false;
var isNav4 = false;
var isIE5  = false;
var isIE4  = false;
var searchReturnValue = '-1|-1';

if (isMoz)
{
	if (parseFloat(navigator.appVersion)>=5)
	{
		is5up = true;
	}
	else
	{
		isIE4=true;
	}
}
else if (isNav)
{
	if (parseFloat(navigator.appVersion)<5)
	{
		isNav4=true;
	}
	else
	{
		is5up = true;
	}
}
else
{
	if (navigator.appVersion.indexOf("MSIE")>0)
	{
		isIE5 = true;
		is5up = true;
	}
	else
	{
		isIE4=true;
	}
}


///////////////////////////////////////////////////////////////////////////////
// ELEMENT POSITION															 //
///////////////////////////////////////////////////////////////////////////////
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}
	return curtop;
}

///////////////////////////////////////////////////////////////////////////////
// DHTML LAYER FUNCTIONS                                                     //
///////////////////////////////////////////////////////////////////////////////

function LayerCreate(name, inleft, intop, width, height, visible, content)
{
	if (isNav4)
	{
		document.writeln('<layer name="' + name + '" left=' + inleft + ' top=' + intop + ' width=' + width + ' height=' + height +	' visibility=' + (visible ? '"show"' : '"hide"') +  '>');
		document.writeln(content);
		document.writeln('</layer>');
	}
	else
	{
		document.writeln('<div id="' + name + '" style="position:absolute; overflow:hidden; left:' + inleft + 'px; top:' + intop + 'px; width:' + width + 'px; height:' + height + 'px;' + '; z-index:6010; visibility:' + (visible ? 'visible;' : 'hidden;'));
		document.writeln(content);
		document.writeln('</div>');
	}
}
function LayerGet(name)
{
	var retVal = null;
	if (isNav4)
	{
		retVal = document.layers[name];
	}
	else if (isIE4)
	{
		retVal = eval('document.all.' + name + '.style');
	}
	else if (is5up)
	{
		var theObj = document.getElementById(name);
		if(theObj != null)
		{
			retVal = theObj.style;
		}
	}
	return retVal;
}
function LayerBackgroundColorSet(name, color)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.bgColor = color;
	}
	else
	{
		layer.backgroundColor = color;
	}
}
function LayerMove(name, x, y)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.moveTo(x, y);
	}
	else
	{
		layer.left = x + "px";
		layer.top  = y + "px";
	}
}
function LayerShow(name)
{
	var layer = LayerGet(name);
	if (layer != null)
	{
		if (isNav4)
		{
			layer.visibility = "show";
		}
		else
		{
			layer.visibility = "visible";
		}
	}
}
function LayerHide(name)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.visibility = "hide";
	}
	else
	{
		layer.visibility = "hidden";
	}
}
function LayerSizeSet(name, w, h)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		//layer.width = w;
		//layer.height = h;
	}
	else
	{
		layer.width = w+"px";
		layer.height = h+"px";
	}
}
function LayerClip(name, clipleft, cliptop, clipright, clipbottom)
{
	var layer = LayerGet(name);
	if (layer == null) return;
	if (isNav4)
	{
		layer.clip.left   = clipleft;
		layer.clip.top    = cliptop;
		layer.clip.right  = clipright;
		layer.clip.bottom = clipbottom;
	  }
	else
	{
		layer.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
	}
}

///////////////////////////////////////////////////////////////////////////////
// OUTBAR                                                                    //
///////////////////////////////////////////////////////////////////////////////

var obDivToOpen;
var obDivToClose;
var obSliderSize = 7;
var obSliderSpeed = 5;
var obHeightOpened = 209;
var obHeightClosed = 18;
var obIsOpening = false;

function TabInitialize(obj)
{
	obDivToOpen = LayerGet(obj);
	obDivToOpen.height = obHeightOpened + "px";
}
function TabOpen(obj)
{
	if(obIsOpening) return;
	
	var tmpObj=LayerGet(obj);
	if (obDivToOpen == tmpObj) return;

	obIsOpening= true;
	if (obDivToOpen)
	{
		obDivToClose = obDivToOpen;
		obDivToOpen = tmpObj;
		obDivToOpen.height = obHeightClosed + "px";
		setTimeout("doTabOpen()", obSliderSpeed);
	}
	return false;
}
function doTabOpen()
{
	if( parseInt(obDivToClose.height) > obHeightClosed+obSliderSize)
	{
		obDivToClose.height = ( parseInt(obDivToClose.height) - obSliderSize ) + "px";
		obDivToOpen.height = ( parseInt(obDivToOpen.height) + obSliderSize ) + "px";
		setTimeout("doTabOpen()", obSliderSpeed);
	}
	else
	{
		obDivToClose.height = obHeightClosed + "px";
		obDivToOpen.height = obHeightOpened + "px";
		obIsOpening=false;
	}
}

///////////////////////////////////////////////////////////////////////////////
// IMAGE MANIPULATION                                                        //
///////////////////////////////////////////////////////////////////////////////

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function resizeSearchWindow()
{
	var width = document.getElementById('SearchTable').scrollWidth;
	var height = document.getElementById('SearchTable').scrollHeight;
	
	if (height>=500)
	{
		height=500;
	}
	
	if (height<=150)
	{
		height=150;
	}
	
	window.resizeTo(width+150, height+60);
}

function resizeInfoWindow()
{
	var width = document.getElementById('InfoTable').scrollWidth;
	var height = document.getElementById('InfoTable').scrollHeight;
	
	if (height>=500)
	{
		height=500;
	}
	
	if (height<=150)
	{
		height=150;
	}
	
	window.resizeTo(width+60, height+60);
}


function checkHidden()
{
	if (document.frmSearchForm.upTesteSHP.value != '')
		{
			document.frmSearchForm.upTesteSHX.value = 
			replace(document.frmSearchForm.upTesteSHP.value,".shp",".shx");
			
			document.frmSearchForm.upTesteDBF.value = 
			replace(document.frmSearchForm.upTesteSHP.value,".shp",".dbf");

		}
}
function replace(string,text,by) 
{ 
// Replaces text with by in string 
	var i = string.indexOf(text); 
	if (string.length == 0) return string; 
	if ((!i) && (text != string.substring(0,text.length))) return string; 
	if (i == -1) return string; 

	var newstr = string.substring(0,i) + by; 

	if (i+text.length < string.length) newstr += 
	replace(string.substring(i+text.length,string.length),text,by); 
	return newstr; 
}

function showElement(value)
{
	if (opener && !opener.closed)
	{
		opener.document.frmMap.txtHiddenFeature.value = value;
		opener.frmMap.submit();
		window.close();
	}
}

function DoneEquip(ParmA,ParmB,ParmC,ParmD,ParmE,ParmF)
{
	var retValue = new Array(ParmA,ParmB,ParmC,ParmD,ParmE,ParmF)
	window.returnValue = retValue;
	window.close();
}

function resizeModal()
{
	var h = parseInt(window.dialogHeight);

	if (h>500)
	{
		h=500;
	}

	if (h<400)
	{
		h=400;
	}

	var height = eval(h + 28);

	window.dialogWidth = "790px";
	window.dialogHeight = height+"px";
}
///////////////////////////////////////////////////////////////////////////////
function OnSearchUnLoad()
{
	window.returnValue = searchReturnValue;
}
function Locate(entity, id)
{
	searchReturnValue = '' + entity + '|' + id;
	opener.document.frmMap.txtHiddenFeature.value = searchReturnValue;
	opener.frmMap.submit();
	window.close();
}

/////////////////////////////////////////////////////////////////////////////////////

function trim(value)
{
      var temp = value;
      var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
      if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
      var obj = /  /g;
      while (temp.match(obj)) { temp = temp.replace(obj, " "); }
      return temp;
}