	var popupCache = new Array();

  function checkFormAnkieta() {
    
    error = 0;
    
    if ($("#kupon2").attr("checked")) {
    
      regexp  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/;
  
      $("#email,#imie,#nazwisko").each(function() {
  
        if ((this.name!='email' && this.value=='') || (this.name=='email' && !regexp.test(this.value))) {
         
          this.focus();
          this.select();
          alert('Wypełnij poprawnie pole '+this.name);
          error = 1;
          return false;
        }
        
      });
    }
    
    return !error ? true : false;
  }
  
  function disableFormAnkieta(){
    
    $(":radio").each( function() { 
      if (this.name!='smak') $(this).attr('disabled', 'disabled');
      
    });
    
    $(".ankieta_button").attr('disabled', 'disabled');
    $("#bigboss_ankieta_kupon :text").attr('disabled', 'disabled');
    
  }
  
  function enableFormAnkieta(){
    
    $(":radio").each( function() { 
      if (this.name!='smak') $(this).removeAttr('disabled');
    });
    $(".ankieta_button").removeAttr('disabled');
    $("#bigboss_ankieta_kupon :text").removeAttr('disabled');
  }


	function gotoUrlNewWinSizeCentered(s, iWidth, iHeight)
	{
	    iWidth += 20;
	    iHeight += 25;
	    iWidth = screen.width;
	    iHeight = screen.height;
	    iLeft = Math.round((screen.width - iWidth) / 2);
	    iTop = Math.round((screen.height - iHeight) / 2);
	    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=no,location=no,resizable=no,scrollbars=no,status=no");
	}

	function getRandomInt(max)
	{
	    return Math.round( Math.random() * (max-1) );
	}

	function gotoUrlNewWinMaximized(s)
	{
	    iWidth = screen.width;
	    iHeight = screen.height;
	    iLeft = Math.round((screen.width - iWidth) / 2);
	    iTop = Math.round((screen.height - iHeight) / 2);
	    newWin = window.open(s, "newWin" + getRandomInt(10000), "width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",dependent=no,location=no,resizable=no,scrollbars=no,status=no");
	}

	function showPopup(id) {
    	showPopupCommon("index.php?id="+id)
    }
	function showPopupCommon(url) {
    	$('#popup').html();
	    docsize=jQuery.iUtil.getSize($('body').get(0));
        docheight=docsize.h;
	    docscroll=jQuery.iUtil.getScroll();
	    $('#overlay').css('display','block').top('-50px').height((docheight+100)+'px');
        $('#overlay').click(function(){popupClose();});
        $('#popup').css('display','block').top((docscroll.t+110)+'px').left((docsize.w/2 - 200)+'px');
        data=popupCache[url];
        if (data) {
            $('#popup').html(data);
            $('#closeButton').click(function(){popupClose();});
        } else {
	        $('#popup').html('<div class="popupCzekaj">czekaj...</div>');
	        $('#closeButton').click(function(){popupClose();});
	        $.get(url, function(data){
            	popupCache[url]=data;
	            $('#popup').html(data);
	            $('#closeButton').click(function(){popupClose();});
	        });
        }
    }


    function popupClose() {
		$('#popup').html('');
		$('#popup').css('display','none');
        $('#overlay').css('display','none');
    }
	function videoPolec(id) {
		popupClose();
		showPopup('107&f='+id);
    }
	function mainOnLoad() {

	}

	function showVideo(id) {
    	$('#popup').html();
	    docsize=jQuery.iUtil.getSize($('body').get(0));
        docheight=docsize.h;
	    docscroll=jQuery.iUtil.getScroll();
//	    $('#overlay').css('display','block').top('-50px').height((docheight+100)+'px');
//        $('#overlay').click(function(){popupClose();});
        $('#popup').css('display','block').top((docscroll.t+120)+'px').left((docsize.w/2 - 150)+'px');
        data=popupCache[id];
        if (0) {
            $('#popup').html(data);
            $('#closeButton').click(function(){popupClose();});
        } else {
	        $('#popup').html('<div class="popupCzekaj">czekaj...</div>');
	        $('#closeButton').click(function(){popupClose();});
	        $.get("video.php?id="+id, function(data){
            	popupCache[id]=data;
	            $('#popup').html('<div id="FCvideo"></div>');
	            $('#closeButton').click(function(){popupClose();});
                p=data.split('|');
	            var so = new SWFObject("/fileadmin/flash/kfc_video.swf", "video", "421", "359", "8", "#ffffff");
	            so.addParam("wmode", "transparent");
	            so.addVariable("id", p[0]);
	            so.addVariable("videopath", p[1]);
	            so.addVariable("mpgpath", p[2]);
	            so.addVariable("videotitle", p[3]);
	            so.addVariable("imagepath", p[4]);
	            so.write("popup");
	            $('#popup').css('z-index','2000');
	        });
        }
    }

    function powiadomZnajomego(f) {
    	se=f['s_email'].value;
    	sn=f['s_name'].value;
    	re=f['r_email'].value;
        if (se.length<6) {
        	alert ('Podaj swój e-mail!');
            return false;
        }
        if (sn.length<1) {
            alert ('Podaj swoje imię!');
            return false;
        }
        if (re.length<6) {
        	alert ('Podaj e-mail adresata!');
            return false;
        }
        f['submit'].value="czekaj";
        $.get("powiadom.php?se="+se+"&sn="+sn+"&re="+re, function(data){
            $('#popup').html(data);
	        $('#closeButton').click(function(){popupClose();});
        });
		return false;
    }
    

    function trim(str) {
        return str.replace(/^\s+|\s+$/g, '') ;;
    }



    function formCheckNewsletter(f)
    {
    	
    	f.email.value = trim(f.email.value);
    	f.fname.value = trim(f.fname.value);
    	f.lname.value = trim(f.lname.value);
    	f.phone.value = trim(f.phone.value);
    	f.zip.value = trim(f.zip.value);
    	f.city.value = trim(f.city.value);
    	
    	if (f.email.value.length < 1) {
    		alert("Pole 'e-mail' musi zostać wypełnione!");
    		return false;
    	}
    	var pattern = /^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    	var m = pattern.exec(f.email.value);
    	if (m == null) {
    		alert("Pole 'e-mail' ma zły format danych!");
    		return false;
    	}

    	if (f.fname.value.length < 2) {
    		alert("Pole 'imię' musi być wypełnione!");
    		return false;
    	}
    	if (f.lname.value.length < 2) {
    		alert("Pole 'nazwisko' musi być wypełnione!");
    		return false;
    	}
    	if (f.sex.selectedIndex == 0) {
    		alert("Pole 'płeć' musi zostać wypełnione!");
    		return false;
    	}
    	if (f.zip.value.length < 6) {
    		alert("Pole 'kod pocztowy' musi zostać wypełnione!");
    		return false;
    	} else {
    		var pattern = /^[0-9][0-9]-[0-9][0-9][0-9]$/;
    		var m = pattern.exec(f.zip.value);
    		if (m == null) {
    			alert("Pole 'kod pocztowy' ma zły format danych! Poprawny format: XX-XXX.");
    			return false;
    		}		
    	}
    	if (f.city.value.length < 2) {
    		alert("Pole 'miasto' musi zostać wypełnione!");
    		return false;
    	}
    	if (f.phone.value.length > 0) {
    		var pattern = /^[0-9]{9}$/;
    		var m = pattern.exec(f.phone.value);
    		if (m == null) {
    			alert("Pole 'tel. kontaktowy' ma zły format danych! Wpisz tylko 9 cyfr bez zera na początku.");
    			return false;
    		}		
    	}
    	if (!f.confirm1.checked) {
    		alert("Pole 'Zgoda na przetwarzanie danych osobowych' musi być zaznaczone!");
    		return false;
    	}
    	if (!f.confirm2.checked) {
    		alert("Pole 'Wyrażam zgodę na komunikację elektroniczną' musi być zaznaczone!");
    		return false;
    	}
    		
    	return true;
    }


    function formCheckNewsletterEdit(f)
    {
    	f.email.value = trim(f.email.value);
    	
    	if (f.email.value.length < 1) {
    		alert("Pole 'e-mail' musi zostać wypełnione!");
    		return false;
    	}
    	var pattern = /^([a-zA-Z0-9_\.\+\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    	var m = pattern.exec(f.email.value);
    	if (m == null) {
    		alert("Pole 'e-mail' ma zły format danych!");
    		return false;
    	}


    		
    	return true;
    }    