var Imgs = new Array();                        
var errors = 0;                                  
var preloadTimer;              
var preloadOK = ''      
var preloadBlad = '' 
                                                                                                            
function preload(url) {                                               
   if (document.images) {                                             
      var i = Imgs.length;                                            
      Imgs[i] = new Image();                                          
      Imgs[i].onerror = preloadOnError;                               
      Imgs[i].src = url;                                              
   }                                                                  
}                                                                     
                                                                             
function preloadOnError() {                                           
   errors++;                                                           
}                                                                     
                                                                        
function preloadStart(ok, blad) {                                     
   preloadOK = ok;                                                    
   preloadBlad = blad;                                                
   preloadCheck();                                                    
}                                                                     
                                                                                              
function preloadCheck() {                                             
   var i=0;                                                           
   var l=Imgs.length;                                                 
   var b = errors;                                                                                           
   while (i<l && Imgi[i].complete || b-->0) i++;                      
   if (i>=l)      
      if (Bledy==0)                                                   
         eval(preloadOK)                                              
      else                                                            
         eval(preloadBlad)                                            
   else                                
      preloadTimer = setTimeout('preloadCheck()',100);                
}                                                                     

var actual = 1;

function odliczaj(sek)
{
	if(sek == 0)
	{
		if(actual % 3 == 0)
		{
			changePhoto(zdjecie1);		
		} else if (actual % 3 == 1) {
			changePhoto(zdjecie2);
		} else if (actual % 3 == 2) {
			changePhoto(zdjecie3);		
		}
		actual++;
		set = setTimeout(function(){odliczaj(5)},1e3)		
	}
	if(sek > 0)
	{
		set = setTimeout(function(){odliczaj(--sek)},1e3)
	}
}

function changePhoto(name)
{
	document.getElementById("zdjecie").style.backgroundImage = "url(userImages/"+name+")";
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function checkActivityForm()
{
	var inp1 = trim(document.getElementById('activityText').value);
	var inp2 = trim(document.getElementById('activityAuthor').value);
	if(inp1.length < 2 || inp2.length < 2)
	{
		alert('Wypelnione pola musza zawierac min. po dwa znaki');
	} else {
		if(document.getElementById('activityText').value == "... 4 czerwca ...")
		{
			alert('Wypelnione pola musza zawierac min. po dwa znaki');
		} else {
			document.getElementById('activityForm').submit();	
		}
	}	
}


function checkNewsletterForm()
{
	
	reg = /^[a-zA-Z0-9acelnószzACELNÓSZZ.\\_\\-]{1,50}@[a-zA-Z0-9acelnószzACELNÓSZZ\\-]+(\.[a-zA-Z0-9acelnószzACELNÓSZZ]+)+$/;
	wyn = document.getElementById('newsletterMail').value.match(reg);
	
	var inp1 = trim(document.getElementById('newsletterMail').value);
	if(wyn == null)
	{
		alert('Podany adres e-mail jest nieprawidlowy'); 	
	} else {
		document.getElementById('newsletterForm').submit();
	}
}

function checkAddPhoto()
{
	if(document.getElementById('photoZgoda').checked)
	{
		document.getElementById('addPhotoForm').submit();
	} else {
		alert('Aby wgrac zdjecie nalezy zaakceptowac oswiadczenie'); 	
	}
	
}


preload('_gfx/ramka-Zdjecie_new.gif'); 
preload('_gfx/activity_bg_new.gif'); 
preload('_gfx/box_1_bg_new.gif'); 
preload('_gfx/box_2_bg_new.gif');
preload('_gfx/box_3_bg_new.gif'); 
preload('_gfx/menu_1_new.gif'); 
preload('_gfx/menu_2_new.gif'); 
preload('_gfx/menu_3_new.gif'); 
preload('_gfx/menu_4_new.gif'); 
preload('_gfx/menu_5_new.gif'); 
preload('_gfx/menu_6_new.gif'); 
preload('_gfx/menu_1_new_sel.gif'); 
preload('_gfx/menu_2_new_sel.gif'); 
preload('_gfx/menu_3_new_sel.gif'); 
preload('_gfx/menu_4_new_sel.gif'); 
preload('_gfx/menu_5_new_sel.gif'); 
preload('_gfx/menu_6_new_sel.gif'); 
preload('_gfx/newsletter_bg_new.gif'); 
preload('_gfx/bg_new.jpg'); 