(function()
{
	if(document.cookie.match(/survey_hide=(\d+)/) != null){ return; }

	var with_GA = false;
//	var with_GA = false;					// Without Google Analytics link
	var show_overlay = 0;
//	var show_overlay = 1;					// Use this to turn on the overlay
 	var search = [];
//	var search = ['string', 'string2'];		// This way a multiple searches can be setuped.
	var check_url = window.location.toString();
	var survey_start = false;

	for(var n = 0, len = search.length; n < len; n++)
	{
		if(check_url.indexOf(search[n]) > -1)
		{
			survey_start = true;
			break;
		}
	}

	if(search.length && !survey_start){ return; }

	function setCookie(name, value, days)
	{
		var date = new Date(); date.setDate(date.getDate()+days);
		document.cookie = name + "=" + value + ';path=/;expires=' + date.toGMTString();
	}

	if(with_GA)
	{
		var matches = document.cookie.match(/__utmz=([^;]+);?/);

		if(matches){ document.getElementById('survey_link').href += '?'+matches[1].replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)\.([^\|]+)\|([^\|]+)\|(.*)/, 'utmc=$3&utmv=$4&$5&$6&$7'); }
	}

	window.later_survey = function(url)
	{
		if(with_GA)
		{
			if(matches){ url += '&'+matches[1].replace(/(\d+)\.(\d+)\.(\d+)\.(\d+)\.([^\|]+)\|([^\|]+)\|(.*)/, 'utmc=$3&utmv=$4&$5&$6&$7'); }
		}

		var new_window_title = '<h1>Rozpocznij ankietę później</h1>';
				var new_window_text = '<p>Spójrz na niebieski pasek narzędzi, a zobaczysz że drugi klawisz wyszukiwarki został utworzony. Można go utworzyć na dwa sposoby.</p>Gdy zakończysz wizytę na stronie marki Sadolin, naciśnij na okienko <b>ankiety</b>, by ją rozpocząć.</p><p><a href="javascript:survey_hide();" onclick="survey_hide()">Naciśnij tu, by powrócić na naszą stronę</a></p>';


				var new_win = window.open(url, 'survey', 'width=950,height=700,resizable=yes,scrollbars=yes');
				new_win.blur();
				var browser = navigator.userAgent.match(/(firefox|msie|opera|safari|chrome)/i)[0].toLowerCase();
				document.getElementById('survey_text').innerHTML = ''+new_window_title+''+new_window_text+'<p><img src="/storage/survey/'+browser+'.png" id="taskbar_'+browser+'"/></p>';
		return false;
	}

	var page_counter = document.cookie.match(/page_counter=(\d+)/);

	page_counter = page_counter != null ? parseInt(page_counter[1]) : 0;

	if(page_counter < 0){ setCookie('page_counter', page_counter+1, 1); }
	else
	{
		document.getElementById('survey').style.visibility = 'visible';
		if(show_overlay){ document.getElementById('survey_overlay').style.display = 'block'; }
	}

	window.survey_hide = function()
	{
		document.getElementById('survey').style.visibility = 'hidden';
		if(show_overlay){ document.getElementById('survey_overlay').style.display = 'none'; }
		setCookie('survey_hide', 1, 100);
	}
})();

