function CopyRestaurant(RestaurantId)
{
	GoUrl("?action=SelToCity&arg1="+RestaurantId+"","self");
}
// ---------------------------------------------------------------
function DodajSubmiasto()
{
	val = prompt("Podaj nazwę nomego SubMiasta");
	if (val != null)
	{
		if (val != "")
		{
			location.href="?action=InsSubCity&arg1="+val;
		}
	}	
}

function ZmienDzielnice(DzielnicaId,RestId)
{
	val = prompt("Podaj nazwę nowej tej kategorii");
	if (val != null)
	{
		if (val != "")
		{
			location.href="?action=UpdDziel&arg1="+RestId+"&arg3="+val+"&arg2="+DzielnicaId; // do topowego okna
		}
	}	
}
function DodajDzielnice()
{
	val = prompt("Podaj nazwę nowej dzielnicy");
	if (val != null)
	{
		if (val != "")
		{
			location.href="?action=InsDziel&arg1="+val; // do topowego okna
		}
	}	
}
function ZmienMiastoAdmin(Object)
{
	
	location.href="?action=ChgCity&arg1="+Object.value;	
	
}
function ZmienMiasto(Object)
{
	
	//location.href="?action=ChgCity&arg1="+Object.value;
	
	switch (Object.value)
	{
		case "6":
			location.href="http://krakow.lunchnet.pl";
			break;
		case "5":
			location.href="http://gdansk.lunchnet.pl";
			break;
		case "4":
			location.href="http://warszawa.lunchnet.pl";
			break;
		case "3":
			location.href="http://poznan.lunchnet.pl";
			break;
		case "2":
			location.href="http://katowice.lunchnet.pl";
			break;
		case "1":
			location.href="http://wroclaw.lunchnet.pl";
			break;
	}
	
}
function DodajDoKoszyka(ItemId)
{
	Object = document.getElementById("ilosc");
	Ilosc = Object.value;
	parent.main.location.href="?action=ZamTow&arg1="+ItemId+"&arg2="+Ilosc;
}
function TowarInfo(ItemId)
{
	location.href="?action=GetTow&arg1="+ItemId;
}

function FinalizujZamowienie()
{
	parent.main.location.href="login.php?action=ClsZamFrm";
}
function DodajJednoDoKoszyka(ItemId,RestId)
{
	parent.main.location.href="?action=ZamTowOne&arg1="+ItemId+"&arg2="+RestId;
}
function DelRest(RestId)
{
	if (confirm("Czy na pewno chcesz BEZPOWROTNIE usunąć tą restauracje??? "))
	{
		parent.location.href="?action=DelRest&arg1="+RestId; // do topowego okna
	}
	else 
		return false;
}
function DelKuchnia(KuchniaId)
{
	if (confirm("Czy na pewno chcesz BEZPOWROTNIE usunąć tą kuchnie??? "))
	{
		parent.location.href="?action=DelKit&arg1="+KuchniaId; // do topowego okna
	}
	else 
		return false;
}
function ZmienNazweKategorii(KategoriaId)
{
	val = prompt("Podaj nazwę nowej tej kategorii");
	if (val != null)
	{
		if (val != "")
		{
			parent.location.href="?action=EdtCat&arg1="+val+"&arg2="+KategoriaId; // do topowego okna
		}
	}	
}
function DeleteTowar(TowarId)
{
	if (confirm("Czy na pewno chcesz BEZPOWROTNIE usunąć tą pozycje z menu??? "))
	{
		parent.location.href="?action=DelTow&arg1="+TowarId; // do topowego okna
	}
	else 
		return false;
}
function AddNewKitchen()
{
	val = prompt("Podaj nazwę nowej kuchni");
	if (val != null)
	{
		if (val != "")
		{
			location.href="?action=AddKit&arg1="+val; 
		}
	}
}

function AddNewRestaurant(KuchniaId)
{
	val = prompt("Podaj nazwę nowej restauracji");
	if (val != null)
	{
		if (val != "")
		{
			parent.location.href="?action=AddRest&arg1="+val+"&arg2="+KuchniaId; // do topowego okna
		}
	}
}
function Search()
{
	input = document.getElementById("SEARCH");

	parent.main.location.href="?action=GetSrc&arg1="+input.value;
}
function GoUrl(url,frame)
{
	if (frame == "main")
		parent.main.location.href=url;
	else if (frame == "new")
		window.open(url);
	else if (frame == "self")
		location.href=url;
		
}
function GetCloseZamowienieForm()
{
	parent.main.location.href="login.php?action=ClsZamFrm";
}

function DodajNowyTowar(RestId)
{
	val = prompt("Podaj nazwę nowej pozycji w menu");
	if (val != null)
	{
		if (val != "")
		{
			parent.location.href="?action=AddTow&arg1="+val+"&arg2="+RestId;
		}
	}
}


function DodajKategorie()
{
	val = prompt("Podaj nazwę dla nowej kategorii");
	if (val != null)
	{
		if (val != "")
		{
			location.href="?action=AddCat&arg1="+val;
		}
	}
}

// =================================================
function CzyNull(Obiekt,StyleOK,StyleAlert)
{
	napis = Obiekt.value;
	//alert (napis);
	if (napis == "")
	{
		Obiekt.focus();
		Obiekt.className = StyleAlert;
	}	
	else
	{
		Obiekt.className = StyleOK;
	}	
}

function CzyInt(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 = 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;
	
	liczba = Math.floor((liczba*100)+0.5);	
	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 BeforeSendMail(FormObject,jezyk)
{
	a=FormObject.length;
	//window.status = "a: "+a;
	for (i=0;i<a;i++)
	{
		test = FormObject.elements[i];
		//alert(test);
		if (test.value == "")
		{
			if (jezyk == 1)
			{
				alert('Nie wszystkie wymagane pola (wyróżnione) zostały wypełnione');
				return false;
			}
			else
			{
				alert('Not all field are filed');
				return false;
			}			
		} 
	}
	return true;
}

function BeforeSubmit(FormObject)
{
	a=FormObject.length;
	//window.status = "a: "+a;
	for (i=0;i<a;i++)
	{
		test = FormObject.elements[i].className;
		//alert(test);
		if (test.length >=6)
		{
			dl = test.length;			
			alerttest = test.substring(dl-6,dl);
			//alert('test: '+test + ' alerttest: '+ alerttest +' dl: '+ dl);
			if (alerttest == "_alert")
			{
				alert('Nie wszystkie wymagane pola (wyróżnione) zostały wypełnione');
				return false;
			}
		} 
	}
	return true;
}


function Pokarz(IdObject)
{
	Object = document.getElementById(IdObject)
	Object.className = "widoczne";
	//alert("widoczne");
}


function Ukryj(IdObject)
{
	Object = document.getElementById(IdObject)
	Object.className = "ukryte";
	//alert("ukryte");
}
function ReloadCalendar(ObiectString)
{
	YearObject = document.getElementById("year");
	MonthObject = document.getElementById("month");	
	param = "?data="+YearObject.value+"-"+MonthObject.value+"-01&object="+ObiectString;
	location.href=param;
}



