function ShowInvisibleElement(element_id, nonEmpty_value)
{
    if (nonEmpty_value != null && nonEmpty_value != "")
    {
        document.getElementById(element_id).style.display='';
        document.getElementById(element_id).style.visibility='';
        if (element_id == 'Password_confirm')
            document.getElementById('Password2').focus();
        else
            document.getElementById(element_id).focus();
    }
    else
    {
        document.getElementById(element_id).style.display='none';
        document.getElementById(element_id).style.visibility='hidden';
        if (element_id == 'Password_confirm')
            document.getElementById('First Name').focus();
    }
}

function CompareValues(value1, value2)
{
    if (value1 == null || value1 == '' || value2 == null || value2 == '')
        return false;
        
    return (value1 == value2);
}

function HighlightText(control, background_color, text_color)
{
    control.style.backgroundColor = background_color;
    control.style.color = text_color;
} 

function gotoRecord(id)
{
    var address = window.location.href;
    address = address.substring(0, address.indexOf("?"));
    location.href = address + "?record=" + id;
}

function NumbersOnly(e)
{
    var keynum;
    var keychar;
    var numcheck;
    
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }

    if (keynum == 8 //backspace
    || keynum == 9  //tab
    || keynum == 13
    || keynum == 16 //shift
    || keynum == 35 //end
    || keynum == 36 || keynum == 37 || keynum == 39 || keynum == 46 || keynum == 188 || keynum == 190)
        return true;
    
    keychar = String.fromCharCode(keynum);
    
    numcheck = /\d/;
    
    return numcheck.test(keychar);
}
function DateOnly(e)
{
    var keynum;
    var keychar;
    var numcheck;
    
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
    
    if (keynum == 16    //Shift
    ||  keynum == 191)  //Forward Slash (/)
        return true;
        
    return NumbersOnly(e);
}
function TimeOnly(e)
{
}
function DateTimeOnly(e)
{
}

function UpdateDateValue(control_id)
{
    var hidden_control = document.getElementById(control_id);
    var month_control = document.getElementById(control_id + '_month');
    var day_control = document.getElementById(control_id + '_day');
    var year_control = document.getElementById(control_id + '_year');
    
    hidden_control.value = month_control.value + '/' + day_control.value + '/' + year_control.value;
}

function UpdateTimeValue(control_id)
{
    var hidden_control = document.getElementById(control_id);
    var month_control = document.getElementById(control_id + '_month');
    var day_control = document.getElementById(control_id + '_day');
    var year_control = document.getElementById(control_id + '_year');
    var hour_control = document.getElementById(control_id + '_hour');
    var minute_control = document.getElementById(control_id + '_minute');
    var ampm_control = document.getElementById(control_id + '_tt');
    
    hidden_control.value = month_control.value + "/" + day_control.value + "/" + year_control.value + " " + hour_control.value + ":" + minute_control.value + " " + ampm_control.value;
}

function submit_form(form, command)
{
    if (command == "")
        command = "save";
    
    document.getElementById('command').value = command;
    
    if (form != "undefined")    
        form.submit();
    else
        alert('Please verify the name of the form; submission failed.');
}

function ValidateRequiredField(control_id)
{
    var control = document.getElementById(control_id);
    
    if (control.value == '' || control.value == 'required')
    {
        if (control.value == 'required')
            control.value = '';
        else
            control.value = 'required';
        control.style.background = 'Red';
        control.style.color = 'White';
        control.focus();
        return false;
    }
    else
        return true;
}

function ClickSpecifiedButton(e, buttonid)
{ 
  var evt = e ? e : window.event;

  var bt = document.getElementById(buttonid);

  if (bt)
  { 
      if (evt.keyCode == 13)
      { 
            bt.click(); 
            return false; 
      } 
  }
}