function doInterstitialLogic() {
	var html = "";
	//check for the interstitial cookie
	var cookie = readCookie("interstitial-0311");
	if (cookie == null) {
		var ip_info = getIPInfo();
		if (ip_info == null) return null;
		if (ip_info.has_ad == true) {
			html += getAdCode(ip_info.country_code);
			$("#interstitial").html(html);
			//uncomment (move the comment to the right ) to enable overlay  $("#interstitial").fadeIn('slow');// 
		}
		//30240 = set for 3 weeks in hours (move the comment to the right ) to enable cookie  createCookie("interstitial-0311","ad_was_shown",30240); // 
	}
}

function doCloseAd() {
	$('#interstitial').fadeOut('slow');
}

function createCookie(name,value,minutes) {
	if (minutes) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*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 getIPInfo() {
	var result = null;
	$.ajax({
		type:"GET",
		url:"/interstitial/service.php",
		data:{request: "ipinfo"},
		dataType:"json",
		async: false,
		success:function(data) {
			if (data.ip != undefined) {
				result = data;
			}
		}
	});
	return result;
}

function getAdCode(ccode) {
	var result = " ";
	$.ajax({
		type:"GET",
		url:"/interstitial/service.php",
		data:{request: "get_ad", country: ccode},
		dataType:"html",
		async: false,
		success:function(data) {
			result = data;
		}
	});
	return result;
}

