﻿
function clearValue(obj, defaultValue)
{
	if (obj.value == defaultValue) { obj.value = ''; }
}

function repopulateValue(obj, defaultValue)
{
	if (obj.value == '') { obj.value = defaultValue; }
}

function SetSelectedIndex(sender, value)
{
	for (var index = 0; index < sender.options.length - 1; index++)
	{
		if (sender.options[index].value == value)
		{
			sender.selectedIndex = index;
			break;
		}
	}
}

function capLock(e)
{
	var kc = e.keyCode ? e.keyCode : e.which;
	var sk = e.shiftKey ? e.shiftKey : ((kc == 16) ? true : false);
	
	var capsLock = document.getElementById('sCapsLock');
	
	if (capsLock)
	{
		if (((kc >= 65 && kc <= 90) && !sk) || ((kc >= 97 && kc <= 122) && sk))
			capsLock.style.visibility = 'visible';
		else
			capsLock.style.visibility = 'hidden';	
	}
}

function ChangeCheckBoxState(id, checkState)
{  
  var cb = document.getElementById(id);
  if (cb != null)
	cb.checked = checkState;
}

function ChangeAllCheckBoxStates(checkState)
{
  // Toggles through all of the checkboxes defined in the CheckBoxIDs array
  // and updates their value to the checkState input parameter
  if (CheckBoxIDs != null)
     for (var i = 0; i < CheckBoxIDs.length; i++)
        ChangeCheckBoxState(CheckBoxIDs[i], checkState);
}

function ChangeAllCheckBoxStatesById(id, checkState)
{
  // Toggles through all of the checkboxes defined in the CheckBoxIDs array
  // and updates their value to the checkState input parameter  
  if (id != null)
     for (var i = 0; i < id.length; i++)
        ChangeCheckBoxState(id[i], checkState);
}

function CountCheckState(id, checkState)
{
	var cb = document.getElementById(id);
	
	if (cb != null && cb.checked == checkState)
		return true;
	else
		return false;
}

function CountAllCheckStates(controlArray, checkState)
{
	// Iterates through all of the checkboxes defined in the CheckBoxIDs array
	// and checks their value to the checkState input parameter
	var count = 0;
  
	if (controlArray != null)
		for (var i = 0; i < controlArray.length; i++)
			if (CountCheckState(controlArray[i], checkState))
				count++;
	
	return count;
}

function CountAllCheckBoxStates(checkState)
{
	return CountAllCheckStates(CheckBoxIDs, checkState);
}

function CountAllRadioButtonStates(checkState)
{
	return CountAllCheckStates(RadioButtonIDs, checkState);
}

function validateControl( controlId )
{
    var isValid = true;
    
    for( var index=0; index < Page_Validators.length; index++ )
    {
        var validator = Page_Validators[index];
        
        if( validator.controltovalidate == controlId )
        {
            ValidatorValidate(validator,null,null)
            
            if( !validator.isvalid )
            {
                isValid = validator.isvalid;
                break;
            }
            
            ValidatorUpdateDisplay(validator);
        }
    }
     
    return isValid;
}

// Need to look for a validator called the same as this control
function validateComponent()
{
    validateControl($get('<%= this.ClientID %>'));
}