function writeSelectBox(matrix, id, size, onchange, css, uppercss) {
	var o;
	var d = window.document;

	var ie4 = (document.all != null);

	if (ie4) {
//		alert("Before!");
		o = createIEString(matrix, id, size, onchange, css, uppercss);
//		alert("After!");
//		alert(s);
	}

	else {
		o = createXString(matrix, id, size, onchange, css);
		
	}
	document.write(o);
}

function createIEString(matrix, id, size, onchange, css, uppercss) {
	var str = "";
		var selectedValue = matrix[0].value;
	
	prefix = '_dhtml_'
	h_name = id.substring(prefix.length);
	
	for (var i=0; i<matrix.length; i++) {
		value    = matrix[i].value;
		selected = matrix[i].selected;
		if(selected != null) {
			selectedValue = value;
			break;
		}
	}
	
	str += '<input type="hidden" name="'+h_name+'" value="'+selectedValue+'" id="'+h_name+'">\n'
	
	// Span startTag	
		str += '<span class="select"';
		if (size == null)
			size = 1;
		str += ' size="' + size + '"';	
		if (id != null)
			str += ' id="' + id + '"';
		if (onchange != null)
			str += ' onchange="' + onchange + '"';
		if (css != null)
			str += ' style="' + css + '"';
		str += '>\n';
	// Table Tag
		str += '<table class="selectTable" cellspacing="0" cellpadding="0"\n';
		str += ' onclick="toggleDropDown(this.parentElement)">\n';
		str += '<tr>\n';
		str += '<td class="selected">&nbsp;</td>\n';
		str += '<td "\n';
		str += ' onmousedown=""\n';
		str += ' onmouseup="">\n';
		str += '<img border="0" onMouseOver="this.src=\'img/selectbutton_over.gif\';dDiv=null" onMouseOut="this.src=\'img/selectbutton.gif\'" onClick="dDiv=null" src="img/selectbutton.gif"></td>\n';
		str += '</tr>\n';
		str += '</table>\n';
		
	// DropDown startTag
		str += '<div ';
		str += ' style="'+uppercss+'" '
		str += ' class="dropDown" onScroll="dDiv=null" onclick="optionClick();" onmouseover="optionOver();" onmouseout="optionOut()">\n';
		
		for (var i=0; i<matrix.length; i++) {
			html     = matrix[i].html;
			value    = matrix[i].value;
			css      = matrix[i].css;
			selected = matrix[i].selected;
			
		// Write option starttag
			str += '<div '
			str += 'class="option"';
			if (value != null)
				str += ' value="' + value + '"';
			if (css != null)
				str += ' style="' + css + ';margin-left:2"';
			if (selected != null)
				str += ' selected';
			str += '>\n';
			
		// Write HTML contents
			str += html;
		// Write end tag
			str += '</div>\n';
		}
		
	//DropDown endtag
		str += '</div>\n';
	// Span endTag
		str += '</span>\n';
	return str;
}

function createXString(matrix, id, size, onchange, css) {
//	var str = "\n";
	// form startTag
	var str = '';
	
	var selectedValue = matrix[0].value;
	
	prefix = '_dhtml_'
	h_name = id.substring(prefix.length);
	
	for (var i=0; i<matrix.length; i++) {
		value    = matrix[i].value;
		selected = matrix[i].selected;
		if(selected != null) {
			selectedValue = value;
			break;
		}
	}
	
	str += '<input type="hidden" name="'+h_name+'" value="'+selectedValue+'" id="'+h_name+'">\n'

	
	// Select startTag
	str += '<select class="selectBox" ';
	if (size == null)
		size = 1;
	str += ' size="' + size + '"';	
	if (id != null)
		str += ' id="' + id + '"';
	if (onchange != null)
		str += ' onchange="' + onchange + '"';
//	if (css != null)
//		str += ' style="' + css + '"';
	str += '>\n';
	// write options
	for (var i=0; i<matrix.length; i++) {
		html     = matrix[i].html;
		value    = matrix[i].value;
		css      = matrix[i].css;
		selected = matrix[i].selected;
		
	// Write option starttag
		str += '\n<option';
		if (value != null)
			str += ' value="' + value + '"';
//		if (css != null)
//			str += ' style="' + css + '"';
		if (selected != null)
			str += ' selected';
		str += '>';
		
	// Write HTML contents
		str += stripTags(html);
	// Write end tag
		str += '</option>\n';
	}
	str += '\n</select>\n';

	return str;
}

function stripTags(str) {
	var s = 0;
	var e = -1;
	var r = "";

	s = str.indexOf("<",e);	

	do {
		r += str.substring(e + 1,s);
		e = str.indexOf(">",s);
		s = str.indexOf("<",e);
	}
	while ((s != -1) && (e != -1))

	r += str.substring(e + 1,str.length);

	return r;
}

function Option(html, value, css, selected) {
	this.html = html;
	this.value = value;
	this.css = css;
	this.selected = selected;
}

function setFormValue(id,val) {
	document.getElementById(id).value = val;
}