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 makeCommandAjaxRequest(param, ajaxManager)
{
    var _rdAjaxManager = $find(rdAjaxManager); 
    if ( _rdAjaxManager != null ) _rdAjaxManager.ajaxRequest(param);
    else alert("Error");
     
    return false;
}

function MakeAjaxRequestToParentWnd(ajaxManager, arg, closeWindow)
{
    GetRadWindow().BrowserWindow.EnableSelectElements();
    GetRadWindow().BrowserWindow.makeCommandAjaxRequest(arg, ajaxManager);  
    
    if ( closeWindow == 1) CloseParentRadWindow();
    else GetRadWindow().BrowserWindow.DisableSelectElements();
  
}

function MakeAjaxRequestToParent(arg, closeWindow)
{
    GetRadWindow().BrowserWindow.EnableSelectElements();
    GetRadWindow().BrowserWindow.makeCommandAjaxRequest(arg, null);  
    if ( closeWindow == 1) CloseParentRadWindow();
    else GetRadWindow().BrowserWindow.DisableSelectElements();
  
}

function EnableSelectElements()
{
   
    var lists = document.getElementsByTagName("SELECT");           
    
    for (var i=0; i < lists.length; i++)           
    {                      
      lists[i].removeAttribute("disabled");                                       
    }       
}

function DisableSelectElements()
{
   
    var lists = document.getElementsByTagName("SELECT");           
    
    for (var i=0; i < lists.length; i++)           
    {                      
        lists[i].disabled = true;                                       
    }       
}

function openCenteredWindow(url, width, height) 
{
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    window.open(url, "subWind", windowFeatures);
}

function CloseWindow()
{
   GetRadWindow().Close();  
}

function ShowNormalWindow(finalUrl, width, height)
{
    if (GetRadWindowManager().GetWindows().length <= 0) 
    {
       
        var oWnd = window.radopen(finalUrl);
        oWnd.SetModal(true);
        oWnd.Show(); 
        if ( width > 0 && height > 0 )
        {
            oWnd.SetSize(width + 2, height);
            oWnd.Center();
         }
        if ( oWnd.IsPinned() == false ) oWnd.TogglePin();
    }
    else
    {
        
        var oWnd = GetRadWindowManager().GetWindows()[0];
        oWnd.SetModal(true);
        oWnd.Show();
        if ( width > 0 && height > 0 )
        {
            oWnd.SetSize(width + 2, height);
            oWnd.Center();
        }
        if ( oWnd.IsPinned() == false ) oWnd.TogglePin();
        oWnd.SetUrl(finalUrl);
    }
}

function ShowSSLWindow(url, width, height)
{
    scroll(0,0);
   
    var finalUrl = "http://www.lossmitalliance.com/";

    if ( url.indexOf("?") > 0 ) finalUrl = finalUrl +url+"&rnd=" + Math.random();
    else finalUrl = finalUrl +url+"?rnd=" + Math.random();
    ShowNormalWindow(finalUrl, width, height);
    return false;
}


function ShowWindow(url, width, height)
{
    scroll(0,0);
   
    var finalUrl = "http://www.lossmitalliance.com/";

    if ( url.indexOf("?") > 0 ) finalUrl = finalUrl +url+"&rnd=" + Math.random();
    else finalUrl = finalUrl +url+"?rnd=" + Math.random();
    ShowNormalWindow(finalUrl,  width, height);
    return 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 hideWindows()
{
    GetRadWindowManager().CloseAll();
}

function CloseParentRadWindow()
{
   setTimeout(function()  
   {  
    GetRadWindow().Close();  
   },1*10);  
}


function Trim(value)
{
    return value.replace(/^\s*([\S\s]*?)\s*$/, '$1');
}

//function ShowToolTip(content)
//{
//    Tip (content, PADDING, 9, BGCOLOR, '#FFEEC2', BORDERCOLOR, '#86b71F', CLICKCLOSE, true);
//}

function strPad( str, places, pad, side )
{
    str+='';
    while ( str.length < places )
    {
        if ( side == "left" ) str = pad + str;
        else str = str + pad;
    }
    return str;
}

function IsArray(obj)
{
    try
    { 
        return(typeof(obj.length)=="undefined")?false:true;
    } 
   catch(err) { return false; } 
}

function RequestReferral(typeRef)
{
    var selectedId = document.getElementById("caseId").value;
    if ( selectedId != null && selectedId != 0)  ShowWindow('Front/Profile/Case Management/Window/CaseRequestReferral.aspx?CaseId='+selectedId+'&TypeId='+typeRef,700,400); 
    else alert("Please select a case for which you want to request the referral"); 
} 

function CustomAlert(msg, title)
{
    
}

function SizeToFit()
{
window.setTimeout(
    function()
    {
        var oWnd = GetRadWindow();
        oWnd.SetWidth(document.body.scrollWidth + 4);
        oWnd.SetHeight(document.body.scrollHeight + 70);
        
    }, 400);
}