var StyleInput = {
  init: function()
  {
		// "checkbox" elements
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++)
		{
			if(inputs[a].type == "checkbox" &&
			   inputs[a].getAttribute('dostyle') == "true")
		  {
				span[a] = document.createElement("span");
				if(inputs[a].checked == true)
				{
  				span[a].className = (inputs[a].getAttribute('classchecked') || 'span_checkbox_checked');
  		  }
  		  else
  		  {
  		    span[a].className = (inputs[a].getAttribute('classnotchecked') || 'span_checkbox_notchecked');
  		  }

				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				span[a].onmouseup = StyleInput.check;
		  }
		}

    // ignore IE6 for select boxes
    if((navigator.userAgent.toLowerCase().indexOf('msie 6') != -1))
    {
      return;
    }

    // "select" elements
		var select = document.getElementsByTagName("select");
		for(a = 0; a < select.length; a++) {
			if(select[a].getAttribute('dostyle') == "true")
			{
			  option = select[a].getElementsByTagName("option");
			  active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++)
				{
					if(option[b].selected == true)
					{
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = (select[a].getAttribute('useclass') || "select");
				span[a].id = "select" + select[a].name;
				span[a].appendChild(textnode);
				select[a].className = select[a].className + ' styled ' + (select[a].getAttribute('usewidth') || "");
				select[a].parentNode.insertBefore(span[a], select[a]);
			}
		}
  },
  choose: function()
  {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
  },
  check: function()
  {
    element = this.nextSibling;
    if(element.checked == true)
    {
      element.checked = false;
      this.className = (this.getAttribute('classnotchecked') || 'span_checkbox_notchecked');
    }
    else
    {
      element.checked = true;
      this.className = (this.getAttribute('classchecked') || 'span_checkbox_checked');
    }
  }
}

window.onload = StyleInput.init;