ICL.Web.Bookmark =
	function()
	{
		var title = document.title;
		var url = location.href;
		if (window.sidebar) 
		{
			window.sidebar.addPanel(title, url, '');
		}
		else if (window.opera && window.print)
		{
			var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
		} 
		else if (document.all)
		{
			window.external.AddFavorite(url, title);
		}
	}

ICL.Web.Boolean = 
	function(s1)
	{

		if (isNaN(parseInt(s1)))
		{
			if (s1.toLowerCase().substring(0,1) == 't')
				return true;
		}
		else
		{
			if (parseInt(s1) != 0)
				return true;
		}
		
		return false;
		
	}

ICL.Web.ErrorAlert = 
	function (el, Message)
	{
		alert(Message);
		el.focus();
		return true;
	}
	
ICL.Web.HasValue = 
	function(s1)
	{

		if (s1 != undefined && s1 != null && s1 != '')
			return true;
			
		return false;
		
	}

ICL.Web.PositionInlinePopup = 
	function(anchor, popup, xOffset, yOffset)
	{
		var anchorTop = YAHOO.util.Dom.getY(anchor);
		var anchorLeft = YAHOO.util.Dom.getX(anchor);
		
		var popupTop = anchorTop + anchor.offsetHeight + 2 + yOffset;
		if (popupTop + popup.offsetHeight > YAHOO.util.Dom.getClientHeight() && anchorTop - popup.offsetHeight - 2 - yOffset > 0)
			popupTop = anchorTop - popup.offsetHeight - 2 - yOffset;
			
		var popupLeft = anchorLeft + xOffset;
		if (popupLeft + popup.offsetWidth > YAHOO.util.Dom.getClientWidth() && anchorLeft + anchor.offsetWidth - popup.offsetWidth + xOffset > 0)
			popupLeft = anchorLeft + anchor.offsetWidth - popup.offsetWidth + xOffset;
			
		YAHOO.util.Dom.setStyle(popup, 'top', popupTop, 'px');
		YAHOO.util.Dom.setStyle(popup, 'left', popupLeft, 'px');
	}
	
ICL.Web.Selection = 
	new function()
	{

		this.range = function()
		{
		
			if (window.getSelection)
			{
				return window.getSelection();
			}
			else if (document.getSelection)
			{
				return document.getSelection();
			}
			else if (document.selection)
			{
				return document.selection.createRange();
			}
			
			return null
		}
		
		this.text = function()
		{
			var r = this.range();
					
			if (window.getSelection)
			{
				return r.toString();
			}
			else if (document.getSelection)
			{
				return r.toString();
			}
			else if (document.selection)
			{
				return r.text;
			}
			
			return null;
			
		}
		
		this.clear = function(el)
		{

			var s = el.value;
			var t = this.text();
				  
			if (t.length > 0) 
			{
				s = s.replace(t, '');					
				el.value = s;
				//TODO: get ClearPartialSelection function working correctly
				el.value.focus;
			}
		}
		
	}

ICL.Web.XmlDoc = 
	function()
	{
		var xdoc;
		if (window.ActiveXObject)
		{
			xdoc = new ActiveXObject("Microsoft.XMLDOM");
			xdoc.async = false;
		}
		else
		{
			xdoc = document.implementation.createDocument("","",null);
		}
		return xdoc;
	}

ICL.Web.ScrollHeight = 
	function() 
	{
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return scrOfY;
	}
	

ICL.Web.ScrollWidth = 
	function() 
	{
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return scrOfX;
	}
	
ICL.Web.DDList = 
	function(id, sGroup, config) 
	{

		ICL.Web.DDList.superclass.constructor.call(this, id, sGroup, config);

		var el = this.getDragEl();
		YAHOO.util.Dom.setStyle(el, "opacity", 0.67); // The proxy is slightly transparent

		this.goingUp = false;
		this.lastY = 0;
	};

YAHOO.extend(ICL.Web.DDList, YAHOO.util.DDProxy, 
{

    startDrag: 
		function(x, y) 
		{

			// make the proxy look like the source element
			var dragEl = this.getDragEl();
			var clickEl = this.getEl();
			YAHOO.util.Dom.setStyle(clickEl, "visibility", "hidden");

			dragEl.innerHTML = clickEl.innerHTML;

			YAHOO.util.Dom.setStyle(dragEl, "color", YAHOO.util.Dom.getStyle(clickEl, "color"));
			YAHOO.util.Dom.setStyle(dragEl, "backgroundColor", YAHOO.util.Dom.getStyle(clickEl, "backgroundColor"));
			YAHOO.util.Dom.setStyle(dragEl, "fontSize", YAHOO.util.Dom.getStyle(clickEl, "fontSize"));
			YAHOO.util.Dom.setStyle(dragEl, "fontWeight", YAHOO.util.Dom.getStyle(clickEl, "fontWeight"));
			YAHOO.util.Dom.setStyle(dragEl, "border", "1px solid #cc9900");
		},

    endDrag: 
		function(e) 
		{

			var srcEl = this.getEl();
			var proxy = this.getDragEl();

			// Show the proxy element and animate it to the src element's location
			YAHOO.util.Dom.setStyle(proxy, "visibility", "");
			var a = new YAHOO.util.Motion( 
				proxy, 
				{ 
					points: 
					{ 
						to: YAHOO.util.Dom.getXY(srcEl)
					}
				}, 
				0.2, 
				YAHOO.util.Easing.easeOut 
			)
			var proxyid = proxy.id;
			var thisid = this.id;

			// Hide the proxy and show the source element when finished with the animation
			a.onComplete.subscribe(function() {
					YAHOO.util.Dom.setStyle(proxyid, "visibility", "hidden");
					YAHOO.util.Dom.setStyle(thisid, "visibility", "");
				});
			a.animate();
		},

    onDragDrop: 
		function(e, id) {

			if (id.indexOf('DragList') > -1)
			{
				var elUl = YAHOO.util.Dom.get(id);
				var elLi = elUl.getElementsByTagName('li');
				var newOrder = new Array();
				for (var i=0;i<elLi.length;i++) 
				{
					newOrder.push(ICL.Web.TextBox.stringAttribute(YAHOO.util.Dom.get(elLi[i].id), 'key', ''));
				}
				var elOrder = YAHOO.util.Dom.get(id.replace(/DragList/,'SortedValues'));
				elOrder.value = newOrder.join(',');
			}
			
		},

    onDrag: 
		function(e) {

			// Keep track of the direction of the drag for use during onDragOver
			var y = YAHOO.util.Event.getPageY(e);

			if (y < this.lastY) {
				this.goingUp = true;
			} else if (y > this.lastY) {
				this.goingUp = false;
			}

			this.lastY = y;
		},

    onDragOver: 
		function(e, id) {
	    
			var srcEl = this.getEl();
			var destEl = YAHOO.util.Dom.get(id);

			// We are only concerned with list items, we ignore the dragover
			// notifications for the list.
			if (destEl.nodeName.toLowerCase() == "li") {
				var orig_p = srcEl.parentNode;
				var p = destEl.parentNode;

				if (this.goingUp) {
					p.insertBefore(srcEl, destEl); // insert above
				} else {
					p.insertBefore(srcEl, destEl.nextSibling); // insert below
				}

				YAHOO.util.DragDropMgr.refreshCache();
			}
		}
});
