﻿function removeContents(controlID)
{
    var control = $(controlID);
    if (control.hasChildNodes())
		while ( control.childNodes.length >= 1 )
			control.removeChild(control.firstChild);
}

//required for IE
function createNamedElement(type, name) {
  var element = null;
  // Try the IE way; this fails on standards-compliant browsers
  try {
    element = document.createElement('<'+type+' name="'+name+'">');
  } catch (e) {
  }
  if (!element || element.nodeName != type.toUpperCase()) {
    // Non-IE browser; use canonical method to create named element
    element = document.createElement(type);
    element.name = name;
  }
  return element;
}

function createHTMLElementAnchor(href, title, text)
{
	var anchor = document.createElement("A");
	anchor.href = href;
	anchor.title = title;
	anchor.innerHTML = text;
	
	return anchor;
}

function createHTMLElementTable(className)
{
	var table = document.createElement("TABLE");
	table.className = className;
	
	return table;
}

function createHTMLElementRow(table, id, row_index, className)
{
	var tr = table.insertRow(row_index);
	if (id != "")
		tr.id = id;
	if (className != "")
		tr.className = className;
	
	return tr;
}

function createHTMLElementHead(scope, className)
{
	var th = document.createElement("TH");
	th.scope = scope;
	th.className = className;
	
	return th;
}

function createHTMLElementCheckBox(chkbox_id, chkbox_name, chkbox_value)
{
	var	chkbox = createNamedElement("INPUT", chkbox_name);
	chkbox.type = "checkbox";
	chkbox.id = chkbox_id;
	chkbox.value = chkbox_value;
	
	return chkbox;
}

function createHTMLElementTD(className)
{
	var td = document.createElement("TD");
	if (className != "") td.className = className;
	
	return td;
}

function createHTMLElementLabel(label_for, text)
{
	var lbl_name = document.createElement("LABEL");
	lbl_name.setAttribute("for", "chk" + label_for);
	lbl_name.innerHTML = text;
	
	return lbl_name;
}

function createHTMLElementUL(className)
{
	var ul = document.createElement("UL");
	ul.className = className;
	
	return ul;
}

function createHTMLElementLI(className)
{
	var li = document.createElement("LI");
	li.className = className;
	
	return li;
}

function createHTMLElementDIV(id, className)
{
	var div = document.createElement("DIV");
	div.id = id;
	if (className != "")
		div.className = className;
		
	return div;
}

function createHTMLElementButton(text, onclick)
{
	var btn = document.createElement("BUTTON");
	btn.innerHTML = text;
	btn.onclick = new Function (onclick);
	
	return btn;
}

function createHTMLElementSpan(text, className)
{
	var spn = document.createElement("span");
	spn.innerHTML = text;
	spn.className = className;
	
	return spn;
}

function createHTMLElementFeedbackSpan(id, text, className)
{
	var spn = document.createElement("span");
	spn.id = id;
	spn.innerHTML = text;
	spn.className = className;
	
	return spn;
}

function createHTMLElementP(text)
{
	var p = document.createElement("P");
	p.innerHTML = text;
	
	return p;
}

function createHTMLElementOption(value, text, className)
{
	var opt = document.createElement("option");
	opt.value = value;
	opt.innerHTML = text;
	if (className != "")
		opt.className = className;
	
	return opt;
}

function createHTMLElementImg(id, src, alt)
{
	var img = document.createElement("img");
	img.id = id;
	img.src = src;
	img.alt = alt;
	
	return img;
}