/* Formularz kontaktowy
* @ dyktek/hadzia...
*/


	// 1 kodujemy, 0 rozkodujemy
	function pl2Uni(string, driv){
	
		var uni = new Array();
		    uni[0] = 'UNI261';
			uni[1] = 'UNI260';
			uni[2] = 'UNI281';
			uni[3] = 'UNI280';
			uni[4] = 'UNI322';
			uni[5] = 'UNI321';
			uni[6] = 'UNI324';
			uni[7] = 'UNI323';
			uni[8] = 'UNI211';
			uni[9] = 'UNI210';
			uni[10] = 'UNI347';
			uni[11] = 'UNI346';
			uni[12] = 'UNI377';
			uni[13] = 'UNI378';
			uni[14] = 'UNI379';
			uni[15] = 'UNI380';	
			uni[16] = 'UNI262';	
			uni[17] = 'UNI263';	
			
		var plWin = new Array();
			plWin[0] = '';
			plWin[1] = '';
			plWin[2] = '';
			plWin[3] = '';
			plWin[4] = '';
			plWin[5] = '';
			plWin[6] = '';
			plWin[7] = '';
			plWin[8] = '';
			plWin[9] = '';
			plWin[10] = '';
			plWin[11] = '';
			plWin[12] = '';
			plWin[13] = '';
			plWin[14] = '';
			plWin[15] = '';			
			plWin[16] = '';
			plWin[17] = '';
			
		var uniReg = new Array();
		    uniReg[0] = /UNI261/g;
			uniReg[1] = /UNI260/g;
			uniReg[2] = /UNI281/g;
			uniReg[3] = /UNI280/g;
			uniReg[4] = /UNI322/g;
			uniReg[5] = /UNI321/g;
			uniReg[6] = /UNI324/g;
			uniReg[7] = /UNI323/g;
			uniReg[8] = /UNI211/g;
			uniReg[9] = /UNI210/g;
			uniReg[10] = /UNI347/g;
			uniReg[11] = /UNI346/g;
			uniReg[12] = /UNI377/g;
			uniReg[13] = /UNI378/g;
			uniReg[14] = /UNI379/g;
			uniReg[15] = /UNI380/g;	
			uniReg[16] = /UNI262/g;	
			uniReg[17] = /UNI263/g;		
			
		var pl = new Array();
			pl[0] = /[||]+/g;
			pl[1] = /(|)+/g;
			pl[2] = /()+/g;
			pl[3] = /()+/g;
			pl[4] = /()+/g;
			pl[5] = /()+/g;
			pl[6] = /()+/g;
			pl[7] = /()+/g;
			pl[8] = /()+/g;
			pl[9] = /()+/g;
			pl[10] = /(|)+/g;
			pl[11] = /(|)+/g;
			pl[12] = /(|)+/g;
			pl[13] = /(|)+/g;
			pl[14] = /()/g;
			pl[15] = /()+/g;	
			pl[16] = /()+/g;
			pl[17] = /()+/g;
			
			var result = new Array();
			
			result[0] = string;
		
			for(i=0; i < pl.length; i++){
				if(driv == 1)
					result[i+1] = result[i].replace(pl[i], uni[i]);
				else if(driv == 0)
					result[i+1] = result[i].replace(uniReg[i], plWin[i]);
			}		
		return result[i];
	}
	

	function isValid(){
	
		var control = new Array();
		control[0] = false;
		control[1] = false;
		control[2] = false;
		
		var imie = document.getElementById('imie');
		var email = document.getElementById('email');
		var tresc = document.getElementById('tresc');
		var firma = document.getElementById('firma');
		var miejscowosc = document.getElementById('miejscowosc');
		var telefon = document.getElementById('telefon');
		
		var regTresc = /^([a-zA-Z0-9ʣѦӬ\-\,\!\&\_\.\: ]{1,})$/;
		var regMiejsc = /^([a-zA-Z0-9ʣѦӬ\-\,\!\&\_\.\: ]{1,})$/;
		var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{1,4})$/;
		var regFon = /^([0-9\- ]{1,})$/;
		
		
		if( regFon.test( telefon.value ) ){
			telefon.style.border = '1px solid #cacaca';
			document.getElementById( 'iKom6' ).innerHTML = 'Telefon';
			control[0] = true 
		} else {
			document.getElementById( 'iKom6' ).innerHTML = 'Wpisz telefon, dozwolone znaki: <b>TYLKO CYFRY</b>';
			telefon.style.border = '1px solid red'; 
			control[0] = false;
		}
		
		
		
		if(regTresc.test(imie.value)){
			imie.style.border = '1px solid #cacaca';
			document.getElementById('iKom').innerHTML = 'Imie i nazwisko';
			control[0] = true 
		} else {
			document.getElementById('iKom').innerHTML = 'Wpisz imie i nazwisko, dozwolone znaki: <b>TYLKO LITERY</b>';
			imie.style.border = '1px solid red'; 
			control[0] = false;
		}
		
		if(regEmail.test(email.value)){
			document.getElementById('iKom2').innerHTML = 'Adres e-mail';
			email.style.border = '1px solid #cacaca';
			control[1] = true;
		} else {
			document.getElementById('iKom2').innerHTML = 'wpisz adres e-mail w poprawnym formacie';
			email.style.border = '1px solid red';
			control[1] = false;
		}
		
		if(regTresc.test(tresc.value)){
			document.getElementById('iKom3').innerHTML = 'Tresc';
			tresc.style.border = '1px solid #cacaca';
			control[2] = true;
		} else {
			document.getElementById('iKom3').innerHTML = 'Wpisz tresc, dozwolone znaki: <b>TYLKO LITERY i CYFRY</b>';
			tresc.style.border = '1px solid red';
			control[2] = false;
		}
		
		if( regMiejsc.test( miejscowosc.value ) ){
			document.getElementById('iKom5').innerHTML = 'Miejscowosc';
			miejscowosc.style.border = '1px solid #cacaca';
			control[2] = true;
		} else {
			document.getElementById('iKom5').innerHTML = 'Wpisz miejscowosc, dozwolone znaki: <b>TYLKO LITERY</b>';
			miejscowosc.style.border = '1px solid red';
			control[2] = false;
		}
		
		
		if(control[0] ==  true && control[1] ==  true && control[2] ==  true){
		var contform = document.getElementById('contform');
		
			advAJAX.post({
				url: 'http://rze.pl/lib/kontakt.php?akcja=send',
				headers : {
				"controler" : "dyktek"
				},
				parameters:{
				"imie" : pl2Uni(imie.value, 1),
				"email" : email.value,
				"tresc" : pl2Uni(tresc.value, 1),
				"firma" : pl2Uni(firma.value, 1),
				"miejscowosc" : pl2Uni(miejscowosc.value, 1),
				"telefon" : telefon.value
				},
				onInitialization : function() {
					contform.innerHTML = 'trwa wysylanie wiadomosci...<br /><img src="pliki/pcz.gif" width="74" height="14" />';
				},
				onSuccess : function(obj) {
					if(obj.responseText == 'wyslano'){
						contform.innerHTML = '<br /><b>wiadomosc zostala wyslana, okienko zamknie si samo w cigu kilku sekund</b>';
						setTimeout("kontakt('clear')",10000);
						
					} else {
					
					contform.innerHTML = obj.responseText;
					
					}
					
				},
				onError : function(obj) {
					cont.innerHTML = '<div style="font-weight:bold; color: red;">nie moge wyslac wiadomosci</div>';
				}		
			});		
		}
		
		

	}
	
	function kontakt(param){
		var cont = document.getElementById('container');
	
		if(param == 'show'){
			
				
				advAJAX.get({
				url: 'http://rze.pl/lib/kontakt.php?akcja=pokaz',
				headers : {
				"controler" : "dyktek"
				},
					onInitialization : function() {
					laduj.style.display = 'block';
				},
				onSuccess : function(obj) {
					cont.innerHTML = obj.responseText;	
				},
				onError : function(obj) {
					cont.innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
				},
				onFinalization : function(){
					laduj.style.display = 'none';
				}
				
				});	
		} else if (param == 'clear'){
			cont.innerHTML = '';
		}
	}
	
	
	
	
	//radek

	wyszukiwarka_tekst = '';

	function wyszukiwarka_blur(ob)
	{
		if (ob.value == '')
		ob.value = wyszukiwarka_tekst;
	}

	function wyszukiwarka_focus(ob)
	{
		if (ob.value == wyszukiwarka_tekst)
		ob.value = '';
	}

	function wyszukiwarka_keyup(ob)
	{
		if (ob.value.length > 1) document.getElementById('szukaj').disabled = false;
		else document.getElementById('szukaj').disabled = true;
	}

	function p(tekst)
	{
		element = document.getElementById('key');
		element.value = 'system: '+tekst;
	}

	var act = new Array()

	function kategoria_over(id)
	{
		element = document.getElementById('kategoria'+id);
		act[id] = 1;
		if(act[id] == 1) element.style.display = 'block';

	}

	function kategoria_out(id)
	{
		element = document.getElementById('kategoria'+id);
		if(act[id] == 0) element.style.display = 'none';
	}

	function kategoria_out_timed(id)
	{
		act[id] = 0;
		setTimeout("kategoria_out("+id+")",50)
	}

	function podkat_over(zwin)
	{
		menu = document.getElementById('podkat');

		if(menu.style.display != 'none')
		{
			zwin.src = 'images/arrow_kat_hover.gif';
		}
		else
		{
			zwin.src = 'images/arrow_kat_down_hover.gif';
		}
	}

	function podkat_out(zwin)
	{
		menu = document.getElementById('podkat');

		if(menu.style.display != 'none')
		{
			zwin.src = 'images/arrow_kat.gif';
		}
		else
		{
			zwin.src = 'images/arrow_kat_down.gif';
		}

	}

	function podkat_zwin(zwin)
	{
		menu = document.getElementById('podkat');

		if(menu.style.display != 'none')
		{
			menu.style.display = 'none';
			zwin.src = 'images/arrow_kat_down.gif';
		}
		else
		{
			menu.style.display = 'block';
			zwin.src = 'images/arrow_kat.gif';
		}
	}

	function over($obiekt)
	{
		$obiekt.style.backgroundColor="#C7D9ED";
		$obiekt.style.color="#376FA0";
		$obiekt.style.cursor="pointer";
	}
	
	function out($obiekt)
	{
		$obiekt.style.backgroundColor="#376FA0";
		$obiekt.style.color="#FFFFFF";
		$obiekt.style.cursor="normal";
	}

	function otworz(zakladka)
	{
		document.getElementById("dp").style.display="none";
		document.getElementById("wu").style.display="none";
		document.getElementById("wiz").style.display="none";
		document.getElementById(zakladka).style.display="block";
	}