// JavaScript Document

//setCookie
function setCookie(c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
	}
	
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 "";
}

function eraseCookie(name) {
	setCookie(name,"",-1);
}


//funkcja ankiety
function ankieta () {
	uri = document.location
	uri2 = uri.toString()
	uri3 = uri2.split('/')
	
	aOk = ['home', 'opartego-na-rekuperatorze-Aeris-350-VV', 'podstawy-rekuperacji', 'referencje']
	
	for (i=0; i<aOk.length; i++) {
		if (aOk[i] == uri3[uri3.length-1]) {
			$("a[href = http://www.rekuperatory.pl/ankieta]").trigger('click')
			$.fancybox(
				{
					'autoDimensions'	: false,
					'width'         	: 460,
					'height'        	: 220,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'overlayOpacity'	: 0.7,
					'overlayColor'		: '#000',
					'type'				: 'iframe',
					'content'			: 'http://www.rekuperatory.pl/ankieta'
				}
			)
		}
	}
}

//ciastko dla postIt


//funcja postIt
function postIt() {
	$('#mainContent')
		.append('<a href="http://www.rekuperatory.pl/szybki-kontakt" id="postIt"><span id="zamPost"></span></a>')
	$('#ofertaFormBtn').each(function(){
	$('#postIt')
		.css('top', $('#ofertaFormBtn').position().top-15)
		.show()
})
}



function wesolych() {
	$.fancybox({
		'width'				: 400,
		'height'			: 600,
		'padding'			: 5,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleShow'			: false,
		'showNavArrows'		: false,
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000',
		'type'				: 'image',
		'href'				: 'http://www.rekuperatory.pl/images/wesolych.jpg',
		'onClosed'			:  function(){
									var futdate2 = new Date()		//Get the current time and date
									var expdate2 = futdate2.getTime()  //Get the milliseconds since Jan 1, 1970
									expdate2 += 3600*24000  //expires in 24 hour(milliseconds)
									futdate2.setTime(expdate2)
									document.cookie = 'wesolych=pOff; expires="'+futdate2.toGMTString()+'"; path=/;'
									return false
								}
	})
}

function checkCookie()
{
	postC = getCookie('post');
	if (postC!=null && postC!="") {  
		return false
	 } else {
		postIt()
	 }
	 
	postW = getCookie('wesolych');
	if (postW!=null && postW!="") {  
		return false
	 } else {
		//wesolych()
	 }

}



/*function checkCookie()
{
ankietaT=getCookie('ankieta');
if (ankietaT!=null && ankietaT!="")
  {
  	return false
  }
else
  {
	//ankieta()
	//setCookie('ankieta',1,1);
  }	
}*/




$(function() {
	$('#zamPost').live ('click', function() {
		$('#postIt').remove()
		var futdate = new Date()		//Get the current time and date
		var expdate = futdate.getTime()  //Get the milliseconds since Jan 1, 1970
		expdate += 3600*1000  //expires in 1 hour(milliseconds)
		futdate.setTime(expdate)
		document.cookie = 'post=pOff; expires="'+futdate.toGMTString()+'"; path=/;'
		return false
	})
	

	
	$("#postIt").live('click', function(){
		$.fancybox({
			'width'				: 500,
			'height'			: 245,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'iframe',
			'href'				: 'http://www.rekuperatory.pl/szybki-kontakt'
		})
		return false
	})
	
	$('#skypeIco').click (function() {
		document.location = 'skype:rekuperatory.pl?chat'
		return false
	})
	
	$(".slidetabs").tabs(".images > div", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",
		
		// start from the beginning after the last tab
		rotate: true
	
	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({autoplay:true, interval:6000});
	
	
	
	$(".swf").fancybox({
			'width'				: 920,
			'height'			: 616,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'swf'
	})

	

	//$.fancybox.showActivity()
	$("a[href = http://www.rekuperatory.pl/zapytanie_ofertowe]").fancybox({
			'width'				: 500,
			'height'			: 470,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'iframe'
			//'href'				: 'zapytanie_ofertowe'
			

	})
	
	$("a[href = http://www.rekuperatory.pl/pytania]").fancybox({
			'width'				: 500,
			'height'			: 480,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'iframe'
			//'href'				: 'pytania'

	})
        
        $("a.architectForm").fancybox({
			'width'				: 500,
			'height'			: 295,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'iframe'
			//'href'			: 'pytania'

	})
	
	$("a[href = http://www.rekuperatory.pl/szybki-kontakt]").fancybox({
			'width'				: 500,
			'height'			: 295,
			'padding'			: 5,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titleShow'			: false,
			'showNavArrows'		: false,
			'overlayOpacity'	: 0.7,
			'overlayColor'		: '#000',
			'type'				: 'iframe'
			//'href'			: 'pytania'

	})

	$(".mainTxtWhite p").each(function(){
            $(this).replaceWith($('<h3><p>' + this.innerHTML + '</p></h3>'));
        });
	$(".mainTxtWhite li").each(function(){
            $(this).replaceWith($('<li><h3><p>' + this.innerHTML + '</p></h3></li>'));
        });
	$(".mainTxtWhite td").each(function(){
            $(this).replaceWith($('<td><h3><p>' + this.innerHTML + '</p></h3></td>'));
        });
	
        $("#othertextarea").css("display","none");
        if($("input[name=radioinne]").is(":checked"))
            $("#othertextarea").css("display","block");
        else{
            $("#othertextarea").css("display","none");
        }
        
        $("input[name=radioinne]").live('click', function(){
            if($("input[name=radioinne]").is(":checked"))
                $("#othertextarea").css("display","block");
            else
                $("#othertextarea").css("display","none");     
        })

        if($("input[name=otrzymano_oferte]:checked").val() == "tak")
            {
                $("#poll_options").css("display","block");
                $("#poll_sendagain").css("display","none");
            }
        else if($("input[name=otrzymano_oferte]:checked").val() == "nie"){
                $("#poll_options").css("display","none");
                $("#poll_sendagain").css("display","block");            
        }
        else
            {
                $("#poll_options").css("display","none");
                $("#poll_sendagain").css("display","none");                   
            }
        $("input[name=otrzymano_oferte]").live('click',function(){
            if(($(this).val() == "tak"))
                {
                    $("#poll_options").css("display","block");
                    $("#poll_sendagain").css("display","none");
                }
            else
                {
                    $("#poll_options").css("display","none");
                    $("#poll_sendagain").css("display","block");                      
                }
        })
        var $unique = $('input[name=odpowiedz]');
            $unique.click(function() {
            $unique.filter(':checked').not(this).removeAttr('checked');
        });

        
	checkCookie()
	//ankieta()
})

