function html5forIE() {
	document.createElement('header');
	document.createElement('nav');
	document.createElement('section');
	document.createElement('article');
	document.createElement('aside');
	document.createElement('footer');
}


(function($){
	$.fn.extend({
	 
	 	customStyle : function(options) {
		  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
		  return this.each(function() {
		  
				var currentSelected = $(this).find(':selected');
				$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
				var selectBoxSpan = $(this).next();
				var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
				var selectBoxSpanInner = selectBoxSpan.find(':first-child');
				selectBoxSpan.css({display:'inline-block'});
				selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
				var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
				$(this).height(selectBoxHeight).change(function(){
					// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
				selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
					// Thanks to Juarez Filho & PaddyMurphy
				});
				
		  });
		  }
		}
	});
})(jQuery);



$(document).ready(function() {


	jQuery.fn.exists = function() { return jQuery(this).length>0; }
	
	
	// Fancybox

	if($(".fancy").exists()) {
		$(".fancy").fancybox({
			'titlePosition'	:	'over',
			'padding'			: 0,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'              : 'image',
			'changeFade'        : 0,
			'onComplete'	:	function() {
				$("#fancybox-wrap").hover(function() {
					$("#fancybox-title").show();
				}, function() {
					$("#fancybox-title").hide();
				});
			}
		});
	}

	
	// Select replace
	
	$('select.styled').customStyle();


	// Left menu

	$("#vert li").each(function() {
		if ($(this).find('ul:first').length > 0) {
			$(this).addClass('arDown');
                        $(this).find('a:first').attr("id","submenu");
		}
		if ($(this).hasClass("on")) {
			$(this).find('ul:first').slideToggle('fast');
		}
	});
        
	$("#vert ul li").click(function(event) {
                if ($(this).find('ul:first').length > 0) {
                        if(event.target.id == "submenu") {
                                $(this).find('ul:first').slideToggle('fast');
                                $(this).toggleClass('on');
                                return false;
                        }
                }
        });





	// Clear input
	
	var startValue = '';
	$('.iTxt').focus(function() {
		startValue = $(this).attr('title');		
		if (this.value == startValue) {this.value='';}
	})
	$('.iTxt').blur(function() {
		if (this.value=='') {this.value = startValue;}
	})



	// Button generate
	
	$("a.btn").each (function() {
		c = $(this).text();
		$(this).text("").
		append('<span class="l"></span>').
		append('<span class="c">'+c+'</span>');
	});



	// Focus border remove

	$("a").focus(function() {
		$(this).blur();
	});




	// _blank
	
	$(function() {
		$('a.blank').click( function() {
			window.open(this.href);
			return false;
		});
	});
	
	//Select all anchor tag with rel set to tooltip
	$('a[rel=tooltip]').mouseover(function(e) {
		
		//Grab the title attribute's value and assign it to a variable
		var tip = $(this).attr('title');	
		
		//Remove the title attribute's to avoid the native tooltip from the browser
		$(this).attr('title','');
		
		//Append the tooltip template and its value
		$("body").append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
				
		//Show the tooltip with faceIn effect
		$('#tooltip').fadeIn('500');
		$('#tooltip').fadeTo('10',0.9);
		
	}).mousemove(function(e) {
	
		//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
		$('#tooltip').css('top', e.pageY - 10 );
		$('#tooltip').css('left', e.pageX + 20 );
		
	}).mouseout(function() {
	
		//Put back the title attribute's value
		$(this).attr('title',$('.tipBody').html());
	
		//Remove the appended tooltip template
		$("body").children('div#tooltip').remove();
		
	});	


});

function chFir(idInput) {
  $(idInput).attr('checked', true);  
  if ($(idInput).val() == "on"){                               
      $(".hidden_company").css("display","block");
	} else { 
	    $(".hidden_company").css("display","none");    
	}
}

function chStr(idInput, min, max) {
	var txt = idInput.value;
	if (txt.length > min && txt.length < max) {
		$(idInput).css("background-position", "-490px -539px");
	} else {
		$(idInput).css("background-position", "-241px -539px");
	}
}

function chKod(idInput) {
	var txt = idInput.value;
	if (txt.match(/^[0-9]{2}\-[0-9]{3}$/) == null) {
		$(idInput).css("background-position", "-241px -539px");
	} else {
		$(idInput).css("background-position", "-490px -539px");
	}
}

function chEmail(idInput) {
  if (idInput.value.match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/) == null){
		$(idInput).css("background-position", "-241px -539px");
	} else {
		$(idInput).css("background-position", "-490px -539px");
	}
}

function chConf() {
  if ($("#password").val().length > 2 && $("#password").val().length < 101){
      if ($("#passwordConf").val().length > 2 && $("#passwordConf").val().length < 101){
          if ($("#password").val() == $("#passwordConf").val()){
            $("#password").css("background-position", "-490px -539px");
            $("#passwordConf").css("background-position", "-490px -539px");
          } else {
            $("#password").css("background-position", "-490px -539px");
            $("#passwordConf").css("background-position", "-241px -539px");
          }  
      } else {
        $("#passwordConf").css("background-position", "0px -539px");
        $("#password").css("background-position", "-490px -539px");
      }  
	} else {
		$("#password").css("background-position", "-241px -539px");
	}
}	

function spr_dos_wyslij() {
        $.post("xemail.php", { email: $('#_email').val(), _a: "stany"});
        document.getElementById('spr_dos').style.display = "none";
        alert("Wysłano");
        return false;
}

function spr_dos_pokaz() {
        document.getElementById('spr_dos').style.display = "";
        return false;
}
function spr_dos_schowaj() {
        document.getElementById('spr_dos').style.display = "none";
        return false;
}	

function sprDost(act) {
        switch (act) {
            case 'send':
                var emailVal = $('#email_sprDost').val();
                var emailSend = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

                if (emailSend.test(emailVal)) {
                        $.post("ajaxShoppingCart.php", 
                               { email: emailVal, _a: "stany"},
                               function(data) {
                                   alert(data);
                               }
                        );
                        $("#sprDost").hide();  
                        $("#err_sprDost").html("");                      
                } else {
                        $("#err_sprDost").html("Niepoprawny email <br>");
                }
                break;
            case 'show':
                $("#sprDost").show();
                $("#err_sprDost").html("");
                break;
            case 'hide':
                $("#sprDost").hide();                
                break;                
            default:
                $("#sprDost").hide();
        }
        
        return false;
}

function addProduct(id) {
  var numeric = /^([0-9]+)([,.])([0-9]+)$/;
  var numeric2 = /^([0-9]+)$/;
  var a = $("input#ilosc_" + id).val();
  var b = id;
        
      if (numeric.test(a) || numeric2.test(a)) {
        $("#addStatus_" + id).html("");
        $.ajax({
            url: 'http://ilazienki.pl/ajaxShoppingCart.php',
            type: "POST",
            data: ({ add: id, quan: $("input#ilosc_" + id).val() }),
            success: function(dane){
                             if(dane.match('Redir') != null) {
                                  window.location.pathname = dane.substr(6);
                             } else {
                                  $("#shoppingCart").html(dane);                              
                                  $("#shoppingCart").fadeIn();
                                  $("#addStatus_" + id).html("Dodano !");
                                  $("#addStatus_" + id).css("color", "green");
                                  $("#p" + id).css("background","url(http://ilazienki.pl/skins/iLazienki/styleImages/i/bg_prod_add.jpg) no-repeat");
                             }
                     }
        });
      } else {
          $("#addStatus_" + id).html("nie dodano !!");
          $("#addStatus_" + id).css("color", "red"); 
      }  
}

