    function getPageSize(){
	    var xScroll, yScroll;
	    
	    if (window.innerHeight && window.scrollMaxY) {  
	      xScroll = window.innerWidth + window.scrollMaxX;
	      yScroll = window.innerHeight + window.scrollMaxY;
	    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	      xScroll = document.body.scrollWidth;
	      yScroll = document.body.scrollHeight;
	    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	      xScroll = document.body.offsetWidth;
	      yScroll = document.body.offsetHeight;
	    }
	    
	    var windowWidth, windowHeight;
	  
	    if (self.innerHeight) { // all except Explorer
	      if(document.documentElement.clientWidth){
	        windowWidth = document.documentElement.clientWidth; 
	      } else {
	        windowWidth = self.innerWidth;
	      }
	      windowHeight = self.innerHeight;
	    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	      windowWidth = document.documentElement.clientWidth;
	      windowHeight = document.documentElement.clientHeight;
	    } else if (document.body) { // other Explorers
	      windowWidth = document.body.clientWidth;
	      windowHeight = document.body.clientHeight;
	    } 
	  
	    // for small pages with total height less then height of the viewport
	    if(yScroll < windowHeight){
	      pageHeight = windowHeight;
	    } else { 
	      pageHeight = yScroll;
	    }
	
	    // for small pages with total width less then width of the viewport
	    if(xScroll < windowWidth){  
	      pageWidth = xScroll;    
	    } else {
	      pageWidth = windowWidth;
	    }
	
	    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	    return arrayPageSize;
	}

	function email_validate(src) {
	  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	  return regex.test(src);
	}
	
	function tel_validate(src) {
	  var regex = /^[+]?[0-9]{7,18}$/;
	  return regex.test(src);
	}
  
	function validateContactBox() {
	    $("#contactTextLabel").removeClass("formError");
	    $("#contactEmailLabel").removeClass("formError");
	    $("#contactPhoneLabel").removeClass("formError");
	    $("#contactClauseLabel").removeClass("formError");
	    
	    var valid = true;
	    if (jQuery.trim($("#contactTextLayer").val()) == "" || jQuery.trim($("#contactTextLayer").val()).length > 3000) {
	      $("#contactTextLabel").addClass("formError");
	      valid = false;
	    }
	      
	    if (jQuery.trim($("#contactEmailLayer").val()) == "") {
	      $("#contactEmailLabel").addClass("formError");
	      valid = false;
	    } 
	    
	    if (jQuery.trim($("#contactClauseLabel").text()) != "" && $("#contactClauseLayer").attr("checked") == false) {
	      $("#contactClauseLabel").addClass("formError");
	      valid = false;
	    } 
	
	    if (jQuery.trim($("#contactEmailLayer").val()) != ""){
		    if (email_validate( jQuery.trim($("#contactEmailLayer").val()) )) {
		 	    $("#contactEmailLabel").removeClass("formError");
		    } else {
			    $("#contactEmailLabel").addClass("formError");
		 	    valid = false;	 	 	
		    }
	    }
	
	    if (jQuery.trim($("#contactPhoneLayer").val()) != ""){
		    if (tel_validate(jQuery.trim($("#contactPhoneLayer").val()) )) {
		 	    $("#contactPhoneLabel").removeClass("formError");
		    } else {
			    $("#contactPhoneLabel").addClass("formError");
		 	    valid = false;	 	 	
		    }
	    }
	    return valid;
	}
  
	function submitContactBox() {
	  if (validateContactBox()) {
		$('#contactLayer').parent(0).append("<div id='contacFormCenterLoading'></div>");
		$('#contacFormCenterLoading').attr("style","opacity:0.6; width: " + $("#contacFormCenter").width() + "px; height: " + $("#contacFormCenter").height() + "px;");
		$('#contacFormCenterLoading').addClass("loading");
  	    $.post("/do/SubmitContactForm", 
	    	{ pageId: $("#pageId").val(), 
	    	  sectionId: $("#sectionId").val(),  
	    	  question: encodeURIComponent($("#contactTextLayer").val()), 
	    	  email: encodeURIComponent($("#contactEmailLayer").val()), 
	    	  phone: $("#contactPhoneLayer").val() },
	    	function(data) { 
	    		$('#contacFormCenterLoading').remove();  
	    	    $('#contactLayer').html(data);
	    	    $('#contactClose').click(function() { 
		  			closeContactBox(); 
		  			return false; 
		  		});
	    	}
	    );
	  }
	}

    function darkbox() {
      var arrayPageSize = getPageSize();
      $('#site').parent(0).append("<div id='darkbox'></div>");
      $('#darkbox').attr("style","opacity:0.0; height: " + arrayPageSize[1]+"px;");  
    }

    function getContactBoxContent() {
	  var url = $(".wyslijPytanie").attr('href');
	  $.ajax({
		    type: "GET",
		    url: url,
		    async: false,
		    success: function (data) {
		  		$('#site').append($(data).find('#contactLayer'));
		  		$('#contactClose').click(function() { 
		  			closeContactBox(); 
		  			return false; 
		  		});
		  		$('#contactSubmit').click(function() { 
		  			submitContactBox(); 
		  			return false; 
		  		});
	  		}
	  }); 
    }
   
    function makeContactBox() {
      darkbox();
      $('#site').parent(0).append("<div id='contacFormBox'></div>");
      $('#contacFormBox').attr("style","opacity: 0;");
      $('#contacFormBox').append("<div id='contacFormTop'></div>");
      $('#contacFormBox').append("<div id='contacFormCenter'></div>");
      $('#contactLayer').attr("style","display: block;"); 
      $('#contacFormCenter').append($('#contactLayer'));
      $('#contacFormBox').append("<div id='contacFormBottom'></div>");
      // <-- ACMS-589
      $('#contacFormCenter').attr("style", "display: none;");
      $('#contacFormTop').attr("style", "display: none;");
      $('#contactLayer').attr("style", "display: none;");
      $('#contacFormBottom').attr("style", "display: none;");
      // --> ACMS-589
    }

    function openContactBox() {
		  makeContactBox();
      $('#darkbox').animate({opacity: 0.6}, 500);
			// <-- ACMS-589
			if (!isMsieBrowser()) {
	  	  boxFadeIn(1000);
			} else{
				boxFadeIn(500);
				//$('#contacFormBox').animate({opacity: 1.0}, 500);	
			}
			// --> ACMS-589
      var height = $('#contacFormBox').height();
      var top = $(document).scrollTop()+80;
      var marginl = Math.round($('#contacFormBox').width()/2);
      $('#contacFormBox').attr("style","height:"+height+"px; top:"+top+"px; margin: 0 0 0 -"+marginl+"px;");
      $('#contactTextLayer').val('');
      $('#contactEmailLayer').val('');
      $('#contactPhoneLayer').val('');
      $("#contactClauseLayer").attr("checked",false);    
    }

    function closeContactBox() {
      $('#darkbox').animate({opacity: 0}, 500, function() {
        $('#contactLayer').attr("style","display: none;"); 
        $('#contacFormBox').remove();
      });    
      $('#contacFormBox').animate({opacity: 0}, 500, function() {
        $('#darkbox').remove();
      });
      $("#contactTextLabel").removeClass("formError");
      $("#contactEmailLabel").removeClass("formError");
      $("#contactPhoneLabel").removeClass("formError");
      $("#contactClauseLabel").removeClass("formError");  
    }
		
		function isMsieBrowser(){
			if($.browser.msie){
        return true;
      }else{
        return false;
      }
		}
		
		function boxFadeIn(speed){
      $('#contacFormCenter').fadeIn(speed);
      $('#contacFormTop').fadeIn(speed);
      $('#contactLayer').fadeIn(speed);
      $('#contacFormBottom').fadeIn(speed);
      $('#contacFormBox').fadeIn(speed);
		}
