/**
* @ js
* # 4n
* # http://www.4n.pl
*/

	var D = document;
	
	function $( ide ){
		return D.getElementById( ide );
	}	
	
	
	function checkFormZam(start){
		
		var spradz = /^([^ ][a-zA-Z0-9¿±æê³ñ¦¶ó¥¡ÆÊ£Ñ¦Ó¬¯\-\,\!\&\_\.\: ]{0,})$/;
		var regEmail = /^([a-zA-Z0-9._-]{1,})@([a-zA-Z0-9._-]{1,})\.([a-zA-Z]{1,4})$/;
		
		var Pola = new Array();
		
		Pola[0] = $( 'nazwa_firmy' ).value;
		Pola[1] = $( 'nip' ).value;
		Pola[2] = $( 'imie' ).value;
		Pola[3] = $( 'nazwisko' ).value;
		Pola[4] = $( 'ulica' ).value;
		Pola[5] = $( 'lokal' ).value;
		Pola[6] = $( 'mieszkanie' ).value;
		Pola[7] = $( 'miejscowosc' ).value;
		Pola[8] = $( 'kod' ).value;
		Pola[9] = $( 'email' ).value;
		Pola[10] = $( 'telefon' ).value;
		
		var NazwyPol = new Array();
		NazwyPol[0] = 'nazwa_firmy';
		NazwyPol[1] = 'nip';
		NazwyPol[2] = 'imie';
		NazwyPol[3] = 'nazwisko';
		NazwyPol[4] = 'ulica';
		NazwyPol[5] = 'lokal';
		NazwyPol[6] = 'mieszkanie';
		NazwyPol[7] = 'miejscowosc';
		NazwyPol[8] = 'kod';
		NazwyPol[9] = 'email';
		NazwyPol[10] = 'telefon';
		
		var kontr = new Array();

		
		for( var i = start; i < 11; i++ ){
			
			if( i == 9 ){
			
				if( regEmail.test(Pola[i]) ){	
					$( NazwyPol[i] ).style.border = '1px solid green';
					kontr[i] = true;
				} else {
					$( NazwyPol[i] ).style.border = '1px solid red';
					kontr[i] = false;
				}
				
			} else {
			
				if( spradz.test(Pola[i]) ){
					$( NazwyPol[i] ).style.border = '1px solid green';
					kontr[i] = true;
				} else {
					$( NazwyPol[i] ).style.border = '1px solid red';
					kontr[i] = false;
				}	
				
			}	
		}
		
		
		
		for( var a = start; a < 11; a++ ){
			if(!kontr[a])
				return false;	
				
		}
		$( 'formAdd' ).submit();
	}
	
	function disFir( ster ){
		if(ster == 0) {
  //			$( 'firma' ).innerHTML = '<input type="radio" id="fi" name="fi" checked /> Firma <input type="radio" id="fi" name="fi"/> Osoba fizyczna<br /><input type="checkbox" name="kurier" /> Chcê otrzymaæ towar kurierem (dodatkowa op³ata 19z³)';
			$( 'fi' ).onclick=function () { disFir(1); };
			$( 'insFun' ).onclick=function () { checkFormZam(0); };
			$( 'fiFrom' ).style.display = 'block';
		} else {
//			$( 'firma' ).innerHTML = '<input type="radio" id="fi" name="fi" checked /> Osoba fizyczna<br /><input type="checkbox" name="kurier" /> Chcê otrzymaæ towar kurierem (dodatkowa op³ata 19z³)';
			$( 'fi' ).onclick=function () { disFir(0); };
			$( 'insFun' ).onclick=function () { checkFormZam(2); };
			$( 'fiFrom' ).style.display = 'none';
		}
		
	}
	
	function sprawdzPrzedzialy( st ){
		var przedzialy = $( 'przedzialy' ).value;
		var kontrola = false;
		var sprawdz = /^(\[[0-9]{2}\:[0-9]{2}\,[0-9]{2}\:[0-9]{2}\]){1}$/;
		if(sprawdz.test(przedzialy)) {
			$( 'przedzialy' ).style.color = 'green';
			kontrola = true;
		} else {
			$( 'przedzialy' ).style.color = 'red';
			kontrola = false;
		}
		
		if(sprawdz && st == 1)
			$( 'reklama' ).submit();
			
			

	}
	
	function checkForm(){
		
		var dane = $('dane').value;
		var telefon = $('telefon').value;
		var adres = $('adres').value;
		
		var spradz = /^([^ ][a-zA-Z0-9¿±æê³ñ¦¶ó¥¡ÆÊ£Ñ¦Ó¬¯\-\,\!\&\_\.\: ]{1,})$/;
		
		var kontr = new Array();
			kontr[0] = false;
			kontr[1] = false;
			kontr[2] = false;
			
		if( spradz.test(dane) ){	
			$('dane').style.border = '1px solid green';
			kontr[0] = true;
		} else {
			$('dane').style.border = '1px solid red';
			kontr[0] = false;
		}
		
		if( spradz.test(telefon) ){	
			$('telefon').style.border = '1px solid green';
			kontr[1] = true;
		} else {
			$('telefon').style.border = '1px solid red';
			kontr[1] = false;
		}
		
		if( spradz.test(adres) ){	
			$('adres').style.border = '1px solid green';
			kontr[2] = true;
		} else {
			$('adres').style.border = '1px solid red';
			kontr[2] = false;
		}
		
		var st = true;
		
		for( var i = 0; i < 3; i++ )
			if(!kontr[i]) st = false;
		
		
		if(st)
			$('kontpraca').submit();
		
		
		
	}
	
	function disSel( ide ){
		if( ide  == 13 )
			$( 'linkuj' ).style.display = 'block';
		else
			$( 'linkuj' ).style.display = 'none';
	}
	
	function wstawForm( id_kont, ide, ster ){
		if( ster == 0 ){
			$(id_kont).style.display = 'block';
			$(id_kont).innerHTML = 'tutaj wpisz opis zdjecia...';
			$('komuopis'+ide).innerHTML = '<div onClick="grabOpis(\''+ide+'\');" class="zat"></div>';
		} else {
			advAJAX.get({
				url: 'index.php?module=galeria&akcja=pokaz_opis&ajax=1&row='+ide,
				onInitialization : function() {
					$(id_kont).style.display = 'block';
					$('komuopis'+ide).innerHTML = '<div style="font-weight:bold; color: green;">czekaj...</div>';
				},
				onSuccess : function(obj) {	
					$(id_kont).style.display = 'block';
					$(id_kont).innerHTML = ''+pl2Uni( obj.responseText, 0 )+'';
					$('komuopis'+ide).innerHTML = '<div onClick="grabOpis(\''+ide+'\');" class="zat"></div>';
				}
			});
		}
		
	}
	
	function grabOpis(ide){
		
		var tresc = pl2Uni( $('opis'+ide).value, 1 );
		var kom = $('komuopis'+ide);
		advAJAX.get({
				url: 'index.php?module=galeria&akcja=zapisz_opis&ajax=1&tresc='+tresc+'&row='+ide,
				onInitialization : function() {
					kom.innerHTML = '<div style="font-weight:bold; color: green;">zapisuje...</div>';
				},
				onSuccess : function(obj) {	
				    kom.innerHTML = '';
					$('opis'+ide).style.display = 'none';			
				}
			});
			
	
	}
		
	function checkPass(akcja){
		
		var login = $( 'login' ).value
		var haslo = $( 'haslo' ).value
		
		
		var st = /^([^ ])$/;
		var str = /^([a-zA-Z]{1,})$/;
		var strInt = /^([0-9]{1,})$/;
		var strSred = /^([a-zA-Z0-9]{6,})$/;
		var strMocne = /^([[a-zA-Z0-9\!\@\#\$\%\^\&\*\(\)\-\+]{6,})$/;
		var strKrzaczki = /^([\!\@\#\$\%\^\&\*\(\)\-\+]{6,})$/;
		var strSredKrzczki = /^([a-zA-Z\!\@\#\$\%\^\&\*\(\)\-\+]{1,})$/;
		
				
		if( st.test(haslo) ){
			$( 'typhasla' ).innerHTML = 'NIEPRAWIDLOWE';
			
		} 
		
		else if( str.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid red; font-weight:bold; color: red;">SLABE</div>';
			$( 'komhasla').style.display = 'block';
			$( 'wymus').value = 1;
		}
		else if( strSred.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid blue; font-weight:bold; color: blue;">SREDNIE</div>';
			$( 'komhasla').style.display = 'block';
			$( 'wymus').value = 1;
		}
		
		else if( strInt.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid red; font-weight:bold; color: red;">SLABE</div>';
			$( 'komhasla').style.display = 'block';
			$( 'wymus').value = 1;
		}
		
		else if( strMocne.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid green; font-weight:bold; color: green;">MOCNE</div>';
			$( 'komhasla').style.display = 'none';
			$( 'wymus').value = 0;
		}
		
		else if( strKrzaczki.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid red; font-weight:bold; color: red;">SLABE</div>';
			$( 'komhasla').style.display = 'block';
			$( 'wymus').value = 1;
		}
		
		else if( strSredKrzczki.test(haslo) ){
			$( 'typhasla' ).innerHTML = '<div style="border-bottom: 3px solid blue; font-weight:bold; color: blue;">SREDNIE</div>';
			$( 'komhasla').style.display = 'block';
			$( 'wymus').value = 1;
		}
		
		
		if(akcja != 'edytuj_usera'){
		
			advAJAX.get({
				url: 'index.php?module=ustawienia&ajax=1&akcja=checklogin&login='+login,
				onInitialization : function() {
					
				},
				onSuccess : function(obj) {	
				var ret = obj.responseText;
			
					if(ret == 1){
						$( 'kl' ).innerHTML = '';	
						$( 'users' ).submit();
					} else {
						$( 'kl' ).innerHTML = '<div style="font-weight:bold; color: red;">login zajety</div>';	
					}	
				},
				onError : function(obj) {}	
			});
			
			
		} else {
			$( 'users' ).submit();
		}
			
		
	
	}
		
	function schowaj(){
		$( 'advertise' ).style.display = 'none';
		$( 'podAd' ).style.display = 'none';
	}
	function showKat( iden ){
	
		var div = $( iden );
		
		if( div.style.display == 'none' )
			div.style.display = 'block';
		else	
			div.style.display = 'none';
	}	
		
	function delFoto( id, skad ){
		
			if(pyt()){
		
			if(skad == 'obrazek_duzy') 
				var kont = 'fotoO';
			else if(skad == 'foto')
				var kont = 'fotoO';
			else
				var kont = 'fotoR';
			
			if(skad == 'foto') 
				var module = 'klienci';
			else	
				var module = 'realizacje';
			
			advAJAX.get({
			url: 'index.php?module='+module+'&ajax=1&akcja=skasuj_foto&skad='+skad+'&row='+id,
			onInitialization : function() {
				$( kont ).innerHTML = '<img src="tpl/images/czekaj_ico.gif" alt="trwa usuwanie..." />';
			},
			onSuccess : function(obj) {	
		
				if(skad == 'obrazek_duzy')	{
					$( 'foto1' ).innerHTML = '<input type="file" name="obrazek1" value="" />';
					$( kont ).innerHTML = '';
				} 
				else if(skad == 'foto'){
					$( kont ).innerHTML = '';
					$( 'foto' ).innerHTML = '<input type="file" name="plik" value="" />';
				}
				else {
					$( 'foto2' ).innerHTML = '<input type="file" name="obrazek2" value="" />';	
					$( kont ).innerHTML = '';
				}
				
			},
			onError : function(obj) {
				$( kont ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
			}	
		});
	} else {
		return 0;
	}
	
	}	
	
	function blokuj( ide ){
		
		advAJAX.get({
		url: 'index.php?module=kategorie&akcja=blokuj&ajax=1&ide='+ide,
		onInitialization : function() {
			$( 'block'+ide ).innerHTML = '<div style="font-weight:bold; color: green;">czekaj...</div>';
		},
		onSuccess : function(obj) {	
			if( obj.responseText == 1 )
				$( 'block'+ide ).innerHTML = '<img onClick="blokuj(\''+ide+'\');" src="tpl/images/ico_unlocked.gif" width="15" height="15" alt="zablokuj" border="0" />';
			else
				$( 'block'+ide ).innerHTML = '<img onClick="blokuj(\''+ide+'\');" src="tpl/images/ico_locked.gif" width="15" height="15" alt="zablokuj" border="0" />';	
			
		},
		onError : function(obj) {
			$( 'block'+ide ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
		}	
	});
		
	}	
	
	function grabSettings( ide ){
		
		var ile_newsow = $( 'ile_newsow' ).value
		var archiwum = $( 'archiwum' ).value;
		var edytors = $( 'edytors' ).value;
		var edytord = $( 'edytord' ).value;
		
		advAJAX.get({
			url: 'index.php?module=news&akcja=zapisz_ustawienia&ajax=1&ile_newsow='+ile_newsow+'&archiwum='+archiwum+'&edytors='+edytors+'&edytord='+edytord+'&row='+ide,
			onInitialization : function() {
				$( 'cont_settings' ).innerHTML = '<div style="font-weight:bold; color: green;">czekaj...</div>';
			},
			onSuccess : function(obj) {	
				$( 'cont_settings' ).innerHTML = obj.responseText;
				$( 'settings' ).style.display = 'block';
			},
			onError : function(obj) {
				$( 'cont_settings' ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
			}	
		});
	}
	
	function displaySettings(){
		var iden = $( 'settings' );
		
		if( iden.style.display == 'none' )
			$( 'settings' ).style.display = 'block';
		else
			$( 'settings' ).style.display = 'none';
		
		
	}
	
	function dis( id ){
		var iden = $( id );
		
		if( iden.style.display == 'none' )
			$( id ).style.display = 'block';
		else if( iden.style.display == 'block' ) 
			$( id ).style.display = 'none';	
	}
	
	function usun( ide, modul, akcja ){

	
		if( pyt() ){
			advAJAX.get({
				url: 'index.php?module='+modul+'&akcja='+akcja+'&ajax=1&row='+ide,
				onInitialization : function() {
					$( 'komu'+ide ).innerHTML = '<img src="tpl/images/czekaj_ico.gif" alt="trwa usuwanie..." />';
				},
				onSuccess : function(obj) {	
					$( 'komu'+ide ).innerHTML = '<div style="font-weight:bold; color: green;">usunieto</div>';
					window.location.reload(); 
				},
				onError : function(obj) {
					$( 'komu'+ide ).innerHTML = '<div style="font-weight:bold; color: red;">blad...</div>';
				}	
				});
		} else {
			
		}
	}
	
	function pyt(){
		if (confirm("Skasowaæ wybrany element?")){
			return true;
		}
		else {
			return false;
		}
	}
	
	
	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(var 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 MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}


browserversion = parseInt(navigator.appVersion);
}
function FirmaRoll(Nazwa) {
objFirma = document.getElementById(Nazwa);
if (objFirma.style.display=="block") objFirma.style.display="none";
else objFirma.style.display="block";
}
function rollOutFlash(myToggle,Nazwa) {
objIn = document.getElementById(Nazwa);
objIn.SetVariable("_root.myToggle"," " + myToggle);
}
/*
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
if (navigator.appName=='Microsoft Internet Explorer') window.attachEvent("onload", correctPNG);
	*/
	

