	function $(id) {
		return document.getElementById (id) ;
	}
	
    if ($('login')) {
        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') {
        var ssl_element = $('ssl');
        if (ssl_element) {
    		$('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 () {
        var action = $('login_form').getAttribute('action') ; 
		if ($('ssl')) {
			var ssl = $('ssl').checked;
			if(ssl) {
                //dwagner - insert https in place of request protocol in login form action
                //$('login_form').action = $('login_form').action.replace(document.location.protocol, 'https:');

                //dwagner - old login via https
                $('login_form').action = "https://"+domain+"/" + action ; 

				createCookie ('ssl', '1', 1) ;
			} else {
                if (domain != document.location.host.replace ('www\.', '')) {
                    $('login_form').action =  document.location.protocol + "//" +domain + "/" + action;
                }    
                createCookie ('ssl', '0', 1) ;
			}

		}	
	}
	function onUserDomainLogin () {
        var action = $('login_form').getAttribute('action') ; 
		if ($('ssl')) {
			var ssl = $('ssl').checked;
			if(ssl) {
                $('login_form').action = "https://"+domain + action ; 

				createCookie ('ssl', '1', 1) ;
			} else {
                $('login_form').action =  document.location.protocol + "//" +domain + action;

                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) ;
	}

function clear_input( inputElement, defaultInputValue ){
    if( inputElement.value == defaultInputValue ){
        inputElement.value = '';
    }
}
function default_input( inputElement, defaultInputValue ){
    if( inputElement.value == '' ){
        inputElement.value = defaultInputValue;
    }
}
