window.onload = function() {
	var formLogin = document.getElementById('form-login')
	if (formLogin) {
		formLogin.focus();
	}
	
	setSelectValue();
}

var isOtherCity = false;
		
function resetCheckbox(obj) {
	var parent   = obj.parentNode;
	var root     = parent.parentNode;
	var cell     = root.getElementsByTagName('td').item(1);
	var checkbox = cell.getElementsByTagName('input').item(0);
	
	if (!checkbox.checked) {
		checkbox.checked = true;
	} else {
		checkbox.checked = false;
	}
}

function rememberValue(obj) {
	var value = obj.options[obj.selectedIndex].value;
	setCookie('selectedValue', value, new Date(Date.parse('Jan 1, 2070')));
}

function setSelectValue() {
	var select  = document.getElementById('form-select');
	var value   = getCookie('selectedValue');
	
	if (select) {
		var options = select.childNodes;
		
		for (var i in options) {
			if (options[i].value == value)
			options[i].selected = true;  
		}
	}
}

function otherCity(obj) {
	var value  = obj.options[obj.selectedIndex].value;
	var parent = obj.parentNode;
	var input  = document.createElement('input');
	
	if (value == 'other' && !isOtherCity) {
		input.className = 'input';
		input.type      = 'text';
		
		parent.innerHTML += '<br />';
		parent.appendChild(input);
		
		isOtherCity = true;
	} else {
		if (isOtherCity) {
			for (var i = 0; i < 2; i ++) {
				parent.removeChild(parent.lastChild);
				isOtherCity = false;
			}
		}
	}
}

function checkValid(obj) {
	if (obj.login.value.length < 2 || obj.pass.value.length < 6) {
		return false;
	}
}