//poster pen

window.addEvent('domready', function(){
	if(window.ie) {
		if($('small_add')==null)
			return;
	    window.addEvent('scroll', function(){			
	        $('small_add').setStyle('top', document.documentElement.scrollTop+135);
		});
	}
    //menu chowane po lewej stronie przy roboczym ekanie na cala szerokosc strony
    if($('float_menu')) {
        $('show_menu').addEvent('mouseover', function(e) {
            $('show_menu').style.display = 'none';
            $('float_menu').style.display = 'block';
        });
        $('float_menu').addEvent('mouseout', function(e) {
            $('float_menu').style.display = 'none';
            $('show_menu').style.display = 'block';
        });
        var eventy = {
            pokaz_tablice: function (element) {
                element.addEvent('mouseout', function(e) {
                    var e = new Event(e);
                    e.stopPropagation();
                });
            }
        };
        $('float_menu').getElements('a').forEach(eventy.pokaz_tablice, eventy);
    }
});

    function loadTipsX3() {
	   var theTips = new TipsX3 ($$('.tipper'), {showDelay:0, hideDelay:0, maxTitleChars:100});
    }
	
//rozwijane menu artykuly
window.addEvent('domready', function(){
    
    $('search_field').addEvent('focus', function(e) {
        this.set('value', '');
    });
//    $('search_field').addEvent('blur', function(e) {
//        this.value='ok';
//    });	
});



window.addEvent('domready', function(){

	new SlideItMoo({
			thumbsContainer: 'thumbs',
			elementScrolled: 'thumb_container',
			overallContainer: 'gallery_container',
			itemsVisible:4, 
			currentElement: 0,
			itemsSelector: '.item_selector',
			autoSlide:2000,
			duration:1000,
			direction: 1
			
			});});




//przypomnienie hasla
function reminpassword() {
    url = '/user/remind';
    div = 'remind_results';
	post = 'email='+$('email').get('value');

	new Request({
        url: url,
        method: 'post',
        data: post,
        onRequest: function(){
            $(div).set('html', '<br/><img src="/images/wait.gif" alt="loading..." />');
        },
		onSuccess: function() {
            $(div).set('html', this.response.text);
		}
	}).send();
}

if(navigator.appName=="Microsoft Internet Explorer"){
		document.write('<style type="text/css">@import url("/style/style_ie.css");</style>');
}else{
		document.write('<style type="text/css">@import url("/style/style_ff.css");</style>');
}

function layerVisibility(layerId){
	if ($(layerId).getStyle('display')=='none'){
		$(layerId).setStyle('display', 'block');
	}else{
		$(layerId).setStyle('display', 'none');
	}
}


/**
* funkcja pokazuje lub chowa warste w zaleznosci od jej obecnego stanu
* COOKIE
*/
function displayLayer(id){
	element = $(id);
	if(element.getStyle('display')=='none'){
		element.setStyle('display', 'block');
		document.cookie=id+"=1";
	}else{
		element.setStyle('display', 'none');
		document.cookie=id+"=0";
	}
}
function showHide(event,class_name){
	var element = $$('.'+class_name);
	target = new Event(event).target;
	element.each(function(item){
		if(item.style.display=="none"){
			item.style.display="table-row";
			target.set('html', 'ukryj');
		}else{
			target.set('html', 'pokaĹź');
			item.style.display="none";
		}
	});
}
/**
* funkcja zmienia warstwy
*/
function changeLayer(toShow, toHide){
	elementToShow = document.getElementById(toShow);
	elementToHide = document.getElementById(toHide);

	elementToShow.style.display="block";
	elementToHide.style.display="none";
}


function getCookie(c_name) {
    if (document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1) {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return null;
}

//ofertownik
function sendOffer(){
	url = '/offer/mail';
    div = 'mailreturn'

    new Request({
        url: url,
        method: 'get',
        onRequest: function(){
            $(div).set('html', '<img src="/images/wait.gif" alt="loading..." />');
        },
        onFailure: function(){
            $(div).set('html', 'BĹ�� serwera. Oferta nie zostaĹ� wysĹ�na.');
        },
        onComplete: function(){
            $(div).set('html', this.response.text);
        }
    }).send();
}

function editCommentClient(productId){
	layer = 'offer_area_'+productId;
	layerComment = 'offer_comment_'+productId;
	$(layer).setStyle('display', 'block');
	$(layerComment).setStyle('display', 'none');

	$('a_save_'+productId).setStyle('display', 'inline');
	$('a_cancel_'+productId).setStyle('display', 'inline');
	$('a_edit_'+productId).setStyle('display', 'none');
}

function cancelEditCommentClient(productId){
	layer = 'offer_area_'+productId;
	layerComment = 'offer_comment_'+productId;
	divError = 'error_comment_'+productId;
	$(layer).setStyle('display', 'none');
	$(layerComment).setStyle('display', 'block');
	$(divError).empty();

	$('a_save_'+productId).setStyle('display', 'none');
	$('a_cancel_'+productId).setStyle('display', 'none');
	$('a_edit_'+productId).setStyle('display', 'inline');
}

function saveCommentClient(productId){
	textarea = 'offer_area_'+productId;
	url = '/offer/addcomment';
	post = 'productid='+productId+'&comment='+$(textarea).get('value');

	new Request.JSON({
        url: url,
        data: post,
        onRequest: function(){
            $('error_comment_'+productId).set('html', '<img src="/images/wait.gif" alt="loading..." />');
        },
		onSuccess: function(jsonObj) {
		    $('error_comment_'+productId).empty();
    		div = 'offer_comment_'+productId;
    		divError = 'error_comment_'+productId;

    		if(jsonObj.result==1){
    			$('a_save_'+productId).setStyle('display', 'none');
    			$('a_cancel_'+productId).setStyle('display', 'none');
    			$('a_edit_'+productId).setStyle('display', 'inline');

    			$(textarea).setStyle('display', 'none');
    			$(div).setStyle('display', 'block');
    			$(div).set('html', jsonObj.value);
    			$(divError).empty();
    		}else{
    			$(divError).set('html', jsonObj.value);
    		}
		}
	}).send();
}
function openRegualtion()
{
window.open("/contest/regulation","Regulamin konkursu promocyjne.pl", "width=800, height=600, menubar=no, toolbar=no, location=no,     scrollbars=yes, resizable=no, status=no, location=no, left=0, top=0");
}