//<!--
/************
This file is part of Genwi JS Lib.
All Rights Reserved.

Desc: HTML Controls.

************/

function HTML(pName)
{
    this.name = pName;
	this.elem = _GL.getUIElem(pName);

	this.show = function(pShow, pNoDisplayChange)
	{
		var e = this.elem;
		if (e)
		{
			e.style.visibility = pShow ? 'visible' : 'hidden';
			if (!pNoDisplayChange)
				e.style.display = pShow ? '' : 'none';
		}
	}

	this.enable = function(pEnable)
	{
		var e = this.elem;
		if (e)
			e.disabled = !pEnable;
	}

	this.focus = function(pFocus)
	{
		var e = this.elem;
		if(e)
		{
			with(e)
			{
				if (pFocus)
					focus();
				else
					blur();
			}
		}
	}

	this.setStyle = function(pStyle, pVal)
	{
		var e = this.elem;
		if (e && !e.length && pVal != null)
			eval('e.style.' + pStyle + '="' + pVal + '"');
	}

	this.setClass = function(pClass)
	{
		var e = this.elem;
		if (e)
			e.className = pClass;
	}

	this.getClass = function()
	{
		var e = this.elem;
		if (e)
			return e.className;
		else
			return "";
	}

	this.setText = function(pText)
	{
		var e = this.elem;
		if(e)
		{
			if (_GL.oClient.bFirefox)
				e.textContent = pText;
			else
				e.innerText = pText;
		}
	}

	this.getText = function()
	{
		var e = this.elem;		
		if (e)
		{
			if (_GL.oClient.bFirefox) 
				return e.textContent;
			else
				return e.innerText;
		}
	}
	
	this.setValue = function(pVal)
	{
		var e = this.elem;
		if (e)
			e.value = pVal;
	}

	this.getValue = function()
	{
		var e = this.elem;
		if (e)
			return e.value;
		return null;
	}
}

function HTMLLayer(pName)
{
	this.base = HTML;
	this.base(pName);

	this.getValue = function()
	{
		var e = this.elem;
		if (e)
			return e.innerHTML;
		else
			return "";
	}

	this.setValue = function(pVal)
	{
		var e = this.elem;
		if (e)
			e.innerHTML = pVal;
	}
}

function HTMLAnchor(pName)
{
	this.base = HTML;
	this.base(pName);

	this.enableBase = this.enable;
	this.enable = function(pEnable)
	{
		var b = pEnable;
		var e = this.elem;
		if (e)
		{
			e.setStyle('cursor', b ? 'hand' : 'default');
			e.setStyle('color', b ? '' : '#CCC');
			this.enableBase(b);
		}
	}
	
	this.setText = function(pTxt)
	{
	    var e = this.elem;
	    if (e)
	    {
	        if (e.innerText)
	            e.innerText = pTxt;
	        else
	            e.textContent = pTxt;
	    }
	}
}

function Overlay(pName, pWidth, pHeight, pShadow, pContentDiv)
{
	this.base = HTMLLayer;
	this.base(pName);

	this.sLeft = this.sTop = -1;
	this.sWidth = pWidth;
	this.sHeight = pHeight;
	this.bShadow = pShadow;
	this.oContentDiv = pContentDiv ? new HTMLLayer(pContentDiv) : null;

	this.display = function(pDisplay)
	{
	    with(this)
	    {
	        var b = pDisplay;
	        
	        if (bShadow)
				_GL.showShadow(b);
	        
	        show(b);
	        
	        if (!b && typeof(oOverlay != 'undefined'))
	            oOverlay = null;
	        
	        if (typeof oReader != 'undefined')
	            oReader.bNaviDisabled = b;
	    }
	           
	}
	
	this.setContent = function(pValue)
	{
	    with(this)
	    {
	        if (oContentDiv)
		        oContentDiv.setValue(pValue);
		    else
		        setValue(pValue);
		        
		    if (sWidth)
		        setStyle('width',  sWidth + 'px');
		    
		    if (sHeight)
		        setStyle('height', sHeight + 'px');
		}
	}

	this.setPosition = function(pLeft, pTop)
	{
		var l = t = 0;
		if (!pLeft || !pTop)
		{
			var a = this.getCenterPos();
			l = a[0];
			t = a[1];
		}
		else
		{
			l = pLeft;
			t = pTop;
		}
		
		this.setStyle('left', l + 'px');
		this.setStyle('top', parseInt(t) + 'px');
	}

	this.getCenterPos = function()
	{
		var bd = document.body, 
			h = w = l = t = 0;
		
		
		if (document.documentElement)
		{
		    h = document.documentElement.clientHeight;
		    w = document.documentElement.clientWidth;
		}
		else
		{
		    h = window.innerHeight;
			w = window.innerWidth;   
		}
	    
	    var eh = this.sHeight || this.elem.offsetHeight,
	        ew = this.sWidth || this.elem.offsetWidth;
	    
		t = bd.scrollTop + (h - eh)/2;
		if (document.documentElement)
			t += document.documentElement.scrollTop;
		
		l = w/2 - ew/2;
		
		return [l, t];
	}
	
	this.resize = function()
	{
	    var fn = this.sIfName,
	        f = window.frames ? window.frames[fn] : _GL.getUIElem(fn);
	  
	    if (f)
	    {
	        var oDoc=f.document?f.document:f.contentDocument,db=oDoc.body,
	        h=db.offsetHeight ? db.offsetHeight : oDoc.height;
	        
	        f.frameElement.style.height = h +'px';
	        f.frameElement.style.width = '100%';
	    }
	}
}

function OverlayPopup (pName, pWidth, pHeight, pShadow, pUrl, pContentDiv)
{
    this.base = Overlay;
	this.base(pName, pWidth, pHeight, pShadow,pContentDiv);
	this.sIfName = this.name + _GL.getRandomNumber();
	
	this.sUrl = pUrl;
	
	this.displayBase = this.display; 
	
	this.display = function(pDisplay)
	{
	    with(this)
	    {
	        var b = typeof pDisplay != 'undefined' ? pDisplay : true;
	        setContent(b ? getIframeUI() :  _GL.getBaseUrl() + 'images/s.gif');
	        displayBase(b);
	        
	        if (b)
	            setPosition();
	    }   
	}
	
	this.close = function()
	{
	    this.display(false);
	}
	
	this.getIframeUI = function()
	{
	    with(this)
	    {
	        var s = '';
	        s+='<iframe frameborder="no" border="0" marginwidth="0" marginheight="0"';
	        s+= ' scrolling="no"';
	        s+=' id="'+ sIfName + '" name="'+ sIfName +'"';
	        s+=' src="'+ sUrl + '"';
	        s+=' width="'+sWidth+'" height="'+sHeight+'"';
            s+='></iframe>';
            
            return s;
        }	
	}
}

function infoBubble(pName,pWidth,pHeight)
{   
    this.base = Overlay;
	this.base(pName, (pWidth || '200'), (pHeight || '200'), false, pName);
	this.sClose = '<a href="#" id="ibClose">Close</a>';
	this.oClose = null;
	
	this.showInfo = function(pValue, pEvent)
	{
	    this.setContent(pValue + this.sClose);
	    this.display(true);
	    var e = pEvent ? pEvent : event, posX, posY;
	    if (e.pageX || e.pageY) 	
	    {
		    posX = e.pageX;
		    posY = e.pageY;
	    }
	    else if (e.clientX || e.clientY)
	    {
	        posX = e.clientX;
		    posY = e.clientY;
	    }
	    this.setPosition(posX-100,posY+5);
	    
	    this.oClose = _GL.getUIElem('ibClose');
	    this.oClose.oIB = this;
	    this.oClose.onclick = function()
	    {
	        this.oIB.display(false);
	        return false;
	    }
	}
}

function selAll(pSel, pForm)
{
    var oFrm = document.forms[pForm];
    if (oFrm)
    {
        var elems = oFrm.elements;
        if (elems)
        {
            for (var i=0, len = elems.length; i<len; i++)
            {
                var e = elems[i];
                if (e && e.type == 'checkbox')
                    e.checked = pSel;
            }
        }
    
    }
    
}

function setTextFocus(pFocusElems)
{
    var aFocusElems = pFocusElems;
    for (var i=0; i<aFocusElems.length;i++)
    {
        var oElem = _GL.getUIElem(aFocusElems[i]);
        if (oElem)
        {
            oElem.defVal = oElem.value;
            oElem.onfocus = function()
            {
                if (this.value.is(this.defVal))
                    this.value = "";
            }
            
            oElem.onblur = function()
            {
                if (this.value == "")
                    this.value = this.defVal;
            }
        }
    }
}
//-->