function showErr(sErrors)
{
	if (sErrors=='')
		return true;
	else
	{
		var eParent=document.getElementById('msg_wrapper');
		var eErrorBox=document.getElementById('err');
		var eConfirmBox=document.getElementById('msg');
		var eWarningBox=document.getElementById('wrn');
		
		if (eErrorBox==null)
		{
			eErrorBox=document.createElement('div');
			eErrorBox.setAttribute("id","err");
			eParent.appendChild(eErrorBox);
		}
		if (eConfirmBox!=null)
			eParent.removeChild(eConfirmBox);

		sErrorFull="<img src='ico/error.png' class='msg_icon' />";
		sErrorFull+="<span class='msg_text'><b>Przy wypełnianiu formularza wystąpiły następujące błędy:</b> </span><ul>";
		sErrorFull+=sErrors+"</ul>";
		
		eErrorBox.innerHTML=sErrorFull;
		
		return false;
	}
}

function validText(asPola,abPelne,asKom)
{
	var sError='';
	var sRegexp=/[\\';<>]/gi;
	var asWynik='';

	for (var i=0;i<asPola.length;i++)
	{
		if (abPelne[i]==true && asPola[i]=='')
			sError+="<li>Obowiązkowe pole '"+asKom[i]+"' nie zostało wypełnione</li>";
		else if (asPola[i]!='')
		{
			sRegexp.lastIndex=0;
			asWynik=sRegexp.exec(asPola[i]);
			if (asWynik) sError+="<li>Pole '"+asKom[i]+"' zawiera niedozwolone znaki \\ ' ; ;&lt; &gt; </li>";
		}
	}
	return sError;
}

function validTextarea(sDane,sKom,bWypeln,iMaxDlug)
{
	var sError='';
	var asWynik='';

	if (bWypeln==true && sDane=='')
		sError+="<li>Obowiązkowe pole '"+sKom+"' nie zostało wypełnione</li>";
		
	if (sDane.length>iMaxDlug)
		sError+="<li>Obowiązkowe pole '"+sKom+"' zawiera zbyt wiele znaków. Maksimum to "+iMaxDlug+"</li>";

	return sError;
}

function validEmail(sEmail,sKom,bWypeln)
{
	var sError='';
	var sRegexp=/^[a-z0-9][\w\.-]*[a-z0-9]@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$/gi;
	sRegexp.lastIndex=0;

	if (bWypeln==true && sEmail=='')
		sError+="<li>Obowiązkowe pole '"+sKom+"' nie zostało wypełnione</li>";
		
	if (sRegexp.exec(sEmail)==null && sEmail!='')
		sError+= "<li>W polu '"+sKom+"' wprowadzono nieprawidłowy adres e-mail</li>";

	return sError;
}

function validDate(sData,sKom,bWypeln)
{
	var sError='';
	var sRegexp=/\b[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}\b/i;
	sRegexp.lastIndex=0;

	if (bWypeln==true && sData=='')
		sError+="<li>Obowiązkowe pole '"+sKom+"' nie zostało wypełnione</li>";
		
	if (!sRegexp.exec(sData) && sData!='')
		sError+="<li>W polu '"+sKom+"' wprowadzono datę w nieprawidłowym formacie. Prawidłowy format to: YYYY-mm-dd (rok-miesiąc-dzień)</li>";
		
	return sError;
}

function validNumber(sNumb,sKom,bWypeln,sLower,sUpper)
{
   var sRegexp=/^[0-9\.,\-]*$/gi;
	sRegexp.lastIndex=0;
	
	if (bWypeln==true && sNumb=='')
		return "<li>Obowiązkowe pole '"+sKom+"' nie zostało wypełnione</li>";

	if (sNumb!='')
	{
	   if (sRegexp.exec(sNumb)==null)
		   return "<li>W polu '"+sKom+"' wprowadzono nieprawidłowe znaki - dopuszczalne są tylko cyfry</li>";
		   
		iNumb=parseInt(sNumb);
		if (iNumb<sLower || iNumb>sUpper)
			return "<li>Pole '"+sKom+"' musi zawierać liczbę całkowitą z przedziału "+sLower+"-"+sUpper+"</li>";
		else
			return '';
	}
	else
		return '';
}

function validPassword(sPass1,sPass2)
{
	if (sPass1!=sPass2)
		return '<li>Hasło powtórzone musi być identyczne</li>';
	else
		return '';
}