var m_off = new Image();
var m_on = new Image();

var dpObject = null;
var ServerTime;

var XDTypeFilter = "";
var XDUnitFilter = "";
var GD_RefreshCount = 5;
var GD_CurrentCount = 0;
var GD_TimeInterval = 0;
var GD_DateFrom = "";
var GD_DateTo = "";
var GD_SpcParam = "";

var PageAppPath = "";

m_off.src = PageAppPath + "images/plus.gif";
m_on.src = PageAppPath + "images/Minus.gif";

window.onload = function ()
{
	if (getCookie(".WEBDEVLAYOUT")==null)
		setCookie(".WEBDEVLAYOUT", 1);

	if (getCookie(".WEBDEVLAYOUT") == "1")
		HidePanel("pmDivert", "imgpmDivert");
}


function debugInfo( msg )
{
	alert(msg);
}

function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getCookie(name)
{
	c = document.cookie;
	var index = c.indexOf(name + "=");
	if (index == -1) return null;
	index = c.indexOf("=", index) + 1;
	var endstr = c.indexOf(";", index);
	if (endstr == -1) endstr = c.length; 
	return unescape(c.substring(index, endstr));
}

function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" + 
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function PanelToggle(ename, f)
{
		var e = document.getElementById(ename);
		if(e == null) return;
		e.style.height = e.offsetHeight;
		h = parseInt(e.style.height);


		if (getCookie(".WEBDEVLAYOUT")==0)
		{
			window.clearInterval(e.getAttribute("timer"));
			e.setAttribute("origHeight",h);
			e.setAttribute("timer", window.setInterval("PanelShrink('" + ename + "')", 20));
			if(f != null) f.src = m_off.src;
			setCookie(".WEBDEVLAYOUT", 1);
		}
		else
		{
			window.clearInterval(e.getAttribute("timer"));
			e.style.height="2";
			e.setAttribute("timer", window.setInterval("PanelExpand('" + ename + "')", 20));
			if(f != null) f.src = m_on.src;
			setCookie(".WEBDEVLAYOUT", 0);
		}
}

function PanelSnapToggle(ename,f)
{
	e = document.getElementById(ename);
	if(e == null) return;

	e.style.height = e.offsetHeight;
	h = parseInt(e.style.height);
	if (h < e.getAttribute("origHeight"))
	{
		e.style.display = "block"
		e.style.height = e.getAttribute("origHeight");
		g = e.filters.item(0);
		g.opacity = 100;
		if(f != null) f.src = m_on.src;
	} else
	{
		e.setAttribute("origHeight",h);
		e.style.height = "0px";
		e.style.display = "none";
		if(f != null) f.src = m_off.src;
	}
}

function HidePanel(ename, ctrl)
{
	e = document.getElementById(ename);
	if(e == null) return;

//	f = e.filters.item(0);
	window.clearInterval(e.getAttribute("timer"));
	e.style.height="0px";
	e.style.display = "none";
//	f.opacity = 0;
	var xl = document.getElementById(ctrl);
	if(xl == null) return;
	xl.src = m_off.src;
}
	
function PanelShrink(ename)
{
	e = document.getElementById(ename);
	if(e == null) return;

	var i = e.style.height.indexOf( 'p' );
	if( i > 0 ) h = parseFloat(e.style.height.substring(0, i));
	else
		h = parseFloat(e.style.height);		
	oh = e.getAttribute("origHeight");

//	f = e.filters.item(0);

	if(h <= 2)
	{
		window.clearInterval(e.getAttribute("timer"));
		e.style.height="0px";
		e.style.display = "none";
//		f.opacity = 0;
	}
	e.style.height = Math.round(h / 1.25);
	pc = Math.round(h / oh * 100);
//	f.opacity = pc;

}

function PanelExpand(ename)
{
	e = document.getElementById(ename);
	if(e == null) return;

	e.style.display = "block";
	h = parseFloat(e.style.height);
	oh = e.getAttribute("origHeight");
//	f = e.filters.item(0);
	if (h >= oh)
	{
		window.clearInterval(e.getAttribute("timer"));
		e.style.height = e.getAttribute("origHeight");
//		f.opacity = 100;
	} else
	{
		nh = Math.round(h*1.25);
		if (nh > oh) nh=oh;
		pc = Math.round(h/oh * 100);
		e.style.height = nh;
//		f.opacity = pc;
	}

}

function OpenWindow(url, name, width, height, options, fullscreen)
{
	window.focus();

	var sw = window.screen.width;
	var sh = window.screen.height;

	var opts = "status=no,toolbar=no,menubar=no,location=no";
	if(fullscreen == true)
	{
		opts += ",scrollbars=1,fullscreen=1";
	}
	else
	{
		opts += ",scrollbars=0,resizable=0";
		if( width != null ) opts += ",width=" + width;
		if( height != null ) opts += ",height=" + height;
		if( options != null ) opts += "," + options;
		opts += ",left=" + (sw - width) / 2;
		opts += ",top=" + (sh - height) / 2;
	}
	var childWin = window.open(url, name, opts, true );
	childWin.focus();
	return childWin;
}

function link_analyzer( Marker, objectConstructor, ObjectData )
{
	var Type = Marker != null ? Marker.toLowerCase() : null;

	this.getType = function ()
	{
		return Type;
	}

	this.findArray = function findArray( Container )
	{
		if( window.document.layers != null ) return Container.document.links;
		else if( document.all != null ) return (Container != window ? Container : document).all.tags( 'a' );
		else return null;
	}

	function getPath( Link )
	{
		var Ret = unescape( Link.href );
		var i = Ret.indexOf( '#' );
		if( i > 0 ) Ret = Ret.substring(0, i);
		if( Link.pathname == '/' && Ret.charAt(Ret.length - 1) != '/' ) Ret += '/';
		return Ret; 
	}

	function getHash( Link )
	{
		var i = Link.href.indexOf( '#' );
		if(0 < i)
		{
			if(i + 1 < Link.href.length)
				return Link.href.substring(i + 1); 
		}
		return null;
	}

	this.accept = function accept( Element, Container )
	{
		var Hash = getHash( Element );
		if( Hash == null ) return false;
		//***	if( getPath(Element) != getPath(Container.window.document.location) )
		//***		return false;
		//***

		var Anchors = Container.window.document.anchors;
		for( var i = 0 ; i < Anchors.length ; i++ )
			if( Anchors[i].name == Hash ) return false;
		return (Type == null || Hash.toLowerCase().search(Type) != -1);
	}

	this.createObject = function createObject( Element, Container )
	{
		var Object = new objectConstructor( Element, Container, getHash(Element), ObjectData );
	}
}
function linkMenuActivator( Link, Container, Name, Layout )
{
	var DELAY_FOR_MOUSE_OUT_ACTIVATOR = 120;

	var Menu = findLayer( Name, Container.window.document );
	if( Menu == null ) return null;

	if( document.layers != null )
	{
		Link.getAbsolutePosition = function ()
		{
			if( Container == Container.window ) return {X: Link.x, Y: Link.y};
			else return {X: Link.x + Container.pageX, Y: Link.y + Container.pageY};
		}

		function getValueOf( SizeString )
		{
			var M = SizeString.match( /([0-9]+\.?[0-9]*)([a-zA-Z]*)/ );
			switch( M[2] )
			{
				case 'px': return parseInt( M[1] );
				case 'pt': return parseInt( M[1] )*96/72;
				case 'mm': return parseInt( M[1] )*96/25.4;
				case 'cm': return parseInt( M[1] )*96/2.54;
			}
		}

		Link.getSize = function ()
		{
			var DEFAULT_FONT_SIZE = 16;
			var DEFAULT_TEXT_LENGTH = 8;
			var FontSize;
			if( document.tags['a'].fontSize != null ) FontSize = getValueOf( document.tags['a'].fontSize );
			else if( document.tags['body'].fontSize != null ) FontSize = getValueOf( document.tags['body'].fontSize );
			else FontSize = DEFAULT_FONT_SIZE;
			var W = FontSize*(0.5*(Link.text != null ? Link.text.length : DEFAULT_TEXT_LENGTH) + 0.2);
			var H = FontSize*1.5;
			return {Width: Math.round(W), Height: Math.round(H)};
		}

		Link.getContext = function ()
			{
				return Container;
			}

		function cancel()
			{
				return false;
			}
		}
		else if( document.all != null )
		{
			Link.getAbsolutePosition = function ()
			{
				var e = Link;
				if( e == null ) return null;
				var x = 0;
				var y = 0;
				var n = e;
				while( n != null )
				{
					x += n.offsetLeft;
					y += n.offsetTop;
					n = n.offsetParent;
				}
				return {X: x, Y: y};
			}
			
			Link.getSize = function ()
			{
				return {Width: Link.offsetWidth, Height: Link.offsetHeight};
			}

			Link.getContext = function ()
			{
				for( var P = Link.offsetParent ; P.tagName != 'BODY' ; P = P.offsetParent )
					if( P.tagName != 'TABLE' && P.tagName != 'TR' && P.tagName != 'TD' ) return P;
			return Container.window;
			}

			function cancel()
			{
				event.cancelBubble = true;
				return false;
			}
		}
		else return null;

	function findLayer( ID, Document )
	{
		var Ls = Document.layers;
		if( Ls == null ) return Document.all[ID];
		if( Ls[ID] != null ) return Ls[ID];
		var L;
		for( var i = 0 ; i < Ls.length ; i++ )
		{
			L = findLayer( ID, Ls[i].document );
			if( L != null ) return L;
		}
		return null;
	}

	Link.onmouseover = function onMouseOver( Evt )
	{
		Menu.clearHide();
		Menu.place( Link.getAbsolutePosition(), Link.getSize(), Layout );
		Menu.show();
		return cancel();
	}

	Link.onmouseout = function onMouseOut( Evt )
	{
		Menu.hideAfter( DELAY_FOR_MOUSE_OUT_ACTIVATOR );
		return cancel();
	}
	Link.href = "#"; //Container.window.document.location.href;
	Menu = new menu( Menu, Link.getContext() );
	return Link;
}
