﻿function OpenURL(url, windowName, height, width)
{
    // default these when needed
    if(isNaN(height) || isNaN(width))
    {
        height = 600;
        width = 800;
    }
    // tack a http protocol on the front if needed
    if(url.substr(0, 4) != 'http')
        url = 'http://' + url;
    window.open(url, '', 'scrollbars=yes,menubar=yes,height=' + height + ',width=' + width + ',resizable=yes,toolbar=yes,location=yes,status=yes')
}

function TestLink(urlTextBoxId, titleTextBoxId)
{
    var txt1 = document.getElementById(urlTextBoxId);
    // may be referring to a control in an ASP.NET grid...
    if(txt1 == null)
        txt1 = document.getElementById(FindControl(urlTextBoxId));
    var txt2 = document.getElementById(titleTextBoxId);
    // may be referring to a control in an ASP.NET grid...
    if(txt2 == null)
        txt2 = document.getElementById(FindControl(titleTextBoxId));
    var hold;
    hold = (txt2 != null && txt2.value.length > 0 ? 'for - ' + txt2.value : '');
    if(txt1 != null && txt1.value.length > 0)
        OpenURL(txt1.value, 'Testing URL ' + hold, 600, 800);
}

// this function searches all the elements of all forms for an element where the id contains the supplied string
// intended use is for accessing controls when ASP.NET puts crazy id's on them (like 'grd_ctl02_txtid')
function FindControl(controlId)
{
    for(var i = 0; i < document.forms.length; i++)
    {
        for(var j = 0; j < document.forms[i].elements.length; j++)
        {
            if(document.forms[i].elements[j].id.indexOf(controlId) != -1)
                return document.forms[i].elements[j].id;
        }
    }
    return '';
}

function ToggleVisible(controlId)
{
    var ctrl = document.getElementById(FindControl(controlId));
    if(ctrl != null)
    {
        if(ctrl.style.visibility == 'hidden')
            ctrl.style.visibility = 'visible';
        else
            ctrl.style.visibility = 'hidden';
    }
}
