//<SCRIPT>
//// PopupCalendar.js ////
// ____________________________________________________________________________
//
//
//   Common methods used by SBNetWebControls.
//
// 01/20/2008 Created. - SC
//
// ____________________________________________________________________________

if(typeof(SBNetWC) == "undefined")
{
	SBNetWC={};
}

SBNetWC.Util = {

	//// properties. ///
	//Hide div list.
	divList: new Array(),

	//// functions. ///

	////////////////////////////////////////////////////////////////////////////
	//This function will attach 'eventFunction' to 'eventName' of object 'control'.
	// 'control' can optionally be the control ID.
	AttachEvent: function(control, eventName, eventFunction)
	{
		var oControl;

		if (control == null)
			return;

		if (typeof (control) == "string")
			oControl = document.getElementById(control);
		else
			oControl = control;

		//alert(typeof(oControl.attachEvent));
		if (typeof (oControl.attachEvent) != "undefined")
			oControl.attachEvent(eventName, eventFunction);
		else
		{
			//If non Microsoft, strip "on" from eventName.
			eventName = eventName.substr(2);
			oControl.addEventListener(eventName, eventFunction, false);
		}
	},

	////////////////////////////////////////////////////////////////////////////

	AddToHideOnDocumentClickList: function(oDiv)
	{
		//alert("SBNetWC.Util.AddToHideOnDocumentClickList()");
		SBNetWC.Util.divList[oDiv.id] = oDiv;
		//	alert(SBNetWC.Util.divList[oDiv.id]);
	},

	HideDivList: function()
	{
		//alert("SBNetWC.Util.HideDivList()");
		for (n in SBNetWC.Util.divList)
		{
			if (typeof (SBNetWC.Util.divList[n]) == "object")
				SBNetWC.Util.divList[n].style.display = "none";
		}
		for (n in SBNetWC.Util.divList)
		{
			if (typeof (SBNetWC.Util.divList[n]) != "object")
				delete (SBNetWC.Util.divList[n]);
		}
	},

	RemoveFromHideOnDocumentClickList: function(oDiv)
	{
		//alert("SBNetWC.Util.RemoveFromHideOnDocumentClickList()");
		delete (SBNetWC.Util.divList[oDiv.id]);
	},

	////////////////////////////////////////////////////////////////////////////

	isIE: function()
	{
		//Match msie
		return !!navigator.userAgent.match(/msie/i);
	},

	isIE6: function()
	{
		//Match "msie 6."
		return !!navigator.userAgent.match(/msie 6\./i);
	},

	//Get the version of the IE browser. Returns zero if non-IE.
	getIEVersion: function()
	{
		//Match "msie x.xx"
		var myregexp = /(msie)\s(\d*.\d*)/i;
		var match = myregexp.exec(navigator.userAgent);
		if (match != null && match.length > 1)
		{
			return parseFloat(match[2]);
		}
		else
			return 0;
	},

	isSafari: function()
	{
		//Match "Safari"
		return !!navigator.userAgent.match(/Safari/i);
	},

	isOpera: function(userAgent)
	{
		//Match "Opera"
		return !!navigator.userAgent.match(/opera/i);
	},

	////////////////////////////////////////////////////////////////////////////

	encodeHTML: function(sText)
	{
		var s = "";
		if (sText != null)
		{
			s = sText;

			//Do extra stuff.	
			s = s.replace(/\&/g, "&amp;");
			s = s.replace(/ /g, "&nbsp;");
			s = s.replace(/\"/g, "&quot;");
			s = s.replace(/\-/g, "&#8209;");
			s = s.replace(/\'/g, "&#39;");
			s = s.replace(/</g, "&lt;");
			s = s.replace(/>/g, "&gt;");
			//s = s.replace(/\r\n/g, "<br />");
		}
		//alert("\"" + sText + "\"");
		//alert("\"" + s + "\"");
		return s;
	},

	////////////////////////////////////////////////////////////////////////////
	//The follwing functions will get window size and control location.

	getMyWindowXY: function(oControl)
	{
		var x = 0;
		var y = 0;

		do
		{
			//alert(oControl.currentStyle.position);
//me			if (oControl.currentStyle.position == "static")
			//if (oControl.currentStyle.position != "absolute")
			    if (oControl.style.position != "absolute")
			{
				x += oControl.offsetLeft;
				y += oControl.offsetTop;
				//NOTE: This does not add in borders and padding.
			}
			oControl = oControl.offsetParent;
		} while (oControl != null);
		return [x, y];
	},

	getStyle: function(oControl, styleName)
	{
		if (window.getComputedStyle)
			return window.getComputedStyle(oElement, null).getPropertyValue(styleName);
		else
		if (oControl.currentStyle)
			return oControl.currentStyle[styleName];
		else
			return oControl.style[styleName];
	},

	getScrollXY: function()
	{
		var scrOfX = 0;
		var 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];
	},

	getWindowSize: function()
	{
		var myWidth = 0;
		var myHeight = 0;

		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;
		}
		//window.alert( 'Width = ' + myWidth );
		//window.alert( 'Height = ' + myHeight );
		return [myWidth, myHeight];
	},

    ////////////////////////////////////////////////////////////////////////////
    //This function will return a client side ASP.NET control using the name of the
    // control's HTML ID field. This will work for controls that get there client
    // side (ClientID) changed by .NET.
    FindASPXControl:function(sType, sName, oParent)
    {
	    var coll;

	    //Find the control
	    if(oParent != null)
		    coll = oParent.getElementsByTagName(sType);
	    else
		    coll = document.body.getElementsByTagName(sType);

	    if(coll != null)
	    {
		    for(var i = 0; i < coll.length; i++) 
		    {
			    var obj = coll[i];
			    if((obj.id == sName) || (obj.id.indexOf(sName) > -1))
			    {
				    //alert("FindASPXControl: " + obj.name);
				    return obj;
			    }
		    }
	    }
	    return null;      
    }
	
}

SBNetWC.Util.AttachEvent(document, "onmousedown", SBNetWC.Util.HideDivList);

//</SCRIPT>
