/**
* Przelacza wybrane checkboxy w formularzu
*
*/
function formSwapCheck( formid, checkname ) {

    f = document.getElementById( formid );
    chboxes = f.elements[checkname];

    if (!chboxes.length) {
        chboxes.checked = !chboxes.checked;
    }
    else {
        for (i=0; i<chboxes.length; i++)
            chboxes[i].checked = !chboxes[i].checked;
    }
    return true;
}

/**
* Walidacja formularza dodawania zdjec w fotogalerii
*
*/
function validFotoAddForm( f, ilePlikow )
{
	var alertPrefix = '';
	var alerts = new Array();
	var validFileCounter = 0;
	var invalidFileCounter = 0;
	
	// czy zaladowano dozwolone pliki?
	for (i=1; i<=ilePlikow; i++)
	{
		if ( f.elements['plik'+i].value.match(/\.(jpe?g|png)$/i) != null )
		{
			validFileCounter++;
		}
		else if ( f.elements['plik'+i].value.length > 0 )
		{
			f.elements['plik'+i].value = '';
			invalidFileCounter++;
		}
	}

	//window.alert( validFileCounter+' '+invalidFileCounter );

	if (validFileCounter == 0 || invalidFileCounter > 0)
		alerts.push('Dozwolone pliki to: JPG,PNG');
		
    if ( alerts.length > 0 )
    {
        window.alert( alertPrefix + '- ' + alerts.join('\n- ') );
        return false;
    }
    return true;
}

