function checkHex($field) {
	$hexnum = $field.value.toUpperCase();
	$hexnum = $hexnum.replace(/[^A-F0-9]/,'');

	$field.value = $hexnum;
}

function inArray($needle,$haystack) {
	if(typeof($haystack) == 'object' && $haystack.length > 0) {
		$arraySearchFor = $needle;
		$haystack.sort(checkInArray);

		if($haystack[0] == $arraySearchFor) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}

function checkInArray($check, $null) {
	if ($check == $arraySearchFor) {
		return false;
	}
	else {
		return true;
	}
}


var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

var checkInitDone = new Array();

$isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox');

$naviapp = navigator.appVersion.toLowerCase().split(';');
if (typeof($naviapp) === 'object') {
	if ($naviapp[1]) {
		$naviapp = $naviapp[1];
	}
	else {
		$naviapp = $naviapp.pop();
	}
}

$browser = $naviapp.indexOf('msie');
$version = $naviapp.replace('msie ','');
$version = parseInt($version);

/* No need to change anything after this */
if(($browser >= 0 && $version > 6) || $browser < 0) {
	document.write('<style type="text/css">select.styled { position: relative; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
}

var Custom = {
	init: function() {
		if(($browser >= 0 && $version > 6) || $browser < 0) {
			var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
			for(a = 0; a < inputs.length; a++) {
				if(!inArray(inputs[a],checkInitDone)) {
					checkInitDone[checkInitDone.length] = inputs[a];

					if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className.indexOf("styled") >= 0) {
						span[a] = document.createElement("span");

						useClass = inputs[a].className.replace(/( )?styled( )?/,'');
						if(useClass != '' && useClass != null) {
							span[a].className = useClass;
						}
						else {
							span[a].className = inputs[a].type;
						}


						useTitle = inputs[a].title;
						if(useTitle != '' && useTitle != null) {
							span[a].title = useTitle;
						}
	
						if(inputs[a].checked == true) {
							if(inputs[a].type == "checkbox") {
								position = "0 -" + (checkboxHeight*2) + "px";
								span[a].style.backgroundPosition = position;
							} else {
								position = "0 -" + (radioHeight*2) + "px";
								span[a].style.backgroundPosition = position;
							}
						}

						inputs[a].style.display = 'none';
						inputs[a].parentNode.insertBefore(span[a], inputs[a]);
						inputs[a].onchange = Custom.clear;

						span[a].onmousedown = Custom.pushed;
						span[a].onmouseup = Custom.check;

	
						span[a].onclick = inputs[a].onclick;
						span[a].onchange = inputs[a].onchange;
						span[a].onfocus = inputs[a].onfocus;
						span[a].onblur = inputs[a].onblur;
						
						document.onmouseup = Custom.clear;
					}

					if(inputs[a].type == "file" && inputs[a].className.indexOf("styled") >= 0) {
						inputFileWrapper = document.createElement('div');
						inputFileWrapper.className = 'filewrapper';

						inputFileWrapper = inputs[a].parentNode.appendChild(inputFileWrapper);

						inputFileField = document.createElement('div');
						inputFileField.className = 'filefield';

						inputFileField = inputFileWrapper.appendChild(inputFileField);

						inputFileButton = document.createElement('div');
						inputFileButton.className = 'filebutton';

						inputFileButton = inputFileField.appendChild(inputFileButton);
						inputFileButton.appendChild(inputs[a]);

						inputs[a].className = 'hidefile';

						inputFakeFile = document.createElement('div');
						inputFakeFile.className = 'fakefile';

						inputFakeFile = inputFileWrapper.appendChild(inputFakeFile);

						inputFakeText = document.createElement('input');
						inputFakeText.type = 'text';
						inputFakeText.name = 'filename';
						inputFakeText.className = 'faketextfeld';
						inputFakeText.readOnly = true;

						inputFakeText = inputFakeFile.appendChild(inputFakeText);

						inputs[a].fakeText = inputFakeText;

						inputs[a].dynChangeFunc = function() { }
						if(typeof(inputs[a].onchange) == 'function') {
							inputs[a].dynChangeFunc = inputs[a].onchange.toString().replace(/[^{]+(.*)[^}]/,'$1');
							inputs[a].dynChangeFunc = inputs[a].dynChangeFunc.replace(/eval\(.*\);/,'');
							inputs[a].dynChangeFunc = inputs[a].dynChangeFunc.replace('{','');
							inputs[a].dynChangeFunc = inputs[a].dynChangeFunc.replace('}','');
						}

						inputs[a].onchange = inputs[a].onmouseout = function () {
							this.fakeText.value = this.value;
							eval(this.dynChangeFunc);
						}

						inputFakeOpen = document.createElement('img');
						inputFakeOpen.src = 'images/ordner_ansicht_1.jpg';
						inputFakeOpen.width  = 34;
						inputFakeOpen.height = 34;
						inputFakeOpen.border = 0;
						inputFakeOpen.className = 'big_icons';

						inputFakeFile.appendChild(inputFakeOpen);

						inputFakeReset = document.createElement('img');
						inputFakeReset.src = 'images/icons/remove.png';
						inputFakeReset.width  = 22;
						inputFakeReset.height = 22;
						inputFakeReset.border = 0;
						inputFakeReset.className = 'big_icons';
						inputFakeReset.resetId = inputFakeText;
						inputFakeReset.oldFile = inputs[a];

						inputFakeReset.onclick = function() {
							$parent  = this.oldFile.parentNode;
							$newFile = document.createElement('input');

							$newFile.dynChangeFunc = this.oldFile.dynChangeFunc;
							$newFile.onchange      = this.oldFile.onchange;
							$newFile.onmouseout    = this.oldFile.onmouseout;
							$newFile.fakeText      = this.oldFile.fakeText;
							$newFile.type          = this.oldFile.type;
							$newFile.className     = this.oldFile.className;
							$newFile.id            = this.oldFile.id;
							$newFile.name          = this.oldFile.name;
							$newFile.size          = this.oldFile.size;

							$parent.removeChild(this.oldFile);
							this.oldFile = $parent.appendChild($newFile);
							this.oldFile.onchange();

							this.resetId.value = '';
						}

						/*inputFakeFile.appendChild(inputFakeReset);*/
					}
				}
			}
			inputs = document.getElementsByTagName("select");
			for(a = 0; a < inputs.length; a++) {
				if(!inArray(inputs[a],checkInitDone)) {
					checkInitDone[checkInitDone.length] = inputs[a];

					if(inputs[a].className.indexOf("styled") >= 0) {
						option = inputs[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");

						useClass = inputs[a].className.replace(/( )?styled( )?/,'');
						if(useClass != '' && useClass != null) {
							span[a].className = useClass;
						}
						else {
							span[a].className = "select";
						}

						span[a].id = "select" + inputs[a].name;
						span[a].appendChild(textnode);
						inputs[a].parentNode.insertBefore(span[a], inputs[a]);
						inputs[a].onchange   = Custom.choose;
						inputs[a].onkeypress = Custom.choose;
						inputs[a].onkeydown  = Custom.choose;
						inputs[a].onkeyup    = Custom.choose;
					}
				}
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(!element.disabled) {
			if(element.checked == true && element.type == "checkbox") {
				this.style.backgroundPosition = "0 0";
				element.checked = false;
			} else {
				if(element.type == "checkbox") {
					this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
				} else {
					this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
					group = this.nextSibling.name;
					inputs = document.getElementsByTagName("input");
					for(a = 0; a < inputs.length; a++) {
						if(inputs[a].name == group && inputs[a] != this.nextSibling) {
							inputs[a].previousSibling.style.backgroundPosition = "0 0";
						}
					}
				}
				element.checked = true;
			}
		}

		if(typeof(element.onclick) == 'function') {
			element.onclick();
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className.indexOf("styled") >= 0) {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className.indexOf("styled") >= 0) {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className.indexOf("styled") >= 0) {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className.indexOf("styled") >= 0) {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	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;

				if(typeof(checkAktiv) == 'function') {
					checkAktiv(this.name,option[d].value);
				}
			}
		}
	}
}

