﻿function ukryj_form () {
	document.getElementById('osoba_zamawiajaca').style.display="none";
	document.getElementById('inna_pojemnik').style.display="none";
	document.getElementById('pojemnik_zarzadzanie').style.display="none";
}

function zalacz () {
	document.getElementById('powieksz_czcionke').style.display="block";
	if (!(!document.getElementById('formularz_cena'))) {
	ukryj_form ();
	};
}

function powiekszenie(e) {	
			if (document.getElementById('tresc').style.fontSize=="" || document.getElementById('tresc').style.fontSize=="8pt" ) {
					document.getElementById('tresc').style.fontSize="12px";
					document.getElementById('link').className="pomniejsz";					
			}
			else {
			document.getElementById('tresc').style.fontSize="8pt";
			document.getElementById('link').className="powieksz";
			};
			(e.preventDefault) ? e.preventDefault() : (e.returnValue = false);
}

//funkcje formularza////////////////////////////////////////////////////////////
function ukryj_firma () {
	document.getElementById('dane_firmy_pojemnik').style.display="none";
	document.getElementById('osoba_zamawiajaca').style.display="inline";
	document.getElementById('osoba_kontaktowa').style.display="none";
}

function pokaz_firma () {
	document.getElementById('dane_firmy_pojemnik').style.display="block";
	document.getElementById('osoba_zamawiajaca').style.display="none";
	document.getElementById('osoba_kontaktowa').style.display="inline";
}

function kontakt_email () {
	document.getElementById('tel_wym').style.display="none";
	document.getElementById('adres_e_wym').style.display="inline";
}

function kontakt_tel () {
	document.getElementById('adres_e_wym').style.display="none";
	document.getElementById('tel_wym').style.display="inline";
}

function inna_niewiem(e) {
	var el;			
			if(window.event && window.event.srcElement) { el = window.event.srcElement; }
			if(e && e.target) { el = e.target; }
			if(!el) { return;	}
	if (el.id=='inna' || el.id=='nie_wiem') {document.getElementById('inna_pojemnik').style.display="block";}
	else {document.getElementById('inna_pojemnik').style.display="none";};
}


function ukryj_administracja () {
	document.getElementById('pojemnik_zarzadzanie').style.display="none";
}

function pokaz_administracja () {
	document.getElementById('pojemnik_zarzadzanie').style.display="block";
}

function aktywny (e) {
			var el;			
			if(window.event && window.event.srcElement) { el = window.event.srcElement; }
			if(e && e.target) { el = e.target; }
			if(!el) { return;	}
	document.getElementById(el.id).style.border='#900 1px solid';
}

function nie_aktywny (e) {
			var el;			
			if(window.event && window.event.srcElement) { el = window.event.srcElement; }
			if(e && e.target) { el = e.target; }
			if(!el) { return;	}
	document.getElementById(el.id).style.border='#999 1px solid';
}


//////////////////////////////////////////////////////////////////////////////

///funkcja do zalanczania javyscripta
/*
function aEL(o,t,f){var a=Array.prototype.slice.call(arguments,3) 
o[t+f]=function(e){return !1===f.apply(o,[e||window.event].concat(a))?e.preventDefault?e.preventDefault():!1:1} 
return(o.x=o.addEventListener)?o.x(t,o[t+f],!1):(o.x=o.attachEvent)?o.x('on'+t,o[t+f]):!1}

function rEL(o,t,f){f=o[t+f] 
return(o.x=o.removeEventListener)?o.x(t,f,!1):(o.x=o.detachEvent)?o.x('on'+t,f):!1 
}


aEL(window, 'load', tada, 'zaladowala sie') 
function tada(ev) { 
alert(ev) ;
} 

rEL(window, 'load', tada);
*/

///wybieranie elementow o odpowiedniej nazwie
function getElementsByName(findName) {
	var aElm=document.body.getElementsByTagName('*');
	for(var i=0; i<aElm.length; i++) {
	if(aElm[i].name==findName) {
		addEvent(document.getElementById(aElm[i].id), "focus", inna_niewiem);
}
} 
}

///wybieranie elementow o odpowiedniej clasie
function getElementsByClassName(findClass) {
var aElm=document.body.getElementsByTagName('*');
for(var i=0; i<aElm.length; i++) {
if(aElm[i].className==findClass) {
addEvent(document.getElementById(aElm[i].id), "focus", aktywny);
addEvent(document.getElementById(aElm[i].id), "blur", nie_aktywny);
}
} 
};


///okienko popapu		

function wyskakujaceOkienko(e) {
			var el;			
				if(window.event && window.event.srcElement) { el = window.event.srcElement; }
				if(e && e.target) { el = e.target; }
				if(!el) { return;	}
				//alert(el.parentNode.tagName);
				if (el.tagName != "A") {element = el.parentNode.href}
				else {element = el.href};
				
				var winopts = "scrollbars=yes,dependent=yes,toolbar=no,resizable=yes,width=" + 702 + ',height=' + 400;
				var win = window.open(element,'_blank',winopts);
				if (win && win.opener)
					{
						kodOkna (win,element,'podgląd szablonu graficznego');
						
					}
			return false;
};

function przypisaniePopapaDlaClass (findClass) {
	var linki = document.getElementsByTagName('a'); 
		for(i=0; i < linki.length; i++) { 
				if (linki[i].className==findClass) {
				 linki[i].onclick = wyskakujaceOkienko;  
				 //addEvent(document.getElementById(linki[i].id), 'click', eventHander);
				 };
		}
};

function kodOkna (win,plik,tytul)
	{	
		
		//plik ="pakiety/wzory_d/"+href.substr(plik.length-8,plik.length);
		//replace("wzory","wzory_d");
		var doc = win.document;
		doc.open('text/html;charset=utf-8');
		doc.write(
		'<?xml version="1.0" encoding="UTF-8"?>'+
		'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'+
		'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">' +
		'<head><title>' + tytul + '</title>' +
		'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' +
		'<meta http-equiv="imagetoolbar" content="false">' +
		'</head><body style="margin:0px; padding:0px;" onclick="window.close();">' +
		'<img src="'+plik+'" alt="wzor pakietu" />' +
		'</body></html>'
		);
		doc.close();
	}

//////////////////////////////////////////



		function addEvent(obj, type, fn) {
			if (obj.addEventListener) {
				obj.addEventListener(type, fn, false);
			} else if (obj.attachEvent) {
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() {obj["e"+type+fn](window.event); }
				obj.attachEvent("on"+type, obj[type+fn]);
			}
		}
		
		function funkcja_inicjujaca() {
			addEvent(document.getElementById("link"), "click", powiekszenie);
			zalacz ();
			przypisaniePopapaDlaClass('popup');
			if (!(!document.getElementById('formularz_cena'))) {
				addEvent(document.getElementById("strona_dla_p"), "focus", ukryj_firma);
				addEvent(document.getElementById("strona_dla_firma"), "focus", pokaz_firma);
				addEvent(document.getElementById("typ_kontaktu_email"), "focus", kontakt_email);
				addEvent(document.getElementById("typ_kontaktu_tel"), "focus", kontakt_tel);
				getElementsByName('rodzaj_informacj');
				getElementsByClassName('wpisywanie');
				addEvent(document.getElementById("statyczna"), "focus", ukryj_administracja);
				addEvent(document.getElementById("panel"), "focus", pokaz_administracja);
			};
			
			if (!(!document.getElementById('formularz_kontakt'))) {
				getElementsByClassName('wpisywanie');
			};
			
		}
		
		addEvent(window, "load", funkcja_inicjujaca);
		
