function playFlash(vidId) {
	var allowed = checkIfVideoWatchAllowed();
	if (allowed == true) {
		window.open('showflash.php?m=' + vidId,'','width=700,height=500')
	}
}

function checkIfVideoWatchAllowed() {

	var currentVideosWatched = getCookie('vidlimit');
	
	if (currentVideosWatched == "") {
		setCookie('vidlimit', 1, vidMaxLimitDays);
		return true;
	} else {
		currentVideosWatched = parseInt(currentVideosWatched);
		if(currentVideosWatched < vidMaxClicksInDays) {
			setCookie('vidlimit', (currentVideosWatched+1), vidMaxLimitDays);
			return true;
		}
	}
	
	window.location = vidMaxRedirectTo;
	return false;
}

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.toGMTString());
}

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 setup() {
	// This is the number of headers you have.
	var numheaders = 3
	
	if (numheaders > 1) {
		var oldcookie = getCookie("numheader")
		if (oldcookie == "") {
			rnd = Math.floor(Math.random()*numheaders) + 1
		} else {
			do {
				rnd = Math.floor(Math.random()*numheaders) + 1
			} while (rnd == oldcookie)
		}
		setCookie("numheader", rnd, 3)
	} else {
		var rnd = 1
	}
	
	document.getElementById('siteHeader').className = 'bg' + rnd;
}
