function f_select(id)
{
	document.MainForm.SelectedID.value=id;
	document.MainForm.submit();
}

function f_commit()
{
	document.MainForm.Commit.value='1';
	document.MainForm.submit();
}

function f_navigate(url)
{
    document.MainForm.action=url;
    document.MainForm.submit();
}

function window_close()
{
  window.close();
}


function top_close()
{
  window.top.close();
}

function f_go_url(url)
{
    window.navigate(url);
}

function opener_refresh()
{
  window.opener.document.MainForm.submit();
}

function show_error(error)
{
	alert(error);
}

function open_center_window(href,name,width,height,other)
{
	var l = (window.screen.width -width)/2;
	var t = (window.screen.height -height)/2;
	
	window.open('wait.htm',name,"left="+l+",top="+t+",width="+width+",height="+height+","+other)
	var win=window.open(href,name,"left="+l+",top="+t+",width="+width+",height="+height+","+other);
	return win;
}

	function ShowDescription(objDiv)
	{	
		x = event.clientX + document.body.scrollLeft; /* get the mouse left position */
		y = event.clientY + document.body.scrollTop+15; /* get the mouse top position  */
		objDiv.filters["alpha"].opacity = 90;
		objDiv.style.display = "block";
		objDiv.style.left = x+document.all.map_img_div.offsetLeft;
		objDiv.style.top = y+document.all.map_img_div.offsetTop;
	}

	function ShowDescriptionAtMouse(objDiv)
	{	
		x = event.clientX + document.body.scrollLeft; /* get the mouse left position */
		y = event.clientY + document.body.scrollTop+15; /* get the mouse top position  */
		objDiv.filters["alpha"].opacity = 90;
		objDiv.style.display = "block";
		objDiv.style.left = x;
		objDiv.style.top = y;
	}
	
	function HideDescription(objDiv)
	{
		objDiv.style.display = "none";
	}


	function ShowRefreshDescriptionAt(objDiv,x,y,sizex)
	{	
		objDiv.filters["alpha"].opacity = 90;
		objDiv.style.display = "block";
		objDiv.style.width = sizex;
		objDiv.style.left = x;
		objDiv.style.top = y;
	}	

	function ShowDescriptionAt(objDiv,x,y,sizex)
	{	
		objDiv.filters["alpha"].opacity = 90;
		objDiv.style.display = "block";
		objDiv.style.width = sizex;
		objDiv.style.left = x+document.all.map_img_div.offsetLeft;
		objDiv.style.top = y+document.all.map_img_div.offsetTop;
	}	

	function ShowIconAt(objDiv,x,y)
	{	
	    if ((x>0) && (y>0))
	    {
			objDiv.filters["alpha"].opacity = 90;
			objDiv.style.display = "block";
			objDiv.style.left = x+document.all.map_img_div.offsetLeft;
			objDiv.style.top = y+document.all.map_img_div.offsetTop;
		}
	}	

	function HideIconInfo()
	{
		HideDescription(document.all.div_mapinfo);
	}

	function HideObjectInfo()
	{
		HideDescription(document.all.div_objectmapinfo);
	}
	
function y2k(number) { return (number < 1000) ? number + 1900 : number; } 

function isDate1 (day,month,year) {
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false;
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
	 (month == test.getMonth()) &&
	 (day == test.getDate()) )
	return 1;
    else
	return 0;
}


function checkIfDate(val)
{
 re = /[^0-9\-]/i; // sprawdza według formatu dd-mm-yyyy
 v = val.search(re);
 if (v!=-1) return 1; // są znaki które nie są liczbami
 arr=val.split("-");
 if ((arr[0]==null)||(arr[1]==null)||(arr[2]==null))
   return 2; // za mało sekcji
 if (arr[3]!=null)
   return 3;  // za dużo sekcji
 if (isDate1(toInteger(arr[0]),toInteger(arr[1]),toInteger(arr[2]))!=1)
   return 4; // zła data
}


function toInteger(val)   // zmienia string na integer
{
	if (val=="01")	 return 1;
	if (val=="02")	 return 2;
	if (val=="03")	 return 3;
	if (val=="04")	 return 4;
	if (val=="05")	 return 5;
	if (val=="06")	 return 6;
	if (val=="07")	 return 7;
	if (val=="08")	 return 8;
	if (val=="09")	 return 9;
    if ((val!="09")&&(val!="08")&&(val!="07")&&(val!="06")&&(val!="05")&&(val!="04")&&(val!="03")&&(val!="02")&&(val!="01"))
	return parseInt(val);
}


function checkIfNumeric(val)
 {
	re = /^[,]/i;
	v = val.search(re);
	if (v!=-1)
	  val="0"+val;
	re = /[^0-9,]/i;
	v = val.search(re);
	if (v!=-1)
	 return 1; // znaki które nie są cyframi
	else
	{
		re = /[,]$/i;
		v = val.search(re);
		if (v!=-1)
		 return 2;  // kropka na końcu
		else
		{
			re = /^[,]/i;
			v = val.search(re);
			if (v!=-1)
			 return 3; // kropka na początku
			else
			{
				re = /,[0-9]*,/i;
				v = val.search(re);
				if (v!=-1)
				 return 4;  // dwie albo więcej kropek
			}
		}
	}
	return 0;
 }

function checkIfNumeric2(val)
 {
	re = /^[\.]/i;
	v = val.search(re);
	if (v!=-1)
	  val="0"+val;
	re = /[^0-9\.]/i;
	v = val.search(re);
	if (v!=-1)
	 return 1; // znaki które nie są cyframi
	else
	{
		re = /[\.]$/i;
		v = val.search(re);
		if (v!=-1)
		 return 2;  // kropka na końcu
		else
		{
			re = /^[\.]/i;
			v = val.search(re);
			if (v!=-1)
			 return 3; // kropka na początku
			else
			{
				re = /\.[0-9]*\./i;
				v = val.search(re);
				if (v!=-1)
				 return 4;  // dwie albo więcej kropek
			}
		}
	}
	return 0;
 }



 function checkIfInteger(val)
 {
	re = /\D/i;
	v = val.search(re);
	if (v!=-1)
	 return 1; // znaki które nie są cyframi
	return 0;
 }

function alertDate(val,pole)
{
 if (val=="") return false;
 tmp=checkIfDate(val);
 if (tmp==1) {alert("["+pole+"] W dacie są znaki które nie są poprawne"); return true;}
 if (tmp==2) {alert("["+pole+"] W dacie jest za mało znaków"); return true;}
 if (tmp==3) {alert("["+pole+"] W dacie jest za dużo znaków"); return true;}
 if (tmp==4) {alert("["+pole+"] Podana data jest błędna"); return true;}
}

function alertInteger(val,pole)
{
 if (val=="") return false;
 tmp=checkIfInteger(val);
 if (tmp==1) {alert("["+pole+"] W danej liczbowej są znaki które nie są poprawne"); return true;}
}

function alertIntegerNonZero(val,pole)
{
 if (val=="") return false;
 tmp=checkIfInteger(val);
 if (tmp==1) {alert("["+pole+"] W danej liczbowej są znaki które nie są poprawne"); return true;}
 if (val=="0") {alert("["+pole+"] Dana liczbowa powinna być większa od zera"); return true;}
}

function alertNumeric(val,pole)
{
 if (val=="") return false;
 tmp=checkIfNumeric(val);
 if (tmp==1) {alert("["+pole+"] W danej numerycznej są znaki które nie są poprawne"); return true;}
 if (tmp==2) {alert("["+pole+"] W danej numerycznej kropka jest na początku"); return true;}
 if (tmp==3) {alert("["+pole+"] W danej numerycznej kropka jest na końcu"); return true;}
 if (tmp==4) {alert("["+pole+"] W danej numerycznej jest za dużo kropek"); return true;}
}

function alertObligatory(val,pole)
{
 if (val=="") { alert("["+pole+"] Nie wypełniono wszystkich potrzebnych danych"); return true;}
 re = /[^\s]/i;
 v = val.search(re);
 if (v==-1)
  { alert("["+pole+"] Nie wypełniono wszystkich potrzebnych danych"); return true;}
}

function alertPolish(val,pole)
{
 if (val=="") return false;
 re = /[ąśćńłóężź]/i;
 v = val.search(re);
 if (v!=-1)
  {
    alert("["+pole+"] W danej są polskie znaki które nie są poprawne");
    return true;
  }
}

function trimString(val)
{
  v=val;
  ind=0;
  while (v.charAt(0)==' ')
  {
    if (v.length>0)
     v=v.substr(1,v.length-1);
  }
  ind=v.length;
  while (v.charAt(ind-1)==' ')
  {
    if (ind>0)
    {
     ind=ind-1;
     v=v.substr(0,ind);
    }
  }
  return v;
}

		function checkIfTime(val)
		{
			re = /[^0-9\:]/i; // sprawdza według formatu 
			v = val.search(re);
			if (v!=-1) return 1; // są znaki które nie są liczbami
			arr=val.split(":");
			if ((arr[0]==null)||(arr[1]==null))
			return 2; // za mało sekcji
			if (arr[2]!=null)
			return 3;  // za dużo sekcji
			x=toInteger(arr[0]);
			if (x>23)
				return 4; // zły czas
			x=toInteger(arr[1]);
			if (x>59)
				return 4; // zły czas
		}

		function alertTime(val,pole)
		{
		if (val=="") return false;
		tmp=checkIfTime(val);
		if (tmp==1) {alert("["+pole+"] W czasie są znaki które nie są poprawne"); return true;}
		if (tmp==2) {alert("["+pole+"] W czasie jest za mało znaków"); return true;}
		if (tmp==3) {alert("["+pole+"] W czasie jest za dużo znaków"); return true;}
		if (tmp==4) {alert("["+pole+"] Podany czas jest błędny"); return true;}
		}

			
