﻿function Calendar(E,T){
 if(!document.getElementById||!document.body.appendChild)return
 var i,j,tBody,Row,od,Do,d,dt
 function cEl(t,p,h,w){
  p.appendChild(t=document.createElement(t))
  if(h)t.innerHTML=h;if(w)t.style.width='27px'
  return t}
 function cB(x){with(cld_BlaTek){
  B=0;x==0?R--:x==1?R++:x==2?(!M?(M=11,R--):M--):(M==11?(M=0,R++):M++)}
 }
 with(cld_BlaTek){
  od=Date.UTC(R,M,1);Do=Date.UTC(R,M+1,1)}
 E=document.getElementById(E)
 while(E.childNodes.length)E.removeChild(E.firstChild)
 tBody=cEl('tbody',cEl('table',E))
 tBody.onmouseup=function(){T.focus()}
 tBody.onmousemove=function(){
  if(window.getSelection)window.getSelection().removeAllRanges()}
 Row=cEl('tr',tBody)
 cEl('td',Row,'&lt;',1).onmousedown=function(){cB(0)}
 cEl('th',Row,cld_BlaTek.R)
 cEl('td',Row,'&gt;',1).onmousedown=function(){cB(1)}
 Row=cEl('tr',tBody)
 cEl('td',Row,'&lt;',1).onmousedown=function(){cB(2)}
 cEl('th',Row,cld_BlaTek.month[cld_BlaTek.M])
 cEl('td',Row,'&gt;',1).onmousedown=function(){cB(3)}

 tBody=cEl('tbody',cEl('table',E))
 Row=cEl('tr',tBody)
 for(i=0;i<7;i++)
  with(cEl('th',Row,cld_BlaTek.day[i]))
   if(i==6)style.backgroundColor='#f88'

 for(i=od;i<Do;i+=86400000){
  with(new Date(i)){d=getUTCDate();dt=getUTCDay()}
  if(dt==1||i==od)Row=cEl('tr',tBody)
  if(dt!=1&&d==1)for(j=1;j<(dt?dt:7);j++)cEl('th',Row);
  dt=cEl('td',Row,d);

  dt.onmousedown=function(x){
	x=+this.innerHTML
	with(cld_BlaTek)
	// tu format zapisu daty
	T.value=(x<10?'0'+x:x)+'/'+((x=M+1)<10?'0'+x:x)+'/'+R;
  }
  
  with(cld_BlaTek)
  if(d==D.getDate()&&M==D.getMonth()&&R==D.getFullYear())
   dt.style.backgroundColor='#cccccc';
  with(cld_BlaTek)
   if((d<D.getDate()&&M==D.getMonth()&&R==D.getFullYear())||(M<D.getMonth()&&R<=D.getFullYear())||R<D.getFullYear()) {
   		dt.style.color='#aaaaaa';
	}
 }
 T.onblur=function(){if(cld_BlaTek.B)E.style.display='none'; sprawdzCzyPoprawneDaty(document.daty.date1.value, document.daty.date2.value);}
 cld_BlaTek.B=1;E.style.display='block'
}

/* POPUPS */

function otworzOkno (tytul, src, szer, wys, opis) {
		szer_ok = szer+10; 
		wys_ok = wys+10; 
		tlo = 'FFFFFF';	
		topmargin = 5;
		
		//if (wys_ok > screen.availWidth) wys_ok = screen.availWidth;
		//if (szer_ok > screen.availHeight) szer_ok = screen.availHeight;

		lok_hor=((screen.availWidth/2)-(szer_ok/2));
		lok_ver=((screen.availHeight/2)-(wys_ok/2));
		

		var okienko = window.open("", "", "toolbar=no, scrollbars=no, menubar=no, top=" + lok_ver + ", left=" + lok_hor + ", width=" + szer_ok + ", height=" + wys_ok);
		okienko.document.write("<html>\n<head>\n<title>" + tytul + "</title>\n</head>\n<style>td {text-align: center; font-family: Arial; font-size: 11px; font-weight: bold}</style>\n<body bgcolor=" + tlo + " marginwidth=0 marginheight=0 topmargin=" + topmargin + " leftmargin=0><center><table cellspacing=\"0\" cellpadding=\"0\" style=\"border: none\" border=0 width=" + szer + " height=" + wys + "><tr><td height=100% align=\"center\" valign=\"middle\"><a href=\"#\" onClick=\"window.close();\"><img src=\"" + src + "\" border=\"0\"></a></td></tr><tr><td>" + opis + "</td></tr></table></body></html>");
		//okienko.document.write("<img src=\"" + src + "\" border=\"0\">");
}

function otworzOknoSimple (url, width, height) {
		lok_hor=((screen.availWidth/2)-(width/2));
		lok_ver=((screen.availHeight/2)-(height/2));
        var Win = window.open(url,"OknoSimple",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=1,menubar=no,top='+lok_ver+',left='+lok_hor+',location=no');
		}


		
function otworzOknoObraz (tytul, url, width, height) {
		if (navigator.appName == 'Microsoft Internet Explorer') {
			width = width+40; 
			height = height+35
		}
		else {
			width = width+20;
			height = height+25
		}
		lok_hor=((screen.availWidth/2)-(width/2));
		lok_ver=((screen.availHeight/2)-(height/2));
        var Win = window.open(url,tytul,'width=' + width + ',height=' + height + ',resizable=0,scrollbars=1,menubar=no,top='+lok_ver+',left='+lok_hor+',location=no');
		Win.document.write = ('onClick="window.close();"');
		}

function otworzOknoObraz2 (tytul, src, szer, wys) {
		szer_ok = szer+10; 
		wys_ok = wys+10; 
		tlo = '#FFFFFF';	
		topmargin = 5;

		lok_hor=((screen.availWidth/2)-(szer_ok/2));
		lok_ver=((screen.availHeight/2)-(wys_ok/2));

		var okienko = window.open('syp', 'okieno', 'toolbar=no,scrollbars=no,menubar=no,top=' + lok_ver + ',left=' + lok_hor + ',width=' + szer_ok + ',height=' + wys_ok);
		okienko.document.write('<html>\n<head>\n<title>' + tytul + '</title>\n<meta name="Pragma" content="no-cache" />\n</head>\n<style>td {text-align: center; font-family: Arial; font-size: 11px; font-weight: bold}</style>\n<body bgcolor="' + tlo + '" marginwidth="0" marginheight="0" topmargin="' + topmargin + '" leftmargin="0"><center><table cellspacing="0" cellpadding="0" style="border: none" border="0" width="' + szer + '" height="' + wys + '"><tr><td height="100%" align="center" valign="middle"><a href="#" onClick="window.close();"><img src="' + src + '" border="0"></a></td></tr></table></body></html>');
}

/* POPUPS */

		
function dataDoSUmyKontrolnej(data) {
		dzien = data.substring(0, 2);
		mc = data.substring(3, 5);
		rok = data.substring(6, 10);
		sumakontrolna = rok*365+mc*30+dzien;
		return sumakontrolna;
}

function sprawdzCzyPoprawneDaty(data1, data2) {
	
	//dzisiaj
	D=new Date();
	dzien=D.getDate();
	mc=D.getMonth()+1;
	rok=D.getFullYear();
	dataZeSlashami = (dzien<10?'0'+dzien:dzien)+'/'+(mc<10?'0'+mc:mc)+'/'+rok;
	dzisiaj = dataDoSUmyKontrolnej(dataZeSlashami);
	
	if ((dataDoSUmyKontrolnej(data1)>=dzisiaj&&dataDoSUmyKontrolnej(data2)>dzisiaj)
		||(dataDoSUmyKontrolnej(data1)>=dzisiaj&&dataDoSUmyKontrolnej(data2)==0)
		||(dataDoSUmyKontrolnej(data2)>=dzisiaj&&dataDoSUmyKontrolnej(data1)==0)) {
	
		//alert ('dzis:'+dzisiaj+', wprowadzono:' + dataDoSUmyKontrolnej(data1)+', '+ dataDoSUmyKontrolnej(data2));
	
		if (data1!=''&&data2!='') {
		
			if (dataDoSUmyKontrolnej(data1)>=dataDoSUmyKontrolnej(data2)) {
			alert ( ZlaDataMsg[0] ); document.daty.date1.value=''; document.daty.date2.value=''}
	
		}
	}
	else {
		alert ( ZlaDataMsg[1] );
		document.daty.date1.value='';
		document.daty.date2.value='';
	}

}

function wstawAktualnaDate() {
Dzisiaj = new Date();
dzien = Dzisiaj.getDate();
if (dzien < 10) dzien = "0" + dzien;
miesiac = (Dzisiaj.getMonth()+1);
if (miesiac < 10) miesiac = "0" + miesiac;
if (Dzisiaj.getYear()<1900) rok = (Dzisiaj.getYear()+1900);
else rok = Dzisiaj.getYear();

DzisiejszaData = dzien  + "/" + miesiac + "/" + rok;
return DzisiejszaData;
}

function spelnijWarunkiEdycjiAdmin() {
	if(document.formularz.nazwa_pl.value=='') alert ('Nazwa pozycji w języku Polskim jest obowiązkowa.');
	else if(document.formularz.foto_0_old.value==''&&document.formularz.foto_0.value=='') alert ('Zdjęcie nr 1 jest obowiązkowe'); 
	else document.formularz.submit();
}

function sprawdzCzyEmail(string) {
	wzor=/^[a-zA-Z0-9ąęóńżźćśłĄĘÓŃŻŹĆŚŁ\.\-]{1,30}@[a-zA-Z0-9ąęóńżźćśłĄĘÓŃŻŹĆŚŁ\-]+(\.[a-zA-Z0-9ąęóńżźćśłĄĘÓŃŻŹĆŚŁ\-]+)+$/;
	if (string.match(wzor)) return true;
	else return false;
}

function sprawdzCzyTelefon(string) {
	wzor=/^[\d\+\s\-]{9,30}$/;
	if (string.match(wzor)) return true;
	else return false;
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function UkryjElement(nazwa) {
	var x = new getObj(nazwa);
	x.style.display = 'none';
}

function obsadzFlasha(nazwa_pliku, szer, wys) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" id="flash" width="'+szer+'" height="'+wys+'">');
  	document.write('<param name="movie" value="'+nazwa_pliku+'">');
	document.write('<param name="bgcolor" value="#FFFFFF">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="allowscriptaccess" value="samedomain">');
  	document.write('<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="'+szer+'" height="'+wys+'" name="flash" src="'+nazwa_pliku+'" bgcolor="#FFFFFF" quality="high" swLiveConnect="true" allowScriptAccess="samedomain"></embed>');
	document.write('</object>');
}
/* NIEUZYWANE */
function zapiszCiacho(tresc) {
	dzis = new Date();
    dzis.setTime(dzis.getTime() + 365*24*60*60*1000);
    s = dzis.toGMTString();
	document.cookie = "oferta_print=" + tresc + "; expires=" + s;
}
function odczytajCiacho(nazwa) {
  var start = document.cookie.indexOf(nazwa + "=");
  var len = start + nazwa.length + 1;
  if ((!start) && (document.cookie.substring(0, nazwa.length) != nazwa))  return null;
  if (start == -1) return null;

  var end = document.cookie.indexOf(";", len);
  if (end == -1) end = document.cookie.length;
  return document.cookie.substring(len, end);
 }
 /* NIEUZYWANE */
 
function drukujOferte() {
	otworzOknoSimple ('drukuj_oferte.php', 670, 700);
}