function hiddeErrorContact(){
	jq(function(){
        jq('span.formError').css({
            display: 'none'
        });
    });
}
jq(document).ready(function()	{
	
	jq('div.module_menu ul.menu ul').hide();
	jq('div.module_menu ul.menu > li > a').removeAttr('href');
	jq('div.module_menu ul.menu > li > a').click(function() {
		jq('div.module_menu ul.menu ul').slideUp("slow");
		if ( jq(this).parent().find('ul').css('display') != 'block') {
			jq(this).parent().find('ul').slideDown("slow");
		}
	});
	jq('div.module_menu ul.menu > li.active ul').show();
	jq('div.module_menu ul.menu > li.active > a').css({ fontWeight: 'bold' });
	jq('table#userProducts tr.userItem').hover(function(){
		jq(this).css({
			backgroundColor: 'white'
		});
	}, function(){
		jq(this).css({
			backgroundColor: 'transparent'
		});
	});
	jq('a.showFormContact').click(function(){
		if ( jq(this).parent().find('.formContactHidden').css('display') == 'none' )	{
			jq('div.formContactHidden').hide('slow');
			jq('a.showFormContact').html( 'Napisz wiadomość' );
			jq(this).parent().find('div.formContactHidden').show('slow');
			jq(this).html( 'Anuluj wysyłanie' );
		} else {
			jq(this).parent().find('div.formContactHidden').hide('slow');
			jq(this).html( 'Napisz wiadomość' );
		}
		return false;
	});
	jq('form.formContactUser').submit(function(){
		
		hiddeErrorContact();
		
		if (!jq(this).find('.conmail').val().match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9_]{2,4}$/i)) {
	        jq(this).find('.errorMail').css({
	            display: 'inline'
	        });
	        return false;   
	    }
		if (!jq(this).find('.condescription').val().match(/^[a-zA-z0-9zążńśźęćłó\-_ ]{6,30}$/i)) {
            jq('.errorDescription').css({
                display: 'inline'
            });
            return false;
        }
		var thisElm = jq(this);
		jq(this).parent().parent().append( '<span class="bold green">Wysyłanie...</span>' );
		var str = jq(this).serialize();
	  	jq.ajax({
	  		type: "POST",
	  		url: 'index.php',
			data: 'option=com_djcatalog&view=userMail&' + str,
	  		error: function( msg )	{
	  			alert("Failed to submit: " + msg);
	  		},
	  		success: function( html ){
				thisElm.parent().parent().html( '<span class="green">Wiadomość została wysłana.</span>' );
	  		}
	  	});
		return false;
	});
	
});

