﻿// JScript File

function ADAjax()
{
    
}

ADAjax.ADRefObjects = new Array();


// RAD window functions
ADAjax.openRadWindow = function(WindowName, URL)
{
    window.radopen(URL, WindowName);
}

ADAjax.closeRadWindow = function(Argument)
{
   var oWindow = ADAjax.getRadWindow();
    if (oWindow != null) 
    {
        if (Argument == null) Argument = "";
        oWindow.Argument = Argument;
        oWindow.Close();
    } 
}

ADAjax.openRadWindowStatic = function(WindowName, URL, checkFunc, param)
{
   var oManager = GetRadWindowManager();
   var isOpen = true;
   var oW;
   var oFunc
   if (!oManager) return;
   
   var oWnd = oManager.GetWindowByName(WindowName);
   
   if (oWnd != null)
   {
        if (oWnd.GetUrl())
        {
            if (checkFunc)
            {
                oW = oWnd.GetContentFrame().contentWindow
                oFunc = eval("oW." + checkFunc)
                if (oFunc)
                {
                    isOpen = false;
                    oFunc(param)
                }
            }
            else
                {isOpen = false;}
        }
   }
   
   if (isOpen)
       window.radopen(myWeb.URLWithRnd(URL),WindowName);
   else
        oWnd.Show();
}

ADAjax.hideRadWindow = function()
{
     var oWindow = ADAjax.getRadWindow();
    if (oWindow != null)
    {
        oWindow.Hide()
    }
}

ADAjax.getObject = function(oName)
{
    return document.getElementById(ADAjax.getObjectNameV1(oName));
}

ADAjax.getObjectNameV1 = function (objName)
{
    var tmpStr = new String("");
    var tmpVal = new Number(-1);
    
    tmpStr = objName;
    if (tmpStr.length < 5) return objName;
    
    tmpStr = tmpStr.toUpperCase();
    if (tmpStr.indexOf("__RO") != 0) return objName;
    tmpStr = tmpStr.substr(4)
    if (isNaN(tmpStr) == true) return objName;
    tmpVal = parseInt(tmpStr);
    if (tmpVal < 0) return objName;
    if (tmpVal >= ADRefObjects.length) return objName;
    
    return ADRefObjects[tmpVal];
        
}

ADAjax.getObjectName = function (objName)
{
    var tmpStr = new String("");
    var tmpVal = new Number(-1);
    var arr = ADAjax.ADRefObjects;
    
    tmpStr = objName;
    if (tmpStr.length < 5) return objName;
    
    tmpStr = tmpStr.toUpperCase();
    if (tmpStr.indexOf("__RO") != 0) return objName;
    tmpStr = tmpStr.substr(4)
    if (isNaN(tmpStr) == true) return objName;
    tmpVal = parseInt(tmpStr);
    if (tmpVal < 0) return objName;
    if (tmpVal >= arr.length) return objName;
    
    return arr[tmpVal];
        
}

ADAjax.hide = function(oName)
{
    var obj = ADAjax.getObject(oName)
    if (obj != null) 
    {obj.style.display = "none";}
 
}
                
ADAjax.show = function(oName, style)
{
    obj = ADAjax.getObject(oName);
    if (obj != null) 
    {
        if (style == null) style = "";
        obj.style.display = style;
    }
}

ADAjax.getRadWindow = function()
	{
	    try
	    {
		var oWindow = null;
		if (window.radWindow) oWindow = window.radWindow;
		else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
		return oWindow;
		}
		catch(e)
		{
		    return null;
		}
	}

ADAjax.setObjectRef = function(objName, index)
{
    try
    {
        var tmpVal;
        if (objName.length > 0)
        {
            if (isNaN(index) == false)
            {
                 tmpVal = parseInt(index);
                 ADAjax.ADRefObjects[tmpVal] = objName;
            }
        }
    }
    catch(e){}
}

ADAjax.setObjectRefV1 = function(objName, index)
{
    try
    {
        var tmpVal;
        if (objName.length > 0)
        {
            if (isNaN(index) == false)
            {
                 tmpVal = parseInt(index);
                 ADRefObjects[tmpVal] = objName;
            }
        }
    }
    catch(e){}
}


ADAjax.openDialog = function(url, refreshObjName, windowName, objIndex)
{
    if (windowName == null) windowName ="dlgMedium";
    if (objIndex == null) objIndex = 0;
    ADAjax.setObjectRef(refreshObjName, objIndex);
    ADAjax.openRadWindow(windowName, url)
}

ADAjax.openDialogV1 = function(url, refreshObjName, windowName, objIndex)
{
    if (windowName == null) windowName ="dlgMedium";
    if (objIndex == null) objIndex = 0;
    ADAjax.setObjectRefV1(refreshObjName, objIndex);
    ADAjax.openRadWindow(windowName, url)
}

ADAjax.getFunction = function(funcName, frameName)
{
    try
    {
    var oFunc;
    var oFrame;
    var tmpVal;
    //alert(typeof window.parent.frames['ifPInfo'])
    //alert(eval("window.parent.frames['ifPInfo'].LoadTopPInfo"))
    //funcName can be passed as FrameName:FunctionName
    try{
    tmpVal = funcName.indexOf(":")
    if (tmpVal > 0)
    {
        tmpStr = funcName
        funcName = tmpStr.substr(0,tmpVal)
        frameName = tmpStr.subStr(tmpVal +1)
    }}catch(e){}
    
    if (typeof frameName == 'string') 
    {
        oFrame = ADAjax.getFrame(frameName)
        if (oFrame == null) return null;
        oFunc = ADAjax.getFuncByCall.call(oFrame,funcName)
        if (oFunc != null) return oFunc; 
        
        return null;
    }
    
    if (window.parent == null) return null;
    oFunc = eval("window.parent." + funcName)
    if (typeof oFunc == 'function') return oFunc;
    
    if (window.top == null) return null;
    oFunc = eval("window.top." + funcName)
    if (typeof oFunc == 'function') return oFunc;
    }
    catch(e){alert(e.message)}
    return null;
}

ADAjax.getFuncByCall = function (funcName)
    {
        var oFunc;
        var tmpStr = "this." + funcName
        oFunc = eval(tmpStr)
        if (typeof oFunc == 'function') return oFunc;
        return null
    }

ADAjax.alertFunction = function(funcName, frameName)
{
    var oFunc = ADAjax.getFunction(funcName, frameName)
    if (oFunc == null)
    {
        alert("Application may be partially loaded.")
        return null;
    }
    return oFunc;
}

ADAjax.getFrame = function(frameName)
{
    try
    {
    var oFrame;
    //alert(typeof window.parent.frames['ifPInfo'])
    //alert(eval("window.parent.frames['ifPInfo'].LoadTopPInfo"))
    if (typeof frameName != 'string') return null;
    
    oFrame = eval("window.frames['" + frameName + "']")
    if (oFrame != null) return oFrame;
    
    oFrame = eval("window.parent.frames['" + frameName + "']")
    if (oFrame != null) return oFrame;
    
    oFrame = eval("window.top.frames['" + frameName + "']")
    if (oFrame != null) return oFrame;
    
    return null;
    
    }
    catch(e){alert(e.message)}
    return null;
}

ADAjax.alertFrame = function(frameName)
{
    var oFrame = ADAjax.getFrame(frameName)
    if (oFrame == null)
    {
        alert("Application may be partially loaded.")
        return null;
    }
    return oFrame;
}




