﻿function makeGenericContainerAjaxRequest(WorkSurfaceID)
{
    if (rdManager != null ) 
    { 
        var params = "ticket=" + WorkSurfaceID;
        rdManager.AjaxRequest(params);
    }
    else  alert("Unable to find the manager");
    
    return false;
}

function makeGenericAjaxRequest(WorkSurfaceID)
{
    var params = "ticket=" + WorkSurfaceID;
    rdAjaxManager.AjaxRequest(params);
    return false;
}

function makeCommandAjaxRequest(param)
{
    var params = "command=" + param;
     rdAjaxManager.AjaxRequest(params);
    return false;
}

function InitTextHelpContent(clientHelpId, section, helpContent)
{
    if ( document.getElementById(clientHelpId) != null ) return;
    var sectionObj = document.getElementById(section);
    try
	{
	    if ( sectionObj == null ) alert("Main section DIV is null");
	    //var helpSection = sectionObj.getElementById("SectionHelp");
	    var helpSection = GetElementByTagNameAndId(sectionObj, "div",section+"Help");
	    if ( helpSection == null ) alert("Unable to find help section");

	    var controlHelp = GetElementByTagNameAndId(helpSection, "div",clientHelpId);
	    if ( controlHelp == null ) AddHelpElement(helpSection, clientHelpId, helpContent);
	}
	catch(err)
	{
		alert(err.description);
	}
}

function GetElementByTagNameAndId(parentElement, tagName, id)
{
    var inputElem = parentElement.getElementsByTagName(tagName);    
            
    for(var i = 0; i < inputElem.length; i++)
    {
        var input = inputElem[i];
        if (input.id == id ) return input;
    }
    
    return null;
}

function AddHelpElement(parent, helpId, helpContent)
{
    var newHelpElem = document.createElement('div');
    newHelpElem.setAttribute('id',helpId);
    newHelpElem.innerHTML = helpContent;
    newHelpElem.className = "HelpContent";
    newHelpElem.style.display="none";
    if ( parent.childNodes.length > 0 ) parent.insertBefore(newHelpElem, parent.childNodes[0]);
    else parent.appendChild(newHelpElem);
}

function showWindowSec(url, width, height)
{
    scroll(0,0);
    alert(width);
    alert(height);
    var oManager = GetRadWindowManager();  
    var oWin = oManager.Open(url, 'rwVideoWindow');  
    oWin.SetUrl(url);
    oWin.SetSize (width, height);  
    oWin.Center();  
    
    oWin.Show();
    return false;  
}

function showWindow(url, width, height)
{
    scroll(0,0);
   
    var finalUrl = url+"&rnd=" + Math.random();
    if (GetRadWindowManager().GetWindows().length <= 0) 
    {
        var oWnd = window.radopen(finalUrl);
        oWnd.SetModal(true);
        oWnd.Show();
        oWnd.SetSize(width + 2, height);
        oWnd.Center();
        oWnd.SetUrl(finalUrl);
    }
    else
    {
        var oWnd = GetRadWindowManager().GetWindows()[0];
        oWnd.SetModal(true);
        oWnd.Show();
        oWnd.SetSize(width + 2, height);
        oWnd.Center();
        oWnd.SetUrl(finalUrl);
    }
    return false;
}

function GetParentRadWindow()
{
    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 hideWindows()
{
    GetRadWindowManager().CloseAll();
}

function CloseParentRadWindow()
{
    GetParentRadWindow().Close();
}

function MakeAjaxRequestToParent(arg, closeWindow)
{
    if ( closeWindow == 1) CloseParentRadWindow();
    var commandId = GetParentRadWindow().BrowserWindow.document.getElementById("hiddenProcessCmdId");
    if ( commandId != null )     commandId.value = "true";
    
    GetParentRadWindow().BrowserWindow.makeCommandAjaxRequest(arg);
}

function Logout()
{
    rdAjaxManager.AjaxRequest("logout");
}

//Highlights a section of a form.
function Highlight(section)
{
   document.getElementById(section).className="SectionHighlight";
   if (  document.getElementById(section+"_Help") != null )
        document.getElementById(section+"_Help").style.display="none";
}

//Makes a section of the form look like all the rest (as in not highlighted).
function Blend(section)
{
   document.getElementById(section).className="DefaultSectionHighlight";
   if (  document.getElementById(section+"_Help") != null )
        document.getElementById(section+"_Help").style.display="inline"; 
}

//Makes a particular section visible (usefull for help sections, as implied by the name).
function ShowHelp(section)
{
    document.getElementById(section).style.display="inline";
}

//Hides a particular section of text (usefull for help sections, as implied by the name).
function HideHelp(section)
{
    
    document.getElementById(section).style.display="none";
}


////Makes a particular section visible (usefull for help sections, as implied by the name).
//function ShowHelp(section, defaultHelpSection)
//{
//    document.getElementById(section).style.display="inline";
//    document.getElementById(defaultHelpSection).style.display="none"; 
//}

////Hides a particular section of text (usefull for help sections, as implied by the name).
//function HideHelp(section, defaultHelpSection)
//{
//    document.getElementById(section).style.display="none";
//    document.getElementById(defaultHelpSection).style.display="inline"; 
//}
