﻿// ConnX General JavaScript functions (loaded each page)

// ##################################################
// ##################################################
// ##################################################

function ChangeConnXButtonValue (controlName, controlValue)
{
	document.getElementById(controlName + '_TextValue').innerHTML = controlValue;
	return true;
}

function ChangeValue (controlName, controlValue)
{
	document.getElementById(controlName).value = controlValue;
	return true;
}

function HideShow (controlName, displayValue)
{
	document.getElementById(controlName).style.display = displayValue;
	return true;
}

function MultilineTextBoxKeyPress (strControlID, strCharCountID, intLength)
{
	document.getElementById(strCharCountID).innerHTML = '(' + (intLength - document.getElementById(strControlID).value.length) + ' chars left)';
	if (intLength > 0)
	{
		if ((intLength - document.getElementById(strControlID).value.length) < 0)
		{
		    document.getElementById(strControlID).value = document.getElementById(strControlID).value.substring(0, intLength);
		    document.getElementById(strCharCountID).innerHTML = '(0 chars left)';
		}
	}
} 

function CheckControl (controlName) 
{
    document.getElementById(controlName).checked = false;
}

function Enable(controlName)
{
	document.getElementById(controlName).disabled = false;
}
	
function Disable(controlName)
{
	document.getElementById(controlName).disabled = true;
}

function ClickControl (strBtnName)
{
    var ctlControl = document.getElementById(strBtnName);
    ctlControl.click();
}

// ##################################################
// ##################################################
// ##################################################


// finds a control that had the given server id, of a the given type in the given parent.
function findControl(parent, tagName, serverId)
{
    var items = parent.getElementsByTagName(tagName);
    // walk the items looking for the right guy
    for (var i = 0; i < items.length; i++)
    {
        var ctl = items[i];
        if (ctl && ctl.id)
        {
            // check the end of the name.
            var subId = ctl.id.substring(ctl.id.length - serverId.length);
            if (subId == serverId)
            {
                return ctl;                        
            }
        }
    }   
    return null;
}

