var sSelectedId = null;

function SetSelectedButtonId(sId)
{
	sSelectedId = sId;
}

function ChangeBtnImage(nLinkId) 
{
	ResetBtnImages();
	var el = document.getElementById(nLinkId);
	if(el == null) return;
	
	SetImage(nLinkId, 2);
}

function ResetBtnImages()
{
	SetImage("linkStronaGlowna", 1);
	SetImage("linkDzialalnosc", 1);
	SetImage("linkDoswiadczenie", 1);
	SetImage("linkKontakt", 1);
	SetImage(sSelectedId, 3);
}

function SetImage(nId, nImgNo)
{
	var el = document.getElementById(nId);
	if(el == null) return;

	if(el.childNodes[0]=="#text" || el.childNodes[0].nodeName=="#text")
	{
		el = el.childNodes[1];
	}
	else	
	{
		el = el.childNodes[0];
	}
	var oldPath = el.src;
	var newPath = oldPath.substring(0, oldPath.length-5) + nImgNo + ".png";
	el.src = newPath;
}

function WalidujPole(pole, komunikat)
{
	var walidacjaOK = true;
	with (pole)
	{
		if(name=="form_email")
		{		
			var apos = value.indexOf("@");
			var dotpos = value.lastIndexOf(".");
			if (apos < 1 || dotpos-apos < 2)
			{
				alert(komunikat);
				walidacjaOK = false;
			}
		}
		else if(name=="form_tresc")
		{
			if(value==null || value=="")
			{
				alert(komunikat);
				walidacjaOK = false;
			}
		}
	}
	return walidacjaOK;
}

function WalidujFormularz(formularz)
{
	with (formularz)
	{
		if (WalidujPole(form_email, "Nie poprawny adres e-mail!")==false)
		{
			form_email.focus();
			return false;
		}
		if(WalidujPole(form_tresc, "Wpisz treść wiadomości!")==false)
		{
			form_tresc.focus();
			return false;
		}
	}

	alert("Wiadomość została wysłana.");
}

