
// +++++++++++++++++++++++++++++++++++++++++++++++++
var ie = (document.getElementById && document.all);
var ns = (document.getElementById && !document.all);
// +++++++++++++++++++++++++++++++++++++++++++++++++

function CheckBoxNone(Klasa)
{
	Kolekcja = document.getElementsByTagName("input");
	for(var a=0;a<Kolekcja.length;a++)
	{
		if(Kolekcja[a].type == 'checkbox')
		{
			if(Kolekcja[a].className == Klasa)
			{
				Kolekcja[a].checked = false;  
			}
		}
	}
}
// --------------------------------------------------------------------------------------
function CheckBoxAll(Klasa)
{
	Kolekcja = document.getElementsByTagName("input");
	for(var a=0;a<Kolekcja.length;a++)
	{
		if(Kolekcja[a].type == 'checkbox')
		{
			if(Kolekcja[a].className == Klasa)
			{
				Kolekcja[a].checked = true;  
			}
		}
	}
}
// --------------------------------------------------------------------------------------
function CheckBoxInvert(Klasa)
{
	Kolekcja = document.getElementsByTagName("input");
	for(var a=0;a<Kolekcja.length;a++)
	{
		if(Kolekcja[a].type == 'checkbox')
		{
			if(Kolekcja[a].className == Klasa)
			{
				Kolekcja[a].checked = !Kolekcja[a].checked;  
			}
		}
	}
}
// --------------------------------------------------------------------------------------
function CzyPESELOK(PESEL) 
{
	w = new Array();
	w[0]=1;
	w[1]=3;
	w[2]=7;
	w[3]=9;
	wk = 0;
	for (i=0;i<=9;i++)
	{
		znak = PESEL.substring(i,i+1);
		wk = (wk+znak*w[i % 4]) % 10 ;
		//alert(wk);
	}
	k = (10-wk) % 10;
	if (PESEL.substring(10,11) == k) 
		return true;
	else 
		return false;
}
// --------------------------------------------------------------------------------------
function CzyDobryPesel(Obiekt,StyleOK,StyleAlert)
{
	napis = Obiekt.value;
	//alert (napis);
	if (!CzyPESELOK(napis))
	{
//		Obiekt.focus();
		Obiekt.className = StyleAlert;
		alert("Wpisany numer PESEL jest NIEPRAWIDŁOWY");
	}	
	else
	{
		Obiekt.className = StyleOK;
	}
}
// --------------------------------------------------------------------------------------
function GetAppMenu(Zdarzenie)
{
	Obj = document.getElementById("AppMenu");
	if (Obj.className == "ukryte")
	{
		if (ie)
		{
			X = Zdarzenie.clientX + document.documentElement.scrollLeft;
			//X = X - (CalDivObj.offsetWidth /2 );
			Y = Zdarzenie.clientY + document.documentElement.scrollTop;
			Obj.style.top = Y+5;
			Obj.style.left = X+5;
		}
		else
		{
			Y = Zdarzenie.pageY+5;	
			X = Zdarzenie.pageX+5 ;
			Obj.setAttribute("style","position:absolute;top:"+Y+"px;left:"+X+"px;");
		}	
//		Pokaz("AppMenu");
		$("#AppMenu").show("fast",function() {Obj.className = "widoczne"});
	}
	else
	{
//		Ukryj("AppMenu");
		$("#AppMenu").hide("fast",function (){Obj.className = "ukryte"});
	}
}
// --------------------------------------------------------------------------------------
function OgraniczTextArea(Obj,Length)
{
	if (Obj.value.length > Length)
	{
		Obj.value = Obj.value.substring(0,Length)
	}
}
// --------------------------------------------------------------------------------------
function Zmien(IdToHide,IdToDsp)
{
	Ukryj(IdToHide);
	Pokaz(IdToDsp);
}
// --------------------------------------------------------------------------------------
function ClearMainBody()
{
	Obj = document.getElementById("MainBody");
	Obj.innerHTML = "<p class='alert'>Proszę czekać trwa ładowanie</p>";
}
// --------------------------------------------------------------------------------------
function CzyNull(Sender)
{	
	if(Sender.value == "")
	{
		if(!$(Sender).hasClass("req"))
		{
			$(Sender).addClass("req");
		}
	}
	else
	{
		$(Sender).removeClass("req");
	}
}
// --------------------------------------------------------------------------------------
function CzyInt(Obiekt,DefaultValue)
{
	napis = Obiekt.value;
	napis = ComaToPoint(napis);
	if (isNaN(napis))
	{
		$(Obiekt).addClass("req");
	}	
	else
	{
		if (napis < 0)
		{		
			$(Obiekt).addClass("req");
		}
		else
		{
			$(Obiekt).removeClass("req");
			Obiekt.value = ToInt(napis);
		}
	}	
}
// --------------------------------------------------------------------------------------
function CzyReal(Obiekt,StyleOK,StyleAlert,OldValue)
{
	napis = Obiekt.value;
	napis = ComaToPoint(napis);
	if (isNaN(napis))
	{
		Obiekt.value = OldValue;
		Obiekt.focus();
		Obiekt.className = StyleAlert;
	}	
	else
	{
		if (napis < 0)
		{		
			Obiekt.value = OldValue;
			Obiekt.focus();
			Obiekt.className = StyleAlert;
		}
		else
		{
			Obiekt.className = StyleOK;
			Obiekt.value = ToCurr(napis);
		}
	}	
}
// --------------------------------------------------------------------------------------
function ComaToPoint (text)
{
	napis = "";
	for (i=0;i<text.length;i++)
	{		
		a=text.substring(i,i+1);
		if (a==',')
			a="."
		napis += a;
	}
	return napis;
}
// --------------------------------------------------------------------------------------
function ToCurr (liczba)
{

	if (liczba > 9999999999999)
		liczba = 9999999999999;
	
	if (liczba < -9999999999999)
		liczba = -9999999999999;
	
	liczba = Math.round(liczba*100);
	liczba = liczba /100;
	return liczba;
}
// --------------------------------------------------------------------------------------
function ToInt (liczba)
{

	if (liczba > 9999999999999)
		liczba = 9999999999999;
	
	liczba = Math.floor(liczba);
	return liczba;
}
// --------------------------------------------------------------------------------------
function SprawdzCombo(ComboObject)
{
	if (ComboObject.value == 0)
		ComboObject.className = "combo_alert";
	else
		ComboObject.className = "combo";
	
	return true;
}
// --------------------------------------------------------------------------------------
function SetRadioNoAlert(Nazwa)
{
	RadioObject = document.getElementsByName(Nazwa);
	a = RadioObject.length;	
	for (i=0;i<a;i++)
	{
		if(RadioObject[i].type == 'radio')
			RadioObject[i].className = "radio";
	}
}
// --------------------------------------------------------------------------------------
function BeforeSubmit(FormObject)
{
	a = FormObject.length;
	//window.status = "a: "+a;
	for (i=0;i<a;i++)
	{
		test = FormObject.elements[i];		
		if($(test).hasClass("req"))
		{
			alert('Nie wszystkie wymagane pola (wyróżnione) zostały wypełnione');
			return false;
		} 
	}
	return true;
}
// --------------------------------------------------------------------------------------
function Pokaz(IdObject)
{
//	Obj = document.getElementById(IdObject)
//	Obj.className = "widoczne";
//	//alert("widoczne");
	$("#"+IdObject).show("fast");
}
// --------------------------------------------------------------------------------------
function Ukryj(IdObject)
{
//	Obj = document.getElementById(IdObject)
//	Obj.className = "ukryte";
//	//alert("ukryte");
	$("#"+IdObject).hide("fast");
}
// --------------------------------------------------------------------------------------
function Przelacz(JQObj,Speed)
{
	Speed = typeof(VClass) != 'undefined' ? VClass : "fast";
//	Obj = document.getElementById(IdObject)
//	Obj.className = "ukryte";
//	//alert("ukryte");
	$(JQObj).toggle(Speed);
}
// --------------------------------------------------------------------------------------
function ReloadCalendar(Action,ObiectString)
{
	YearObject = document.getElementById("year");
	MonthObject = document.getElementById("month");	
	param = "?action="+Action+"&arg1="+YearObject.value+"-"+MonthObject.value+"-01&arg2="+ObiectString;
	location.href=param;
}
// --------------------------------------------------------------------------------------
function GoUrl(url)
{
	location.href=url;
}
// --------------------------------------------------------------------------------------
function CreateNewObject(IdObject,Zdarzenie,SenderObj,VClass)
{
	VClass = typeof(VClass) != 'undefined' ? VClass : "absolut PopUp";
	
	DivObj = document.getElementById(IdObject+"_out");
	if (!DivObj)	
	{
		DivObj = document.createElement("div");	
		DivObj.setAttribute("id",IdObject+"_out");	
		DivObj.className = VClass;
		DivObj.innerHTML = PrepareCloud("<div id='"+IdObject+"'>Loading...</div>",IdObject);
		BodyObj = document.getElementsByTagName("body");
		BodyObj[0].appendChild(DivObj);		
		if (ie)
		{
			X = Zdarzenie.clientX + document.documentElement.scrollLeft;
			//X = X - (DivObj.offsetWidth);
			
			if (X < 0)
				X=5;
			Y = Zdarzenie.clientY + document.documentElement.scrollTop;
			DivObj.style.top = Y+8;
			DivObj.style.left = X+8;
		}
		else
		{
			Y = Zdarzenie.pageY + 8;	
//			X = Zdarzenie.pageX - (DivObj.offsetWidth) +8;
			X = Zdarzenie.pageX  +8;
			if (X<0) 
				X=5;
			DivObj.setAttribute("style","top:"+Y+"px;left:"+X+"px;");
		}
		return true;
	}
	else
	{
		// zniszczenie obiektu!
		DivObj.className = "ukryte";
		BodyObj = document.getElementsByTagName("body");
		BodyObj[0].removeChild(DivObj);
		return false;
	}
}
// --------------------------------------------------------------------------------------
function DestroyObject(IdObject)
{
	DivObj = document.getElementById(IdObject);
	if (DivObj)	
	{
		DivObj.className = "ukryte";
		BodyObj = document.getElementsByTagName("body");
		BodyObj[0].removeChild(DivObj);
	}
}
// --------------------------------------------------------------------------------------
function PrepareCloud(Msg,IdObject)
{
	retval = "";
	
	retval += "<table id='TableToolTip'>";
	
	retval += "<tr>";
	retval += "<td id='LeftTopToolTip'></td>";	
	retval += "<td id='TopToolTip' class='r'><a class='link' OnClick='DestroyObject(\""+IdObject+"_out\")'><img alt='' src='/img/cross.png'></a></td>";	
	retval += "<td id='RightTopToolTip'></td>";	
	retval += "</tr>";
	
	retval += "<tr>";
	retval += "<td id='LeftToolTip'></td>";	
	retval += "<td id='ToolTip'>"+Msg+"</td>";	
	retval += "<td id='RightToolTip'></td>";	
	retval += "</tr>";
	
	retval += "<tr>";
	retval += "<td id='LeftBottomToolTip'></td>";	
	retval += "<td id='BottomToolTip'></td>";	
	retval += "<td id='RightBottomToolTip'></td>";	
	retval += "</tr>";	
	
	
	retval += "</table>";
	
	return retval;	
	
}
// --------------------------------------------------------------------------------------

