var div = '';
var div2 = '';
var LanguageDiv = 'language';
var CurrencyDiv = 'currency';
var x = 0; var y = 0;
var language_content = '';
var currency_content = '';

function language_change(obj,current_language) {
        var x = 0; var y = 0;
        while (obj) {
                x += obj.offsetLeft;
                y += obj.offsetTop;
                obj = obj.offsetParent;
        }

        language_content = "<ul width='100%'>\
                   <li id='ENG' onclick='setCookie(\"language\",\"ENG\");document.location.href=\"/\";' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'>English</li>\
                   <li id='EST' onclick='setCookie(\"language\",\"EST\");document.location.href=\"/et\";' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'>Eesti</li>\
                   <!--<li id='FIN' onclick='setCookie(\"language\",\"FIN\");document.location.href=\"/fi\";' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'>Suomi</li>-->\
                   </ul>";

	if(document.getElementById(LanguageDiv) && document.getElementById(LanguageDiv).style.display != "none"){
                nd(LanguageDiv);
		return;
        }
        if(document.getElementById(CurrencyDiv)){
                nd(CurrencyDiv);
        }

        if (!document.getElementById(LanguageDiv)){
                div = document.createElement("div");
                div.id = LanguageDiv;
                div.style.width = 102 + "px";

                div.innerHTML = language_content;

                div.style.left = parseInt(x) - 70 + "px";
                div.style.top = parseInt(y) + 16 + "px";
                div.style.display = '';
                document.body.appendChild(div);
        }
        else if (document.getElementById(LanguageDiv).style.display == "none"){
                div.innerHTML = language_content;
                div.style.display = '';
        }
        document.getElementById(current_language).style.display = 'none';
}

function currency_change(obj,current_currency) {
        var x = 0; var y = 0;
        while (obj) {
                x += obj.offsetLeft;
                y += obj.offsetTop;
                obj = obj.offsetParent;
        }

        currency_content = "<table width='100%' cellpadding='0' cellspacing='0'>\
                   <tr id='EUR' onclick='setCookie(\"currency\",\"EUR\");location.reload(true);' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'><td width='25px'>EUR</td><td align='right'>Euros</td></tr>\
                   <tr id='EEK' onclick='setCookie(\"currency\",\"EEK\");location.reload(true);' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'><td width='25px'>EEK</td><td align='right'>Eesti krooni</td></tr>\
                   <tr id='USD' onclick='setCookie(\"currency\",\"USD\");location.reload(true);' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='this.style.backgroundColor=\"silver\"'><td width='25px'>USD</td><td align='right'>U.S. Dollars</td></tr>\
                   </table>";

        if(document.getElementById(CurrencyDiv) && document.getElementById(CurrencyDiv).style.display != "none"){
                nd(CurrencyDiv);
                return;
        }

        if(document.getElementById(LanguageDiv)){
                nd(LanguageDiv);
        }

        if (!document.getElementById(CurrencyDiv)){
                div2 = document.createElement("div");
                div2.id = CurrencyDiv;
                div2.style.width = 172 + "px";

                div2.innerHTML = currency_content;

                div2.style.left = parseInt(x) - 145 + "px";
                div2.style.top = parseInt(y) + 16 + "px";
                div2.style.display = '';
                document.body.appendChild(div2);
        }
        else if (document.getElementById(CurrencyDiv).style.display == "none"){
                div2.innerHTML = currency_content;
                div2.style.display = '';
        }
        document.getElementById(current_currency).style.display = 'none';
}


function nd(id){
        document.getElementById(id).style.display = 'none';
}

function setCookie(name, value, path, domain, secure) {
	var expires=new Date();
	expires.setDate(expires.getDate()+365);
	var path="/";

    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
