function fpieces()
{
	$('#format_pieces input:checked').attr('checked',false);
}

function wRemember(question)
{
	if(confirm(question))
	{
		$('#remember_wycen').val(true);
	}
	else
	{
		$('#remember_wycen').val(false);
	}
	
	$('form#login_form').submit();
}


function send_friend(lang)
{
	if(!formValidate2())
	{
		return true;
	}
	$('#loader').show();
	 $('#send').hide();
	$.ajax({
        type: "POST",
        url: 'sendfriend,' + lang + '.html',
        data: {tresc:$('#tresc').val(),name:$('#name').val(),email:$('#email').val(),friend_email:$('#friend_email').val()},
        success: function(msg){
            $('#loader').hide();
            
        }
    });
}

function send_friend_pre(lang)
{
		$('#send').show()
		$('#przechowalnia').hide();
		$('#loader').show();
		$.ajax({
        type: "POST",
        url: 'sendfriend,' + lang + '.html',
        data: false,
        success: function(msg){
            $('#loader').hide();
            $('#url').val(msg);
        }
    });
}



function add_przechowalnia(lang)
{
	$('#loader').show();
	$.ajax({
        type: "POST",
        url: 'przechowalnia,' + lang + ',add.html',
        data: {p_name:$('#p_name').val()},
        success: function(msg){
        	$('#wycen').html(msg);
            $('#loader').hide();
            $('#przechowalnia').hide();
        }
    });
}



function  formValidate2(){
        $('.validateError').remove();
        $('[req]').removeClass('validateBorder');
        $.each($("[req]").get(), function(nr, item){
            item = '#' + item.id;
            value = $(item).attr('value');
            switch ($(item).attr('req')) {
                case 'email':
                    if (!value.isEmail()) {
                        setError(item, 'Nieprawidłowy adres e-mail');
                    }
                    break;
                case 'string':
                    if (value.length < 2) {
                        setError(item, 'Pole jest wymagane');
                    }
                    break;
            }
        })
        if ($('.validateError').length) {
            return false;
        }
        else {
            return true;
        }
    }



function ajax(lang){
	$('#send').remove();
	$('#przechowalnia').remove();
	$('#loader').show();
	$('#loader').css('height',$('#content').height()-20);
	
    $.ajax({
        type: "POST",
        url: 'wycen_teraz,' + lang + '.html',
        data: $("form").serializeArray(),
        success: function(msg){
            $('#form_wycen_teraz').html(msg);
           
            $('#loader').hide();
            $("a[rel^='prettyPhoto']").prettyPhoto();
        }
    });
}

function ajax_send(lang){
	$('#send').remove();
	$('#przechowalnia').remove();	
	$('#loader').show();
	$('#loader').css('height',$('#content').height()-20);
	
    $.ajax({
        type: "POST",
        url: 'wycen_teraz,' + lang + '.html',
        data: $("form").serializeArray(),
        success: function(msg){
            $('#form_wycen_teraz').html(msg);
			$('#wyslij').click();
        }
    });
}


function form_wycena_start(){
	$('#wycen_teraz select').each(function(e,item){
		
		if( $(item).attr('name') != 'intCategoryId' ){
			$(item).find('option:first').attr('selected', 'selected').parent('select');
		}	
		
		
	});
}


function kopiuj_dane()
	{
		$('#delivery_company_name').val($('#company_name').val());
		$('#delivery_adress').val($('#company_adress').val());
		$('#delivery_post_code').val($('#company_post_code').val());
		$('#delivery_city').val($('#company_city').val());
		$('#delivery_contact_person').val($('#first_last_name').val());
		$('#delivery_telephone').val($('#telephone').val());
		$('#delivery_telephone').val($('#telephone').val());
		$('#country').attr('value',$('#company_country').val());
		
		
	}
	
	
function  formValidate(){
	
        $('.validateError').remove();
        $('[req]').removeClass('validateBorder');
        $.each($("[req]").get(), function(nr, item){
            item = '#' + item.id;
            value = $(item).attr('value');
            switch ($(item).attr('req')) {
                case 'email':
                    if (!value.isEmail()) {
                        setError(item, 'Nieprawidłowy adres e-mail');
                    }
                    break;
                case 'login':
                	if(value.search(/[#ęółąśćźż ^&*+=]/i) != -1)
                	{
                		setError(item, 'Dozwolone znaki: a-z 0-9 - _ ');
                	}
                case 'string':
                    if (value.length < 2) {
                        setError(item, 'Pole jest wymagane');
                    }
                    break;
                case 'date':
                    break;
                case 'select':
                    if (value == 0) {
                        setError(item, 'Wymagane wybranie opcji');
                    }
                    break;
                case 'password':
                    if (value.length < 3) {
                        setError(item, 'Hasło jest za krótkie');
                    }
                    break;
                case 're-password':
                    if (value != $('[req=password]').attr('value')) {
                        setError(item, 'Hasło różni sie od wcześniej podanego');
                    }break;
                case 're-new-password':
                    if (value != $('[req=new-password]').attr('value')) {
                        setError(item, 'Hasło różni sie od wcześniej podanego');
                    }    
            }
        })
        if ($('.validateError').length) {
            return false;
        }
        else {
            return true;
        }
        
    }
	
function  setError(item, value){
        $(item).addClass('validateBorder');
        $(item).after('<div class="validateError" >' + value + '</div>');
    }
	
	
String.prototype.isEmail = function(){
    var rx = new RegExp("\\w+([-+.\’]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    var matches = rx.exec(this);
    return (matches != null && this == matches[0]);
};
String.prototype.isURL = function(){
    var rx = new RegExp("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-\\+ ./?%:&=#\\[\\]]*)?");
    var matches = rx.exec(this);
    return (matches != null && this == matches[0]);
};
String.prototype.trim = function(){
    return this.replace(/^\s+|\s+$/g, '');
};



function checklogin(value,lang){
    $.ajax({
        type: "POST",
        url: 'check,' + lang + '.html',
        data: {'login':value},
        success: function(msg){
			if(msg)
			{
				 setError('#login',msg);
			}
			else
			{
				 $('.validateError').remove();
			     $('[req]').removeClass('validateBorder');
			}
			
        }
    });
    
    
}



function changeDelivery(lang)
{
		$('#loader').show();
		$('#loader').css('height',$('#content').height()-20);
	    $.ajax({
	        type: "POST",
	        url: 'order,' + lang + '.html',
	        data: $('#delivery_form').serializeArray(),
	        success: function(msg){
	            $('#delivery').html(msg);
	            $('#loader').hide();

	        }
	    });
}
var args;
var block = 0;
var di=-1;
var fin = 1000;
var fout = 7000;
function dymki()
{
	if(arguments.length) 
	{
		args = arguments;
		$('.dymek').click(function(){ $(this).hide();})
	}
	setTimeout("dymki()",500);
	
	if(block){return true;}
	
	if(di+1==args.length)
		di=0;
	else
		di++;
	
	eval("dymek"+args[di]+"()");	
	block=1;
	$('#dymek'+args[di]).delay(fin).fadeIn('fast',function(){
		$('#dymek'+args[di]).delay(fout).fadeOut('fast',function(){block=0;})
	});
	
	
    
}


function dymek0(fin,fout)
{
	$('#dymek0').css('position','fixed')
				.css('right','25px')
				.css('top',Math.round($(window).height()/2)-$('#dymek0').height()+20+'px')
}

function dymek1(fin,fout)
{
	var w = Math.round(Math.random()*16);
	$('#dymek1').css('left',$($('.category_box')[w]).position().left-76+'px');
	$('#dymek1').css('top',$($('.category_box')[w]).position().top-25-$('#dymek1').height()+'px');
}

function dymek2(fin,fout)
{
	var w = Math.round(Math.random()*16);
	$('#dymek2').css('left',$($('.category_box')[w]).position().left-78+50+'px');
	$('#dymek2').css('top',$($('.category_box')[w]).position().top-$('#dymek2').height()+'px');
}

function dymek3(fin,fout)
{
	$('#dymek3').css('left',$('#content').position().left+130+'px');
	$('#dymek3').css('top',$('#content').position().top-318-$('#dymek3').height()+'px');
}

function dymek4(fin,fout)
{
	$('#dymek4').css('left',$('#content').position().left+350+'px');
	$('#dymek4').css('top',$('#content').position().top-318-$('#dymek4').height()+'px');
}

function dymek5(fin,fout)
{
	$('#dymek5').css('left',$('#content').position().left+470+'px');
	$('#dymek5').css('top',$('#content').position().top-318-$('#dymek5').height()+'px');
}

function dymek6(fin,fout)
{
	$('#dymek6').css('left',$('#content').position().left+150+'px');
	$('#dymek6').css('top',$('#content').position().top-455-$('#dymek6').height()+'px');
}

function dymek7(fin,fout)
{
	$('#dymek7').css('left',$('#content').position().left+720+'px');
	$('#dymek7').css('top',$('#content').position().top-318-$('#dymek7').height()+'px');
}

function dymek8(fin,fout)
{
	$('#dymek8').css('left',$('#content').position().left+620+'px');
	$('#dymek8').css('top',$('#content').position().top-318-$('#dymek8').height()+'px');
}


function dymek9(fin,fout)
{
	var w = Math.round(Math.random()*$('.product').length)-1;
	$('#dymek9').css('left',$($('.product')[w]).position().left+80+'px');
	$('#dymek9').css('top',$($('.product')[w]).position().top-28-$('#dymek9').height()+'px');
} 

function dymek10(fin,fout)
{
	$('#dymek10').css('left',$('#form_wycen_teraz').position().left+482+'px');
	$('#dymek10').css('top',$('#form_wycen_teraz').position().top-3-$('#dymek10').height()+'px');
} 

//---------------------------------------


