﻿// dhtml File dynamic html helper functions

/* row_add_cell_text 
 *      - add a cell to the row with a text field.
 * row = table row
 * text = text to add
 */
function row_add_cell_text(row, text)
{
	var cell = row.insertCell(row.cells.length);
  	var node = document.createTextNode(text);
  	cell.appendChild(node);
}

/* row_add_cell_input 
 *      - add a cell to the row with an input field
 * name_id = name & id to give to the input text
 * text = text to add
 */
function row_add_cell_input(row, name_id, width, value)
{
	var cell = row.insertCell(row.cells.length);
	var el = document.createElement("input");
	if (width == null)
		width = "52px";
	el.type = "text";
	el.name = name_id;
	el.id = name_id;
	el.style.width = width;
	if (value != null)
	    el.value = value;
	cell.appendChild(el);
	return cell;
}

/* row_add_cell_input_text 
 *      - add a cell to the row with an input text and text beside.
 * name_id = name & id to give to the input text
 * row = table row
 * text = text to add
 */
function row_add_cell_input_text(row, name_id, text, value)
{
	var cell = row_add_cell_input(row, name_id, null, value);
	var node = document.createTextNode(text);
	cell.appendChild(node);
}


function getRadioCheckedId(name)
{
    try {
        var r = document.getElementsByName(name);	
    } catch (error) {
        alert("Could not get radio element by name: " + name);
        return;
    }
	
	for (var i = 0; i < r.length; i++) 
	{
	    if (r[i].checked) 
	        return r[i].id; 
	}
	alert("Warning. No Radio button is selected for " + name);
}

function clearRadioCheckedId(name)
{
    try {
        var r = document.getElementsByName(name);	
    } catch (error) {
        alert("Could not get radio element by name: " + name);
        return;
    }
	
	for (var i = 0; i < r.length; i++) 
	{
	    r[i].checked = false; 
	}
	// alert("Warning. No Radio button is selected for " + name);
}

function cond_set_text_value(set, id, value)
{
	if (set) 
	{
		set_text_value(id, value);
		// should also enable
	}
	else
	{
		set_text_value(id, "");
		// should also disable
	}
}

function set_text_value(id, value)
{
	var e = document.getElementById(id);
	e.value = value;
}

function set_text_values(name, value)
{
	var e = document.getElementsByName(name);
	for (var i =0; i < e.length; i++)
		e[i].value = value;
}

function en_dis_children(name, disabled)
{
	var e = document.getElementsByName(name);
	for (var j = 0; j < e.length; j++)
	{
		//alert(parrent_name + " " + e.length);
		e[j].disabled = disabled;
	}
}

