function confirmLink(theLink, theSqlQuery)
{
    // Confirmation is not required in the configuration file
    var is_confirmed = confirm(theSqlQuery);
    if (is_confirmed) {
        theLink.href += '&submit=yes';
    }

    return is_confirmed;
} // end of the 'confirmLink()' function


function extendsubmitfileform(formid,file_id,action_file){
	res = document.getElementById(formid);

	res.file_id.value=file_id;
	res.action_file.value=action_file;

	try {
		res.onsubmit();
		}
	catch(e){}
	res.submit.click();
}

function fakeformsubmit(formid,value){
	res = document.getElementById(formid);
	res.onchangeerror.value=value;

	try {
		res.onsubmit();
		}
	catch(e){}
	res.submit.click();
}

function extendsubmitform(formid,pressbutton,i,addsubmit){
	checkfields=check_count(formid);

	if (checkfields != 1 && i==1){
		alert('Zaznacz tylko jeden element');
	} else if (checkfields == 0 && i==2) {
		alert('Zaznacz jeden lub więcej elemetów');
	} else if (checkfields != 2 && i==3) {
		alert('Zaznacz tylko dwa elementy');		
	} else if (checkfields < 2 && i==4) {
		alert('Zaznacz dwa lub więcej elementow');				
	} else {

		res = document.getElementById(formid);
		res.action.value=pressbutton;
		if (addsubmit==1) {
			res.submit2.value=pressbutton;
		}
		try {
			res.onsubmit();
			}
		catch(e){}
		res.submit();
	}
}

function check_count(formid) {
	var licznik = 0;

	res = document.getElementById(formid);
	pola= res.elements;
	for (i=0;i<pola.length;++ i) {
		if (pola[i].checked) {
			licznik++;
		}
	}
	return licznik;
}


function check_uncheck(formid,check) {
	var licznik = 0;
	res = document.getElementById(formid);
	pola= res.elements;

	for (i=0;i<pola.length;++ i) {
		if (pola[i].type=='checkbox') {
			pola[i].checked=check;
		}
	}
	return true;
}

function reset_field_value(formid,field_name,field_name2)
{
	res = document.getElementById(formid);
	pola= res.elements;
	for (i=0;i<pola.length;++ i) {
		if (pola[i].name==field_name) {
			pola[i].value='';
		}
		if (pola[i].name==field_name2) {
			pola[i].value='';
		}
	}
}

function MakeAdres (formid,script) {
	lista='';
	res = document.getElementById(formid);
	pola= res.elements;
	for (i=0;i<pola.length;++ i) {
		if (pola[i].type=='checkbox') {
			if (pola[i].checked) {
				if (lista=='')
					lista=pola[i].value;
				else
					lista+=','+pola[i].value;
			}
		}
	}

	if (lista=='') {
		alert ("Proszę zaznaczyć osoby");
	} else {
		newwindow=window.open(script+lista,'_print');
	}
}


function CalculateSrednia(formid) {
	res = document.getElementById(formid);
	pola= res.elements;

	licz=0;
	suma=0;

	for (i=0;i<pola.length;++i) {
		if (pola[i].name=='o_mowienie' || pola[i].name=='o_pisanie' || pola[i].name== 'o_czytany' || pola[i].name=='o_zesluchu' || pola[i].name=='o_test') {
			licz++;
			suma= suma +parseFloat(pola[i].value);
		}
	}

	if (suma==0 || suma > licz*6 || licz==0) {
		alert('błędna wartość oceny !'+suma+' '+licz);
	} else {
		suma2=suma*10;
		srednia_duza=Math.round(suma2/licz);
		if (srednia_duza%10<=3 || srednia_duza%10>=7) {
			srednia=Math.round(suma/licz);
		} else {
			srednia=Math.floor(suma/licz)+0.5;
		}

		if (confirm('Suma ocen:'+suma+'\nOcen: '+licz+' \nSrednia: '+(suma/licz)+' \nSrednia wyliczona:'+srednia)) {
			pola.o_koncowa.value=srednia;
		}
	}
}

 function przelacz(id) {
 		current = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
  		document.getElementById(id).style.display = current;
 };