
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showPopin(urlValue, widthValue, heightValue, capValue, fullscreen){
	if (fullscreen){
		$(window).resize(function() {
			$('#TB_window').css({ top: 0, marginTop: 0, marginLeft:0, left:0, width: $(window).width(), height: $(window).height() });
			$('#TB_iframeContent').css({ width: '100%', height: '100%' });
		});
		widthValue = $(window).width();
		heightValue = $(window).height();
	}
	
	var x = readCookie('capping')
	if (x) { x = parseInt(x) + 1 } else { x = 1 }
	createCookie('capping',x,30);

	if (x <= capValue){
		$(document).ready(function(){
			tb_show("","" + urlValue + "?KeepThis=true&TB_iframe=true&height=" + heightValue + "&width=" + widthValue + "");
		});
	}
}
