var _window = null;
function openPicture(image, size)
{
	if (_window && _window.close)
		_window.close();

	var value = 0;
	
	if (size[0] > screen.width)
	{
		value = 0.9 * screen.width;
		size[1] *= value / size[0];
		size[0]  = value;
	}
	else if (size[1] > screen.height)
	{
		value = 0.8 * screen.height;
		size[0] *= value / size[1];
		size[1]  = value;
	}
	
	_window = window.open(image, 'pictureView', 'width='+size[0]+',height='+size[1]+',left=0,top=0,screenX=0,screenY=0');
	
	return false;
}
function fixEmail(_this)
{
	_this.href = _this.href.replace('##', '@');
}
var _calendarWorking = 0;
function showDay(timestamp, calendarId)
{
    if (_calendarWorking > 0)
        return;
    
    _calendarWorking = calendarId;
    
    $('#calendarEntries'+_calendarWorking).hide('slow', function() {
        $.get('system/exec/calendar.data.php?timestamp=' + timestamp, function(data) {
            if (data != '')
                $('#calendarEntries'+_calendarWorking).html(data).show('slow');
            _calendarWorking = 0;
        })
    });
}
function vote(voteId, answerId)
{
    $('input[type=radio][name=answer]').attr('disabled', 'disabled');
    $.get('system/exec/vote.php?voteId='+voteId+'&answerId='+answerId, function(data) {
        $('#voteContainer').html(data);
    });
}
function addEntry()
{
    if (!confirm('Ni lägger nu till ert meddelande till gästboken. Vill ni fortsätta?'))
        return false;
        
    var name = $('#entryNameField').val(),
        body = $('#entryTextField').val();
        
    if (/^[\s]*$/.test(name) || /^[\s]*$/.test(body) ||
        name.length < 3 || body.length < 3)
    {
        alert('Fört kort namn eller meddelande.');
        return false;
    }
    
    $.post('system/exec/guestbook.add.php', { name: name, text: body }, function(data) {
        self.location.reload();
    });
    
    return false;
}