﻿//Method toggle
//turns a specific div element to display as a block or as inline
//Parameters: itemname - the id name of the div object to display
//					asblock - if true display as a block otherwise display inline
function toggle(itemname, asblock)
{
	try
	{
		//get all div elements
		tmp = document.getElementsByTagName('div');
		for (i=0;i<tmp.length;i++)
		{
			//if the div element is the one we want display it
			if (tmp[i].className == itemname) 
			{
				//if wanting to display as a block, the do so, otherwise display inline
				if(asblock)
					tmp[i].style.display	= (tmp[i].style.display == 'none' || tmp[i].style.display == '') 
						? 'block' : 'block';
				else
					tmp[i].style.display	= (tmp[i].style.display == 'none' || tmp[i].style.display == '') 
						? 'inline' : 'inline';
			}
		}
	}
	catch(e)
	{
		return e.message;
	}
}

//Method toggleOff
//turns a specific div element to not display
//Parameters: itemname - the id name of the div object to hide
//					asblock - if true display as a block otherwise display inline
function toggleOff(itemname, asblock)
{
	try
	{
		tmp = document.getElementsByTagName('div');
		for (i=0;i<tmp.length;i++)
		{
			if (tmp[i].className == itemname)
			{ 
				if(asblock)
					tmp[i].style.display	= (tmp[i].style.display == 'block') ? 'none' : 'none';
				else
					tmp[i].style.display	= (tmp[i].style.display == 'inline') ? 'none' : 'none';
			}
		}
	}
	catch(e)
	{
		return e.message;
	}
}

//Method setProgError
//set the error section to display an error
//Parameters: errorText - the friendly error text to display
//					location - the location of the error
//					message - the specific error given by javascript
function setProgError(errorText, location, message)
{
	try
	{
		toggle('progErr');
		var errorLabel = document.getElementById('_ctl0_lblProgError');
		if(message && location)
			errorLabel.innerHTML = errorText + ' (' + location + ' - ' + message + ')';
		else if(location)
			errorLabel.innerHTML = errorText + ' (' + location + ')';
		else if(message)
			errorLabel.innerHTML = errorText + ' (' + message + ')';
		else
		errorLabel.innerHTML = errorText;
	}
	catch(e)
	{
		return e.message;
	}
}

//Method clearProgError
//clears the error dispaly
function clearProgError()
{
	try
	{
		toggleOff('progErr');
		var errorLabel = document.getElementById('lblProgError');
		errorLabel.innerText = '';
	}
	catch(e)
	{
		return e.message;
	}
}

//Method getKey
//retrieve the given key from the url text
//Parameters: key_str - the name of the key to retrieve
function getKey(key_str)
{
	if(window.location.search) 
	{
		var query = window.location.search.substr(1);
		var pairs = query.split("&");
		for(var i = 0; i < pairs.length; i++) 
		{
			var pair = pairs[i].split("=");
			if(unescape(pair[0]) == key_str)
				return unescape(pair[1]);
		}
	}
	return "";
}

//Method findPos
//retrieves the x and y pixel coordinates of the given object
//Parameters: obj - the html object on the page to retrieve the position of
function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) 
		//As long as there is a parent to the object, add the parent's offset
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//Method windowSize
//retrieves the pixel size of the current window
function windowSize()
{
	var myWidth = 0, myHeight = 0;
	try
	{
		if(typeof(window.innerWidth) == 'number')
		{
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if(document.documentElement && 
			(document.documentElement.clientWidth || document.documentElement.clientHeight))
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if(document.body && (document.body.clientWidth || document.body.clientHeight))
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
	}
	catch(e)
	{
		setProgError("Error getting the window size!", "windowSize", e.message)
	}
	
	return [myWidth, myHeight];
}

//Method getScrollXY
//get the extra scrolling XY pixel coordinates
//Used on the MapPoint site to determine pushpin location when window has been scrolled
function getScrollXY() 
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  }
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  
  return [scrOfX, scrOfY];
}