///* Better then onload http://www.javascriptkit.com/dhtmltutors/domready.shtml */
//var alreadyrunflag=0 //flag to indicate whether target function has already been run
//if (document.addEventListener)
//{
//    document.addEventListener("DOMContentLoaded", function(){alreadyrunflag=1; init()}, false)
//}
//else if (document.all && !window.opera)
//{
//    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
//    var contentloadtag=document.getElementById("contentloadtag")
//    contentloadtag.onreadystatechange=function()
//    {
//        if (this.readyState=="complete")
//        {
//            alreadyrunflag=1
//            init()
//        }
//    }
//}
//else if(/Safari/i.test(navigator.userAgent)){ //Test for Safari
//  var _timer=setInterval(function(){
//  if(/loaded|complete/.test(document.readyState)){
//    clearInterval(_timer)
//    init() // call target function
//  }}, 10)
//}

//window.onload=function()
//{
//  setTimeout("if (!alreadyrunflag){ init()}", 0)
//}
///* End better then onload */


//function init()
//{
//    /*Attach event to java functions*/
//  
//}

////////////////////////
// Check web window size
function checkSize(pHeight, pWidth, pWidthLimit, pHeightLimit) {
	var horizontalSize //Width of map image
	var verticalSize; //Height of map image
	var horizontalMargin = 20; //Horizontal margins and borders
	var verticalMargin = 52; // Vertical margins and borders
	//All except Explorer
	if (self.innerHeight)
	{
		horizontalSize = parseInt(self.innerWidth) - horizontalMargin;
		verticalSize = parseInt(self.innerHeight) - verticalMargin;
	}
	//Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		horizontalSize = parseInt(document.documentElement.clientWidth) - horizontalMargin;
		verticalSize = parseInt(document.documentElement.clientHeight) - verticalMargin;
	}
	//Other Explorers
	else if (document.body)
	{
		horizontalSize = parseInt(document.body.clientWidth) - horizontalMargin;
		verticalSize = parseInt(document.body.clientHeight) - verticalMargin;
	}
	//Check if window should be resized
	if (horizontalSize < pWidthLimit && verticalSize < pHeightLimit)
	{
		if (((pHeight != verticalSize) || pWidth != horizontalSize))
		{
			resize_window();
		}
	}
}

/////////////////////////
// Resize window
function resize_window()
{
	var w, h;
	var wmargin = 20;
	var hmargin = 85;
	//All except Explorer
	if (self.innerHeight)
	{
		w = parseInt(self.innerWidth) - wmargin;
		h = parseInt(self.innerHeight) - hmargin;
	}
	//Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		w = parseInt(document.documentElement.clientWidth) - wmargin;
		h = parseInt(document.documentElement.clientHeight) - hmargin;
	}
	//Other Explorers 
	else if (document.body)
	{
		w = parseInt(document.body.clientWidth) - wmargin;
		h = parseInt(document.body.clientHeight) - hmargin;
	}
	//Set hidden variables to right value
	parent.mainFrame.document.getElementById('txtWidth').value = w;
	parent.mainFrame.document.getElementById('txtHeight').value = h;
	
	//Wait for 500 ms before check if current size is right
	setTimeout("resizeTemp(" + h + "," + w + ")", 500);
}

////////////////////////////
//If map size havent changed update map with new values
function resizeTemp(temprh, temprw)
{
	var w, h;
	var wmargin = 20;
	var hmargin = 85;
	//All except Explorer
	if (self.innerHeight)
	{
		w = parseInt(self.innerWidth) - wmargin;
		h = parseInt(self.innerHeight) - hmargin;
	}
	//Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		w = parseInt(document.documentElement.clientWidth) - wmargin;
		h = parseInt(document.documentElement.clientHeight) - hmargin;
	}
	//Other Explorers
	else if (document.body)
	{
		w = parseInt(document.body.clientWidth) - wmargin;
		h = parseInt(document.body.clientHeight) - hmargin;
	}
	if((temprh != h || temprw == w) && parent.mainFrame.document.getElementById('txtSearch').value == '')
	{
		parent.mainFrame.document.getElementById('txtSearch').value = 'doNotUpdate';
		parent.mainFrame.document.getElementById('Form1').submit();
	}
}


/////////////////////////
//
function selectedSearchPoint(x, y)
{
	parent.mainFrame.document.getElementById('txtSearchCoord').value = x + ";" + y;
	parent.mainFrame.document.getElementById('Form1').submit();
}

/////////////////////////
//
function selectedSearch(id, layer)
{
	parent.mainFrame.document.getElementById('txtSearchId').value = id;
	parent.mainFrame.document.getElementById('txtSearchLayer').value = layer;
	parent.mainFrame.document.getElementById('txtSearch').value = 'doNotUpdate';
	parent.mainFrame.document.getElementById('Form1').submit();
}

/////////////////////////
//
function layerCover()
{
	if (parent.layerFrame.document.getElementById('divCover') != null)
	{
		parent.layerFrame.document.getElementById('divCover').style.visibility = "hidden";
	}
}

///////////////////////////////////
// Send parameters to overviewmap
function reloadOverview()
{
	var tempStr = parent.document.getElementById("leftFrameSet").rows;
	splitString = tempStr.split(",");
	if (splitString[1] == "242")
	{
		if(document.getElementById('txtOverview').value != 'doNotUpdate')
		{
			if(document.getElementById('txtOverview').value == 'noOverview')
			{
				splitString = tempStr.split(",");
				parent.document.getElementById("leftFrameSet").rows = splitString[0] + ",26";
			}
			else
			{
				if(parent.overviewFrame)
				{
					parent.overviewFrame.location = "overview.aspx?x=" +document.getElementById('Form1').txtXcoord.value+ "&y=" +document.Form1.txtYcoord.value+ "&z=" +document.Form1.txtZoom.value+ "&bx1=" +document.Form1.txtBoundsX1.value+ "&bx2=" +document.Form1.txtBoundsX2.value+ "&by1=" +document.Form1.txtBoundsY1.value+ "&by2=" +document.Form1.txtBoundsY2.value;
				}
			}
		}
		document.getElementById('txtOverview').value = '';
	}
}

/////////////////////////
//
function updateSearchWSelect()
{
	//Check if a selection is made
	if(document.getElementById('txtTool').value == 'selectRect' || document.getElementById('txtTool').value == 'selectPoint' || document.getElementById('txtTool').value == 'selectPolygon')
	{
		if(document.getElementById('txtSearch').value != 'doNotUpdate')
		{
		//	parent.layerFrame.document.getElementById('txtMapSelect').value = 'showUrval';
			parent.layerFrame.document.getElementById('Form1').submit();
		}
	}
	// Check if selection is erased
	if(document.getElementById('txtUnselect').value == 'unSelect' || document.getElementById('txtUnselect').value == 'unSelectWrite')
	{
		document.getElementById('txtUnselect').value = '';
		parent.layerFrame.document.getElementById('Form1').submit();
	}
	document.getElementById('txtSearch').value = '';
}
