function change_cl(el) {
	$('.pphoto img').attr('src',$('.pphoto img').attr('src').replace('gif', 'png'));
	$('.pphoto img').attr('src',$('.pphoto img').attr('src').replace('370x', 'png'));
	$('#back').css('background', $('#' + el.id).css('background'));
	$('#color').attr('value', $('#' + el.id).attr('title'));
	$('#colorname').html($('#' + el.id).attr('title'));
}

function change_cl_nophoto(el) {
	
	$('#nophoto').html('Brak podglądu w innych wersjach kolorystycznych. przepraszamy');
	$('#color').attr('value', $('#' + el.id).attr('title'));
	$('#colorname').html($('#' + el.id).attr('title'));
}

function reload() {
	$.ajax( {
		type : "POST",
		url : 'reload,pl.html',
		data : $("form").serializeArray(),
		success : function(msg) {
			$('#wycena').html(msg);
		}
	});

}

function addProduct() {
	$('#confirm').css('left',$(window).width()/2-184+'px');
	$('#confirm').css('top',$(window).scrollTop()+$(window).height()/2-100+'px');
	$('#shadow').fadeIn(500);
	$('#confirm').fadeIn(500);
	$('#shadow').css('width','100%');
	$('#shadow').css('height',$(window).scrollTop()+$(window).height()+'px');
	$.ajax( {
		url : 'index.php?class=logicSiteAddProduct&type=logic',
		type : 'post',
		cache : false,
		data : $('#buy').serializeArray(),
		success : function(html) {
			$('#button').css('opacity',0.5);
			$('#card').html(html);
		}
	});
}



function change(action, intId, value){
	$('#continue').hide();
    $.ajax({
        url: 'index.php?class=logicSiteShoppingCardReload&type=logic',
        type: 'post',
        cache: false,
        data: {
            action: action,
            id: intId,
            quantity: value
        },
        success: function(html){
            $('#shopping_card').html(html);
            $('#continue').show();
        }
    });
    
    
}




function  formValidate(){
        $('.validateError').remove();
        $('[required]').removeClass('validateBorder');
        
        $.each($("[required]").get(), function(nr, item){
			
            item = '#' + item.id;
            value = $(item).attr('value');
            switch ($(item).attr('required')) {
                case 'email':
                    if (!value.isEmail()) {
                        setError(item, 'Nieprawidłowy adres e-mail');
                    }
                    
                    break;
                case 'string':
                    if (value.length < 3) {
                        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 != $('[required=password]').attr('value')) {
                        setError(item, 'HasĹ‚o rĂłĹĽni sie od wczeĹ›niej podanego');
                    }
                case 're-new-password':
                    if (value != $('[required=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();
			     $('[required]').removeClass('validateBorder');
			}
			
        }
    });
    
    
}  
