﻿function Test(control)
{
    var oText = control;
    



}


function openWindow(url, target)
{
	var iWidth = screen.availWidth;
	var iHeight = screen.availHeight;
	var width = 750;
	var height = 650;
	
	openCustomWindow(url, target, width, height);
	
	return false;
}

function openCustomWindow(url, target, width, height)
{
	var iWidth = screen.availWidth;
	var iHeight = screen.availHeight;
	var iLeft, iTop;

	if (width <= 0)
	    width = 750;
	if (height <= 0)
	    height = 650;
	    
	iLeft = (iWidth / 2) - (width / 2);
	iTop = (iHeight / 2) - (height / 2);

	var w = openCustomWindowWithTopAndLeft(url, target, width, height, iTop, iLeft);
	return false;
}
function openCustomWindowWithTopAndLeft(url, target, width, height, top, left)
{
    var iWidth = screen.availWidth;
    var iHeight = screen.availHeight;

    if (width <= 0)
        width = 750;
    if (height <= 0)
        height = 650;
    if (top < 0)
        top = (iHeight / 2) - (height / 2);
    if (left < 0)
        left = (iWidth / 2) - (width / 2);
        
        
    var options = "height=" + height + ",width=" + width + ",scrollbars,resizable=yes,top=" + top.toString() + ",left=" + left.toString()
    var w = window.open(url, target, options);

    w.focus();

    return w;
}
function openCustomWindowWithTopAndRight(url, target, width, height, top, right)
{
    var iWidth = screen.availWidth;
    var iHeight = screen.availHeight;
    var iLeft;

    if (width <= 0)
        width = 750;
    if (height <= 0)
        height = 650;
    if (top < 0)
        top = (iHeight / 2) - (height / 2);
    if (right < 0)
        right = 0;

    iLeft = iWidth - right - width;
    if (iLeft < 0)
        iLeft = 10;

    var options = "height=" + height + ",width=" + width + ",scrollbars,resizable=yes,top=" + top.toString() + ",left=" + iLeft.toString()
    var w = window.open(url, target, options);

    w.focus();

    return w;
}
function getBodyControl(tagName, ID)
{
    var sID; 
    var oReturn = null;
    var oControl;
    var oControls = document.getElementsByTagName(tagName);
    var iCount = oControls.length;
    
    for (var i = 0; i < iCount; i++)
    {
        oControl = oControls[i];
        
        if (ID == null)
        {
            oReturn = oControl;
            break;
        }
            
        if (oControl != null && oControl != 'null')
        {
            sID = oControl.id;
            if (IsComplexIDLookedForID(sID, ID))
            {
                oReturn = oControl;
                break;
            }
        }
    }
    return oReturn;
}

function CheckUncheck(flag)
{
	var oItems = document.getElementsByTagName("input")
	var oItem;

	for (var i=0; i < oItems.length; i++) 
	{
		oItem = oItems[i];
		
		if (oItem.type == 'checkbox')
			oItem.checked = flag;
	}
	oItem = null;
	oItems = null;
	return true;
}

function IsComplexIDLookedForID(ComplexID, LookedForID)
{
    var bRet = false;
    var sID;
    var sIDs = ComplexID.split("_");
    var iCount = sIDs.length;
    
    if (iCount > 0)
    {
        sID = sIDs[iCount - 1];
        if (sID == LookedForID || LookedForID == "")
            bRet = true;
    }
    return bRet;
}

function MarkTextInTextBox(id)
{
    var sText;
    var oControl = getBodyControl("input", id);
    
    if (oControl != null && oControl != 'undefined')
    {
	    sText = oControl.value;
	    if (sText.length > 0)
		    oControl.select();
    }
}


function popUp(evt, Element, Field) 
{
    var oElement, oField, oStyle, iLeft, iTop, iY;

    if (IsBrowserOkForJavaToolTip()) 
    {
        oElement = getBodyControl("span", Element);
        oField = getBodyControl("img", Field);
        oStyle = oElement.style;
        iY = oElement.verticaladd;

        var oBrowser = BrowserDetect;
        oElement.innerText = oField.title;
        oField.title = "";
        var iL = window.length;

        if (oBrowser.browser == "Explorer" && oBrowser.version < 9)
        {
            iTop = parseInt(evt.clientY) + parseInt(document.body.scrollTop) + parseInt(evt.y);
            iTop = (parseInt(evt.screenY));
            iTop -= 100;
            iTop = evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 150;

            iLeft = evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) - 40;
        }
        else
        {
            iTop = (parseInt(evt.pageY) + parseInt(evt.y)) / 2;
            if (iY != null && iY != 'undefined')
                iTop -= parseInt(iY);
            iLeft = Math.max(2, parseInt(evt.x) + 15);    // subtract 75 px, but if result negative, use value of 2
        }
        oStyle.pixelTop = iTop;
        oStyle.pixelLeft = iLeft

        if (oElement.innerText.length > 0)
            oStyle.visibility = "visible";
    }
}

function popDown(Element, Field, SavedText) 
{
    var oElement, oField, oStyle;
    if (IsBrowserOkForJavaToolTip()) 
    {
        oElement = getBodyControl("span", Element);
        oField = getBodyControl("img", Field);
        oStyle = oElement.style;

        oField.title = SavedText;
        oStyle.visibility = "hidden";
    }
}

function IsBrowserOkForJavaToolTip()
{
    
    if (1 == 0)
        return true;
    else
    {
        BrowserDetect.init();
        
        switch (BrowserDetect.browser) {
            case "Explorer":
                return true;
                break;
            case "Opera":
                return true;
                break;
            case "Konqueror":
                return true;
                break;
            case "Firefox":
                return false;
                break;
            case "Safari":
                // note, neither safari 3 nor 4 works with this.
                // Safari 3.2.2 = 5.0   = Safari 4 (Hmm!!!)
                // Safari 4 Public Beta = 5.0
                return false;
                break;
            case "Mozilla":
                return false;
                break;
            case "Chrome":
                return false;
                break;
            
            default:
                return false;
                break;
        }
    }
}

function isFireFox()
{

    BrowserDetect.init();

    switch (BrowserDetect.browser)
    {
        case "Firefox":
            return true;
            break;
        default:
            return false;
            break;
    }

}
