function update_inputs() {
	// Check that the browser is DOM compliant and add javascript behavior to all text inputs
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all inputs
		var input;
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++) {
			input = inputs[i];
			if (((input.getAttribute("type") == "text") || (input.getAttribute("type") == "password") || (input.getAttribute("type") == "file")) &&
				 (input.getAttribute("id") != "search")) {
				input.onfocus= function() {
					this.style.border = "1px solid #EE0000"; 
					this.style.color = "#000000";
					this.select();
					
					if (document.getElementById('contextual_help')) { update_help(this.id); }
				}
				input.onblur = function() {
					this.style.border = "1px solid #84512C";
					this.style.color = "#B8713D";
					if (document.getElementById('contextual_help')) { document.getElementById('contextual_help').innerHTML = "Aide contextuelle..."; }
				}
            }
        	else if (input.getAttribute("id") == "search") {
				input.onfocus= function() {
					this.style.border = "1px solid #EE0000"; 
					this.style.color = "#000000";
					this.select();
				}
				input.onblur = function() {
					this.style.border = "1px solid #000000";
					this.style.color = "#B8713D"; 
				}
        	}
		}
	}
}

function update_selects() {
	// Check that the browser is DOM compliant and add javascript behavior to all text inputs
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all inputs
		var input;
		var inputs = document.getElementsByTagName('select');
		for (var i = 0; i < inputs.length; i++) {
			input = inputs[i];
			input.onfocus= function() {
				  this.style.border="1px solid #EE0000";
				  if (document.getElementById('contextual_help')) { update_help(this.id); }
			}
			input.onblur = function() {
				  this.style.border="1px solid #84512C";
				  if (document.getElementById('contextual_help')) { document.getElementById('contextual_help').innerHTML = "Aide contextuelle..."; }
			}
		}
	}
}

function update_textareas() {
	// Check that the browser is DOM compliant and add javascript behavior to all textareas
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all inputs
		var input;
		var inputs = document.getElementsByTagName('textarea');
		for (var i = 0; i < inputs.length; i++) {
			input = inputs[i];
			input.onfocus= function() {
				this.style.border = "1px solid #EE0000";
				this.style.color = "#000000";
				if (document.getElementById('contextual_help')) { update_help(this.id); }
			}
			input.onblur = function() {
				this.style.border="1px solid #84512C"
				this.style.color = "#B8713D";
				this.value=this.value
				if (document.getElementById('contextual_help')) { document.getElementById('contextual_help').innerHTML = "Aide contextuelle..."; }
			}
        }
	}
}

function update_radioboxes() {
	// Check that the browser is DOM compliant and add javascript behavior to all text inputs
	// this doesn't work except in IE
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all inputs
		var input;
		var inputs = document.getElementsByTagName('input');
		for (var i = 0; i < inputs.length; i++) {
			input = inputs[i];
			if ((input.getAttribute("type") == "checkbox") || (input.getAttribute("type") == "radio")) {
				input.onfocus= function() { if (document.getElementById('contextual_help')) { update_help(this.id); } }
				input.onblur = function() { if (document.getElementById('contextual_help')) { document.getElementById('contextual_help').innerHTML = "Aide contextuelle..."; } }
            }
		}
	}
}

function update_files() {
	var inputs = document.getElementsByTagName('input');
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type != 'file') { continue; }
		if (inputs[i].parentNode.className != 'upload') { continue; }
		
		inputs[i].relatedElement = document.getElementById("fake_" + inputs[i].name);
		inputs[i].onchange = inputs[i].onkeyup = function () { this.relatedElement.value = this.value; }
	}	
}

function initialize_forms(){
	if (!document.getElementsByTagName) { return; }

	update_inputs()
	update_textareas()
	update_radioboxes();
	update_selects()
	update_files();
}