/*
    Copyright (c) 2009, SpatialPoint, LLC.
    
    All rights reserved.
    
    http://www.spatialpoint.com
*/

function IsEmptyTextBox(controlId)
{
    return (document.getElementById(controlId) == null || (document.getElementById(controlId).value == ''));
}

function HighlightRequiredField(controlId)
{
    var labelControl = document.getElementById(controlId);
    if (labelControl != null)
    {
        labelControl.style.color = 'red';
    }
    
}

function ClearRequiredField(controlId)
{
    var labelControl = document.getElementById(controlId);
    if (labelControl != null)
    {
        labelControl.style.color = 'black';
    }
}

function SetFocusToControl(controlId)
{
    var labelControl = document.getElementById(controlId);
    
    if (labelControl != null)
    {
        labelControl.focus();
    }
}

function HideControl(controlId) {
    var control = document.getElementById(controlId);

    if (control != null) {
        control.style.display = 'none';
        control.style.visibility = 'hidden';
    }
}

function ShowControl(controlId) {
    var control = document.getElementById(controlId);

    if (control != null) {
        control.style.display = 'block';
        control.style.visibility = 'visible';
    }
}

function ClearRequriedAddressFieldControlLabel(controlId)
{
    ClearRequiredField(MASTER_CONTROL_PAGE + ADDRESS_LOOKUP_CONTROL + LABEL_CONTROL_PREFIX + controlId);
}

function ClearRequriedFieldControlLabel(controlId)
{
    ClearRequiredField(MASTER_CONTROL_PAGE + LABEL_CONTROL_PREFIX + controlId);
}

function HighlightRequriedAddressFieldControlLabel(controlId)
{
    HighlightRequiredField(MASTER_CONTROL_PAGE + ADDRESS_LOOKUP_CONTROL + LABEL_CONTROL_PREFIX + controlId);
    SetFocusToControl(controlId);
}

function HighlightRequriedFieldControlLabel(controlId)
{
    HighlightRequiredField(MASTER_CONTROL_PAGE + LABEL_CONTROL_PREFIX + controlId);
    SetFocusToControl(controlId);
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}