	function $(id) {
		return document.getElementById (id) ;
	}
	
	try {
		if ($('login').value == '') {
			$('login').focus() ;
		}	
	} catch (e) {} 	
	
	function createCookie (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+encodeURIComponent(value)+expires+"; path=/";
	} 
	
	function readCookie (name) {
	     var nameEQ = name + "=";
	     var ca = document.cookie.split(';');
	     for(var i=0;i < ca.length;i++) {
		     var c = ca[i];
		     while (c.charAt(0)==' ') c = c.substring(1,c.length);
		     if (c.indexOf(nameEQ) == 0) return decodeURIComponent(c.substring(nameEQ.length,c.length));
		     }
	     return null;
	}
	
	function randomize_box() {
		var host = document.location.host.replace ('www\.', '') ;
		var random = Math.floor(Math.random()*100);
		if (host == 'poczta.o2.pl' || host == 'poczta10.o2.pl') {
			domain = (random % 2) ? 'poczta10.o2.pl' : 'poczta.o2.pl' ;
		} else {
			return host ;
		}
		return domain ;		
	}
	
	var domain = randomize_box () ;
	var ssl = readCookie ('ssl') ;
	if (ssl || document.location.protocol == 'https') {
		$('ssl').checked = 'checked' ;	
	}

	if (domain) {
		var p = $('preload') ;
		p.src = document.location.protocol + '//' + domain + WEBMAIL_PATH+'preload.html' ;
	}

	if ($('ssl') && ssl !== '0') {
		$('ssl').checked = 'checked' ;
	}
	
	function onLogin () {
		if ($('ssl')) {
			var ssl = $('ssl').checked;
			if(ssl) { 
				$('login_form').action = "https://"+domain+"/login.html" ;
				createCookie ('ssl', '1', 1) ;
			} else { 
                if (domain != document.host.replace ('www\.', '')) {
                    $('login_form').action =  document.location.protocol + "//" +domain + "/login.html" ; 	
                }    
				createCookie ('ssl', '0', 1) ;
			}
		}	
	}

	var ls = $('language-select') ;
	if (ls) {
		var lang = readCookie ('lang') || WEBMAIL_LANG ;
		if (lang) {
			var o = ls.options ;
			for (var i=0; i<o.length; i++) {
				if (o[i].value == lang) {
					ls.selectedIndex = i ;
					break ;
				}
			}
		}

		ls.onchange = function () {
			onLangSelect () ;
			$('lang-form').submit () ;
		}
	}

	function onLangSelect () {
		var lang = $('language-select').value ;
		createCookie ('lang', lang) ;
	}


