﻿function lTrim(str) 
{ 
    return str.replace(/^[ ]+/, ''); 
} 
 
function rTrim(str) 
{ 
    return str.replace(/[ ]+$/, ''); 
} 
 
function Trim(str) 
{ 
    return lTrim(rTrim(str)); 
}

function hideControl(control)
{
    control.style.display = "none";
}

function showControl(control)
{
    control.style.display = "";
}

function updateRequiredFieldNotifierState(notifierControlID, updateControlID)
{
    var updateControl = document.all[updateControlID];
    var notifierControl = document.all[notifierControlID];
    
    if(updateControl != null)
    {
        var inputTextLength = Trim(updateControl.value).length;
        if(inputTextLength > 0)
        {
            hideControl(notifierControl);
        }
        else
        {
            showControl(notifierControl);
        }
    }
}

function updateRequiredFieldsNotifierState(firstNotifierControlID, secondNotifierControlID, firstUpdateControlID, secondUpdateControlID)
{
    var firstControl = document.all[firstUpdateControlID];
    var secondControl = document.all[secondUpdateControlID];
    var firstNotifierControl = document.all[firstNotifierControlID];
    var secondNotifierControl = document.all[secondNotifierControlID];
    
    if(firstControl != null)
    {
        var inputTextLength = Trim(firstControl.value).length;
        if(inputTextLength > 0)
        {
            hideControl(firstNotifierControl);
            hideControl(secondNotifierControl);
            return;
        }
    }
    
    if(secondControl != null)
    {
        var inputTextLength = Trim(secondControl.value).length;
        if(inputTextLength > 0)
        {
            hideControl(firstNotifierControl);
            hideControl(secondNotifierControl);
            return;
        }
    }
    
    if(firstNotifierControl != null)
    {
        showControl(firstNotifierControl);
    }
    
    if(secondNotifierControl != null)
    {
        showControl(secondNotifierControl);
    }
}
