(function(){
        $.fn.target = function(){
                return $('.targetblank').click( function() {
                window.open(
                     $(this).attr('href') );
                     return false;
                });
        }
})(jQuery);

$(document).ready(function()
{
    $('a').target();

    $("#sizePlus").click(function(){
        var currentFontSize = $('#content').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum + 1;
        $('#content').css('font-size', newFontSize);
        return false;
        });

    $("#sizeMoins").click(function(){
        var currentFontSize = $('#content').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum - 1;
        $('#content').css('font-size', newFontSize);
        return false;
    });
})

// JavaScript Document
function Deplacer(sourceList,destList)
{
	if (sourceList.options.selectedIndex >= 0)
	{
		option = new Option(sourceList.options[sourceList.options.selectedIndex].text , sourceList.options[sourceList.options.selectedIndex].value);
		
		destList.options[destList.options.length] = option;
		sourceList.options[sourceList.options.selectedIndex] = null;
	}
	else
	{
		alert("Aucun joueur sélectionné");
	}
}

function SelectAllItemsInList(list)
{
	for (i=0; i<list.length; i++) 
	{
		list.options[i].selected = true;
	} 
}

function MoveAllListItems(sourceList, destList)
{
	for( i = sourceList.length - 1; i >= 0; i--)
	{
		if (sourceList.options[i].selected)
		{
			MoveListItem(sourceList, destList, i);
		}
	}
}

function MoveListItem(sourceList, destList, sourceItemIndex)
{
	option = new Option(sourceList.options[sourceItemIndex].text , sourceList.options[sourceItemIndex].value);
		
	destList.options[destList.options.length] = option;
	sourceList.options[sourceItemIndex] = null;
}

/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */
function openCalendar(form, field, type) 
{
    window.open("./calendar.php", "calendar", "width=500,height=300,status=yes");
	dateField = eval("document." + form + "." + field);
	dateType = type;
}

var day;
var month;
var year;
var hour;
var dateField;
var clock_set = 0;

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) 
{
    i = parseInt(i, 10)
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   string type of number
 */
function formatNum2(i, valtype) 
{
    f = (i < 10 ? '0' : '') + i;
	
    if (valtype && valtype != '') 
	{
        switch(valtype) 
		{
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 * @param   int default value
 * @param   string type of number
 */
function formatNum2d(i, default_v, valtype) 
{
    i = parseInt(i, 10);

    if (isNaN(i)) 
		return default_v;

	return formatNum2(i, valtype)
}

/**
 * Initializes calendar window.
 */
function initCalendar() 
{
	if (!year && !month && !day) 
	{
        /* Called for first time */
		if (window.opener.dateField.value) 
		{
            value = window.opener.dateField.value;
            parts   = value.split(' ');
            value   = parts[0];
			
			hour = parts[1];
			
			date        = value.split("-");
			
			day         = parseInt(date[0],10);
			month       = parseInt(date[1],10) - 1;
			year        = parseInt(date[2],10);
        }
		else
		{
			dt      = new Date();
            year    = dt.getFullYear();
            month   = dt.getMonth();
            day     = dt.getDate();
		}
    } 
	else 
	{
        /* Moving in calendar */
        if (month > 11) 
		{
            month = 0;
            year++;
        }
        if (month < 0) 
		{
            month = 11;
            year--;
        }
    }

    if (document.getElementById) 
	{
        cnt = document.getElementById("calendar_data");
    } 
	else if (document.all) 
	{
        cnt = document.all["calendar_data"];
    }

	cnt.innerHTML = "";

    str = ""

    //heading table
    str += '<table class="calendarHeader"><tr><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
	
    for (i =0; i < 12; i++) 
	{
        if (i == month) 
			selected = ' selected="selected"';
        else 
			selected = '';
        
		str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
    }
	
    str += '</select>';
    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th><th width="50%">';
    str += '<form method="NONE" onsubmit="return 0">';
    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
    str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
	
    for (i = year - 25; i < year + 25; i++) 
	{
        if (i == year) 
			selected = ' selected="selected"';
        else 
			selected = '';
			
        str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
    }
	
    str += '</select>';
    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
    str += '</form>';
    str += '</th></tr></table>';

    str += '<table class="calendarContent"><tr>';
    
	for (i = 0; i < 7; i++) 
	{
        str += "<th>" + day_names[i] + "</th>";
    }
	
    str += "</tr>";

    var firstDay = new Date(year, month, 1).getDay();
    var lastDay = new Date(year, month + 1, 0).getDate();

    str += "<tr>";

    dayInWeek = 0;
	
    for (i = 0; i < firstDay; i++) 
	{
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
	
    for (i = 1; i <= lastDay; i++) 
	{
        if (dayInWeek == 7) 
		{
            str += "</tr><tr>";
            dayInWeek = 0;
        }

        dispmonth = 1 + month;

        actVal = "" + formatNum2(i, 'day') + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum4(year);
				
        if (i == day) 
		{
            style = ' class="selected"';
            current_date = actVal;
        } 
		else 
		{
            style = '';
        }
		
        str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
        dayInWeek++;
    }
	
    for (i = dayInWeek; i < 7; i++) 
	{
        str += "<td>&nbsp;</td>";
    }

    str += "</tr></table>";

    cnt.innerHTML = str;

	if (document.getElementById) 
	{
		cnt = document.getElementById("clock_data");
	} 
	else if (document.all) 
	{
		cnt = document.all["clock_data"];
	}

	str = '';
	
	str += '<fieldset>';
	str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + actVal + '\')">';
	str += '<select id="hour">';
	
	for (i = 9; i < 21; i++)
	{
		str += ReturnHourSelectItem(i, false);
		str += ReturnHourSelectItem(i, true);
	}
	
	str += '</select>';
	
	str += '<input type="submit" value="' + submit_text + '"/>';
	str += '</form>';
	str += '</fieldset>';

	cnt.innerHTML = str;
	clock_set = 1;
}

function ReturnHourSelectItem(hourParam, isHalf)
{
	val = formatNum2(i, 'hour') + ':';
	if (isHalf)
		val += '30';
	else
		val += '00';
		
	selected = (hour == val) ? ' selected="selected"' : '';
	
	return '<option value="' + val + '"' + selected + '>' + val + '</option>';
}

/**
 * Returns date from calendar.
 *
 * @param   string     date text
 */
function returnDate(d) 
{
    txt = d;
	
    if (window.opener.dateType != 'date') 
	{
        // need to get time
        hour = document.getElementById('hour').value;
        
        txt += ' ' + hour;
    }

    window.opener.dateField.value = txt;
    window.close();
}