var IE = false;

window.onload = function() {


	// input element on front page
	//
	var input = document.getElementById('s1Login');
	if (input) {
		var parent = input.parentNode;
		var img = document.createElement('img');
		var a = document.createElement('a');
		a.setAttribute('href', '#');
		img.onclick = function() { img.parentNode.parentNode.parentNode.parentNode.submit(); };
		img.setAttribute('src', '/media/images/buttons/next_step.gif');
		a.appendChild(img);

		input.style.position = 'absolute';
		input.style.top = '-100px'; 
		parent.appendChild(a);
	}

	// form on front page
	//
	var form = document.getElementById('s1Form');
	if (form) {
		var userinput = document.getElementById('s1Username');
		var roominput = document.getElementById('s1Workplace');
		var passinput = document.getElementById('s1Password');
		var parent = userinput.parentNode;
	
		var options = document.createElement('div');
		var label1 = document.createElement('label');
		var label2 = document.createElement('label');
				
		options.setAttribute('id', 's1Choose');
		options.style.marginBottom = '3px';
		// lazy
		options.innerHTML = '<label for="opt1"><input id="opt1" onclick="javascript:updates1Forms()" onchange="javascript:updates1Forms()" checked="checked" type="radio" name="user" />New user</label><br /><label for="opt2"><input id="opt2" onclick="javascript:updates1Forms()" onchange="javascript:updates1Forms()" type="radio" name="user" />Returning user</label>';
		
		
		var s = roominput.getElementsByTagName('strong')[0];
		s.parentNode.removeChild(s);

		parent.insertBefore(options, userinput);	
		updates1Forms();
	}

	var input = document.getElementById('s2Register');
	if (input) {
		var parent = input.parentNode;
		var img = document.createElement('img');
		var a = document.createElement('a');
		a.setAttribute('href', '#');
		parent.appendChild(a);
		img.onclick = function() { img.parentNode.parentNode.parentNode.submit(); };
		img.setAttribute('src', '/media/images/buttons/register.gif');
		a.appendChild(img);
	}
	
	
	var inputs = document.getElementsByTagName('input');
	if (inputs) {
		for (i = 0; i < inputs.length; i++) {
			var input = inputs.item(i);
			if (input.getAttribute('type') == 'text' ||
				input.getAttribute('type') == 'password') {
				inputs.item(i).onfocus = function() { highlightField(this); };
			}
		}
	}

	var selects = document.getElementsByTagName('select');
	if (selects) {
		for (i = 0; i < selects.length; i++) {
			selects.item(i).onfocus = function() { highlightField(this); };
			var sel = selects.item(i);
						
			if (sel.style.pixelWidth == 0) {
				// any ie-specific stuff goes here
			
			}
			
		}
	}


	
	
};


function highlightField(o) {

	var inputs = document.getElementsByTagName('input');
	if (inputs) {
		for (i = 0; i < inputs.length; i++) {
			inputs.item(i).style.backgroundColor = "";
			inputs.item(i).style.borderColor = "#999";
		}	
	}
	var selects = document.getElementsByTagName('select');
	if (selects) {
		for (i = 0; i < selects.length; i++) {
			selects.item(i).style.backgroundColor = "";
			selects.item(i).style.borderColor = "#999";
		}
	}
	o.style.borderColor = "#333";
	o.style.backgroundColor = "#fffac1";

//	o.style.borderColor = "#ffffef";
}



function updates1Forms() {
	var wp = document.getElementById('s1Workplace');
	var up = document.getElementById('s1Username');
	var ra = document.getElementById('s1Choose');	

	if (ra.firstChild.firstChild.checked) {
		up.style.display = "none";
		wp.style.display = "block";		
	} else {
		wp.style.display = "none";
		up.style.display = "block";
	}

}