var hostName;

function setHostName(hn) {
    hostName = hn;
}

function Functions()
{   
    if(document.getElementById("tetris-get-league") != null){
        document.getElementById("tetris-get-league").onclick = function() {
            $("#getLeagueDialog").dialog({
                    width: 420,
                    height: 120,
                    modal: true,
                    show: 'blind'
            });    
        }
    };
    
    if(document.getElementById("tetris-new-league") != null){
        document.getElementById("tetris-new-league").onclick = function() {
            $("#getLeagueDialog").dialog({
                    width: 420,
                    height: 120,
                    modal: true,
                    show: 'blind'
            });    
        }
    };
    
    if(document.getElementById("tetris-mail") != null){
        document.getElementById("tetris-mail").onclick = function() {
            var mailf = document.mailform;                        
            $("#mailDialog").dialog({
                    width: 320,
                    height: 320,
                    modal: true,
                    show: 'blind',
                    buttons: 
                    {
                            "Send": function() 
                            { 
                                var subjectv = mailf.esubject.value;
                                var textv = mailf.etext.value;
                                    $.ajax( {
                                            url : "ajax/sendMail.php?subject="+subjectv+"&text="+textv
                                    });  
                                    $(this).dialog("destroy");
                            }
                    }
            });    
        }
    };
    
    if(document.getElementById("tetris-league-display") != null){
        document.getElementById("tetris-league-display").onclick = function() {
            var leagueform = document.leagueform;
            var leagueformName = leagueform.groupName.value;
            window.parent.location="http://"+hostName+"/?"+leagueformName;
        }
    };
    
    if(document.getElementById("facebook-share") != null){
        document.getElementById("facebook-share").onclick = function() {
            var addr = "http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F"+hostName;
            window.open(addr,'_blank');        
        }
    };

}

function reload(leagueName){
    var host = "http://" + hostName;
    if(leagueName == "")
        window.parent.location=host;
    else
	window.parent.location=host+"/?"+leagueName;
};

function cl(string) {
    dataWygasniecia = new Date();        
    dataWygasniecia.setMonth(dataWygasniecia.getMonth() +1); 
    document.cookie = "lang=" +string+ ";EXPIRES=" +dataWygasniecia.toGMTString();
    document.cookie = "lang=" +string+ ";EXPIRES=" +dataWygasniecia.toGMTString() +";PATH=/;DOMAIN=."+hostName;
    location.reload();
};
