var popupWindow;
try
{

	popupWindow = GetRadWindow();

	if (popupWindow){}

}
catch(e)
{
	popupWindow = null;
}

if (popupWindow != null)
{
	self.close = function () {
		closeEditWindow();
	}
}

function closeEditWindow()
{
	var wnd = GetRadWindow();
	wnd.Close();
}

function getScreenResolution()
{
	document.getElementById("ScreenResolution").value = screen.width;
}
/*
function openEditWindow(name, url)
{
	var nLeft = (window.screen.availWidth) / 8;
	var nTop = (window.screen.availHeight) / 8;
	var nHeight = (window.screen.availHeight) * .75;
	var nWidth = (window.screen.availWidth) * .75;
	
	var url2 = '';
	if (url.indexOf('?') > 0)
		{
		url2 = url + '&res=' + window.screen.width
		}
	else
		{
		url2 = url + '?res=' + window.screen.width
		}
		
	var theWin = window.open(url2,name,'directories=0,toolbar=no,status=yes,scrollbars=yes,resizable=yes,screenX=0,screenY=0,left=' + nLeft + ',top=' + nTop + ',width=' + nWidth + ',height=' + nHeight + '')
	if (theWin) theWin.focus();
}
*/
function openEditWindow(name, url)
{   
    var nLeft = (window.document.body.clientWidth) / 8;
    var nTop = (window.document.body.clientHeight) / 8;
    var nHeight = (window.document.body.clientHeight) * .75;
    var nWidth = (window.document.body.clientWidth) * .75;
    
    var url2 = '';
    
    if (url.indexOf('?') > 0)
    {
        url2 = url + '&res=' + window.screen.width
    }
    else
    {
        url2 = url + '?res=' + window.screen.width
    }

    var oManager = null;
    
    try
    {
        oManager = GetRadWindowManager();
        var wnd = oManager.Open(url2, name);
        window.AdminMenu_MenuPanel.disabled = true;
     }
     catch(e){}

    try
    {
        var oWnd = GetRadWindow();
        oManager = GetRadWindow().GetWindowManager();
        nLeft = (oWnd.BrowserWindow.document.body.clientWidth) / 8;
        nTop = (oWnd.BrowserWindow.document.body.clientHeight) / 8;
        nHeight = (oWnd.BrowserWindow.document.body.clientHeight) * 0.75;
        nWidth = (oWnd.BrowserWindow.document.body.clientWidth) * 0.75;
        url2 = "CMSAdmin/" + url2;
        var wnd = oManager.Open(url2, name);
    }
    catch(e){}
    
    wnd.SetSize(nWidth, nHeight);
    wnd.MoveTo(nLeft, nTop);
    
} 
function RadWindow_ClientShow(wnd)
{
    wnd.Reload();
}
/*
 Refresh Parent Window..
 Similar to window.parent.location.reload()
 */
function reloadParentWindow()
{
	var wnd = GetRadWindow();
	var a = popupWindow.GetWindowManager().GetWindows();

	// apparently 2 with one RadWindow open.
	if (a.length == 2)
	{
		wnd.BrowserWindow.location.reload();
	}
	else
	{
		// Seems to be that the order is <Browser Window> -> <First RadWindow> -> <Second RadWindow>
		// So we subtract 2 from the length, i.e. 3 - 2 = 1 = the second array item
		a[a.length - 2].Reload();
	}
	wnd.Close();
}

/*
 Redirect Parent Window to specific URL..
 Similar to window.parent.location.href
 */
function redirectParentWindow(url)
{
    var wnd = GetRadWindow();
	var a = popupWindow.GetWindowManager().GetWindows();
	
	if (a.length == 1)
	{
		wnd.BrowserWindow.location.href = url;
	}
	
	wnd.Close();
}

function openWindow(name, url, nWidth, nHeight)
{      
    var nLeft = (window.document.body.clientWidth) / 8;
    var nTop = (window.document.body.clientHeight) / 8;
     
    var url2 = '';
    
    if (url.indexOf('?') > 0)
    {
        url2 = url + '&res=' + window.screen.width
    }
    else
    {
        url2 = url + '?res=' + window.screen.width
    }

    var oManager = null;
    
    try
    {
        oManager = GetRadWindowManager();
        var wnd = oManager.Open(url2, name);
        window.AdminMenu_MenuPanel.disabled = true;
     }
     catch(e){}

    try
    {
        var oWnd = GetRadWindow();
        oManager = GetRadWindow().GetWindowManager();               
        var wnd = oManager.Open(url2, name);
    }
    catch(e){}
    
    wnd.SetSize(nWidth, nHeight);
    wnd.MoveTo(nLeft, nTop); 
    
    if (!wnd) return;     
} 

function RadWindow_ClientClose(wnd)
{
    var oManager = GetRadWindowManager();
    // apparently 1 because the window is still closing
    if (oManager.GetWindows().length == 1)
    {
        window.AdminMenu_MenuPanel.disabled = false;
    }
}
function GetRadWindow()
{   
    var oWindow = null;    
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
    
    return oWindow;
}


function CloseOnReload()
{
    GetRadWindow().Close();    
}

function divDisplay(divID)
{
	if (document.getElementById(divID).style.display == 'block')	{
		document.getElementById(divID).style.display = "none";
	}
	else	{
		document.getElementById(divID).style.display = "block";
	}
}

function divDisplaySwitch(divID, YesNoID)
{
	if (document.getElementById(YesNoID).value == 'Yes' || document.getElementById(YesNoID).value == 'yes')	{
		document.getElementById(divID).style.display = "block";
	}
	else	{
		document.getElementById(divID).style.display = "none";
	}
}

function switchPage(currentDiv, requestedDiv)
{
	divDisplay(currentDiv);
	divDisplay(requestedDiv);
}
