
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
  		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  		x=x.replace(/^\s+|\s+$/g,"");
  		if (x==c_name)
    	{
    		return unescape(y);
    	}
  	}
}

function setCookie(c_name,value,exdays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}


function CloseAd()
{
	el = document.getElementById('ad');
	el.style.display = 'none'; // Hide the ad.
}

function ShowAd()
{
 	el = document.getElementById('ad');
 	el.style.display = 'block'; // Show the ad.
 	
 	el_inner = document.getElementById('ad-inner');
	el_inner.innerHTML = 
		'<a href="' + GetAdURL() + '"><img src="' + GetAdImage() + '" align="center" /></a>' +
		'Tato reklama se automaticky zavře za 15 sekund. ' + 
		'<a href="javascript:CloseAd();">Zavřít</a><br/>';

 	setTimeout('CloseAd();', 15000); // 15 seconds to hide.

	// Google Analytics
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-24203657-2']);
	_gaq.push(['_trackPageview']);
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript';
		ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' +
		'<https://ssl/> ' : 'http://www <http://www/> ') +
		'.google-analytics.com/ga.js';

		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(ga, s);
	})();

}

var expdays = 1;  // cookie is disabled

function CheckAd()
{
	if (imageIsSet==null || !imageIsSet)
		return;
	var ad=getCookie("chfwebad");
	
  	if (ad==null || ad=="")
  	{
	  	ShowAd();	
    	setCookie("chfwebad","chfwebad",expdays);    	
  	} 	
}


/**
 * Returns the week number for this date.  dowOffset is the day of week the week
 * "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday),
 * the week returned is the ISO 8601 week number.
 * @param int dowOffset
 * @return int
 */
Date.prototype.getWeek = function () {	
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */
	var dowOffset = 0;

	dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
	var newYear = new Date(this.getFullYear(),0,1);
	var day = newYear.getDay() - dowOffset; //the day of week the year begins on
	day = (day >= 0 ? day : day + 7);
	var daynum = Math.floor((this.getTime() - newYear.getTime() - 
	(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
	var weeknum;
	//if the year starts before the middle of a week
	if(day < 4) {
		weeknum = Math.floor((daynum+day-1)/7) + 1;
		if(weeknum > 52) {
			nYear = new Date(this.getFullYear() + 1,0,1);
			nday = nYear.getDay() - dowOffset;
			nday = nday >= 0 ? nday : nday + 7;
			/*if the next year starts before the middle of
 			  the week, it is week #1 of that year*/
			weeknum = nday < 4 ? 1 : 53;
		}
	}
	else {
		weeknum = Math.floor((daynum+day-1)/7);
	}
	return weeknum;
};

